]>
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" |
be34f849 | 67 | #include "continuations.h" |
c906108c | 68 | |
1042e4c0 SS |
69 | /* readline include files */ |
70 | #include "readline/readline.h" | |
71 | #include "readline/history.h" | |
72 | ||
73 | /* readline defines this. */ | |
74 | #undef savestring | |
75 | ||
034dad6f | 76 | #include "mi/mi-common.h" |
7371cf6d | 77 | #include "python/python.h" |
104c1213 | 78 | |
44feb3ce TT |
79 | /* Arguments to pass as context to some catch command handlers. */ |
80 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
81 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 82 | |
4a64f543 | 83 | /* Prototypes for local functions. */ |
c906108c | 84 | |
a14ed312 | 85 | static void enable_delete_command (char *, int); |
c906108c | 86 | |
a14ed312 | 87 | static void enable_once_command (char *, int); |
c906108c | 88 | |
a14ed312 | 89 | static void disable_command (char *, int); |
c906108c | 90 | |
a14ed312 | 91 | static void enable_command (char *, int); |
c906108c | 92 | |
95a42b64 TT |
93 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
94 | void *), | |
95 | void *); | |
c906108c | 96 | |
a14ed312 | 97 | static void ignore_command (char *, int); |
c906108c | 98 | |
4efb68b1 | 99 | static int breakpoint_re_set_one (void *); |
c906108c | 100 | |
a14ed312 | 101 | static void clear_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static void catch_command (char *, int); |
c906108c | 104 | |
a9634178 | 105 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 106 | |
98deb0da | 107 | static void break_command_1 (char *, int, int); |
c906108c | 108 | |
a14ed312 | 109 | static void mention (struct breakpoint *); |
c906108c | 110 | |
4a64f543 MS |
111 | /* This function is used in gdbtk sources and thus can not be made |
112 | static. */ | |
63c252f8 | 113 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
a6d9a66e UW |
114 | struct symtab_and_line, |
115 | enum bptype); | |
c906108c | 116 | |
76897487 KB |
117 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
118 | ||
a6d9a66e UW |
119 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
120 | CORE_ADDR bpaddr, | |
88f7da05 | 121 | enum bptype bptype); |
76897487 | 122 | |
6c95b8df PA |
123 | static void describe_other_breakpoints (struct gdbarch *, |
124 | struct program_space *, CORE_ADDR, | |
5af949e3 | 125 | struct obj_section *, int); |
c906108c | 126 | |
6c95b8df PA |
127 | static int breakpoint_address_match (struct address_space *aspace1, |
128 | CORE_ADDR addr1, | |
129 | struct address_space *aspace2, | |
130 | CORE_ADDR addr2); | |
131 | ||
85d721b8 PA |
132 | static int watchpoint_locations_match (struct bp_location *loc1, |
133 | struct bp_location *loc2); | |
134 | ||
f1310107 TJB |
135 | static int breakpoint_location_address_match (struct bp_location *bl, |
136 | struct address_space *aspace, | |
137 | CORE_ADDR addr); | |
138 | ||
a14ed312 | 139 | static void breakpoints_info (char *, int); |
c906108c | 140 | |
d77f58be SS |
141 | static void watchpoints_info (char *, int); |
142 | ||
e5a67952 MS |
143 | static int breakpoint_1 (char *, int, |
144 | int (*) (const struct breakpoint *)); | |
c906108c | 145 | |
4efb68b1 | 146 | static int breakpoint_cond_eval (void *); |
c906108c | 147 | |
4efb68b1 | 148 | static void cleanup_executing_breakpoints (void *); |
c906108c | 149 | |
a14ed312 | 150 | static void commands_command (char *, int); |
c906108c | 151 | |
a14ed312 | 152 | static void condition_command (char *, int); |
c906108c | 153 | |
c5aa993b JM |
154 | typedef enum |
155 | { | |
156 | mark_inserted, | |
157 | mark_uninserted | |
158 | } | |
159 | insertion_state_t; | |
c906108c | 160 | |
0bde7532 | 161 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 162 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 163 | |
a14ed312 | 164 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
165 | |
166 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 167 | |
4efb68b1 | 168 | static int watchpoint_check (void *); |
c906108c | 169 | |
a14ed312 | 170 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 171 | |
a14ed312 | 172 | static int hw_breakpoint_used_count (void); |
c906108c | 173 | |
a14ed312 | 174 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 175 | |
a14ed312 | 176 | static void hbreak_command (char *, int); |
c906108c | 177 | |
a14ed312 | 178 | static void thbreak_command (char *, int); |
c906108c | 179 | |
51be5b68 | 180 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp); |
c906108c | 181 | |
a14ed312 | 182 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 183 | |
a14ed312 | 184 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 185 | |
a14ed312 | 186 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 187 | |
a14ed312 | 188 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 189 | |
d85310f7 MS |
190 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
191 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 192 | |
a14ed312 | 193 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 194 | |
d03285ec UW |
195 | static void detach_single_step_breakpoints (void); |
196 | ||
6c95b8df PA |
197 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
198 | CORE_ADDR pc); | |
1aafd4da | 199 | |
fe3f5fa8 | 200 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
201 | static void incref_bp_location (struct bp_location *loc); |
202 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 203 | |
39d61571 | 204 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 205 | |
b60e7edf | 206 | static void update_global_location_list (int); |
a5606eee | 207 | |
b60e7edf | 208 | static void update_global_location_list_nothrow (int); |
74960c60 | 209 | |
d77f58be | 210 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 | 211 | |
d77f58be | 212 | static int is_watchpoint (const struct breakpoint *bpt); |
60e1c644 | 213 | |
74960c60 | 214 | static void insert_breakpoint_locations (void); |
a5606eee | 215 | |
a96d9b2e SDJ |
216 | static int syscall_catchpoint_p (struct breakpoint *b); |
217 | ||
1042e4c0 SS |
218 | static void tracepoints_info (char *, int); |
219 | ||
220 | static void delete_trace_command (char *, int); | |
221 | ||
222 | static void enable_trace_command (char *, int); | |
223 | ||
224 | static void disable_trace_command (char *, int); | |
225 | ||
226 | static void trace_pass_command (char *, int); | |
227 | ||
9c06b0b4 TJB |
228 | static int is_masked_watchpoint (const struct breakpoint *b); |
229 | ||
0fb4aa4b PA |
230 | /* Assuming we're creating a static tracepoint, does S look like a |
231 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
232 | #define is_marker_spec(s) \ | |
f5a8e22b | 233 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 234 | |
5cea2a26 PA |
235 | /* A reference-counted struct command_line. This lets multiple |
236 | breakpoints share a single command list. */ | |
237 | struct counted_command_line | |
238 | { | |
239 | /* The reference count. */ | |
240 | int refc; | |
241 | ||
242 | /* The command list. */ | |
243 | struct command_line *commands; | |
244 | }; | |
245 | ||
246 | struct command_line * | |
247 | breakpoint_commands (struct breakpoint *b) | |
248 | { | |
249 | return b->commands ? b->commands->commands : NULL; | |
250 | } | |
3daf8fe5 | 251 | |
f3b1572e PA |
252 | /* Flag indicating that a command has proceeded the inferior past the |
253 | current breakpoint. */ | |
254 | ||
255 | static int breakpoint_proceeded; | |
256 | ||
956a9fb9 | 257 | const char * |
2cec12e5 AR |
258 | bpdisp_text (enum bpdisp disp) |
259 | { | |
4a64f543 MS |
260 | /* NOTE: the following values are a part of MI protocol and |
261 | represent values of 'disp' field returned when inferior stops at | |
262 | a breakpoint. */ | |
bc043ef3 | 263 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 264 | |
2cec12e5 AR |
265 | return bpdisps[(int) disp]; |
266 | } | |
c906108c | 267 | |
4a64f543 | 268 | /* Prototypes for exported functions. */ |
c906108c | 269 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 270 | if such is available. */ |
c906108c SS |
271 | static int can_use_hw_watchpoints; |
272 | ||
920d2a44 AC |
273 | static void |
274 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
275 | struct cmd_list_element *c, | |
276 | const char *value) | |
277 | { | |
3e43a32a MS |
278 | fprintf_filtered (file, |
279 | _("Debugger's willingness to use " | |
280 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
281 | value); |
282 | } | |
283 | ||
fa8d40ab JJ |
284 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
285 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 286 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
287 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
288 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
289 | static void |
290 | show_pending_break_support (struct ui_file *file, int from_tty, | |
291 | struct cmd_list_element *c, | |
292 | const char *value) | |
293 | { | |
3e43a32a MS |
294 | fprintf_filtered (file, |
295 | _("Debugger's behavior regarding " | |
296 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
297 | value); |
298 | } | |
fa8d40ab | 299 | |
765dc015 | 300 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 301 | set with "break" but falling in read-only memory. |
765dc015 VP |
302 | If 0, gdb will warn about such breakpoints, but won't automatically |
303 | use hardware breakpoints. */ | |
304 | static int automatic_hardware_breakpoints; | |
305 | static void | |
306 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
307 | struct cmd_list_element *c, | |
308 | const char *value) | |
309 | { | |
3e43a32a MS |
310 | fprintf_filtered (file, |
311 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
312 | value); |
313 | } | |
314 | ||
33e5cbd6 PA |
315 | /* If on, gdb will keep breakpoints inserted even as inferior is |
316 | stopped, and immediately insert any new breakpoints. If off, gdb | |
317 | will insert breakpoints into inferior only when resuming it, and | |
318 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
319 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
320 | ||
321 | static const char always_inserted_auto[] = "auto"; | |
322 | static const char always_inserted_on[] = "on"; | |
323 | static const char always_inserted_off[] = "off"; | |
324 | static const char *always_inserted_enums[] = { | |
325 | always_inserted_auto, | |
326 | always_inserted_off, | |
327 | always_inserted_on, | |
328 | NULL | |
329 | }; | |
330 | static const char *always_inserted_mode = always_inserted_auto; | |
331 | static void | |
74960c60 | 332 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 333 | struct cmd_list_element *c, const char *value) |
74960c60 | 334 | { |
33e5cbd6 | 335 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
336 | fprintf_filtered (file, |
337 | _("Always inserted breakpoint " | |
338 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
339 | value, |
340 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
341 | else | |
3e43a32a MS |
342 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
343 | value); | |
74960c60 VP |
344 | } |
345 | ||
33e5cbd6 PA |
346 | int |
347 | breakpoints_always_inserted_mode (void) | |
348 | { | |
349 | return (always_inserted_mode == always_inserted_on | |
350 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
351 | } | |
765dc015 | 352 | |
a14ed312 | 353 | void _initialize_breakpoint (void); |
c906108c | 354 | |
c906108c SS |
355 | /* Are we executing breakpoint commands? */ |
356 | static int executing_breakpoint_commands; | |
357 | ||
c02f5703 MS |
358 | /* Are overlay event breakpoints enabled? */ |
359 | static int overlay_events_enabled; | |
360 | ||
e09342b5 TJB |
361 | /* See description in breakpoint.h. */ |
362 | int target_exact_watchpoints = 0; | |
363 | ||
c906108c | 364 | /* Walk the following statement or block through all breakpoints. |
4a64f543 MS |
365 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the |
366 | current breakpoint. */ | |
c906108c | 367 | |
5c44784c | 368 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 369 | |
5c44784c JM |
370 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
371 | for (B = breakpoint_chain; \ | |
372 | B ? (TMP=B->next, 1): 0; \ | |
373 | B = TMP) | |
c906108c | 374 | |
4a64f543 MS |
375 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
376 | not provided so update_global_location_list must not be called | |
377 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 378 | |
876fa593 JK |
379 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
380 | for (BP_TMP = bp_location; \ | |
381 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
382 | BP_TMP++) | |
7cc221ef | 383 | |
1042e4c0 SS |
384 | /* Iterator for tracepoints only. */ |
385 | ||
386 | #define ALL_TRACEPOINTS(B) \ | |
387 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 388 | if (is_tracepoint (B)) |
1042e4c0 | 389 | |
7cc221ef | 390 | /* Chains of all breakpoints defined. */ |
c906108c SS |
391 | |
392 | struct breakpoint *breakpoint_chain; | |
393 | ||
876fa593 JK |
394 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
395 | ||
396 | static struct bp_location **bp_location; | |
397 | ||
398 | /* Number of elements of BP_LOCATION. */ | |
399 | ||
400 | static unsigned bp_location_count; | |
401 | ||
4a64f543 MS |
402 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
403 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
404 | result from bp_location_has_shadow. You can use it for roughly | |
405 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
406 | an address you need to read. */ | |
876fa593 JK |
407 | |
408 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
409 | ||
4a64f543 MS |
410 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
411 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
412 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
413 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
414 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
415 | |
416 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 417 | |
4a64f543 MS |
418 | /* The locations that no longer correspond to any breakpoint, unlinked |
419 | from bp_location array, but for which a hit may still be reported | |
420 | by a target. */ | |
20874c92 VP |
421 | VEC(bp_location_p) *moribund_locations = NULL; |
422 | ||
c906108c SS |
423 | /* Number of last breakpoint made. */ |
424 | ||
95a42b64 TT |
425 | static int breakpoint_count; |
426 | ||
86b17b60 PA |
427 | /* The value of `breakpoint_count' before the last command that |
428 | created breakpoints. If the last (break-like) command created more | |
429 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
430 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
431 | static int prev_breakpoint_count; | |
c906108c | 432 | |
1042e4c0 SS |
433 | /* Number of last tracepoint made. */ |
434 | ||
95a42b64 | 435 | static int tracepoint_count; |
1042e4c0 | 436 | |
6149aea9 PA |
437 | static struct cmd_list_element *breakpoint_set_cmdlist; |
438 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 439 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 440 | |
468d015d JJ |
441 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
442 | static int | |
443 | breakpoint_enabled (struct breakpoint *b) | |
444 | { | |
0d381245 | 445 | return (b->enable_state == bp_enabled); |
468d015d JJ |
446 | } |
447 | ||
c906108c SS |
448 | /* Set breakpoint count to NUM. */ |
449 | ||
95a42b64 | 450 | static void |
fba45db2 | 451 | set_breakpoint_count (int num) |
c906108c | 452 | { |
86b17b60 | 453 | prev_breakpoint_count = breakpoint_count; |
c906108c | 454 | breakpoint_count = num; |
4fa62494 | 455 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
456 | } |
457 | ||
86b17b60 PA |
458 | /* Used by `start_rbreak_breakpoints' below, to record the current |
459 | breakpoint count before "rbreak" creates any breakpoint. */ | |
460 | static int rbreak_start_breakpoint_count; | |
461 | ||
95a42b64 TT |
462 | /* Called at the start an "rbreak" command to record the first |
463 | breakpoint made. */ | |
86b17b60 | 464 | |
95a42b64 TT |
465 | void |
466 | start_rbreak_breakpoints (void) | |
467 | { | |
86b17b60 | 468 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
469 | } |
470 | ||
471 | /* Called at the end of an "rbreak" command to record the last | |
472 | breakpoint made. */ | |
86b17b60 | 473 | |
95a42b64 TT |
474 | void |
475 | end_rbreak_breakpoints (void) | |
476 | { | |
86b17b60 | 477 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
478 | } |
479 | ||
4a64f543 | 480 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
481 | |
482 | void | |
fba45db2 | 483 | clear_breakpoint_hit_counts (void) |
c906108c SS |
484 | { |
485 | struct breakpoint *b; | |
486 | ||
487 | ALL_BREAKPOINTS (b) | |
488 | b->hit_count = 0; | |
489 | } | |
490 | ||
9add0f1b TT |
491 | /* Allocate a new counted_command_line with reference count of 1. |
492 | The new structure owns COMMANDS. */ | |
493 | ||
494 | static struct counted_command_line * | |
495 | alloc_counted_command_line (struct command_line *commands) | |
496 | { | |
497 | struct counted_command_line *result | |
498 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 499 | |
9add0f1b TT |
500 | result->refc = 1; |
501 | result->commands = commands; | |
502 | return result; | |
503 | } | |
504 | ||
505 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
506 | ||
507 | static void | |
508 | incref_counted_command_line (struct counted_command_line *cmd) | |
509 | { | |
510 | if (cmd) | |
511 | ++cmd->refc; | |
512 | } | |
513 | ||
514 | /* Decrement reference count. If the reference count reaches 0, | |
515 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
516 | nothing if *CMDP is NULL. */ | |
517 | ||
518 | static void | |
519 | decref_counted_command_line (struct counted_command_line **cmdp) | |
520 | { | |
521 | if (*cmdp) | |
522 | { | |
523 | if (--(*cmdp)->refc == 0) | |
524 | { | |
525 | free_command_lines (&(*cmdp)->commands); | |
526 | xfree (*cmdp); | |
527 | } | |
528 | *cmdp = NULL; | |
529 | } | |
530 | } | |
531 | ||
532 | /* A cleanup function that calls decref_counted_command_line. */ | |
533 | ||
534 | static void | |
535 | do_cleanup_counted_command_line (void *arg) | |
536 | { | |
537 | decref_counted_command_line (arg); | |
538 | } | |
539 | ||
540 | /* Create a cleanup that calls decref_counted_command_line on the | |
541 | argument. */ | |
542 | ||
543 | static struct cleanup * | |
544 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
545 | { | |
546 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
547 | } | |
548 | ||
c906108c SS |
549 | /* Default address, symtab and line to put a breakpoint at |
550 | for "break" command with no arg. | |
4a64f543 | 551 | If default_breakpoint_valid is zero, the other three are |
c906108c SS |
552 | not valid, and "break" with no arg is an error. |
553 | ||
554 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
555 | ||
556 | int default_breakpoint_valid; | |
557 | CORE_ADDR default_breakpoint_address; | |
558 | struct symtab *default_breakpoint_symtab; | |
559 | int default_breakpoint_line; | |
6c95b8df PA |
560 | struct program_space *default_breakpoint_pspace; |
561 | ||
c906108c | 562 | \f |
48cb2d85 VP |
563 | /* Return the breakpoint with the specified number, or NULL |
564 | if the number does not refer to an existing breakpoint. */ | |
565 | ||
566 | struct breakpoint * | |
567 | get_breakpoint (int num) | |
568 | { | |
569 | struct breakpoint *b; | |
570 | ||
571 | ALL_BREAKPOINTS (b) | |
572 | if (b->number == num) | |
573 | return b; | |
574 | ||
575 | return NULL; | |
576 | } | |
5c44784c | 577 | |
c906108c | 578 | \f |
adc36818 PM |
579 | |
580 | void | |
581 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
582 | int from_tty) | |
583 | { | |
584 | struct bp_location *loc = b->loc; | |
585 | ||
586 | for (; loc; loc = loc->next) | |
587 | { | |
588 | xfree (loc->cond); | |
589 | loc->cond = NULL; | |
590 | } | |
591 | xfree (b->cond_string); | |
592 | b->cond_string = NULL; | |
593 | xfree (b->cond_exp); | |
594 | b->cond_exp = NULL; | |
595 | ||
596 | if (*exp == 0) | |
597 | { | |
598 | if (from_tty) | |
599 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
600 | } | |
601 | else | |
602 | { | |
603 | char *arg = exp; | |
cc59ec59 | 604 | |
adc36818 PM |
605 | /* I don't know if it matters whether this is the string the user |
606 | typed in or the decompiled expression. */ | |
607 | b->cond_string = xstrdup (arg); | |
608 | b->condition_not_parsed = 0; | |
609 | ||
610 | if (is_watchpoint (b)) | |
611 | { | |
612 | innermost_block = NULL; | |
613 | arg = exp; | |
614 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
615 | if (*arg) | |
616 | error (_("Junk at end of expression")); | |
617 | b->cond_exp_valid_block = innermost_block; | |
618 | } | |
619 | else | |
620 | { | |
621 | for (loc = b->loc; loc; loc = loc->next) | |
622 | { | |
623 | arg = exp; | |
624 | loc->cond = | |
625 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
626 | if (*arg) | |
627 | error (_("Junk at end of expression")); | |
628 | } | |
629 | } | |
630 | } | |
631 | breakpoints_changed (); | |
8d3788bd | 632 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
633 | } |
634 | ||
c906108c SS |
635 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
636 | ||
637 | static void | |
fba45db2 | 638 | condition_command (char *arg, int from_tty) |
c906108c | 639 | { |
52f0bd74 | 640 | struct breakpoint *b; |
c906108c | 641 | char *p; |
52f0bd74 | 642 | int bnum; |
c906108c SS |
643 | |
644 | if (arg == 0) | |
e2e0b3e5 | 645 | error_no_arg (_("breakpoint number")); |
c906108c SS |
646 | |
647 | p = arg; | |
648 | bnum = get_number (&p); | |
5c44784c | 649 | if (bnum == 0) |
8a3fe4f8 | 650 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
651 | |
652 | ALL_BREAKPOINTS (b) | |
653 | if (b->number == bnum) | |
2f069f6f | 654 | { |
7371cf6d PM |
655 | /* Check if this breakpoint has a Python object assigned to |
656 | it, and if it has a definition of the "stop" | |
657 | method. This method and conditions entered into GDB from | |
658 | the CLI are mutually exclusive. */ | |
659 | if (b->py_bp_object | |
660 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
661 | error (_("Cannot set a condition where a Python 'stop' " | |
662 | "method has been defined in the breakpoint.")); | |
2566ad2d | 663 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
664 | return; |
665 | } | |
c906108c | 666 | |
8a3fe4f8 | 667 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
668 | } |
669 | ||
a7bdde9e VP |
670 | /* Check that COMMAND do not contain commands that are suitable |
671 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
672 | Throw if any such commands is found. */ |
673 | ||
a7bdde9e VP |
674 | static void |
675 | check_no_tracepoint_commands (struct command_line *commands) | |
676 | { | |
677 | struct command_line *c; | |
cc59ec59 | 678 | |
a7bdde9e VP |
679 | for (c = commands; c; c = c->next) |
680 | { | |
681 | int i; | |
682 | ||
683 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
684 | error (_("The 'while-stepping' command can " |
685 | "only be used for tracepoints")); | |
a7bdde9e VP |
686 | |
687 | for (i = 0; i < c->body_count; ++i) | |
688 | check_no_tracepoint_commands ((c->body_list)[i]); | |
689 | ||
690 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 691 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
692 | command directly. */ |
693 | if (strstr (c->line, "collect ") == c->line) | |
694 | error (_("The 'collect' command can only be used for tracepoints")); | |
695 | ||
51661e93 VP |
696 | if (strstr (c->line, "teval ") == c->line) |
697 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
698 | } |
699 | } | |
700 | ||
d77f58be SS |
701 | /* Encapsulate tests for different types of tracepoints. */ |
702 | ||
a7bdde9e | 703 | int |
d77f58be | 704 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 705 | { |
0fb4aa4b PA |
706 | return (b->type == bp_tracepoint |
707 | || b->type == bp_fast_tracepoint | |
708 | || b->type == bp_static_tracepoint); | |
a7bdde9e | 709 | } |
d77f58be | 710 | |
95a42b64 TT |
711 | /* A helper function that validsates that COMMANDS are valid for a |
712 | breakpoint. This function will throw an exception if a problem is | |
713 | found. */ | |
48cb2d85 | 714 | |
95a42b64 TT |
715 | static void |
716 | validate_commands_for_breakpoint (struct breakpoint *b, | |
717 | struct command_line *commands) | |
48cb2d85 | 718 | { |
d77f58be | 719 | if (is_tracepoint (b)) |
a7bdde9e | 720 | { |
4a64f543 MS |
721 | /* We need to verify that each top-level element of commands is |
722 | valid for tracepoints, that there's at most one | |
723 | while-stepping element, and that while-stepping's body has | |
724 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
725 | struct command_line *c; |
726 | struct command_line *while_stepping = 0; | |
727 | for (c = commands; c; c = c->next) | |
728 | { | |
a7bdde9e VP |
729 | if (c->control_type == while_stepping_control) |
730 | { | |
731 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
732 | error (_("The 'while-stepping' command " |
733 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 734 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
735 | error (_("The 'while-stepping' command " |
736 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
737 | |
738 | if (while_stepping) | |
3e43a32a MS |
739 | error (_("The 'while-stepping' command " |
740 | "can be used only once")); | |
a7bdde9e VP |
741 | else |
742 | while_stepping = c; | |
743 | } | |
744 | } | |
745 | if (while_stepping) | |
746 | { | |
747 | struct command_line *c2; | |
748 | ||
749 | gdb_assert (while_stepping->body_count == 1); | |
750 | c2 = while_stepping->body_list[0]; | |
751 | for (; c2; c2 = c2->next) | |
752 | { | |
a7bdde9e VP |
753 | if (c2->control_type == while_stepping_control) |
754 | error (_("The 'while-stepping' command cannot be nested")); | |
755 | } | |
756 | } | |
757 | } | |
758 | else | |
759 | { | |
760 | check_no_tracepoint_commands (commands); | |
761 | } | |
95a42b64 TT |
762 | } |
763 | ||
0fb4aa4b PA |
764 | /* Return a vector of all the static tracepoints set at ADDR. The |
765 | caller is responsible for releasing the vector. */ | |
766 | ||
767 | VEC(breakpoint_p) * | |
768 | static_tracepoints_here (CORE_ADDR addr) | |
769 | { | |
770 | struct breakpoint *b; | |
771 | VEC(breakpoint_p) *found = 0; | |
772 | struct bp_location *loc; | |
773 | ||
774 | ALL_BREAKPOINTS (b) | |
775 | if (b->type == bp_static_tracepoint) | |
776 | { | |
777 | for (loc = b->loc; loc; loc = loc->next) | |
778 | if (loc->address == addr) | |
779 | VEC_safe_push(breakpoint_p, found, b); | |
780 | } | |
781 | ||
782 | return found; | |
783 | } | |
784 | ||
95a42b64 | 785 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 786 | validate that only allowed commands are included. */ |
95a42b64 TT |
787 | |
788 | void | |
4a64f543 MS |
789 | breakpoint_set_commands (struct breakpoint *b, |
790 | struct command_line *commands) | |
95a42b64 TT |
791 | { |
792 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 793 | |
9add0f1b TT |
794 | decref_counted_command_line (&b->commands); |
795 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 796 | breakpoints_changed (); |
8d3788bd | 797 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
798 | } |
799 | ||
45a43567 TT |
800 | /* Set the internal `silent' flag on the breakpoint. Note that this |
801 | is not the same as the "silent" that may appear in the breakpoint's | |
802 | commands. */ | |
803 | ||
804 | void | |
805 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
806 | { | |
807 | int old_silent = b->silent; | |
808 | ||
809 | b->silent = silent; | |
810 | if (old_silent != silent) | |
8d3788bd | 811 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
812 | } |
813 | ||
814 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
815 | breakpoint work for any thread. */ | |
816 | ||
817 | void | |
818 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
819 | { | |
820 | int old_thread = b->thread; | |
821 | ||
822 | b->thread = thread; | |
823 | if (old_thread != thread) | |
8d3788bd | 824 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
825 | } |
826 | ||
827 | /* Set the task for this breakpoint. If TASK is 0, make the | |
828 | breakpoint work for any task. */ | |
829 | ||
830 | void | |
831 | breakpoint_set_task (struct breakpoint *b, int task) | |
832 | { | |
833 | int old_task = b->task; | |
834 | ||
835 | b->task = task; | |
836 | if (old_task != task) | |
8d3788bd | 837 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
838 | } |
839 | ||
95a42b64 TT |
840 | void |
841 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
842 | { |
843 | struct breakpoint *b = closure; | |
cc59ec59 | 844 | |
a7bdde9e VP |
845 | validate_actionline (&line, b); |
846 | } | |
847 | ||
95a42b64 TT |
848 | /* A structure used to pass information through |
849 | map_breakpoint_numbers. */ | |
850 | ||
851 | struct commands_info | |
852 | { | |
853 | /* True if the command was typed at a tty. */ | |
854 | int from_tty; | |
86b17b60 PA |
855 | |
856 | /* The breakpoint range spec. */ | |
857 | char *arg; | |
858 | ||
95a42b64 TT |
859 | /* Non-NULL if the body of the commands are being read from this |
860 | already-parsed command. */ | |
861 | struct command_line *control; | |
86b17b60 | 862 | |
95a42b64 TT |
863 | /* The command lines read from the user, or NULL if they have not |
864 | yet been read. */ | |
865 | struct counted_command_line *cmd; | |
866 | }; | |
867 | ||
868 | /* A callback for map_breakpoint_numbers that sets the commands for | |
869 | commands_command. */ | |
870 | ||
c906108c | 871 | static void |
95a42b64 | 872 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 873 | { |
95a42b64 | 874 | struct commands_info *info = data; |
c906108c | 875 | |
95a42b64 TT |
876 | if (info->cmd == NULL) |
877 | { | |
878 | struct command_line *l; | |
5c44784c | 879 | |
95a42b64 TT |
880 | if (info->control != NULL) |
881 | l = copy_command_lines (info->control->body_list[0]); | |
882 | else | |
86b17b60 PA |
883 | { |
884 | struct cleanup *old_chain; | |
885 | char *str; | |
c5aa993b | 886 | |
3e43a32a MS |
887 | str = xstrprintf (_("Type commands for breakpoint(s) " |
888 | "%s, one per line."), | |
86b17b60 PA |
889 | info->arg); |
890 | ||
891 | old_chain = make_cleanup (xfree, str); | |
892 | ||
893 | l = read_command_lines (str, | |
894 | info->from_tty, 1, | |
d77f58be | 895 | (is_tracepoint (b) |
86b17b60 PA |
896 | ? check_tracepoint_command : 0), |
897 | b); | |
898 | ||
899 | do_cleanups (old_chain); | |
900 | } | |
a7bdde9e | 901 | |
95a42b64 TT |
902 | info->cmd = alloc_counted_command_line (l); |
903 | } | |
904 | ||
905 | /* If a breakpoint was on the list more than once, we don't need to | |
906 | do anything. */ | |
907 | if (b->commands != info->cmd) | |
908 | { | |
909 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
910 | incref_counted_command_line (info->cmd); | |
911 | decref_counted_command_line (&b->commands); | |
912 | b->commands = info->cmd; | |
913 | breakpoints_changed (); | |
8d3788bd | 914 | observer_notify_breakpoint_modified (b); |
c5aa993b | 915 | } |
95a42b64 TT |
916 | } |
917 | ||
918 | static void | |
4a64f543 MS |
919 | commands_command_1 (char *arg, int from_tty, |
920 | struct command_line *control) | |
95a42b64 TT |
921 | { |
922 | struct cleanup *cleanups; | |
923 | struct commands_info info; | |
924 | ||
925 | info.from_tty = from_tty; | |
926 | info.control = control; | |
927 | info.cmd = NULL; | |
928 | /* If we read command lines from the user, then `info' will hold an | |
929 | extra reference to the commands that we must clean up. */ | |
930 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
931 | ||
932 | if (arg == NULL || !*arg) | |
933 | { | |
86b17b60 | 934 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
935 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
936 | breakpoint_count); | |
95a42b64 TT |
937 | else if (breakpoint_count > 0) |
938 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
939 | else |
940 | { | |
941 | /* So that we don't try to free the incoming non-NULL | |
942 | argument in the cleanup below. Mapping breakpoint | |
943 | numbers will fail in this case. */ | |
944 | arg = NULL; | |
945 | } | |
95a42b64 | 946 | } |
9766ced4 SS |
947 | else |
948 | /* The command loop has some static state, so we need to preserve | |
949 | our argument. */ | |
950 | arg = xstrdup (arg); | |
86b17b60 PA |
951 | |
952 | if (arg != NULL) | |
953 | make_cleanup (xfree, arg); | |
954 | ||
955 | info.arg = arg; | |
95a42b64 TT |
956 | |
957 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
958 | ||
959 | if (info.cmd == NULL) | |
960 | error (_("No breakpoints specified.")); | |
961 | ||
962 | do_cleanups (cleanups); | |
963 | } | |
964 | ||
965 | static void | |
966 | commands_command (char *arg, int from_tty) | |
967 | { | |
968 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 969 | } |
40c03ae8 EZ |
970 | |
971 | /* Like commands_command, but instead of reading the commands from | |
972 | input stream, takes them from an already parsed command structure. | |
973 | ||
974 | This is used by cli-script.c to DTRT with breakpoint commands | |
975 | that are part of if and while bodies. */ | |
976 | enum command_control_type | |
977 | commands_from_control_command (char *arg, struct command_line *cmd) | |
978 | { | |
95a42b64 TT |
979 | commands_command_1 (arg, 0, cmd); |
980 | return simple_control; | |
40c03ae8 | 981 | } |
876fa593 JK |
982 | |
983 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
984 | ||
985 | static int | |
986 | bp_location_has_shadow (struct bp_location *bl) | |
987 | { | |
988 | if (bl->loc_type != bp_loc_software_breakpoint) | |
989 | return 0; | |
990 | if (!bl->inserted) | |
991 | return 0; | |
992 | if (bl->target_info.shadow_len == 0) | |
993 | /* bp isn't valid, or doesn't shadow memory. */ | |
994 | return 0; | |
995 | return 1; | |
996 | } | |
997 | ||
8defab1a | 998 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
999 | by replacing any memory breakpoints with their shadowed contents. |
1000 | ||
1001 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1002 | bl->address - bp_location_placed_address_before_address_max |
1003 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1004 | The range we were requested to resolve shadows for is: |
1005 | memaddr ... memaddr + len | |
1006 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1007 | memaddr + len <= (bl->address |
1008 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1009 | and: |
35df4500 | 1010 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1011 | |
8defab1a DJ |
1012 | void |
1013 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1014 | { |
4a64f543 MS |
1015 | /* Left boundary, right boundary and median element of our binary |
1016 | search. */ | |
876fa593 JK |
1017 | unsigned bc_l, bc_r, bc; |
1018 | ||
4a64f543 MS |
1019 | /* Find BC_L which is a leftmost element which may affect BUF |
1020 | content. It is safe to report lower value but a failure to | |
1021 | report higher one. */ | |
876fa593 JK |
1022 | |
1023 | bc_l = 0; | |
1024 | bc_r = bp_location_count; | |
1025 | while (bc_l + 1 < bc_r) | |
1026 | { | |
35df4500 | 1027 | struct bp_location *bl; |
876fa593 JK |
1028 | |
1029 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1030 | bl = bp_location[bc]; |
876fa593 | 1031 | |
4a64f543 MS |
1032 | /* Check first BL->ADDRESS will not overflow due to the added |
1033 | constant. Then advance the left boundary only if we are sure | |
1034 | the BC element can in no way affect the BUF content (MEMADDR | |
1035 | to MEMADDR + LEN range). | |
876fa593 | 1036 | |
4a64f543 MS |
1037 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1038 | offset so that we cannot miss a breakpoint with its shadow | |
1039 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1040 | |
35df4500 TJB |
1041 | if ((bl->address + bp_location_shadow_len_after_address_max |
1042 | >= bl->address) | |
1043 | && (bl->address + bp_location_shadow_len_after_address_max | |
1044 | <= memaddr)) | |
876fa593 JK |
1045 | bc_l = bc; |
1046 | else | |
1047 | bc_r = bc; | |
1048 | } | |
1049 | ||
128070bb PA |
1050 | /* Due to the binary search above, we need to make sure we pick the |
1051 | first location that's at BC_L's address. E.g., if there are | |
1052 | multiple locations at the same address, BC_L may end up pointing | |
1053 | at a duplicate location, and miss the "master"/"inserted" | |
1054 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1055 | B: | |
1056 | ||
1057 | L1@A, L2@A, L3@B, ... | |
1058 | ||
1059 | BC_L could end up pointing at location L2, while the "master" | |
1060 | location could be L1. Since the `loc->inserted' flag is only set | |
1061 | on "master" locations, we'd forget to restore the shadow of L1 | |
1062 | and L2. */ | |
1063 | while (bc_l > 0 | |
1064 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1065 | bc_l--; | |
1066 | ||
876fa593 JK |
1067 | /* Now do full processing of the found relevant range of elements. */ |
1068 | ||
1069 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1070 | { |
35df4500 | 1071 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1072 | CORE_ADDR bp_addr = 0; |
1073 | int bp_size = 0; | |
1074 | int bptoffset = 0; | |
1075 | ||
35df4500 TJB |
1076 | /* bp_location array has BL->OWNER always non-NULL. */ |
1077 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1078 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1079 | bl->owner->number); |
ffce0d52 | 1080 | |
876fa593 JK |
1081 | /* Performance optimization: any futher element can no longer affect BUF |
1082 | content. */ | |
1083 | ||
35df4500 TJB |
1084 | if (bl->address >= bp_location_placed_address_before_address_max |
1085 | && memaddr + len <= (bl->address | |
1086 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1087 | break; |
1088 | ||
35df4500 | 1089 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1090 | continue; |
35df4500 | 1091 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1092 | current_program_space->aspace, 0)) |
1093 | continue; | |
1094 | ||
c5aa993b JM |
1095 | /* Addresses and length of the part of the breakpoint that |
1096 | we need to copy. */ | |
35df4500 TJB |
1097 | bp_addr = bl->target_info.placed_address; |
1098 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1099 | |
c5aa993b JM |
1100 | if (bp_addr + bp_size <= memaddr) |
1101 | /* The breakpoint is entirely before the chunk of memory we | |
1102 | are reading. */ | |
1103 | continue; | |
8defab1a | 1104 | |
c5aa993b JM |
1105 | if (bp_addr >= memaddr + len) |
1106 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1107 | reading. */ |
c5aa993b | 1108 | continue; |
c5aa993b | 1109 | |
8defab1a DJ |
1110 | /* Offset within shadow_contents. */ |
1111 | if (bp_addr < memaddr) | |
1112 | { | |
1113 | /* Only copy the second part of the breakpoint. */ | |
1114 | bp_size -= memaddr - bp_addr; | |
1115 | bptoffset = memaddr - bp_addr; | |
1116 | bp_addr = memaddr; | |
1117 | } | |
c5aa993b | 1118 | |
8defab1a DJ |
1119 | if (bp_addr + bp_size > memaddr + len) |
1120 | { | |
1121 | /* Only copy the first part of the breakpoint. */ | |
1122 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1123 | } | |
c5aa993b | 1124 | |
8defab1a | 1125 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1126 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1127 | } |
c906108c | 1128 | } |
c906108c | 1129 | \f |
c5aa993b | 1130 | |
60e1c644 PA |
1131 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1132 | ||
a5606eee | 1133 | static int |
d77f58be | 1134 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1135 | { |
1136 | return (bpt->type == bp_hardware_watchpoint | |
1137 | || bpt->type == bp_read_watchpoint | |
1138 | || bpt->type == bp_access_watchpoint); | |
1139 | } | |
7270d8f2 | 1140 | |
60e1c644 PA |
1141 | /* Return true if BPT is of any watchpoint kind, hardware or |
1142 | software. */ | |
1143 | ||
1144 | static int | |
d77f58be | 1145 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1146 | { |
1147 | return (is_hardware_watchpoint (bpt) | |
1148 | || bpt->type == bp_watchpoint); | |
1149 | } | |
1150 | ||
f6bc2008 PA |
1151 | /* Assuming that B is a watchpoint: returns true if the current thread |
1152 | and its running state are safe to evaluate or update watchpoint B. | |
1153 | Watchpoints on local expressions need to be evaluated in the | |
1154 | context of the thread that was current when the watchpoint was | |
1155 | created, and, that thread needs to be stopped to be able to select | |
1156 | the correct frame context. Watchpoints on global expressions can | |
1157 | be evaluated on any thread, and in any state. It is presently left | |
1158 | to the target allowing memory accesses when threads are | |
1159 | running. */ | |
1160 | ||
1161 | static int | |
1162 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1163 | { | |
1164 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1165 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1166 | && !is_executing (inferior_ptid))); | |
1167 | } | |
1168 | ||
d0fb5eae JK |
1169 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1170 | associated bp_watchpoint_scope breakpoint. */ | |
1171 | ||
1172 | static void | |
1173 | watchpoint_del_at_next_stop (struct breakpoint *b) | |
1174 | { | |
1175 | gdb_assert (is_watchpoint (b)); | |
1176 | ||
1177 | if (b->related_breakpoint != b) | |
1178 | { | |
1179 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1180 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1181 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1182 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1183 | b->related_breakpoint = b; | |
1184 | } | |
1185 | b->disposition = disp_del_at_next_stop; | |
1186 | } | |
1187 | ||
567e1b4e JB |
1188 | /* Assuming that B is a watchpoint: |
1189 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1190 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1191 | - Evaluate the condition if there is one, and store the result |
1192 | in b->loc->cond. | |
a5606eee VP |
1193 | - Update the list of values that must be watched in B->loc. |
1194 | ||
4a64f543 MS |
1195 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1196 | nothing. If this is local watchpoint that is out of scope, delete | |
1197 | it. | |
1198 | ||
1199 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1200 | removed + inserted on each stop here. Normal breakpoints must | |
1201 | never be removed because they might be missed by a running thread | |
1202 | when debugging in non-stop mode. On the other hand, hardware | |
1203 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1204 | to each LWP since they are stored in each LWP's hardware debug | |
1205 | registers. Therefore, such LWP must be stopped first in order to | |
1206 | be able to modify its hardware watchpoints. | |
1207 | ||
1208 | Hardware watchpoints must be reset exactly once after being | |
1209 | presented to the user. It cannot be done sooner, because it would | |
1210 | reset the data used to present the watchpoint hit to the user. And | |
1211 | it must not be done later because it could display the same single | |
1212 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1213 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1214 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1215 | not user-visible - its hit is suppressed if the memory content has | |
1216 | not changed. | |
1217 | ||
1218 | The following constraints influence the location where we can reset | |
1219 | hardware watchpoints: | |
1220 | ||
1221 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1222 | called several times when GDB stops. | |
1223 | ||
1224 | [linux] | |
1225 | * Multiple hardware watchpoints can be hit at the same time, | |
1226 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1227 | hit at a time as the reason for stopping, and all the other hits | |
1228 | are presented later, one after the other, each time the user | |
1229 | requests the execution to be resumed. Execution is not resumed | |
1230 | for the threads still having pending hit event stored in | |
1231 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1232 | the inferior on the first stop the thread hit event is kept being | |
1233 | reported from its cached value by linux_nat_stopped_data_address | |
1234 | until the real thread resume happens after the watchpoint gets | |
1235 | presented and thus its LWP_INFO->STATUS gets reset. | |
1236 | ||
1237 | Therefore the hardware watchpoint hit can get safely reset on the | |
1238 | watchpoint removal from inferior. */ | |
a79d3c27 | 1239 | |
b40ce68a | 1240 | static void |
a5606eee | 1241 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1242 | { |
a5606eee | 1243 | int within_current_scope; |
a5606eee | 1244 | struct frame_id saved_frame_id; |
66076460 | 1245 | int frame_saved; |
a5606eee | 1246 | |
d0fb5eae JK |
1247 | gdb_assert (is_watchpoint (b)); |
1248 | ||
f6bc2008 PA |
1249 | /* If this is a local watchpoint, we only want to check if the |
1250 | watchpoint frame is in scope if the current thread is the thread | |
1251 | that was used to create the watchpoint. */ | |
1252 | if (!watchpoint_in_thread_scope (b)) | |
1253 | return; | |
1254 | ||
a5606eee VP |
1255 | if (b->disposition == disp_del_at_next_stop) |
1256 | return; | |
1257 | ||
66076460 | 1258 | frame_saved = 0; |
a5606eee VP |
1259 | |
1260 | /* Determine if the watchpoint is within scope. */ | |
1261 | if (b->exp_valid_block == NULL) | |
1262 | within_current_scope = 1; | |
1263 | else | |
1264 | { | |
b5db5dfc UW |
1265 | struct frame_info *fi = get_current_frame (); |
1266 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1267 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1268 | ||
1269 | /* If we're in a function epilogue, unwinding may not work | |
1270 | properly, so do not attempt to recreate locations at this | |
1271 | point. See similar comments in watchpoint_check. */ | |
1272 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1273 | return; | |
66076460 DJ |
1274 | |
1275 | /* Save the current frame's ID so we can restore it after | |
1276 | evaluating the watchpoint expression on its own frame. */ | |
1277 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1278 | took a frame parameter, so that we didn't have to change the | |
1279 | selected frame. */ | |
1280 | frame_saved = 1; | |
1281 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1282 | ||
a5606eee VP |
1283 | fi = frame_find_by_id (b->watchpoint_frame); |
1284 | within_current_scope = (fi != NULL); | |
1285 | if (within_current_scope) | |
1286 | select_frame (fi); | |
1287 | } | |
1288 | ||
b5db5dfc UW |
1289 | /* We don't free locations. They are stored in the bp_location array |
1290 | and update_global_location_list will eventually delete them and | |
1291 | remove breakpoints if needed. */ | |
1292 | b->loc = NULL; | |
1293 | ||
a5606eee VP |
1294 | if (within_current_scope && reparse) |
1295 | { | |
1296 | char *s; | |
d63d0675 | 1297 | |
a5606eee VP |
1298 | if (b->exp) |
1299 | { | |
1300 | xfree (b->exp); | |
1301 | b->exp = NULL; | |
1302 | } | |
d63d0675 | 1303 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1304 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1305 | /* If the meaning of expression itself changed, the old value is | |
1306 | no longer relevant. We don't want to report a watchpoint hit | |
1307 | to the user when the old value and the new value may actually | |
1308 | be completely different objects. */ | |
1309 | value_free (b->val); | |
fa4727a6 DJ |
1310 | b->val = NULL; |
1311 | b->val_valid = 0; | |
60e1c644 PA |
1312 | |
1313 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1314 | expression is stored in the breakpoint object, not in the | |
1315 | locations (re)created below. */ | |
1316 | if (b->cond_string != NULL) | |
1317 | { | |
1318 | if (b->cond_exp != NULL) | |
1319 | { | |
1320 | xfree (b->cond_exp); | |
1321 | b->cond_exp = NULL; | |
1322 | } | |
1323 | ||
1324 | s = b->cond_string; | |
1325 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1326 | } | |
a5606eee | 1327 | } |
a5606eee VP |
1328 | |
1329 | /* If we failed to parse the expression, for example because | |
1330 | it refers to a global variable in a not-yet-loaded shared library, | |
1331 | don't try to insert watchpoint. We don't automatically delete | |
1332 | such watchpoint, though, since failure to parse expression | |
1333 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1334 | if ( !target_has_execution) |
1335 | { | |
1336 | /* Without execution, memory can't change. No use to try and | |
1337 | set watchpoint locations. The watchpoint will be reset when | |
1338 | the target gains execution, through breakpoint_re_set. */ | |
1339 | } | |
1340 | else if (within_current_scope && b->exp) | |
a5606eee | 1341 | { |
0cf6dd15 | 1342 | int pc = 0; |
fa4727a6 | 1343 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1344 | struct program_space *frame_pspace; |
a5606eee | 1345 | |
0cf6dd15 | 1346 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1347 | |
a5606eee VP |
1348 | /* Avoid setting b->val if it's already set. The meaning of |
1349 | b->val is 'the last value' user saw, and we should update | |
1350 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1351 | happens, the code that reports it updates b->val directly. |
1352 | We don't keep track of the memory value for masked | |
1353 | watchpoints. */ | |
1354 | if (!b->val_valid && !is_masked_watchpoint (b)) | |
fa4727a6 DJ |
1355 | { |
1356 | b->val = v; | |
1357 | b->val_valid = 1; | |
1358 | } | |
a5606eee | 1359 | |
2d134ed3 PA |
1360 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1361 | ||
a5606eee | 1362 | /* Look at each value on the value chain. */ |
9fa40276 | 1363 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1364 | { |
1365 | /* If it's a memory location, and GDB actually needed | |
1366 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1367 | must watch it. If the first value returned is |
1368 | still lazy, that means an error occurred reading it; | |
1369 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1370 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1371 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1372 | { |
1373 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1374 | |
a5606eee VP |
1375 | /* We only watch structs and arrays if user asked |
1376 | for it explicitly, never if they just happen to | |
1377 | appear in the middle of some value chain. */ | |
fa4727a6 | 1378 | if (v == result |
a5606eee VP |
1379 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1380 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1381 | { | |
1382 | CORE_ADDR addr; | |
1383 | int len, type; | |
1384 | struct bp_location *loc, **tmp; | |
1385 | ||
42ae5230 | 1386 | addr = value_address (v); |
a5606eee VP |
1387 | len = TYPE_LENGTH (value_type (v)); |
1388 | type = hw_write; | |
1389 | if (b->type == bp_read_watchpoint) | |
1390 | type = hw_read; | |
1391 | else if (b->type == bp_access_watchpoint) | |
1392 | type = hw_access; | |
1393 | ||
39d61571 | 1394 | loc = allocate_bp_location (b); |
a5606eee VP |
1395 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1396 | ; | |
1397 | *tmp = loc; | |
a6d9a66e | 1398 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1399 | |
1400 | loc->pspace = frame_pspace; | |
a5606eee VP |
1401 | loc->address = addr; |
1402 | loc->length = len; | |
1403 | loc->watchpoint_type = type; | |
1404 | } | |
1405 | } | |
9fa40276 TJB |
1406 | } |
1407 | ||
1408 | /* Change the type of breakpoint between hardware assisted or | |
1409 | an ordinary watchpoint depending on the hardware support | |
1410 | and free hardware slots. REPARSE is set when the inferior | |
1411 | is started. */ | |
a9634178 | 1412 | if (reparse) |
9fa40276 | 1413 | { |
e09342b5 | 1414 | int reg_cnt; |
9fa40276 TJB |
1415 | enum bp_loc_type loc_type; |
1416 | struct bp_location *bl; | |
a5606eee | 1417 | |
a9634178 | 1418 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1419 | |
1420 | if (reg_cnt) | |
9fa40276 TJB |
1421 | { |
1422 | int i, target_resources_ok, other_type_used; | |
1423 | ||
a9634178 TJB |
1424 | /* Use an exact watchpoint when there's only one memory region to be |
1425 | watched, and only one debug register is needed to watch it. */ | |
1426 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1427 | ||
9fa40276 | 1428 | /* We need to determine how many resources are already |
e09342b5 TJB |
1429 | used for all other hardware watchpoints plus this one |
1430 | to see if we still have enough resources to also fit | |
1431 | this watchpoint in as well. To guarantee the | |
1432 | hw_watchpoint_used_count call below counts this | |
1433 | watchpoint, make sure that it is marked as a hardware | |
1434 | watchpoint. */ | |
a9634178 TJB |
1435 | if (b->type == bp_watchpoint) |
1436 | b->type = bp_hardware_watchpoint; | |
9fa40276 | 1437 | |
a9634178 | 1438 | i = hw_watchpoint_used_count (b->type, &other_type_used); |
e09342b5 | 1439 | target_resources_ok = target_can_use_hardware_watchpoint |
a9634178 | 1440 | (b->type, i, other_type_used); |
e09342b5 | 1441 | if (target_resources_ok <= 0) |
a9634178 | 1442 | { |
9c06b0b4 TJB |
1443 | /* If there's no works_in_software_mode method, we |
1444 | assume that the watchpoint works in software mode. */ | |
1445 | int sw_mode = (!b->ops || !b->ops->works_in_software_mode | |
1446 | || b->ops->works_in_software_mode (b)); | |
1447 | ||
1448 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1449 | error (_("Target does not support this type of " |
1450 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1451 | else if (target_resources_ok < 0 && !sw_mode) |
1452 | error (_("There are not enough available hardware " | |
1453 | "resources for this watchpoint.")); | |
a9634178 TJB |
1454 | else |
1455 | b->type = bp_watchpoint; | |
1456 | } | |
9fa40276 | 1457 | } |
9c06b0b4 TJB |
1458 | else if (b->ops && b->ops->works_in_software_mode |
1459 | && !b->ops->works_in_software_mode (b)) | |
a9634178 TJB |
1460 | error (_("Expression cannot be implemented with " |
1461 | "read/access watchpoint.")); | |
9fa40276 TJB |
1462 | else |
1463 | b->type = bp_watchpoint; | |
1464 | ||
1465 | loc_type = (b->type == bp_watchpoint? bp_loc_other | |
1466 | : bp_loc_hardware_watchpoint); | |
1467 | for (bl = b->loc; bl; bl = bl->next) | |
1468 | bl->loc_type = loc_type; | |
1469 | } | |
1470 | ||
1471 | for (v = val_chain; v; v = next) | |
1472 | { | |
a5606eee VP |
1473 | next = value_next (v); |
1474 | if (v != b->val) | |
1475 | value_free (v); | |
1476 | } | |
1477 | ||
c7437ca6 PA |
1478 | /* If a software watchpoint is not watching any memory, then the |
1479 | above left it without any location set up. But, | |
1480 | bpstat_stop_status requires a location to be able to report | |
1481 | stops, so make sure there's at least a dummy one. */ | |
1482 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1483 | { | |
1484 | b->loc = allocate_bp_location (b); | |
1485 | b->loc->pspace = frame_pspace; | |
1486 | b->loc->address = -1; | |
1487 | b->loc->length = -1; | |
1488 | b->loc->watchpoint_type = -1; | |
1489 | } | |
a5606eee VP |
1490 | } |
1491 | else if (!within_current_scope) | |
7270d8f2 | 1492 | { |
ac74f770 MS |
1493 | printf_filtered (_("\ |
1494 | Watchpoint %d deleted because the program has left the block\n\ | |
1495 | in which its expression is valid.\n"), | |
a5606eee | 1496 | b->number); |
d0fb5eae | 1497 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1498 | } |
a5606eee VP |
1499 | |
1500 | /* Restore the selected frame. */ | |
66076460 DJ |
1501 | if (frame_saved) |
1502 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1503 | } |
1504 | ||
a5606eee | 1505 | |
74960c60 VP |
1506 | /* Returns 1 iff breakpoint location should be |
1507 | inserted in the inferior. */ | |
1508 | static int | |
35df4500 | 1509 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1510 | { |
35df4500 | 1511 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1512 | return 0; |
1513 | ||
35df4500 | 1514 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1515 | return 0; |
1516 | ||
35df4500 | 1517 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1518 | return 0; |
1519 | ||
56710373 PA |
1520 | /* This is set for example, when we're attached to the parent of a |
1521 | vfork, and have detached from the child. The child is running | |
1522 | free, and we expect it to do an exec or exit, at which point the | |
1523 | OS makes the parent schedulable again (and the target reports | |
1524 | that the vfork is done). Until the child is done with the shared | |
1525 | memory region, do not insert breakpoints in the parent, otherwise | |
1526 | the child could still trip on the parent's breakpoints. Since | |
1527 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1528 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1529 | return 0; |
1530 | ||
1042e4c0 SS |
1531 | /* Tracepoints are inserted by the target at a time of its choosing, |
1532 | not by us. */ | |
35df4500 | 1533 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1534 | return 0; |
1535 | ||
74960c60 VP |
1536 | return 1; |
1537 | } | |
1538 | ||
35df4500 TJB |
1539 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1540 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
1541 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. | |
879bfdc2 | 1542 | |
4a64f543 MS |
1543 | NOTE drow/2003-09-09: This routine could be broken down to an |
1544 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1545 | static int |
35df4500 | 1546 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1547 | struct ui_file *tmp_error_stream, |
fa3a767f | 1548 | int *disabled_breaks, |
26bb91f3 | 1549 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1550 | { |
1551 | int val = 0; | |
1552 | ||
35df4500 | 1553 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1554 | return 0; |
1555 | ||
8181d85f | 1556 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1557 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1558 | bl->target_info.placed_address = bl->address; | |
1559 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 1560 | bl->target_info.length = bl->length; |
8181d85f | 1561 | |
35df4500 TJB |
1562 | if (bl->loc_type == bp_loc_software_breakpoint |
1563 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1564 | { |
35df4500 | 1565 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1566 | { |
1567 | /* If the explicitly specified breakpoint type | |
1568 | is not hardware breakpoint, check the memory map to see | |
1569 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1570 | |
765dc015 VP |
1571 | Two important cases are: |
1572 | - location type is not hardware breakpoint, memory | |
1573 | is readonly. We change the type of the location to | |
1574 | hardware breakpoint. | |
4a64f543 MS |
1575 | - location type is hardware breakpoint, memory is |
1576 | read-write. This means we've previously made the | |
1577 | location hardware one, but then the memory map changed, | |
1578 | so we undo. | |
765dc015 | 1579 | |
4a64f543 MS |
1580 | When breakpoints are removed, remove_breakpoints will use |
1581 | location types we've just set here, the only possible | |
1582 | problem is that memory map has changed during running | |
1583 | program, but it's not going to work anyway with current | |
1584 | gdb. */ | |
765dc015 | 1585 | struct mem_region *mr |
35df4500 | 1586 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1587 | |
1588 | if (mr) | |
1589 | { | |
1590 | if (automatic_hardware_breakpoints) | |
1591 | { | |
765dc015 VP |
1592 | enum bp_loc_type new_type; |
1593 | ||
1594 | if (mr->attrib.mode != MEM_RW) | |
1595 | new_type = bp_loc_hardware_breakpoint; | |
1596 | else | |
1597 | new_type = bp_loc_software_breakpoint; | |
1598 | ||
35df4500 | 1599 | if (new_type != bl->loc_type) |
765dc015 VP |
1600 | { |
1601 | static int said = 0; | |
cc59ec59 | 1602 | |
35df4500 | 1603 | bl->loc_type = new_type; |
765dc015 VP |
1604 | if (!said) |
1605 | { | |
3e43a32a MS |
1606 | fprintf_filtered (gdb_stdout, |
1607 | _("Note: automatically using " | |
1608 | "hardware breakpoints for " | |
1609 | "read-only addresses.\n")); | |
765dc015 VP |
1610 | said = 1; |
1611 | } | |
1612 | } | |
1613 | } | |
35df4500 | 1614 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1615 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1616 | warning (_("cannot set software breakpoint " |
1617 | "at readonly address %s"), | |
35df4500 | 1618 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1619 | } |
1620 | } | |
1621 | ||
879bfdc2 DJ |
1622 | /* First check to see if we have to handle an overlay. */ |
1623 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1624 | || bl->section == NULL |
1625 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1626 | { |
1627 | /* No overlay handling: just set the breakpoint. */ | |
1628 | ||
35df4500 TJB |
1629 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1630 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1631 | &bl->target_info); | |
879bfdc2 | 1632 | else |
35df4500 TJB |
1633 | val = target_insert_breakpoint (bl->gdbarch, |
1634 | &bl->target_info); | |
879bfdc2 DJ |
1635 | } |
1636 | else | |
1637 | { | |
4a64f543 | 1638 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1639 | Shall we set a breakpoint at the LMA? */ |
1640 | if (!overlay_events_enabled) | |
1641 | { | |
1642 | /* Yes -- overlay event support is not active, | |
1643 | so we must try to set a breakpoint at the LMA. | |
1644 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1645 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1646 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1647 | bl->owner->number); |
879bfdc2 DJ |
1648 | else |
1649 | { | |
35df4500 TJB |
1650 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1651 | bl->section); | |
879bfdc2 | 1652 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1653 | bl->overlay_target_info = bl->target_info; |
1654 | bl->overlay_target_info.placed_address = addr; | |
1655 | val = target_insert_breakpoint (bl->gdbarch, | |
1656 | &bl->overlay_target_info); | |
879bfdc2 | 1657 | if (val != 0) |
99361f52 | 1658 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1659 | "Overlay breakpoint %d " |
1660 | "failed: in ROM?\n", | |
35df4500 | 1661 | bl->owner->number); |
879bfdc2 DJ |
1662 | } |
1663 | } | |
1664 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1665 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1666 | { |
1667 | /* Yes. This overlay section is mapped into memory. */ | |
35df4500 TJB |
1668 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1669 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1670 | &bl->target_info); | |
879bfdc2 | 1671 | else |
35df4500 TJB |
1672 | val = target_insert_breakpoint (bl->gdbarch, |
1673 | &bl->target_info); | |
879bfdc2 DJ |
1674 | } |
1675 | else | |
1676 | { | |
1677 | /* No. This breakpoint will not be inserted. | |
1678 | No error, but do not mark the bp as 'inserted'. */ | |
1679 | return 0; | |
1680 | } | |
1681 | } | |
1682 | ||
1683 | if (val) | |
1684 | { | |
1685 | /* Can't set the breakpoint. */ | |
35df4500 | 1686 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1687 | { |
4a64f543 | 1688 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1689 | val = 0; |
35df4500 | 1690 | bl->shlib_disabled = 1; |
8d3788bd | 1691 | observer_notify_breakpoint_modified (bl->owner); |
879bfdc2 DJ |
1692 | if (!*disabled_breaks) |
1693 | { | |
1694 | fprintf_unfiltered (tmp_error_stream, | |
1695 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1696 | bl->owner->number); |
879bfdc2 | 1697 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1698 | "Temporarily disabling shared " |
1699 | "library breakpoints:\n"); | |
879bfdc2 DJ |
1700 | } |
1701 | *disabled_breaks = 1; | |
1702 | fprintf_unfiltered (tmp_error_stream, | |
35df4500 | 1703 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1704 | } |
1705 | else | |
879bfdc2 | 1706 | { |
35df4500 | 1707 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1708 | { |
1709 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1710 | fprintf_unfiltered (tmp_error_stream, |
1711 | "Cannot insert hardware " | |
1712 | "breakpoint %d.\n", | |
35df4500 | 1713 | bl->owner->number); |
879bfdc2 DJ |
1714 | } |
1715 | else | |
1716 | { | |
1717 | fprintf_unfiltered (tmp_error_stream, | |
1718 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1719 | bl->owner->number); |
879bfdc2 DJ |
1720 | fprintf_filtered (tmp_error_stream, |
1721 | "Error accessing memory address "); | |
35df4500 | 1722 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1723 | tmp_error_stream); |
879bfdc2 DJ |
1724 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1725 | safe_strerror (val)); | |
1726 | } | |
1727 | ||
1728 | } | |
1729 | } | |
1730 | else | |
35df4500 | 1731 | bl->inserted = 1; |
879bfdc2 DJ |
1732 | |
1733 | return val; | |
1734 | } | |
1735 | ||
35df4500 | 1736 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1737 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1738 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1739 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1740 | { |
77b06cd7 TJB |
1741 | gdb_assert (bl->owner->ops != NULL |
1742 | && bl->owner->ops->insert_location != NULL); | |
1743 | ||
1744 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1745 | |
1746 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1747 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1748 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1749 | { |
1750 | struct bp_location *loc, **loc_temp; | |
1751 | ||
1752 | /* But don't try to insert it, if there's already another | |
1753 | hw_access location that would be considered a duplicate | |
1754 | of this one. */ | |
1755 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1756 | if (loc != bl |
85d721b8 | 1757 | && loc->watchpoint_type == hw_access |
35df4500 | 1758 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1759 | { |
35df4500 TJB |
1760 | bl->duplicate = 1; |
1761 | bl->inserted = 1; | |
1762 | bl->target_info = loc->target_info; | |
1763 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1764 | val = 0; |
1765 | break; | |
1766 | } | |
1767 | ||
1768 | if (val == 1) | |
1769 | { | |
77b06cd7 TJB |
1770 | bl->watchpoint_type = hw_access; |
1771 | val = bl->owner->ops->insert_location (bl); | |
1772 | ||
1773 | if (val) | |
1774 | /* Back to the original value. */ | |
1775 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1776 | } |
1777 | } | |
1778 | ||
35df4500 | 1779 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1780 | } |
1781 | ||
35df4500 | 1782 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1783 | { |
77b06cd7 TJB |
1784 | gdb_assert (bl->owner->ops != NULL |
1785 | && bl->owner->ops->insert_location != NULL); | |
1786 | ||
1787 | val = bl->owner->ops->insert_location (bl); | |
1788 | if (val) | |
1789 | { | |
1790 | bl->owner->enable_state = bp_disabled; | |
1791 | ||
1792 | if (val == 1) | |
1793 | warning (_("\ | |
1794 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1795 | of catchpoint."), bl->owner->number); | |
1796 | else | |
1797 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1798 | } | |
1799 | ||
1800 | bl->inserted = (val == 0); | |
1640b821 DJ |
1801 | |
1802 | /* We've already printed an error message if there was a problem | |
1803 | inserting this catchpoint, and we've disabled the catchpoint, | |
1804 | so just return success. */ | |
1805 | return 0; | |
879bfdc2 DJ |
1806 | } |
1807 | ||
1808 | return 0; | |
1809 | } | |
1810 | ||
6c95b8df PA |
1811 | /* This function is called when program space PSPACE is about to be |
1812 | deleted. It takes care of updating breakpoints to not reference | |
1813 | PSPACE anymore. */ | |
1814 | ||
1815 | void | |
1816 | breakpoint_program_space_exit (struct program_space *pspace) | |
1817 | { | |
1818 | struct breakpoint *b, *b_temp; | |
876fa593 | 1819 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1820 | |
1821 | /* Remove any breakpoint that was set through this program space. */ | |
1822 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1823 | { | |
1824 | if (b->pspace == pspace) | |
1825 | delete_breakpoint (b); | |
1826 | } | |
1827 | ||
1828 | /* Breakpoints set through other program spaces could have locations | |
1829 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1830 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1831 | { |
1832 | struct bp_location *tmp; | |
1833 | ||
1834 | if (loc->pspace == pspace) | |
1835 | { | |
2bdf28a0 | 1836 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1837 | if (loc->owner->loc == loc) |
1838 | loc->owner->loc = loc->next; | |
1839 | else | |
1840 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1841 | if (tmp->next == loc) | |
1842 | { | |
1843 | tmp->next = loc->next; | |
1844 | break; | |
1845 | } | |
1846 | } | |
1847 | } | |
1848 | ||
1849 | /* Now update the global location list to permanently delete the | |
1850 | removed locations above. */ | |
1851 | update_global_location_list (0); | |
1852 | } | |
1853 | ||
74960c60 VP |
1854 | /* Make sure all breakpoints are inserted in inferior. |
1855 | Throws exception on any error. | |
1856 | A breakpoint that is already inserted won't be inserted | |
1857 | again, so calling this function twice is safe. */ | |
1858 | void | |
1859 | insert_breakpoints (void) | |
1860 | { | |
1861 | struct breakpoint *bpt; | |
1862 | ||
1863 | ALL_BREAKPOINTS (bpt) | |
1864 | if (is_hardware_watchpoint (bpt)) | |
4a64f543 | 1865 | update_watchpoint (bpt, 0 /* don't reparse. */); |
74960c60 | 1866 | |
b60e7edf | 1867 | update_global_location_list (1); |
74960c60 | 1868 | |
c35b1492 PA |
1869 | /* update_global_location_list does not insert breakpoints when |
1870 | always_inserted_mode is not enabled. Explicitly insert them | |
1871 | now. */ | |
1872 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1873 | insert_breakpoint_locations (); |
1874 | } | |
1875 | ||
c906108c SS |
1876 | /* insert_breakpoints is used when starting or continuing the program. |
1877 | remove_breakpoints is used when the program stops. | |
1878 | Both return zero if successful, | |
1879 | or an `errno' value if could not write the inferior. */ | |
1880 | ||
74960c60 VP |
1881 | static void |
1882 | insert_breakpoint_locations (void) | |
c906108c | 1883 | { |
a5606eee | 1884 | struct breakpoint *bpt; |
35df4500 | 1885 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1886 | int error = 0; |
c906108c SS |
1887 | int val = 0; |
1888 | int disabled_breaks = 0; | |
81d0cc19 | 1889 | int hw_breakpoint_error = 0; |
c906108c | 1890 | |
81d0cc19 | 1891 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1892 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1893 | |
81d0cc19 GS |
1894 | /* Explicitly mark the warning -- this will only be printed if |
1895 | there was an error. */ | |
1896 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1897 | |
1898 | save_current_space_and_thread (); | |
1899 | ||
35df4500 | 1900 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1901 | { |
35df4500 | 1902 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1903 | continue; |
1904 | ||
4a64f543 MS |
1905 | /* There is no point inserting thread-specific breakpoints if |
1906 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1907 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1908 | if (bl->owner->thread != -1 |
1909 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1910 | continue; |
1911 | ||
35df4500 | 1912 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1913 | |
1914 | /* For targets that support global breakpoints, there's no need | |
1915 | to select an inferior to insert breakpoint to. In fact, even | |
1916 | if we aren't attached to any process yet, we should still | |
1917 | insert breakpoints. */ | |
1918 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1919 | && ptid_equal (inferior_ptid, null_ptid)) | |
1920 | continue; | |
1921 | ||
35df4500 | 1922 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
879bfdc2 DJ |
1923 | &hw_breakpoint_error); |
1924 | if (val) | |
e236ba44 | 1925 | error = val; |
879bfdc2 | 1926 | } |
c906108c | 1927 | |
4a64f543 MS |
1928 | /* If we failed to insert all locations of a watchpoint, remove |
1929 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1930 | ALL_BREAKPOINTS (bpt) |
1931 | { | |
1932 | int some_failed = 0; | |
1933 | struct bp_location *loc; | |
1934 | ||
1935 | if (!is_hardware_watchpoint (bpt)) | |
1936 | continue; | |
1937 | ||
d6b74ac4 | 1938 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1939 | continue; |
74960c60 VP |
1940 | |
1941 | if (bpt->disposition == disp_del_at_next_stop) | |
1942 | continue; | |
a5606eee VP |
1943 | |
1944 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1945 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1946 | { |
1947 | some_failed = 1; | |
1948 | break; | |
1949 | } | |
1950 | if (some_failed) | |
1951 | { | |
1952 | for (loc = bpt->loc; loc; loc = loc->next) | |
1953 | if (loc->inserted) | |
1954 | remove_breakpoint (loc, mark_uninserted); | |
1955 | ||
1956 | hw_breakpoint_error = 1; | |
1957 | fprintf_unfiltered (tmp_error_stream, | |
1958 | "Could not insert hardware watchpoint %d.\n", | |
1959 | bpt->number); | |
1960 | error = -1; | |
1961 | } | |
1962 | } | |
1963 | ||
e236ba44 | 1964 | if (error) |
81d0cc19 GS |
1965 | { |
1966 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1967 | message about possibly exhausted resources. */ | |
879bfdc2 | 1968 | if (hw_breakpoint_error) |
81d0cc19 | 1969 | { |
c6510018 MS |
1970 | fprintf_unfiltered (tmp_error_stream, |
1971 | "Could not insert hardware breakpoints:\n\ | |
1972 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1973 | } |
81d0cc19 GS |
1974 | target_terminal_ours_for_output (); |
1975 | error_stream (tmp_error_stream); | |
1976 | } | |
f7545552 TT |
1977 | |
1978 | do_cleanups (cleanups); | |
c906108c SS |
1979 | } |
1980 | ||
c906108c | 1981 | int |
fba45db2 | 1982 | remove_breakpoints (void) |
c906108c | 1983 | { |
35df4500 | 1984 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1985 | int val = 0; |
c906108c | 1986 | |
35df4500 | 1987 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 1988 | { |
35df4500 TJB |
1989 | if (bl->inserted) |
1990 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 1991 | } |
3a1bae8e | 1992 | return val; |
c906108c SS |
1993 | } |
1994 | ||
6c95b8df PA |
1995 | /* Remove breakpoints of process PID. */ |
1996 | ||
1997 | int | |
1998 | remove_breakpoints_pid (int pid) | |
1999 | { | |
35df4500 | 2000 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2001 | int val; |
2002 | struct inferior *inf = find_inferior_pid (pid); | |
2003 | ||
35df4500 | 2004 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2005 | { |
35df4500 | 2006 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2007 | continue; |
2008 | ||
35df4500 | 2009 | if (bl->inserted) |
6c95b8df | 2010 | { |
35df4500 | 2011 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2012 | if (val != 0) |
2013 | return val; | |
2014 | } | |
2015 | } | |
2016 | return 0; | |
2017 | } | |
2018 | ||
c906108c | 2019 | int |
fba45db2 | 2020 | reattach_breakpoints (int pid) |
c906108c | 2021 | { |
6c95b8df | 2022 | struct cleanup *old_chain; |
35df4500 | 2023 | struct bp_location *bl, **blp_tmp; |
c906108c | 2024 | int val; |
86b887df | 2025 | struct ui_file *tmp_error_stream; |
fa3a767f | 2026 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2027 | struct inferior *inf; |
2028 | struct thread_info *tp; | |
2029 | ||
2030 | tp = any_live_thread_of_process (pid); | |
2031 | if (tp == NULL) | |
2032 | return 1; | |
2033 | ||
2034 | inf = find_inferior_pid (pid); | |
2035 | old_chain = save_inferior_ptid (); | |
2036 | ||
2037 | inferior_ptid = tp->ptid; | |
a4954f26 | 2038 | |
86b887df | 2039 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2040 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2041 | |
35df4500 | 2042 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2043 | { |
35df4500 | 2044 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2045 | continue; |
2046 | ||
35df4500 | 2047 | if (bl->inserted) |
c5aa993b | 2048 | { |
35df4500 TJB |
2049 | bl->inserted = 0; |
2050 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2051 | if (val != 0) |
2052 | { | |
ce696e05 | 2053 | do_cleanups (old_chain); |
c5aa993b JM |
2054 | return val; |
2055 | } | |
2056 | } | |
2057 | } | |
ce696e05 | 2058 | do_cleanups (old_chain); |
c906108c SS |
2059 | return 0; |
2060 | } | |
2061 | ||
e58b0e63 PA |
2062 | static int internal_breakpoint_number = -1; |
2063 | ||
84f4c1fe PM |
2064 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2065 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2066 | from internal_breakpoint_number and that variable decremented. | |
2067 | Otherwis the breakpoint number will be populated from | |
2068 | breakpoint_count and that value incremented. Internal breakpoints | |
2069 | do not set the internal var bpnum. */ | |
2070 | static void | |
2071 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2072 | { | |
2073 | if (internal) | |
2074 | b->number = internal_breakpoint_number--; | |
2075 | else | |
2076 | { | |
2077 | set_breakpoint_count (breakpoint_count + 1); | |
2078 | b->number = breakpoint_count; | |
2079 | } | |
2080 | } | |
2081 | ||
e62c965a | 2082 | static struct breakpoint * |
a6d9a66e UW |
2083 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2084 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2085 | { |
e62c965a PP |
2086 | struct symtab_and_line sal; |
2087 | struct breakpoint *b; | |
2088 | ||
4a64f543 | 2089 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2090 | |
2091 | sal.pc = address; | |
2092 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2093 | sal.pspace = current_program_space; |
e62c965a | 2094 | |
a6d9a66e | 2095 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2096 | b->number = internal_breakpoint_number--; |
2097 | b->disposition = disp_donttouch; | |
2098 | ||
2099 | return b; | |
2100 | } | |
2101 | ||
17450429 PP |
2102 | static const char *const longjmp_names[] = |
2103 | { | |
2104 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2105 | }; | |
2106 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2107 | ||
2108 | /* Per-objfile data private to breakpoint.c. */ | |
2109 | struct breakpoint_objfile_data | |
2110 | { | |
2111 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2112 | struct minimal_symbol *overlay_msym; | |
2113 | ||
2114 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2115 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2116 | ||
2117 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2118 | struct minimal_symbol *terminate_msym; | |
2119 | ||
2120 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2121 | struct minimal_symbol *exception_msym; | |
2122 | }; | |
2123 | ||
2124 | static const struct objfile_data *breakpoint_objfile_key; | |
2125 | ||
2126 | /* Minimal symbol not found sentinel. */ | |
2127 | static struct minimal_symbol msym_not_found; | |
2128 | ||
2129 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2130 | ||
2131 | static int | |
2132 | msym_not_found_p (const struct minimal_symbol *msym) | |
2133 | { | |
2134 | return msym == &msym_not_found; | |
2135 | } | |
2136 | ||
2137 | /* Return per-objfile data needed by breakpoint.c. | |
2138 | Allocate the data if necessary. */ | |
2139 | ||
2140 | static struct breakpoint_objfile_data * | |
2141 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2142 | { | |
2143 | struct breakpoint_objfile_data *bp_objfile_data; | |
2144 | ||
2145 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2146 | if (bp_objfile_data == NULL) | |
2147 | { | |
2148 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2149 | sizeof (*bp_objfile_data)); | |
2150 | ||
2151 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2152 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2153 | } | |
2154 | return bp_objfile_data; | |
2155 | } | |
2156 | ||
e62c965a | 2157 | static void |
af02033e | 2158 | create_overlay_event_breakpoint (void) |
e62c965a | 2159 | { |
69de3c6a | 2160 | struct objfile *objfile; |
af02033e | 2161 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2162 | |
69de3c6a PP |
2163 | ALL_OBJFILES (objfile) |
2164 | { | |
2165 | struct breakpoint *b; | |
17450429 PP |
2166 | struct breakpoint_objfile_data *bp_objfile_data; |
2167 | CORE_ADDR addr; | |
69de3c6a | 2168 | |
17450429 PP |
2169 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2170 | ||
2171 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2172 | continue; | |
2173 | ||
2174 | if (bp_objfile_data->overlay_msym == NULL) | |
2175 | { | |
2176 | struct minimal_symbol *m; | |
2177 | ||
2178 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2179 | if (m == NULL) | |
2180 | { | |
2181 | /* Avoid future lookups in this objfile. */ | |
2182 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2183 | continue; | |
2184 | } | |
2185 | bp_objfile_data->overlay_msym = m; | |
2186 | } | |
e62c965a | 2187 | |
17450429 PP |
2188 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2189 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
69de3c6a PP |
2190 | bp_overlay_event); |
2191 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2192 | |
69de3c6a PP |
2193 | if (overlay_debugging == ovly_auto) |
2194 | { | |
2195 | b->enable_state = bp_enabled; | |
2196 | overlay_events_enabled = 1; | |
2197 | } | |
2198 | else | |
2199 | { | |
2200 | b->enable_state = bp_disabled; | |
2201 | overlay_events_enabled = 0; | |
2202 | } | |
e62c965a PP |
2203 | } |
2204 | update_global_location_list (1); | |
2205 | } | |
2206 | ||
0fd8e87f | 2207 | static void |
af02033e | 2208 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2209 | { |
6c95b8df | 2210 | struct program_space *pspace; |
6c95b8df PA |
2211 | struct cleanup *old_chain; |
2212 | ||
2213 | old_chain = save_current_program_space (); | |
0fd8e87f | 2214 | |
6c95b8df | 2215 | ALL_PSPACES (pspace) |
af02033e PP |
2216 | { |
2217 | struct objfile *objfile; | |
2218 | ||
2219 | set_current_program_space (pspace); | |
2220 | ||
2221 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2222 | { |
af02033e PP |
2223 | int i; |
2224 | struct gdbarch *gdbarch; | |
17450429 | 2225 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2226 | |
af02033e PP |
2227 | gdbarch = get_objfile_arch (objfile); |
2228 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2229 | continue; |
2230 | ||
17450429 PP |
2231 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2232 | ||
2233 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2234 | { |
2235 | struct breakpoint *b; | |
af02033e | 2236 | const char *func_name; |
17450429 | 2237 | CORE_ADDR addr; |
6c95b8df | 2238 | |
17450429 | 2239 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2240 | continue; |
0fd8e87f | 2241 | |
17450429 PP |
2242 | func_name = longjmp_names[i]; |
2243 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2244 | { | |
2245 | struct minimal_symbol *m; | |
2246 | ||
2247 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2248 | if (m == NULL) | |
2249 | { | |
2250 | /* Prevent future lookups in this objfile. */ | |
2251 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2252 | continue; | |
2253 | } | |
2254 | bp_objfile_data->longjmp_msym[i] = m; | |
2255 | } | |
2256 | ||
2257 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
2258 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master); | |
af02033e PP |
2259 | b->addr_string = xstrdup (func_name); |
2260 | b->enable_state = bp_disabled; | |
2261 | } | |
0fd8e87f | 2262 | } |
af02033e | 2263 | } |
0fd8e87f | 2264 | update_global_location_list (1); |
6c95b8df PA |
2265 | |
2266 | do_cleanups (old_chain); | |
0fd8e87f UW |
2267 | } |
2268 | ||
af02033e | 2269 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2270 | static void |
af02033e | 2271 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2272 | { |
2273 | struct program_space *pspace; | |
aa7d318d | 2274 | struct cleanup *old_chain; |
af02033e | 2275 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2276 | |
2277 | old_chain = save_current_program_space (); | |
2278 | ||
2279 | ALL_PSPACES (pspace) | |
17450429 PP |
2280 | { |
2281 | struct objfile *objfile; | |
2282 | CORE_ADDR addr; | |
2283 | ||
2284 | set_current_program_space (pspace); | |
2285 | ||
aa7d318d TT |
2286 | ALL_OBJFILES (objfile) |
2287 | { | |
2288 | struct breakpoint *b; | |
17450429 | 2289 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2290 | |
17450429 | 2291 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2292 | |
17450429 PP |
2293 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2294 | continue; | |
2295 | ||
2296 | if (bp_objfile_data->terminate_msym == NULL) | |
2297 | { | |
2298 | struct minimal_symbol *m; | |
2299 | ||
2300 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2301 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2302 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2303 | { | |
2304 | /* Prevent future lookups in this objfile. */ | |
2305 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2306 | continue; | |
2307 | } | |
2308 | bp_objfile_data->terminate_msym = m; | |
2309 | } | |
aa7d318d | 2310 | |
17450429 PP |
2311 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2312 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
aa7d318d TT |
2313 | bp_std_terminate_master); |
2314 | b->addr_string = xstrdup (func_name); | |
2315 | b->enable_state = bp_disabled; | |
2316 | } | |
17450429 PP |
2317 | } |
2318 | ||
aa7d318d TT |
2319 | update_global_location_list (1); |
2320 | ||
2321 | do_cleanups (old_chain); | |
2322 | } | |
2323 | ||
186c406b TT |
2324 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2325 | ||
2326 | void | |
2327 | create_exception_master_breakpoint (void) | |
2328 | { | |
2329 | struct objfile *objfile; | |
17450429 | 2330 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2331 | |
2332 | ALL_OBJFILES (objfile) | |
2333 | { | |
17450429 PP |
2334 | struct breakpoint *b; |
2335 | struct gdbarch *gdbarch; | |
2336 | struct breakpoint_objfile_data *bp_objfile_data; | |
2337 | CORE_ADDR addr; | |
2338 | ||
2339 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2340 | ||
2341 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2342 | continue; | |
2343 | ||
2344 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2345 | |
17450429 | 2346 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2347 | { |
17450429 | 2348 | struct minimal_symbol *debug_hook; |
186c406b | 2349 | |
17450429 PP |
2350 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2351 | if (debug_hook == NULL) | |
2352 | { | |
2353 | bp_objfile_data->exception_msym = &msym_not_found; | |
2354 | continue; | |
2355 | } | |
2356 | ||
2357 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2358 | } |
17450429 PP |
2359 | |
2360 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2361 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2362 | ¤t_target); | |
2363 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2364 | b->addr_string = xstrdup (func_name); | |
2365 | b->enable_state = bp_disabled; | |
186c406b TT |
2366 | } |
2367 | ||
2368 | update_global_location_list (1); | |
2369 | } | |
2370 | ||
c906108c | 2371 | void |
fba45db2 | 2372 | update_breakpoints_after_exec (void) |
c906108c | 2373 | { |
35df4500 | 2374 | struct breakpoint *b, *b_tmp; |
876fa593 | 2375 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2376 | |
25b22b0a PA |
2377 | /* We're about to delete breakpoints from GDB's lists. If the |
2378 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2379 | writing the breakpoints' "shadow contents" back into memory. The | |
2380 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2381 | do that. Instead, the target is responsible from marking | |
2382 | breakpoints out as soon as it detects an exec. We don't do that | |
2383 | here instead, because there may be other attempts to delete | |
2384 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2385 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2386 | if (bploc->pspace == current_program_space) |
2387 | gdb_assert (!bploc->inserted); | |
c906108c | 2388 | |
35df4500 | 2389 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2390 | { |
6c95b8df PA |
2391 | if (b->pspace != current_program_space) |
2392 | continue; | |
2393 | ||
4a64f543 | 2394 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2395 | if (b->type == bp_shlib_event) |
2396 | { | |
2397 | delete_breakpoint (b); | |
2398 | continue; | |
2399 | } | |
c906108c | 2400 | |
4a64f543 | 2401 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2402 | if (b->type == bp_jit_event) |
2403 | { | |
2404 | delete_breakpoint (b); | |
2405 | continue; | |
2406 | } | |
2407 | ||
1900040c | 2408 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2409 | as must overlay event and longjmp master breakpoints. */ |
2410 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2411 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2412 | || b->type == bp_exception_master) | |
c4093a6a JM |
2413 | { |
2414 | delete_breakpoint (b); | |
2415 | continue; | |
2416 | } | |
2417 | ||
4a64f543 | 2418 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 2419 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
2420 | { |
2421 | delete_breakpoint (b); | |
2422 | continue; | |
2423 | } | |
2424 | ||
611c83ae PA |
2425 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2426 | after an exec. */ | |
186c406b TT |
2427 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2428 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2429 | { |
2430 | delete_breakpoint (b); | |
2431 | continue; | |
2432 | } | |
2433 | ||
ce78b96d JB |
2434 | if (b->type == bp_catchpoint) |
2435 | { | |
2436 | /* For now, none of the bp_catchpoint breakpoints need to | |
2437 | do anything at this point. In the future, if some of | |
2438 | the catchpoints need to something, we will need to add | |
2439 | a new method, and call this method from here. */ | |
2440 | continue; | |
2441 | } | |
2442 | ||
c5aa993b JM |
2443 | /* bp_finish is a special case. The only way we ought to be able |
2444 | to see one of these when an exec() has happened, is if the user | |
2445 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2446 | carries them to the call-site of the current callee, by setting | |
2447 | a temporary bp there and resuming. But in this case, the finish | |
2448 | will carry them entirely through the vfork & exec. | |
2449 | ||
2450 | We don't want to allow a bp_finish to remain inserted now. But | |
2451 | we can't safely delete it, 'cause finish_command has a handle to | |
2452 | the bp on a bpstat, and will later want to delete it. There's a | |
2453 | chance (and I've seen it happen) that if we delete the bp_finish | |
2454 | here, that its storage will get reused by the time finish_command | |
2455 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2456 | We really must allow finish_command to delete a bp_finish. | |
2457 | ||
53a5351d JM |
2458 | In the absense of a general solution for the "how do we know |
2459 | it's safe to delete something others may have handles to?" | |
2460 | problem, what we'll do here is just uninsert the bp_finish, and | |
2461 | let finish_command delete it. | |
2462 | ||
2463 | (We know the bp_finish is "doomed" in the sense that it's | |
2464 | momentary, and will be deleted as soon as finish_command sees | |
2465 | the inferior stopped. So it doesn't matter that the bp's | |
2466 | address is probably bogus in the new a.out, unlike e.g., the | |
2467 | solib breakpoints.) */ | |
c5aa993b | 2468 | |
c5aa993b JM |
2469 | if (b->type == bp_finish) |
2470 | { | |
2471 | continue; | |
2472 | } | |
2473 | ||
2474 | /* Without a symbolic address, we have little hope of the | |
2475 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2476 | a.out. */ |
c5aa993b JM |
2477 | if (b->addr_string == NULL) |
2478 | { | |
2479 | delete_breakpoint (b); | |
2480 | continue; | |
2481 | } | |
c5aa993b | 2482 | } |
1900040c | 2483 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2484 | create_overlay_event_breakpoint (); |
2485 | create_longjmp_master_breakpoint (); | |
2486 | create_std_terminate_master_breakpoint (); | |
186c406b | 2487 | create_exception_master_breakpoint (); |
c906108c SS |
2488 | } |
2489 | ||
2490 | int | |
fba45db2 | 2491 | detach_breakpoints (int pid) |
c906108c | 2492 | { |
35df4500 | 2493 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2494 | int val = 0; |
ce696e05 | 2495 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2496 | struct inferior *inf = current_inferior (); |
c5aa993b | 2497 | |
39f77062 | 2498 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2499 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2500 | |
6c95b8df | 2501 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2502 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2503 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2504 | { |
35df4500 | 2505 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2506 | continue; |
2507 | ||
35df4500 TJB |
2508 | if (bl->inserted) |
2509 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2510 | } |
d03285ec UW |
2511 | |
2512 | /* Detach single-step breakpoints as well. */ | |
2513 | detach_single_step_breakpoints (); | |
2514 | ||
ce696e05 | 2515 | do_cleanups (old_chain); |
3a1bae8e | 2516 | return val; |
c906108c SS |
2517 | } |
2518 | ||
35df4500 | 2519 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2520 | Note that this is used to detach breakpoints from a child fork. |
2521 | When we get here, the child isn't in the inferior list, and neither | |
2522 | do we have objects to represent its address space --- we should | |
35df4500 | 2523 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2524 | |
c906108c | 2525 | static int |
35df4500 | 2526 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2527 | { |
2528 | int val; | |
c5aa993b | 2529 | |
35df4500 TJB |
2530 | /* BL is never in moribund_locations by our callers. */ |
2531 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2532 | |
35df4500 | 2533 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2534 | /* Permanent breakpoints cannot be inserted or removed. */ |
2535 | return 0; | |
2536 | ||
74960c60 VP |
2537 | /* The type of none suggests that owner is actually deleted. |
2538 | This should not ever happen. */ | |
35df4500 | 2539 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2540 | |
35df4500 TJB |
2541 | if (bl->loc_type == bp_loc_software_breakpoint |
2542 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2543 | { |
c02f5703 MS |
2544 | /* "Normal" instruction breakpoint: either the standard |
2545 | trap-instruction bp (bp_breakpoint), or a | |
2546 | bp_hardware_breakpoint. */ | |
2547 | ||
2548 | /* First check to see if we have to handle an overlay. */ | |
2549 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2550 | || bl->section == NULL |
2551 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2552 | { |
2553 | /* No overlay handling: just remove the breakpoint. */ | |
2554 | ||
35df4500 TJB |
2555 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2556 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2557 | else |
35df4500 | 2558 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2559 | } |
c906108c SS |
2560 | else |
2561 | { | |
4a64f543 | 2562 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2563 | Did we set a breakpoint at the LMA? */ |
2564 | if (!overlay_events_enabled) | |
2565 | { | |
2566 | /* Yes -- overlay event support is not active, so we | |
2567 | should have set a breakpoint at the LMA. Remove it. | |
2568 | */ | |
c02f5703 MS |
2569 | /* Ignore any failures: if the LMA is in ROM, we will |
2570 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2571 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2572 | target_remove_hw_breakpoint (bl->gdbarch, | |
2573 | &bl->overlay_target_info); | |
c02f5703 | 2574 | else |
35df4500 TJB |
2575 | target_remove_breakpoint (bl->gdbarch, |
2576 | &bl->overlay_target_info); | |
c02f5703 MS |
2577 | } |
2578 | /* Did we set a breakpoint at the VMA? | |
2579 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2580 | if (bl->inserted) |
c906108c | 2581 | { |
c02f5703 MS |
2582 | /* Yes -- remove it. Previously we did not bother to |
2583 | remove the breakpoint if the section had been | |
2584 | unmapped, but let's not rely on that being safe. We | |
2585 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2586 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2587 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2588 | &bl->target_info); | |
aa67235e UW |
2589 | |
2590 | /* However, we should remove *software* breakpoints only | |
2591 | if the section is still mapped, or else we overwrite | |
2592 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2593 | else if (section_is_mapped (bl->section)) |
2594 | val = target_remove_breakpoint (bl->gdbarch, | |
2595 | &bl->target_info); | |
aa67235e UW |
2596 | else |
2597 | val = 0; | |
c906108c | 2598 | } |
c02f5703 MS |
2599 | else |
2600 | { | |
2601 | /* No -- not inserted, so no need to remove. No error. */ | |
2602 | val = 0; | |
2603 | } | |
c906108c | 2604 | } |
879d1e6b UW |
2605 | |
2606 | /* In some cases, we might not be able to remove a breakpoint | |
2607 | in a shared library that has already been removed, but we | |
2608 | have not yet processed the shlib unload event. */ | |
35df4500 | 2609 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2610 | val = 0; |
2611 | ||
c906108c SS |
2612 | if (val) |
2613 | return val; | |
35df4500 | 2614 | bl->inserted = (is == mark_inserted); |
c906108c | 2615 | } |
35df4500 | 2616 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2617 | { |
77b06cd7 TJB |
2618 | gdb_assert (bl->owner->ops != NULL |
2619 | && bl->owner->ops->remove_location != NULL); | |
2620 | ||
35df4500 | 2621 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2622 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2623 | |
c906108c | 2624 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2625 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2626 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2627 | bl->owner->number); |
c906108c | 2628 | } |
35df4500 TJB |
2629 | else if (bl->owner->type == bp_catchpoint |
2630 | && breakpoint_enabled (bl->owner) | |
2631 | && !bl->duplicate) | |
ce78b96d | 2632 | { |
77b06cd7 TJB |
2633 | gdb_assert (bl->owner->ops != NULL |
2634 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2635 | |
77b06cd7 | 2636 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2637 | if (val) |
2638 | return val; | |
77b06cd7 | 2639 | |
35df4500 | 2640 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2641 | } |
c906108c SS |
2642 | |
2643 | return 0; | |
2644 | } | |
2645 | ||
6c95b8df | 2646 | static int |
35df4500 | 2647 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2648 | { |
2649 | int ret; | |
2650 | struct cleanup *old_chain; | |
2651 | ||
35df4500 TJB |
2652 | /* BL is never in moribund_locations by our callers. */ |
2653 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2654 | |
35df4500 | 2655 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2656 | /* Permanent breakpoints cannot be inserted or removed. */ |
2657 | return 0; | |
2658 | ||
2659 | /* The type of none suggests that owner is actually deleted. | |
2660 | This should not ever happen. */ | |
35df4500 | 2661 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2662 | |
2663 | old_chain = save_current_space_and_thread (); | |
2664 | ||
35df4500 | 2665 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2666 | |
35df4500 | 2667 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2668 | |
2669 | do_cleanups (old_chain); | |
2670 | return ret; | |
2671 | } | |
2672 | ||
c906108c SS |
2673 | /* Clear the "inserted" flag in all breakpoints. */ |
2674 | ||
25b22b0a | 2675 | void |
fba45db2 | 2676 | mark_breakpoints_out (void) |
c906108c | 2677 | { |
35df4500 | 2678 | struct bp_location *bl, **blp_tmp; |
c906108c | 2679 | |
35df4500 TJB |
2680 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2681 | if (bl->pspace == current_program_space) | |
2682 | bl->inserted = 0; | |
c906108c SS |
2683 | } |
2684 | ||
53a5351d JM |
2685 | /* Clear the "inserted" flag in all breakpoints and delete any |
2686 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2687 | |
2688 | Plus other such housekeeping that has to be done for breakpoints | |
2689 | between runs. | |
2690 | ||
53a5351d JM |
2691 | Note: this function gets called at the end of a run (by |
2692 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2693 | init_wait_for_inferior). */ |
c906108c SS |
2694 | |
2695 | ||
2696 | ||
2697 | void | |
fba45db2 | 2698 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2699 | { |
35df4500 TJB |
2700 | struct breakpoint *b, *b_tmp; |
2701 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2702 | int ix; |
6c95b8df | 2703 | struct program_space *pspace = current_program_space; |
c906108c | 2704 | |
50c71eaf PA |
2705 | /* If breakpoint locations are shared across processes, then there's |
2706 | nothing to do. */ | |
2567c7d9 | 2707 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2708 | return; |
2709 | ||
35df4500 | 2710 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2711 | { |
35df4500 TJB |
2712 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2713 | if (bl->pspace == pspace | |
2714 | && bl->owner->enable_state != bp_permanent) | |
2715 | bl->inserted = 0; | |
6c95b8df | 2716 | } |
075f6582 | 2717 | |
35df4500 | 2718 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2719 | { |
6c95b8df PA |
2720 | if (b->loc && b->loc->pspace != pspace) |
2721 | continue; | |
2722 | ||
c5aa993b JM |
2723 | switch (b->type) |
2724 | { | |
2725 | case bp_call_dummy: | |
c906108c | 2726 | |
c5aa993b | 2727 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2728 | cause problems when the inferior is rerun, so we better get |
2729 | rid of it. */ | |
2730 | ||
2731 | case bp_watchpoint_scope: | |
2732 | ||
2733 | /* Also get rid of scope breakpoints. */ | |
2734 | ||
2735 | case bp_shlib_event: | |
2736 | ||
2737 | /* Also remove solib event breakpoints. Their addresses may | |
2738 | have changed since the last time we ran the program. | |
2739 | Actually we may now be debugging against different target; | |
2740 | and so the solib backend that installed this breakpoint may | |
2741 | not be used in by the target. E.g., | |
2742 | ||
2743 | (gdb) file prog-linux | |
2744 | (gdb) run # native linux target | |
2745 | ... | |
2746 | (gdb) kill | |
2747 | (gdb) file prog-win.exe | |
2748 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2749 | */ | |
c906108c | 2750 | |
c5aa993b JM |
2751 | delete_breakpoint (b); |
2752 | break; | |
c906108c | 2753 | |
c5aa993b JM |
2754 | case bp_watchpoint: |
2755 | case bp_hardware_watchpoint: | |
2756 | case bp_read_watchpoint: | |
2757 | case bp_access_watchpoint: | |
c906108c | 2758 | |
c5aa993b JM |
2759 | /* Likewise for watchpoints on local expressions. */ |
2760 | if (b->exp_valid_block != NULL) | |
2761 | delete_breakpoint (b); | |
967af18d | 2762 | else if (context == inf_starting) |
c860120c | 2763 | { |
4a64f543 MS |
2764 | /* Reset val field to force reread of starting value in |
2765 | insert_breakpoints. */ | |
c860120c PM |
2766 | if (b->val) |
2767 | value_free (b->val); | |
2768 | b->val = NULL; | |
fa4727a6 | 2769 | b->val_valid = 0; |
c860120c | 2770 | } |
c5aa993b JM |
2771 | break; |
2772 | default: | |
c5aa993b JM |
2773 | break; |
2774 | } | |
2775 | } | |
1c5cfe86 PA |
2776 | |
2777 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2778 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2779 | decref_bp_location (&bl); | |
1c5cfe86 | 2780 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2781 | } |
2782 | ||
6c95b8df PA |
2783 | /* These functions concern about actual breakpoints inserted in the |
2784 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2785 | we need to hop over the bkpt --- so we check for address space | |
2786 | match, not program space. */ | |
2787 | ||
c2c6d25f JM |
2788 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2789 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2790 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2791 | permanent breakpoint. | |
2792 | - When continuing from a location with an ordinary breakpoint, we | |
2793 | actually single step once before calling insert_breakpoints. | |
2794 | - When continuing from a localion with a permanent breakpoint, we | |
2795 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2796 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2797 | |
c2c6d25f | 2798 | enum breakpoint_here |
6c95b8df | 2799 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2800 | { |
35df4500 | 2801 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2802 | int any_breakpoint_here = 0; |
c906108c | 2803 | |
35df4500 | 2804 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2805 | { |
35df4500 TJB |
2806 | if (bl->loc_type != bp_loc_software_breakpoint |
2807 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2808 | continue; |
2809 | ||
f1310107 | 2810 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2811 | if ((breakpoint_enabled (bl->owner) |
2812 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2813 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2814 | { |
2815 | if (overlay_debugging | |
35df4500 TJB |
2816 | && section_is_overlay (bl->section) |
2817 | && !section_is_mapped (bl->section)) | |
075f6582 | 2818 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2819 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2820 | return permanent_breakpoint_here; |
2821 | else | |
2822 | any_breakpoint_here = 1; | |
2823 | } | |
2824 | } | |
c906108c | 2825 | |
c2c6d25f | 2826 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2827 | } |
2828 | ||
1c5cfe86 PA |
2829 | /* Return true if there's a moribund breakpoint at PC. */ |
2830 | ||
2831 | int | |
6c95b8df | 2832 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2833 | { |
2834 | struct bp_location *loc; | |
2835 | int ix; | |
2836 | ||
2837 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2838 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2839 | return 1; |
2840 | ||
2841 | return 0; | |
2842 | } | |
c2c6d25f | 2843 | |
c36b740a | 2844 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2845 | inserted using regular breakpoint_chain / bp_location array |
2846 | mechanism. This does not check for single-step breakpoints, which | |
2847 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2848 | |
2849 | int | |
4a64f543 MS |
2850 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2851 | CORE_ADDR pc) | |
c906108c | 2852 | { |
35df4500 | 2853 | struct bp_location *bl, **blp_tmp; |
c906108c | 2854 | |
35df4500 | 2855 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2856 | { |
35df4500 TJB |
2857 | if (bl->loc_type != bp_loc_software_breakpoint |
2858 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2859 | continue; |
2860 | ||
35df4500 | 2861 | if (bl->inserted |
f1310107 | 2862 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2863 | { |
2864 | if (overlay_debugging | |
35df4500 TJB |
2865 | && section_is_overlay (bl->section) |
2866 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2867 | continue; /* unmapped overlay -- can't be a match */ |
2868 | else | |
2869 | return 1; | |
2870 | } | |
c5aa993b | 2871 | } |
c36b740a VP |
2872 | return 0; |
2873 | } | |
2874 | ||
2875 | /* Returns non-zero iff there's either regular breakpoint | |
2876 | or a single step breakpoint inserted at PC. */ | |
2877 | ||
2878 | int | |
6c95b8df | 2879 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2880 | { |
6c95b8df | 2881 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2882 | return 1; |
c906108c | 2883 | |
6c95b8df | 2884 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2885 | return 1; |
2886 | ||
c906108c SS |
2887 | return 0; |
2888 | } | |
2889 | ||
4fa8626c DJ |
2890 | /* This function returns non-zero iff there is a software breakpoint |
2891 | inserted at PC. */ | |
2892 | ||
2893 | int | |
3e43a32a MS |
2894 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2895 | CORE_ADDR pc) | |
4fa8626c | 2896 | { |
35df4500 | 2897 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2898 | |
35df4500 | 2899 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2900 | { |
35df4500 | 2901 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2902 | continue; |
2903 | ||
35df4500 TJB |
2904 | if (bl->inserted |
2905 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2906 | aspace, pc)) |
4fa8626c DJ |
2907 | { |
2908 | if (overlay_debugging | |
35df4500 TJB |
2909 | && section_is_overlay (bl->section) |
2910 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2911 | continue; /* unmapped overlay -- can't be a match */ |
2912 | else | |
2913 | return 1; | |
2914 | } | |
2915 | } | |
2916 | ||
1aafd4da | 2917 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2918 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2919 | return 1; |
2920 | ||
4fa8626c DJ |
2921 | return 0; |
2922 | } | |
2923 | ||
9093389c PA |
2924 | int |
2925 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2926 | CORE_ADDR addr, ULONGEST len) | |
2927 | { | |
2928 | struct breakpoint *bpt; | |
2929 | ||
2930 | ALL_BREAKPOINTS (bpt) | |
2931 | { | |
2932 | struct bp_location *loc; | |
2933 | ||
2934 | if (bpt->type != bp_hardware_watchpoint | |
2935 | && bpt->type != bp_access_watchpoint) | |
2936 | continue; | |
2937 | ||
2938 | if (!breakpoint_enabled (bpt)) | |
2939 | continue; | |
2940 | ||
2941 | for (loc = bpt->loc; loc; loc = loc->next) | |
2942 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2943 | { | |
2944 | CORE_ADDR l, h; | |
2945 | ||
2946 | /* Check for intersection. */ | |
2947 | l = max (loc->address, addr); | |
2948 | h = min (loc->address + loc->length, addr + len); | |
2949 | if (l < h) | |
2950 | return 1; | |
2951 | } | |
2952 | } | |
2953 | return 0; | |
2954 | } | |
2955 | ||
075f6582 DJ |
2956 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2957 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2958 | |
2959 | int | |
6c95b8df PA |
2960 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2961 | ptid_t ptid) | |
c906108c | 2962 | { |
35df4500 | 2963 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2964 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2965 | int thread = -1; |
4a306c9a | 2966 | int task = 0; |
a6f1cd96 | 2967 | |
35df4500 | 2968 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2969 | { |
35df4500 TJB |
2970 | if (bl->loc_type != bp_loc_software_breakpoint |
2971 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2972 | continue; |
2973 | ||
35df4500 TJB |
2974 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2975 | if (!breakpoint_enabled (bl->owner) | |
2976 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2977 | continue; |
2978 | ||
f1310107 | 2979 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
2980 | continue; |
2981 | ||
35df4500 | 2982 | if (bl->owner->thread != -1) |
075f6582 | 2983 | { |
a6f1cd96 JB |
2984 | /* This is a thread-specific breakpoint. Check that ptid |
2985 | matches that thread. If thread hasn't been computed yet, | |
2986 | it is now time to do so. */ | |
2987 | if (thread == -1) | |
2988 | thread = pid_to_thread_id (ptid); | |
35df4500 | 2989 | if (bl->owner->thread != thread) |
a6f1cd96 | 2990 | continue; |
075f6582 | 2991 | } |
a6f1cd96 | 2992 | |
35df4500 | 2993 | if (bl->owner->task != 0) |
4a306c9a JB |
2994 | { |
2995 | /* This is a task-specific breakpoint. Check that ptid | |
2996 | matches that task. If task hasn't been computed yet, | |
2997 | it is now time to do so. */ | |
2998 | if (task == 0) | |
2999 | task = ada_get_task_number (ptid); | |
35df4500 | 3000 | if (bl->owner->task != task) |
4a306c9a JB |
3001 | continue; |
3002 | } | |
3003 | ||
a6f1cd96 | 3004 | if (overlay_debugging |
35df4500 TJB |
3005 | && section_is_overlay (bl->section) |
3006 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3007 | continue; /* unmapped overlay -- can't be a match */ |
3008 | ||
3009 | return 1; | |
c5aa993b | 3010 | } |
c906108c SS |
3011 | |
3012 | return 0; | |
3013 | } | |
c906108c | 3014 | \f |
c5aa993b | 3015 | |
c906108c SS |
3016 | /* bpstat stuff. External routines' interfaces are documented |
3017 | in breakpoint.h. */ | |
3018 | ||
3019 | int | |
fba45db2 | 3020 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3021 | { |
533be4dd | 3022 | return (ep->type == bp_catchpoint); |
c906108c SS |
3023 | } |
3024 | ||
f431efe5 PA |
3025 | /* Frees any storage that is part of a bpstat. Does not walk the |
3026 | 'next' chain. */ | |
3027 | ||
3028 | static void | |
198757a8 VP |
3029 | bpstat_free (bpstat bs) |
3030 | { | |
3031 | if (bs->old_val != NULL) | |
3032 | value_free (bs->old_val); | |
9add0f1b | 3033 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3034 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3035 | xfree (bs); |
3036 | } | |
3037 | ||
c906108c SS |
3038 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3039 | Also free any storage that is part of a bpstat. */ | |
3040 | ||
3041 | void | |
fba45db2 | 3042 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3043 | { |
3044 | bpstat p; | |
3045 | bpstat q; | |
3046 | ||
3047 | if (bsp == 0) | |
3048 | return; | |
3049 | p = *bsp; | |
3050 | while (p != NULL) | |
3051 | { | |
3052 | q = p->next; | |
198757a8 | 3053 | bpstat_free (p); |
c906108c SS |
3054 | p = q; |
3055 | } | |
3056 | *bsp = NULL; | |
3057 | } | |
3058 | ||
3059 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3060 | is part of the bpstat is copied as well. */ | |
3061 | ||
3062 | bpstat | |
fba45db2 | 3063 | bpstat_copy (bpstat bs) |
c906108c SS |
3064 | { |
3065 | bpstat p = NULL; | |
3066 | bpstat tmp; | |
3067 | bpstat retval = NULL; | |
3068 | ||
3069 | if (bs == NULL) | |
3070 | return bs; | |
3071 | ||
3072 | for (; bs != NULL; bs = bs->next) | |
3073 | { | |
3074 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3075 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3076 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3077 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3078 | if (bs->old_val != NULL) |
3c3185ac JK |
3079 | { |
3080 | tmp->old_val = value_copy (bs->old_val); | |
3081 | release_value (tmp->old_val); | |
3082 | } | |
31cc81e9 | 3083 | |
c906108c SS |
3084 | if (p == NULL) |
3085 | /* This is the first thing in the chain. */ | |
3086 | retval = tmp; | |
3087 | else | |
3088 | p->next = tmp; | |
3089 | p = tmp; | |
3090 | } | |
3091 | p->next = NULL; | |
3092 | return retval; | |
3093 | } | |
3094 | ||
4a64f543 | 3095 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3096 | |
3097 | bpstat | |
fba45db2 | 3098 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3099 | { |
c5aa993b JM |
3100 | if (bsp == NULL) |
3101 | return NULL; | |
c906108c | 3102 | |
c5aa993b JM |
3103 | for (; bsp != NULL; bsp = bsp->next) |
3104 | { | |
f431efe5 | 3105 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3106 | return bsp; |
3107 | } | |
c906108c SS |
3108 | return NULL; |
3109 | } | |
3110 | ||
4a64f543 MS |
3111 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3112 | stopped at. *BSP upon return is a bpstat which points to the | |
3113 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3114 | good for anything but further calls to bpstat_num). | |
3115 | ||
8671a17b PA |
3116 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3117 | Return -1 if stopped at a breakpoint that has been deleted since | |
3118 | we set it. | |
3119 | Return 1 otherwise. */ | |
c906108c SS |
3120 | |
3121 | int | |
8671a17b | 3122 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3123 | { |
3124 | struct breakpoint *b; | |
3125 | ||
3126 | if ((*bsp) == NULL) | |
3127 | return 0; /* No more breakpoint values */ | |
8671a17b | 3128 | |
4a64f543 MS |
3129 | /* We assume we'll never have several bpstats that correspond to a |
3130 | single breakpoint -- otherwise, this function might return the | |
3131 | same number more than once and this will look ugly. */ | |
f431efe5 | 3132 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3133 | *bsp = (*bsp)->next; |
3134 | if (b == NULL) | |
3135 | return -1; /* breakpoint that's been deleted since */ | |
3136 | ||
3137 | *num = b->number; /* We have its number */ | |
3138 | return 1; | |
c906108c SS |
3139 | } |
3140 | ||
3141 | /* Modify BS so that the actions will not be performed. */ | |
3142 | ||
3143 | void | |
fba45db2 | 3144 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3145 | { |
3146 | for (; bs != NULL; bs = bs->next) | |
3147 | { | |
9add0f1b | 3148 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3149 | bs->commands_left = NULL; |
c906108c SS |
3150 | if (bs->old_val != NULL) |
3151 | { | |
3152 | value_free (bs->old_val); | |
3153 | bs->old_val = NULL; | |
3154 | } | |
3155 | } | |
3156 | } | |
3157 | ||
f3b1572e PA |
3158 | /* Called when a command is about to proceed the inferior. */ |
3159 | ||
3160 | static void | |
3161 | breakpoint_about_to_proceed (void) | |
3162 | { | |
3163 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3164 | { | |
3165 | struct thread_info *tp = inferior_thread (); | |
3166 | ||
3167 | /* Allow inferior function calls in breakpoint commands to not | |
3168 | interrupt the command list. When the call finishes | |
3169 | successfully, the inferior will be standing at the same | |
3170 | breakpoint as if nothing happened. */ | |
16c381f0 | 3171 | if (tp->control.in_infcall) |
f3b1572e PA |
3172 | return; |
3173 | } | |
3174 | ||
3175 | breakpoint_proceeded = 1; | |
3176 | } | |
3177 | ||
4a64f543 MS |
3178 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3179 | command. */ | |
c906108c | 3180 | static void |
4efb68b1 | 3181 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3182 | { |
3183 | executing_breakpoint_commands = 0; | |
3184 | } | |
3185 | ||
4a64f543 MS |
3186 | /* Execute all the commands associated with all the breakpoints at |
3187 | this location. Any of these commands could cause the process to | |
3188 | proceed beyond this point, etc. We look out for such changes by | |
3189 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3190 | |
347bddb7 PA |
3191 | Returns true if a breakpoint command resumed the inferior. In that |
3192 | case, it is the caller's responsibility to recall it again with the | |
3193 | bpstat of the current thread. */ | |
3194 | ||
3195 | static int | |
3196 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3197 | { |
3198 | bpstat bs; | |
3199 | struct cleanup *old_chain; | |
347bddb7 | 3200 | int again = 0; |
c906108c SS |
3201 | |
3202 | /* Avoid endless recursion if a `source' command is contained | |
3203 | in bs->commands. */ | |
3204 | if (executing_breakpoint_commands) | |
347bddb7 | 3205 | return 0; |
c906108c SS |
3206 | |
3207 | executing_breakpoint_commands = 1; | |
3208 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3209 | ||
cf6c5ffb TT |
3210 | prevent_dont_repeat (); |
3211 | ||
4a64f543 | 3212 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3213 | bs = *bsp; |
3214 | ||
3215 | breakpoint_proceeded = 0; | |
3216 | for (; bs != NULL; bs = bs->next) | |
3217 | { | |
9add0f1b | 3218 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3219 | struct command_line *cmd; |
3220 | struct cleanup *this_cmd_tree_chain; | |
3221 | ||
3222 | /* Take ownership of the BSP's command tree, if it has one. | |
3223 | ||
3224 | The command tree could legitimately contain commands like | |
3225 | 'step' and 'next', which call clear_proceed_status, which | |
3226 | frees stop_bpstat's command tree. To make sure this doesn't | |
3227 | free the tree we're executing out from under us, we need to | |
3228 | take ownership of the tree ourselves. Since a given bpstat's | |
3229 | commands are only executed once, we don't need to copy it; we | |
3230 | can clear the pointer in the bpstat, and make sure we free | |
3231 | the tree when we're done. */ | |
9add0f1b TT |
3232 | ccmd = bs->commands; |
3233 | bs->commands = NULL; | |
3234 | this_cmd_tree_chain | |
3235 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3236 | cmd = bs->commands_left; | |
3237 | bs->commands_left = NULL; | |
6c50ab1c | 3238 | |
c906108c SS |
3239 | while (cmd != NULL) |
3240 | { | |
3241 | execute_control_command (cmd); | |
3242 | ||
3243 | if (breakpoint_proceeded) | |
3244 | break; | |
3245 | else | |
3246 | cmd = cmd->next; | |
3247 | } | |
6c50ab1c JB |
3248 | |
3249 | /* We can free this command tree now. */ | |
3250 | do_cleanups (this_cmd_tree_chain); | |
3251 | ||
c906108c | 3252 | if (breakpoint_proceeded) |
32c1e744 VP |
3253 | { |
3254 | if (target_can_async_p ()) | |
347bddb7 PA |
3255 | /* If we are in async mode, then the target might be still |
3256 | running, not stopped at any breakpoint, so nothing for | |
3257 | us to do here -- just return to the event loop. */ | |
3258 | ; | |
32c1e744 VP |
3259 | else |
3260 | /* In sync mode, when execute_control_command returns | |
3261 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3262 | Breakpoint commands for that stop were not run, since |
3263 | execute_command does not run breakpoint commands -- | |
3264 | only command_line_handler does, but that one is not | |
3265 | involved in execution of breakpoint commands. So, we | |
3266 | can now execute breakpoint commands. It should be | |
3267 | noted that making execute_command do bpstat actions is | |
3268 | not an option -- in this case we'll have recursive | |
3269 | invocation of bpstat for each breakpoint with a | |
3270 | command, and can easily blow up GDB stack. Instead, we | |
3271 | return true, which will trigger the caller to recall us | |
3272 | with the new stop_bpstat. */ | |
3273 | again = 1; | |
3274 | break; | |
32c1e744 | 3275 | } |
c906108c | 3276 | } |
c2b8ed2c | 3277 | do_cleanups (old_chain); |
347bddb7 PA |
3278 | return again; |
3279 | } | |
3280 | ||
3281 | void | |
3282 | bpstat_do_actions (void) | |
3283 | { | |
3284 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3285 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3286 | && target_has_execution | |
3287 | && !is_exited (inferior_ptid) | |
3288 | && !is_executing (inferior_ptid)) | |
3289 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3290 | and only return when it is stopped at the next breakpoint, we | |
3291 | keep doing breakpoint actions until it returns false to | |
3292 | indicate the inferior was not resumed. */ | |
16c381f0 | 3293 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3294 | break; |
c906108c SS |
3295 | } |
3296 | ||
fa4727a6 DJ |
3297 | /* Print out the (old or new) value associated with a watchpoint. */ |
3298 | ||
3299 | static void | |
3300 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3301 | { | |
3302 | if (val == NULL) | |
3303 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3304 | else | |
79a45b7d TT |
3305 | { |
3306 | struct value_print_options opts; | |
3307 | get_user_print_options (&opts); | |
3308 | value_print (val, stream, &opts); | |
3309 | } | |
fa4727a6 DJ |
3310 | } |
3311 | ||
e514a9d6 | 3312 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3313 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3314 | by having it set different print_it values. |
3315 | ||
3316 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3317 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3318 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3319 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3320 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3321 | |
3322 | Return values from this routine (ultimately used by bpstat_print() | |
3323 | and normal_stop() to decide what to do): | |
3324 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3325 | don't print anything else. | |
3326 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3327 | that something to be followed by a location. | |
3328 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3329 | that something to be followed by a location. | |
3330 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3331 | analysis. */ | |
c906108c | 3332 | |
917317f4 | 3333 | static enum print_stop_action |
fba45db2 | 3334 | print_it_typical (bpstat bs) |
c906108c | 3335 | { |
f7545552 | 3336 | struct cleanup *old_chain; |
4f8d1dc6 | 3337 | struct breakpoint *b; |
89f9893c | 3338 | const struct bp_location *bl; |
8b93c638 | 3339 | struct ui_stream *stb; |
f7545552 TT |
3340 | int bp_temp = 0; |
3341 | enum print_stop_action result; | |
3342 | ||
f431efe5 PA |
3343 | gdb_assert (bs->bp_location_at != NULL); |
3344 | ||
3345 | bl = bs->bp_location_at; | |
3346 | b = bs->breakpoint_at; | |
c906108c | 3347 | |
f7545552 TT |
3348 | stb = ui_out_stream_new (uiout); |
3349 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3350 | ||
4f8d1dc6 | 3351 | switch (b->type) |
c906108c | 3352 | { |
e514a9d6 JM |
3353 | case bp_breakpoint: |
3354 | case bp_hardware_breakpoint: | |
f431efe5 | 3355 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3356 | if (bl->address != bl->requested_address) |
3357 | breakpoint_adjustment_warning (bl->requested_address, | |
3358 | bl->address, | |
4f8d1dc6 VP |
3359 | b->number, 1); |
3360 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3361 | if (bp_temp) |
3362 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3363 | else | |
3364 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3365 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3366 | { |
3367 | ui_out_field_string (uiout, "reason", | |
3368 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3369 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3370 | } | |
4f8d1dc6 | 3371 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3372 | ui_out_text (uiout, ", "); |
f7545552 | 3373 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3374 | break; |
3375 | ||
3376 | case bp_shlib_event: | |
917317f4 JM |
3377 | /* Did we stop because the user set the stop_on_solib_events |
3378 | variable? (If so, we report this as a generic, "Stopped due | |
3379 | to shlib event" message.) */ | |
a3f17187 | 3380 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3381 | result = PRINT_NOTHING; |
e514a9d6 JM |
3382 | break; |
3383 | ||
c4093a6a | 3384 | case bp_thread_event: |
4a64f543 | 3385 | /* Not sure how we will get here. |
c4093a6a | 3386 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3387 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3388 | result = PRINT_NOTHING; |
c4093a6a JM |
3389 | break; |
3390 | ||
1900040c | 3391 | case bp_overlay_event: |
4a64f543 | 3392 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3393 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3394 | result = PRINT_NOTHING; |
1900040c MS |
3395 | break; |
3396 | ||
0fd8e87f UW |
3397 | case bp_longjmp_master: |
3398 | /* These should never be enabled. */ | |
3399 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3400 | result = PRINT_NOTHING; | |
3401 | break; | |
3402 | ||
aa7d318d TT |
3403 | case bp_std_terminate_master: |
3404 | /* These should never be enabled. */ | |
3e43a32a MS |
3405 | printf_filtered (_("std::terminate Master Breakpoint: " |
3406 | "gdb should not stop!\n")); | |
aa7d318d TT |
3407 | result = PRINT_NOTHING; |
3408 | break; | |
3409 | ||
186c406b TT |
3410 | case bp_exception_master: |
3411 | /* These should never be enabled. */ | |
3e43a32a MS |
3412 | printf_filtered (_("Exception Master Breakpoint: " |
3413 | "gdb should not stop!\n")); | |
186c406b TT |
3414 | result = PRINT_NOTHING; |
3415 | break; | |
3416 | ||
e514a9d6 JM |
3417 | case bp_watchpoint: |
3418 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3419 | annotate_watchpoint (b->number); |
3420 | if (ui_out_is_mi_like_p (uiout)) | |
3421 | ui_out_field_string | |
3422 | (uiout, "reason", | |
3423 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3424 | mention (b); | |
f7545552 | 3425 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3426 | ui_out_text (uiout, "\nOld value = "); |
3427 | watchpoint_value_print (bs->old_val, stb->stream); | |
3428 | ui_out_field_stream (uiout, "old", stb); | |
3429 | ui_out_text (uiout, "\nNew value = "); | |
3430 | watchpoint_value_print (b->val, stb->stream); | |
3431 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3432 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3433 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3434 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3435 | break; |
3436 | ||
3437 | case bp_read_watchpoint: | |
9dc5e2a9 | 3438 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3439 | ui_out_field_string |
3440 | (uiout, "reason", | |
3441 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3442 | mention (b); |
f7545552 | 3443 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3444 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3445 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3446 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3447 | ui_out_text (uiout, "\n"); |
f7545552 | 3448 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3449 | break; |
3450 | ||
3451 | case bp_access_watchpoint: | |
fa4727a6 | 3452 | if (bs->old_val != NULL) |
8b93c638 | 3453 | { |
4f8d1dc6 | 3454 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3455 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3456 | ui_out_field_string |
3457 | (uiout, "reason", | |
3458 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3459 | mention (b); |
f7545552 | 3460 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3461 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3462 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3463 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3464 | ui_out_text (uiout, "\nNew value = "); |
3465 | } | |
3466 | else | |
3467 | { | |
4f8d1dc6 | 3468 | mention (b); |
9dc5e2a9 | 3469 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3470 | ui_out_field_string |
3471 | (uiout, "reason", | |
3472 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3473 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3474 | ui_out_text (uiout, "\nValue = "); |
3475 | } | |
fa4727a6 | 3476 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3477 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3478 | ui_out_text (uiout, "\n"); |
f7545552 | 3479 | result = PRINT_UNKNOWN; |
e514a9d6 | 3480 | break; |
4ce44c66 | 3481 | |
e514a9d6 | 3482 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3483 | here. */ |
e514a9d6 | 3484 | |
11cf8741 | 3485 | case bp_finish: |
9dc5e2a9 | 3486 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3487 | ui_out_field_string |
3488 | (uiout, "reason", | |
3489 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3490 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3491 | break; |
3492 | ||
e514a9d6 | 3493 | case bp_until: |
9dc5e2a9 | 3494 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3495 | ui_out_field_string |
3496 | (uiout, "reason", | |
3497 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3498 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3499 | break; |
3500 | ||
c2d11a7d | 3501 | case bp_none: |
e514a9d6 JM |
3502 | case bp_longjmp: |
3503 | case bp_longjmp_resume: | |
186c406b TT |
3504 | case bp_exception: |
3505 | case bp_exception_resume: | |
e514a9d6 | 3506 | case bp_step_resume: |
2c03e5be | 3507 | case bp_hp_step_resume: |
e514a9d6 JM |
3508 | case bp_watchpoint_scope: |
3509 | case bp_call_dummy: | |
aa7d318d | 3510 | case bp_std_terminate: |
1042e4c0 | 3511 | case bp_tracepoint: |
7a697b8d | 3512 | case bp_fast_tracepoint: |
4efc6507 | 3513 | case bp_jit_event: |
0e30163f JK |
3514 | case bp_gnu_ifunc_resolver: |
3515 | case bp_gnu_ifunc_resolver_return: | |
e514a9d6 | 3516 | default: |
f7545552 TT |
3517 | result = PRINT_UNKNOWN; |
3518 | break; | |
e514a9d6 | 3519 | } |
f7545552 TT |
3520 | |
3521 | do_cleanups (old_chain); | |
3522 | return result; | |
e514a9d6 JM |
3523 | } |
3524 | ||
3525 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3526 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3527 | 'print_it' in the bpstat structure. Under some circumstances we |
3528 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3529 | normal_stop(). */ |
e514a9d6 JM |
3530 | |
3531 | static enum print_stop_action | |
3532 | print_bp_stop_message (bpstat bs) | |
3533 | { | |
3534 | switch (bs->print_it) | |
3535 | { | |
3536 | case print_it_noop: | |
4a64f543 | 3537 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3538 | return PRINT_UNKNOWN; |
3539 | break; | |
3540 | ||
3541 | case print_it_done: | |
3542 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3543 | relevant messages. */ |
e514a9d6 JM |
3544 | return PRINT_SRC_AND_LOC; |
3545 | break; | |
3546 | ||
3547 | case print_it_normal: | |
4f8d1dc6 | 3548 | { |
f431efe5 PA |
3549 | struct breakpoint *b = bs->breakpoint_at; |
3550 | ||
1a6a67de TJB |
3551 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3552 | which has since been deleted. */ | |
3553 | if (b == NULL) | |
3554 | return PRINT_UNKNOWN; | |
3555 | ||
4f8d1dc6 VP |
3556 | /* Normal case. Call the breakpoint's print_it method, or |
3557 | print_it_typical. */ | |
1a6a67de | 3558 | if (b->ops != NULL && b->ops->print_it != NULL) |
4f8d1dc6 VP |
3559 | return b->ops->print_it (b); |
3560 | else | |
3561 | return print_it_typical (bs); | |
3562 | } | |
3563 | break; | |
3086aeae | 3564 | |
e514a9d6 | 3565 | default: |
8e65ff28 | 3566 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3567 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3568 | break; |
c906108c | 3569 | } |
c906108c SS |
3570 | } |
3571 | ||
e514a9d6 JM |
3572 | /* Print a message indicating what happened. This is called from |
3573 | normal_stop(). The input to this routine is the head of the bpstat | |
3574 | list - a list of the eventpoints that caused this stop. This | |
3575 | routine calls the generic print routine for printing a message | |
3576 | about reasons for stopping. This will print (for example) the | |
3577 | "Breakpoint n," part of the output. The return value of this | |
3578 | routine is one of: | |
c906108c | 3579 | |
4a64f543 | 3580 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3581 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3582 | code to print the location. An example is |
c5aa993b JM |
3583 | "Breakpoint 1, " which should be followed by |
3584 | the location. | |
917317f4 | 3585 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3586 | to also print the location part of the message. |
3587 | An example is the catch/throw messages, which | |
4a64f543 | 3588 | don't require a location appended to the end. |
917317f4 | 3589 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3590 | further info to be printed. */ |
c906108c | 3591 | |
917317f4 | 3592 | enum print_stop_action |
fba45db2 | 3593 | bpstat_print (bpstat bs) |
c906108c SS |
3594 | { |
3595 | int val; | |
c5aa993b | 3596 | |
c906108c | 3597 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3598 | (Currently all watchpoints go on the bpstat whether hit or not. |
3599 | That probably could (should) be changed, provided care is taken | |
c906108c | 3600 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3601 | for (; bs; bs = bs->next) |
3602 | { | |
3603 | val = print_bp_stop_message (bs); | |
3604 | if (val == PRINT_SRC_ONLY | |
3605 | || val == PRINT_SRC_AND_LOC | |
3606 | || val == PRINT_NOTHING) | |
3607 | return val; | |
3608 | } | |
c906108c | 3609 | |
e514a9d6 | 3610 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3611 | with and nothing was printed. */ |
917317f4 | 3612 | return PRINT_UNKNOWN; |
c906108c SS |
3613 | } |
3614 | ||
4a64f543 MS |
3615 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3616 | used inside a catch_errors to evaluate the breakpoint condition. | |
3617 | The argument is a "struct expression *" that has been cast to a | |
3618 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3619 | |
3620 | static int | |
4efb68b1 | 3621 | breakpoint_cond_eval (void *exp) |
c906108c | 3622 | { |
278cd55f | 3623 | struct value *mark = value_mark (); |
c5aa993b | 3624 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3625 | |
c906108c SS |
3626 | value_free_to_mark (mark); |
3627 | return i; | |
3628 | } | |
3629 | ||
5760d0ab | 3630 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3631 | |
3632 | static bpstat | |
5760d0ab | 3633 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3634 | { |
3635 | bpstat bs; | |
3636 | ||
3637 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3638 | bs->next = NULL; |
3639 | **bs_link_pointer = bs; | |
3640 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3641 | bs->breakpoint_at = bl->owner; |
3642 | bs->bp_location_at = bl; | |
3643 | incref_bp_location (bl); | |
c906108c SS |
3644 | /* If the condition is false, etc., don't do the commands. */ |
3645 | bs->commands = NULL; | |
9add0f1b | 3646 | bs->commands_left = NULL; |
c906108c SS |
3647 | bs->old_val = NULL; |
3648 | bs->print_it = print_it_normal; | |
3649 | return bs; | |
3650 | } | |
3651 | \f | |
d983da9c DJ |
3652 | /* The target has stopped with waitstatus WS. Check if any hardware |
3653 | watchpoints have triggered, according to the target. */ | |
3654 | ||
3655 | int | |
3656 | watchpoints_triggered (struct target_waitstatus *ws) | |
3657 | { | |
d92524f1 | 3658 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3659 | CORE_ADDR addr; |
3660 | struct breakpoint *b; | |
3661 | ||
3662 | if (!stopped_by_watchpoint) | |
3663 | { | |
3664 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3665 | as not triggered. */ | |
3666 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3667 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3668 | b->watchpoint_triggered = watch_triggered_no; |
3669 | ||
3670 | return 0; | |
3671 | } | |
3672 | ||
3673 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3674 | { | |
3675 | /* We were stopped by a watchpoint, but we don't know where. | |
3676 | Mark all watchpoints as unknown. */ | |
3677 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3678 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3679 | b->watchpoint_triggered = watch_triggered_unknown; |
3680 | ||
3681 | return stopped_by_watchpoint; | |
3682 | } | |
3683 | ||
3684 | /* The target could report the data address. Mark watchpoints | |
3685 | affected by this data address as triggered, and all others as not | |
3686 | triggered. */ | |
3687 | ||
3688 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3689 | if (is_hardware_watchpoint (b)) |
d983da9c | 3690 | { |
a5606eee | 3691 | struct bp_location *loc; |
d983da9c DJ |
3692 | |
3693 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee | 3694 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 TJB |
3695 | { |
3696 | if (is_masked_watchpoint (loc->owner)) | |
3697 | { | |
3698 | CORE_ADDR newaddr = addr & loc->owner->hw_wp_mask; | |
3699 | CORE_ADDR start = loc->address & loc->owner->hw_wp_mask; | |
3700 | ||
3701 | if (newaddr == start) | |
3702 | { | |
3703 | b->watchpoint_triggered = watch_triggered_yes; | |
3704 | break; | |
3705 | } | |
3706 | } | |
3707 | /* Exact match not required. Within range is sufficient. */ | |
3708 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3709 | addr, loc->address, | |
3710 | loc->length)) | |
3711 | { | |
3712 | b->watchpoint_triggered = watch_triggered_yes; | |
3713 | break; | |
3714 | } | |
3715 | } | |
d983da9c DJ |
3716 | } |
3717 | ||
3718 | return 1; | |
3719 | } | |
3720 | ||
c906108c SS |
3721 | /* Possible return values for watchpoint_check (this can't be an enum |
3722 | because of check_errors). */ | |
3723 | /* The watchpoint has been deleted. */ | |
3724 | #define WP_DELETED 1 | |
3725 | /* The value has changed. */ | |
3726 | #define WP_VALUE_CHANGED 2 | |
3727 | /* The value has not changed. */ | |
3728 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3729 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3730 | #define WP_IGNORE 4 | |
c906108c SS |
3731 | |
3732 | #define BP_TEMPFLAG 1 | |
3733 | #define BP_HARDWAREFLAG 2 | |
3734 | ||
4a64f543 MS |
3735 | /* Evaluate watchpoint condition expression and check if its value |
3736 | changed. | |
553e4c11 JB |
3737 | |
3738 | P should be a pointer to struct bpstat, but is defined as a void * | |
3739 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3740 | |
3741 | static int | |
4efb68b1 | 3742 | watchpoint_check (void *p) |
c906108c SS |
3743 | { |
3744 | bpstat bs = (bpstat) p; | |
3745 | struct breakpoint *b; | |
3746 | struct frame_info *fr; | |
3747 | int within_current_scope; | |
3748 | ||
f431efe5 | 3749 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3750 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3751 | b = bs->breakpoint_at; |
c906108c | 3752 | |
d0fb5eae JK |
3753 | gdb_assert (is_watchpoint (b)); |
3754 | ||
f6bc2008 PA |
3755 | /* If this is a local watchpoint, we only want to check if the |
3756 | watchpoint frame is in scope if the current thread is the thread | |
3757 | that was used to create the watchpoint. */ | |
3758 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3759 | return WP_IGNORE; |
f6bc2008 | 3760 | |
c906108c SS |
3761 | if (b->exp_valid_block == NULL) |
3762 | within_current_scope = 1; | |
3763 | else | |
3764 | { | |
edb3359d DJ |
3765 | struct frame_info *frame = get_current_frame (); |
3766 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3767 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3768 | ||
4a64f543 MS |
3769 | /* in_function_epilogue_p() returns a non-zero value if we're |
3770 | still in the function but the stack frame has already been | |
3771 | invalidated. Since we can't rely on the values of local | |
3772 | variables after the stack has been destroyed, we are treating | |
3773 | the watchpoint in that state as `not changed' without further | |
3774 | checking. Don't mark watchpoints as changed if the current | |
3775 | frame is in an epilogue - even if they are in some other | |
3776 | frame, our view of the stack is likely to be wrong and | |
3777 | frame_find_by_id could error out. */ | |
a0f49112 | 3778 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3779 | return WP_IGNORE; |
a0f49112 | 3780 | |
101dcfbe | 3781 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3782 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3783 | |
3784 | /* If we've gotten confused in the unwinder, we might have | |
3785 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3786 | if (within_current_scope) |
3787 | { | |
3788 | struct symbol *function; | |
3789 | ||
3790 | function = get_frame_function (fr); | |
3791 | if (function == NULL | |
3792 | || !contained_in (b->exp_valid_block, | |
3793 | SYMBOL_BLOCK_VALUE (function))) | |
3794 | within_current_scope = 0; | |
3795 | } | |
69fbadd5 | 3796 | |
edb3359d | 3797 | if (within_current_scope) |
c906108c SS |
3798 | /* If we end up stopping, the current frame will get selected |
3799 | in normal_stop. So this call to select_frame won't affect | |
3800 | the user. */ | |
0f7d239c | 3801 | select_frame (fr); |
c906108c | 3802 | } |
c5aa993b | 3803 | |
c906108c SS |
3804 | if (within_current_scope) |
3805 | { | |
4a64f543 MS |
3806 | /* We use value_{,free_to_}mark because it could be a *long* |
3807 | time before we return to the command level and call | |
3808 | free_all_values. We can't call free_all_values because we | |
3809 | might be in the middle of evaluating a function call. */ | |
c906108c | 3810 | |
0cf6dd15 | 3811 | int pc = 0; |
9c06b0b4 | 3812 | struct value *mark; |
fa4727a6 DJ |
3813 | struct value *new_val; |
3814 | ||
9c06b0b4 TJB |
3815 | if (is_masked_watchpoint (b)) |
3816 | /* Since we don't know the exact trigger address (from | |
3817 | stopped_data_address), just tell the user we've triggered | |
3818 | a mask watchpoint. */ | |
3819 | return WP_VALUE_CHANGED; | |
3820 | ||
3821 | mark = value_mark (); | |
0cf6dd15 | 3822 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3823 | |
4a64f543 MS |
3824 | /* We use value_equal_contents instead of value_equal because |
3825 | the latter coerces an array to a pointer, thus comparing just | |
3826 | the address of the array instead of its contents. This is | |
3827 | not what we want. */ | |
fa4727a6 | 3828 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3829 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3830 | { |
fa4727a6 DJ |
3831 | if (new_val != NULL) |
3832 | { | |
3833 | release_value (new_val); | |
3834 | value_free_to_mark (mark); | |
3835 | } | |
c906108c SS |
3836 | bs->old_val = b->val; |
3837 | b->val = new_val; | |
fa4727a6 | 3838 | b->val_valid = 1; |
c906108c SS |
3839 | return WP_VALUE_CHANGED; |
3840 | } | |
3841 | else | |
3842 | { | |
60e1c644 | 3843 | /* Nothing changed. */ |
c906108c | 3844 | value_free_to_mark (mark); |
c906108c SS |
3845 | return WP_VALUE_NOT_CHANGED; |
3846 | } | |
3847 | } | |
3848 | else | |
3849 | { | |
3850 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3851 | if we temporarily ignored the watchpoint, then when |
3852 | we reenter the block in which it is valid it contains | |
3853 | garbage (in the case of a function, it may have two | |
3854 | garbage values, one before and one after the prologue). | |
3855 | So we can't even detect the first assignment to it and | |
3856 | watch after that (since the garbage may or may not equal | |
3857 | the first value assigned). */ | |
4ce44c66 JM |
3858 | /* We print all the stop information in print_it_typical(), but |
3859 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3860 | will be deleted already. So we have no choice but print the |
3861 | information here. */ | |
9dc5e2a9 | 3862 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3863 | ui_out_field_string |
3864 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3865 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3866 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3867 | ui_out_text (uiout, |
3868 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3869 | which its expression is valid.\n"); |
4ce44c66 | 3870 | |
cdac0397 PA |
3871 | /* Make sure the watchpoint's commands aren't executed. */ |
3872 | decref_counted_command_line (&b->commands); | |
d0fb5eae | 3873 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3874 | |
3875 | return WP_DELETED; | |
3876 | } | |
3877 | } | |
3878 | ||
18a18393 VP |
3879 | /* Return true if it looks like target has stopped due to hitting |
3880 | breakpoint location BL. This function does not check if we | |
3881 | should stop, only if BL explains the stop. */ | |
3882 | static int | |
6c95b8df PA |
3883 | bpstat_check_location (const struct bp_location *bl, |
3884 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3885 | { |
3886 | struct breakpoint *b = bl->owner; | |
3887 | ||
2bdf28a0 JK |
3888 | /* BL is from existing struct breakpoint. */ |
3889 | gdb_assert (b != NULL); | |
3890 | ||
f1310107 TJB |
3891 | if (b->ops && b->ops->breakpoint_hit) |
3892 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); | |
3893 | ||
e8595ef6 SS |
3894 | /* By definition, the inferior does not report stops at |
3895 | tracepoints. */ | |
d77f58be | 3896 | if (is_tracepoint (b)) |
e8595ef6 SS |
3897 | return 0; |
3898 | ||
cc60f2e3 | 3899 | if (!is_watchpoint (b) |
18a18393 | 3900 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3901 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3902 | { |
6c95b8df PA |
3903 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3904 | aspace, bp_addr)) | |
18a18393 VP |
3905 | return 0; |
3906 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3907 | && section_is_overlay (bl->section) |
18a18393 VP |
3908 | && !section_is_mapped (bl->section)) |
3909 | return 0; | |
3910 | } | |
cc60f2e3 | 3911 | |
18a18393 VP |
3912 | /* Continuable hardware watchpoints are treated as non-existent if the |
3913 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3914 | some data address). Otherwise gdb won't stop on a break instruction | |
3915 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3916 | been defined. Also skip watchpoints which we know did not trigger | |
3917 | (did not match the data address). */ | |
cc60f2e3 PA |
3918 | |
3919 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3920 | && b->watchpoint_triggered == watch_triggered_no) |
3921 | return 0; | |
f1310107 | 3922 | |
18a18393 VP |
3923 | if (b->type == bp_hardware_breakpoint) |
3924 | { | |
3925 | if (bl->address != bp_addr) | |
3926 | return 0; | |
3927 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3928 | && section_is_overlay (bl->section) |
18a18393 VP |
3929 | && !section_is_mapped (bl->section)) |
3930 | return 0; | |
3931 | } | |
ce78b96d | 3932 | |
18a18393 VP |
3933 | return 1; |
3934 | } | |
3935 | ||
3936 | /* If BS refers to a watchpoint, determine if the watched values | |
3937 | has actually changed, and we should stop. If not, set BS->stop | |
3938 | to 0. */ | |
3939 | static void | |
3940 | bpstat_check_watchpoint (bpstat bs) | |
3941 | { | |
2bdf28a0 JK |
3942 | const struct bp_location *bl; |
3943 | struct breakpoint *b; | |
3944 | ||
3945 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3946 | bl = bs->bp_location_at; |
2bdf28a0 | 3947 | gdb_assert (bl != NULL); |
f431efe5 | 3948 | b = bs->breakpoint_at; |
2bdf28a0 | 3949 | gdb_assert (b != NULL); |
18a18393 | 3950 | |
cc60f2e3 | 3951 | if (is_watchpoint (b)) |
18a18393 | 3952 | { |
18a18393 VP |
3953 | int must_check_value = 0; |
3954 | ||
3955 | if (b->type == bp_watchpoint) | |
3956 | /* For a software watchpoint, we must always check the | |
3957 | watched value. */ | |
3958 | must_check_value = 1; | |
3959 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3960 | /* We have a hardware watchpoint (read, write, or access) | |
3961 | and the target earlier reported an address watched by | |
3962 | this watchpoint. */ | |
3963 | must_check_value = 1; | |
3964 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3965 | && b->type == bp_hardware_watchpoint) | |
3966 | /* We were stopped by a hardware watchpoint, but the target could | |
3967 | not report the data address. We must check the watchpoint's | |
3968 | value. Access and read watchpoints are out of luck; without | |
3969 | a data address, we can't figure it out. */ | |
3970 | must_check_value = 1; | |
3971 | ||
3972 | if (must_check_value) | |
3973 | { | |
3e43a32a MS |
3974 | char *message |
3975 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3976 | b->number); | |
18a18393 VP |
3977 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3978 | int e = catch_errors (watchpoint_check, bs, message, | |
3979 | RETURN_MASK_ALL); | |
3980 | do_cleanups (cleanups); | |
3981 | switch (e) | |
3982 | { | |
3983 | case WP_DELETED: | |
3984 | /* We've already printed what needs to be printed. */ | |
3985 | bs->print_it = print_it_done; | |
3986 | /* Stop. */ | |
3987 | break; | |
60e1c644 PA |
3988 | case WP_IGNORE: |
3989 | bs->print_it = print_it_noop; | |
3990 | bs->stop = 0; | |
3991 | break; | |
18a18393 VP |
3992 | case WP_VALUE_CHANGED: |
3993 | if (b->type == bp_read_watchpoint) | |
3994 | { | |
85d721b8 PA |
3995 | /* There are two cases to consider here: |
3996 | ||
4a64f543 | 3997 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3998 | In that case, trust the target, and always report |
3999 | the watchpoint hit to the user. Even though | |
4000 | reads don't cause value changes, the value may | |
4001 | have changed since the last time it was read, and | |
4002 | since we're not trapping writes, we will not see | |
4003 | those, and as such we should ignore our notion of | |
4004 | old value. | |
4005 | ||
4a64f543 | 4006 | 2. We're watching the triggered memory for both |
85d721b8 PA |
4007 | reads and writes. There are two ways this may |
4008 | happen: | |
4009 | ||
4a64f543 | 4010 | 2.1. This is a target that can't break on data |
85d721b8 PA |
4011 | reads only, but can break on accesses (reads or |
4012 | writes), such as e.g., x86. We detect this case | |
4013 | at the time we try to insert read watchpoints. | |
4014 | ||
4a64f543 | 4015 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
4016 | watchpoints, but, the user set an access or write |
4017 | watchpoint watching the same memory as this read | |
4018 | watchpoint. | |
4019 | ||
4020 | If we're watching memory writes as well as reads, | |
4021 | ignore watchpoint hits when we find that the | |
4022 | value hasn't changed, as reads don't cause | |
4023 | changes. This still gives false positives when | |
4024 | the program writes the same value to memory as | |
4025 | what there was already in memory (we will confuse | |
4026 | it for a read), but it's much better than | |
4027 | nothing. */ | |
4028 | ||
4029 | int other_write_watchpoint = 0; | |
4030 | ||
4031 | if (bl->watchpoint_type == hw_read) | |
4032 | { | |
4033 | struct breakpoint *other_b; | |
4034 | ||
4035 | ALL_BREAKPOINTS (other_b) | |
4036 | if ((other_b->type == bp_hardware_watchpoint | |
4037 | || other_b->type == bp_access_watchpoint) | |
4038 | && (other_b->watchpoint_triggered | |
4039 | == watch_triggered_yes)) | |
4040 | { | |
4041 | other_write_watchpoint = 1; | |
4042 | break; | |
4043 | } | |
4044 | } | |
4045 | ||
4046 | if (other_write_watchpoint | |
4047 | || bl->watchpoint_type == hw_access) | |
4048 | { | |
4049 | /* We're watching the same memory for writes, | |
4050 | and the value changed since the last time we | |
4051 | updated it, so this trap must be for a write. | |
4052 | Ignore it. */ | |
4053 | bs->print_it = print_it_noop; | |
4054 | bs->stop = 0; | |
4055 | } | |
18a18393 VP |
4056 | } |
4057 | break; | |
4058 | case WP_VALUE_NOT_CHANGED: | |
4059 | if (b->type == bp_hardware_watchpoint | |
4060 | || b->type == bp_watchpoint) | |
4061 | { | |
4062 | /* Don't stop: write watchpoints shouldn't fire if | |
4063 | the value hasn't changed. */ | |
4064 | bs->print_it = print_it_noop; | |
4065 | bs->stop = 0; | |
4066 | } | |
4067 | /* Stop. */ | |
4068 | break; | |
4069 | default: | |
4070 | /* Can't happen. */ | |
4071 | case 0: | |
4072 | /* Error from catch_errors. */ | |
4073 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
d0fb5eae | 4074 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
4075 | /* We've already printed what needs to be printed. */ |
4076 | bs->print_it = print_it_done; | |
4077 | break; | |
4078 | } | |
4079 | } | |
4080 | else /* must_check_value == 0 */ | |
4081 | { | |
4082 | /* This is a case where some watchpoint(s) triggered, but | |
4083 | not at the address of this watchpoint, or else no | |
4084 | watchpoint triggered after all. So don't print | |
4085 | anything for this watchpoint. */ | |
4086 | bs->print_it = print_it_noop; | |
4087 | bs->stop = 0; | |
4088 | } | |
4089 | } | |
4090 | } | |
4091 | ||
4092 | ||
4093 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4094 | of breakpoint referred to by BS. If we should not stop for this | |
4095 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4096 | |
18a18393 VP |
4097 | static void |
4098 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4099 | { | |
4100 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4101 | const struct bp_location *bl; |
4102 | struct breakpoint *b; | |
4103 | ||
4104 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4105 | bl = bs->bp_location_at; |
2bdf28a0 | 4106 | gdb_assert (bl != NULL); |
f431efe5 | 4107 | b = bs->breakpoint_at; |
2bdf28a0 | 4108 | gdb_assert (b != NULL); |
18a18393 VP |
4109 | |
4110 | if (frame_id_p (b->frame_id) | |
edb3359d | 4111 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4112 | bs->stop = 0; |
4113 | else if (bs->stop) | |
4114 | { | |
4115 | int value_is_zero = 0; | |
60e1c644 PA |
4116 | struct expression *cond; |
4117 | ||
7371cf6d PM |
4118 | /* Evaluate Python breakpoints that have a "stop" |
4119 | method implemented. */ | |
4120 | if (b->py_bp_object) | |
4121 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4122 | ||
60e1c644 PA |
4123 | if (is_watchpoint (b)) |
4124 | cond = b->cond_exp; | |
4125 | else | |
4126 | cond = bl->cond; | |
4127 | ||
f431efe5 | 4128 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4129 | { |
60e1c644 PA |
4130 | int within_current_scope = 1; |
4131 | ||
c5bc3a77 DJ |
4132 | /* We use value_mark and value_free_to_mark because it could |
4133 | be a long time before we return to the command level and | |
4134 | call free_all_values. We can't call free_all_values | |
4135 | because we might be in the middle of evaluating a | |
4136 | function call. */ | |
4137 | struct value *mark = value_mark (); | |
4138 | ||
edb3359d DJ |
4139 | /* Need to select the frame, with all that implies so that |
4140 | the conditions will have the right context. Because we | |
4141 | use the frame, we will not see an inlined function's | |
4142 | variables when we arrive at a breakpoint at the start | |
4143 | of the inlined function; the current frame will be the | |
4144 | call site. */ | |
60e1c644 PA |
4145 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4146 | select_frame (get_current_frame ()); | |
4147 | else | |
4148 | { | |
4149 | struct frame_info *frame; | |
4150 | ||
4151 | /* For local watchpoint expressions, which particular | |
4152 | instance of a local is being watched matters, so we | |
4153 | keep track of the frame to evaluate the expression | |
4154 | in. To evaluate the condition however, it doesn't | |
4155 | really matter which instantiation of the function | |
4156 | where the condition makes sense triggers the | |
4157 | watchpoint. This allows an expression like "watch | |
4158 | global if q > 10" set in `func', catch writes to | |
4159 | global on all threads that call `func', or catch | |
4160 | writes on all recursive calls of `func' by a single | |
4161 | thread. We simply always evaluate the condition in | |
4162 | the innermost frame that's executing where it makes | |
4163 | sense to evaluate the condition. It seems | |
4164 | intuitive. */ | |
4165 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4166 | if (frame != NULL) | |
4167 | select_frame (frame); | |
4168 | else | |
4169 | within_current_scope = 0; | |
4170 | } | |
4171 | if (within_current_scope) | |
4172 | value_is_zero | |
4173 | = catch_errors (breakpoint_cond_eval, cond, | |
4174 | "Error in testing breakpoint condition:\n", | |
4175 | RETURN_MASK_ALL); | |
4176 | else | |
4177 | { | |
4178 | warning (_("Watchpoint condition cannot be tested " | |
4179 | "in the current scope")); | |
4180 | /* If we failed to set the right context for this | |
4181 | watchpoint, unconditionally report it. */ | |
4182 | value_is_zero = 0; | |
4183 | } | |
4a64f543 | 4184 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4185 | value_free_to_mark (mark); |
18a18393 | 4186 | } |
60e1c644 PA |
4187 | |
4188 | if (cond && value_is_zero) | |
18a18393 VP |
4189 | { |
4190 | bs->stop = 0; | |
4191 | } | |
4192 | else if (b->thread != -1 && b->thread != thread_id) | |
4193 | { | |
4194 | bs->stop = 0; | |
4195 | } | |
4196 | else if (b->ignore_count > 0) | |
4197 | { | |
4198 | b->ignore_count--; | |
4199 | annotate_ignore_count_change (); | |
4200 | bs->stop = 0; | |
4a64f543 | 4201 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4202 | ++(b->hit_count); |
8d3788bd | 4203 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4204 | } |
4205 | } | |
4206 | } | |
4207 | ||
4208 | ||
9709f61c | 4209 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4210 | BP_ADDR in thread PTID. |
c906108c | 4211 | |
d983da9c | 4212 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4213 | don't understand this stop. Result is a chain of bpstat's such |
4214 | that: | |
c906108c | 4215 | |
c5aa993b | 4216 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4217 | |
c5aa993b | 4218 | if we understand why we stopped, the result is not null. |
c906108c | 4219 | |
c5aa993b JM |
4220 | Each element of the chain refers to a particular breakpoint or |
4221 | watchpoint at which we have stopped. (We may have stopped for | |
4222 | several reasons concurrently.) | |
c906108c | 4223 | |
c5aa993b JM |
4224 | Each element of the chain has valid next, breakpoint_at, |
4225 | commands, FIXME??? fields. */ | |
c906108c SS |
4226 | |
4227 | bpstat | |
6c95b8df PA |
4228 | bpstat_stop_status (struct address_space *aspace, |
4229 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4230 | { |
0d381245 | 4231 | struct breakpoint *b = NULL; |
afe38095 | 4232 | struct bp_location *bl; |
20874c92 | 4233 | struct bp_location *loc; |
5760d0ab JK |
4234 | /* First item of allocated bpstat's. */ |
4235 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4236 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4237 | bpstat bs; |
20874c92 | 4238 | int ix; |
429374b8 | 4239 | int need_remove_insert; |
f431efe5 | 4240 | int removed_any; |
c906108c | 4241 | |
f431efe5 PA |
4242 | /* First, build the bpstat chain with locations that explain a |
4243 | target stop, while being careful to not set the target running, | |
4244 | as that may invalidate locations (in particular watchpoint | |
4245 | locations are recreated). Resuming will happen here with | |
4246 | breakpoint conditions or watchpoint expressions that include | |
4247 | inferior function calls. */ | |
c5aa993b | 4248 | |
429374b8 JK |
4249 | ALL_BREAKPOINTS (b) |
4250 | { | |
4251 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4252 | continue; | |
a5606eee | 4253 | |
429374b8 JK |
4254 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4255 | { | |
4a64f543 MS |
4256 | /* For hardware watchpoints, we look only at the first |
4257 | location. The watchpoint_check function will work on the | |
4258 | entire expression, not the individual locations. For | |
4259 | read watchpoints, the watchpoints_triggered function has | |
4260 | checked all locations already. */ | |
429374b8 JK |
4261 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4262 | break; | |
18a18393 | 4263 | |
429374b8 JK |
4264 | if (bl->shlib_disabled) |
4265 | continue; | |
c5aa993b | 4266 | |
429374b8 JK |
4267 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4268 | continue; | |
c5aa993b | 4269 | |
4a64f543 MS |
4270 | /* Come here if it's a watchpoint, or if the break address |
4271 | matches. */ | |
c5aa993b | 4272 | |
4a64f543 MS |
4273 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4274 | explain stop. */ | |
c5aa993b | 4275 | |
f431efe5 PA |
4276 | /* Assume we stop. Should we find a watchpoint that is not |
4277 | actually triggered, or if the condition of the breakpoint | |
4278 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4279 | bs->stop = 1; |
4280 | bs->print = 1; | |
d983da9c | 4281 | |
f431efe5 PA |
4282 | /* If this is a scope breakpoint, mark the associated |
4283 | watchpoint as triggered so that we will handle the | |
4284 | out-of-scope event. We'll get to the watchpoint next | |
4285 | iteration. */ | |
d0fb5eae | 4286 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
f431efe5 PA |
4287 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; |
4288 | } | |
4289 | } | |
4290 | ||
4291 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4292 | { | |
f1310107 | 4293 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4294 | { |
5760d0ab | 4295 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4296 | /* For hits of moribund locations, we should just proceed. */ |
4297 | bs->stop = 0; | |
4298 | bs->print = 0; | |
4299 | bs->print_it = print_it_noop; | |
4300 | } | |
4301 | } | |
4302 | ||
f431efe5 PA |
4303 | /* Now go through the locations that caused the target to stop, and |
4304 | check whether we're interested in reporting this stop to higher | |
4305 | layers, or whether we should resume the target transparently. */ | |
4306 | ||
4307 | removed_any = 0; | |
4308 | ||
5760d0ab | 4309 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4310 | { |
4311 | if (!bs->stop) | |
4312 | continue; | |
4313 | ||
4314 | bpstat_check_watchpoint (bs); | |
4315 | if (!bs->stop) | |
4316 | continue; | |
4317 | ||
4318 | b = bs->breakpoint_at; | |
18a18393 | 4319 | |
429374b8 | 4320 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4321 | || b->type == bp_longjmp_master |
186c406b TT |
4322 | || b->type == bp_std_terminate_master |
4323 | || b->type == bp_exception_master) | |
429374b8 JK |
4324 | /* We do not stop for these. */ |
4325 | bs->stop = 0; | |
4326 | else | |
4327 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4328 | |
429374b8 JK |
4329 | if (bs->stop) |
4330 | { | |
4331 | ++(b->hit_count); | |
8d3788bd | 4332 | observer_notify_breakpoint_modified (b); |
c906108c | 4333 | |
4a64f543 | 4334 | /* We will stop here. */ |
429374b8 JK |
4335 | if (b->disposition == disp_disable) |
4336 | { | |
4337 | if (b->enable_state != bp_permanent) | |
4338 | b->enable_state = bp_disabled; | |
f431efe5 | 4339 | removed_any = 1; |
429374b8 JK |
4340 | } |
4341 | if (b->silent) | |
4342 | bs->print = 0; | |
4343 | bs->commands = b->commands; | |
9add0f1b TT |
4344 | incref_counted_command_line (bs->commands); |
4345 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4346 | if (bs->commands_left | |
4347 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4348 | || (xdb_commands | |
4349 | && strcmp ("Q", | |
4350 | bs->commands_left->line) == 0))) | |
429374b8 | 4351 | { |
9add0f1b | 4352 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4353 | bs->print = 0; |
4354 | } | |
429374b8 JK |
4355 | } |
4356 | ||
4357 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4358 | if (bs->stop == 0 || bs->print == 0) | |
4359 | bs->print_it = print_it_noop; | |
429374b8 | 4360 | } |
876fa593 | 4361 | |
d983da9c DJ |
4362 | /* If we aren't stopping, the value of some hardware watchpoint may |
4363 | not have changed, but the intermediate memory locations we are | |
4364 | watching may have. Don't bother if we're stopping; this will get | |
4365 | done later. */ | |
d832cb68 | 4366 | need_remove_insert = 0; |
5760d0ab JK |
4367 | if (! bpstat_causes_stop (bs_head)) |
4368 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4369 | if (!bs->stop |
f431efe5 PA |
4370 | && bs->breakpoint_at |
4371 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4372 | { |
4a64f543 | 4373 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4374 | need_remove_insert = 1; |
d983da9c DJ |
4375 | } |
4376 | ||
d832cb68 | 4377 | if (need_remove_insert) |
2d134ed3 | 4378 | update_global_location_list (1); |
f431efe5 PA |
4379 | else if (removed_any) |
4380 | update_global_location_list (0); | |
d832cb68 | 4381 | |
5760d0ab | 4382 | return bs_head; |
c906108c | 4383 | } |
628fe4e4 JK |
4384 | |
4385 | static void | |
4386 | handle_jit_event (void) | |
4387 | { | |
4388 | struct frame_info *frame; | |
4389 | struct gdbarch *gdbarch; | |
4390 | ||
4391 | /* Switch terminal for any messages produced by | |
4392 | breakpoint_re_set. */ | |
4393 | target_terminal_ours_for_output (); | |
4394 | ||
4395 | frame = get_current_frame (); | |
4396 | gdbarch = get_frame_arch (frame); | |
4397 | ||
4398 | jit_event_handler (gdbarch); | |
4399 | ||
4400 | target_terminal_inferior (); | |
4401 | } | |
4402 | ||
4403 | /* Prepare WHAT final decision for infrun. */ | |
4404 | ||
4405 | /* Decide what infrun needs to do with this bpstat. */ | |
4406 | ||
c906108c | 4407 | struct bpstat_what |
0e30163f | 4408 | bpstat_what (bpstat bs_head) |
c906108c | 4409 | { |
c906108c | 4410 | struct bpstat_what retval; |
628fe4e4 JK |
4411 | /* We need to defer calling `solib_add', as adding new symbols |
4412 | resets breakpoints, which in turn deletes breakpoint locations, | |
4413 | and hence may clear unprocessed entries in the BS chain. */ | |
4414 | int shlib_event = 0; | |
4415 | int jit_event = 0; | |
0e30163f | 4416 | bpstat bs; |
c906108c | 4417 | |
628fe4e4 | 4418 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4419 | retval.call_dummy = STOP_NONE; |
186c406b | 4420 | retval.is_longjmp = 0; |
628fe4e4 | 4421 | |
0e30163f | 4422 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4423 | { |
628fe4e4 JK |
4424 | /* Extract this BS's action. After processing each BS, we check |
4425 | if its action overrides all we've seem so far. */ | |
4426 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4427 | enum bptype bptype; | |
4428 | ||
c906108c | 4429 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4430 | { |
4431 | /* I suspect this can happen if it was a momentary | |
4432 | breakpoint which has since been deleted. */ | |
4433 | bptype = bp_none; | |
4434 | } | |
f431efe5 | 4435 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4436 | bptype = bp_none; |
20874c92 | 4437 | else |
f431efe5 | 4438 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4439 | |
4440 | switch (bptype) | |
c906108c SS |
4441 | { |
4442 | case bp_none: | |
628fe4e4 | 4443 | break; |
c906108c SS |
4444 | case bp_breakpoint: |
4445 | case bp_hardware_breakpoint: | |
4446 | case bp_until: | |
4447 | case bp_finish: | |
4448 | if (bs->stop) | |
4449 | { | |
4450 | if (bs->print) | |
628fe4e4 | 4451 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4452 | else |
628fe4e4 | 4453 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4454 | } |
4455 | else | |
628fe4e4 | 4456 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4457 | break; |
4458 | case bp_watchpoint: | |
4459 | case bp_hardware_watchpoint: | |
4460 | case bp_read_watchpoint: | |
4461 | case bp_access_watchpoint: | |
4462 | if (bs->stop) | |
4463 | { | |
4464 | if (bs->print) | |
628fe4e4 | 4465 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4466 | else |
628fe4e4 | 4467 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4468 | } |
4469 | else | |
628fe4e4 JK |
4470 | { |
4471 | /* There was a watchpoint, but we're not stopping. | |
4472 | This requires no further action. */ | |
4473 | } | |
c906108c SS |
4474 | break; |
4475 | case bp_longjmp: | |
186c406b | 4476 | case bp_exception: |
628fe4e4 | 4477 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4478 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4479 | break; |
4480 | case bp_longjmp_resume: | |
186c406b | 4481 | case bp_exception_resume: |
628fe4e4 | 4482 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4483 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4484 | break; |
4485 | case bp_step_resume: | |
4486 | if (bs->stop) | |
628fe4e4 JK |
4487 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4488 | else | |
c906108c | 4489 | { |
628fe4e4 JK |
4490 | /* It is for the wrong frame. */ |
4491 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4492 | } |
c906108c | 4493 | break; |
2c03e5be PA |
4494 | case bp_hp_step_resume: |
4495 | if (bs->stop) | |
4496 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4497 | else | |
4498 | { | |
4499 | /* It is for the wrong frame. */ | |
4500 | this_action = BPSTAT_WHAT_SINGLE; | |
4501 | } | |
4502 | break; | |
c906108c | 4503 | case bp_watchpoint_scope: |
c4093a6a | 4504 | case bp_thread_event: |
1900040c | 4505 | case bp_overlay_event: |
0fd8e87f | 4506 | case bp_longjmp_master: |
aa7d318d | 4507 | case bp_std_terminate_master: |
186c406b | 4508 | case bp_exception_master: |
628fe4e4 | 4509 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4510 | break; |
ce78b96d | 4511 | case bp_catchpoint: |
c5aa993b JM |
4512 | if (bs->stop) |
4513 | { | |
4514 | if (bs->print) | |
628fe4e4 | 4515 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4516 | else |
628fe4e4 | 4517 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4518 | } |
4519 | else | |
628fe4e4 JK |
4520 | { |
4521 | /* There was a catchpoint, but we're not stopping. | |
4522 | This requires no further action. */ | |
4523 | } | |
4524 | break; | |
4525 | case bp_shlib_event: | |
4526 | shlib_event = 1; | |
4527 | ||
4528 | /* If requested, stop when the dynamic linker notifies GDB | |
4529 | of events. This allows the user to get control and place | |
4530 | breakpoints in initializer routines for dynamically | |
4531 | loaded objects (among other things). */ | |
4532 | if (stop_on_solib_events) | |
4533 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4534 | else | |
4535 | this_action = BPSTAT_WHAT_SINGLE; | |
4536 | break; | |
4537 | case bp_jit_event: | |
4538 | jit_event = 1; | |
4539 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4540 | break; |
c906108c | 4541 | case bp_call_dummy: |
53a5351d JM |
4542 | /* Make sure the action is stop (silent or noisy), |
4543 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4544 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4545 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4546 | break; |
4547 | case bp_std_terminate: | |
4548 | /* Make sure the action is stop (silent or noisy), | |
4549 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4550 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4551 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4552 | break; |
1042e4c0 | 4553 | case bp_tracepoint: |
7a697b8d | 4554 | case bp_fast_tracepoint: |
0fb4aa4b | 4555 | case bp_static_tracepoint: |
1042e4c0 SS |
4556 | /* Tracepoint hits should not be reported back to GDB, and |
4557 | if one got through somehow, it should have been filtered | |
4558 | out already. */ | |
4559 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4560 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4561 | break; |
4562 | case bp_gnu_ifunc_resolver: | |
4563 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4564 | this_action = BPSTAT_WHAT_SINGLE; | |
4565 | break; | |
4566 | case bp_gnu_ifunc_resolver_return: | |
4567 | /* The breakpoint will be removed, execution will restart from the | |
4568 | PC of the former breakpoint. */ | |
4569 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4570 | break; | |
628fe4e4 JK |
4571 | default: |
4572 | internal_error (__FILE__, __LINE__, | |
4573 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4574 | } |
628fe4e4 JK |
4575 | |
4576 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4577 | } |
628fe4e4 | 4578 | |
0e30163f JK |
4579 | /* These operations may affect the bs->breakpoint_at state so they are |
4580 | delayed after MAIN_ACTION is decided above. */ | |
4581 | ||
628fe4e4 JK |
4582 | if (shlib_event) |
4583 | { | |
4584 | if (debug_infrun) | |
4585 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4586 | ||
4587 | /* Check for any newly added shared libraries if we're supposed | |
4588 | to be adding them automatically. */ | |
4589 | ||
4590 | /* Switch terminal for any messages produced by | |
4591 | breakpoint_re_set. */ | |
4592 | target_terminal_ours_for_output (); | |
4593 | ||
4594 | #ifdef SOLIB_ADD | |
4595 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4596 | #else | |
4597 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4598 | #endif | |
4599 | ||
4600 | target_terminal_inferior (); | |
4601 | } | |
4602 | ||
4603 | if (jit_event) | |
4604 | { | |
4605 | if (debug_infrun) | |
4606 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4607 | ||
4608 | handle_jit_event (); | |
4609 | } | |
4610 | ||
0e30163f JK |
4611 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4612 | { | |
4613 | struct breakpoint *b = bs->breakpoint_at; | |
4614 | ||
4615 | if (b == NULL) | |
4616 | continue; | |
4617 | switch (b->type) | |
4618 | { | |
4619 | case bp_gnu_ifunc_resolver: | |
4620 | gnu_ifunc_resolver_stop (b); | |
4621 | break; | |
4622 | case bp_gnu_ifunc_resolver_return: | |
4623 | gnu_ifunc_resolver_return_stop (b); | |
4624 | break; | |
4625 | } | |
4626 | } | |
4627 | ||
c906108c SS |
4628 | return retval; |
4629 | } | |
4630 | ||
4631 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4632 | without hardware support). This isn't related to a specific bpstat, | |
4633 | just to things like whether watchpoints are set. */ | |
4634 | ||
c5aa993b | 4635 | int |
fba45db2 | 4636 | bpstat_should_step (void) |
c906108c SS |
4637 | { |
4638 | struct breakpoint *b; | |
cc59ec59 | 4639 | |
c906108c | 4640 | ALL_BREAKPOINTS (b) |
717a8278 | 4641 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4642 | return 1; |
c906108c SS |
4643 | return 0; |
4644 | } | |
4645 | ||
67822962 PA |
4646 | int |
4647 | bpstat_causes_stop (bpstat bs) | |
4648 | { | |
4649 | for (; bs != NULL; bs = bs->next) | |
4650 | if (bs->stop) | |
4651 | return 1; | |
4652 | ||
4653 | return 0; | |
4654 | } | |
4655 | ||
c906108c | 4656 | \f |
c5aa993b | 4657 | |
170b53b2 UW |
4658 | /* Compute a string of spaces suitable to indent the next line |
4659 | so it starts at the position corresponding to the table column | |
4660 | named COL_NAME in the currently active table of UIOUT. */ | |
4661 | ||
4662 | static char * | |
4663 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4664 | { | |
4665 | static char wrap_indent[80]; | |
4666 | int i, total_width, width, align; | |
4667 | char *text; | |
4668 | ||
4669 | total_width = 0; | |
4670 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4671 | { | |
4672 | if (strcmp (text, col_name) == 0) | |
4673 | { | |
4674 | gdb_assert (total_width < sizeof wrap_indent); | |
4675 | memset (wrap_indent, ' ', total_width); | |
4676 | wrap_indent[total_width] = 0; | |
4677 | ||
4678 | return wrap_indent; | |
4679 | } | |
4680 | ||
4681 | total_width += width + 1; | |
4682 | } | |
4683 | ||
4684 | return NULL; | |
4685 | } | |
4686 | ||
859825b8 JK |
4687 | /* Print the LOC location out of the list of B->LOC locations. */ |
4688 | ||
170b53b2 UW |
4689 | static void |
4690 | print_breakpoint_location (struct breakpoint *b, | |
4691 | struct bp_location *loc) | |
0d381245 | 4692 | { |
6c95b8df PA |
4693 | struct cleanup *old_chain = save_current_program_space (); |
4694 | ||
859825b8 JK |
4695 | if (loc != NULL && loc->shlib_disabled) |
4696 | loc = NULL; | |
4697 | ||
6c95b8df PA |
4698 | if (loc != NULL) |
4699 | set_current_program_space (loc->pspace); | |
4700 | ||
56435ebe TT |
4701 | if (b->display_canonical) |
4702 | ui_out_field_string (uiout, "what", b->addr_string); | |
4703 | else if (b->source_file && loc) | |
0d381245 VP |
4704 | { |
4705 | struct symbol *sym | |
4706 | = find_pc_sect_function (loc->address, loc->section); | |
4707 | if (sym) | |
4708 | { | |
4709 | ui_out_text (uiout, "in "); | |
4710 | ui_out_field_string (uiout, "func", | |
4711 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4712 | ui_out_text (uiout, " "); |
4713 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4714 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4715 | } |
4716 | ui_out_field_string (uiout, "file", b->source_file); | |
4717 | ui_out_text (uiout, ":"); | |
4718 | ||
4719 | if (ui_out_is_mi_like_p (uiout)) | |
4720 | { | |
4721 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4722 | char *fullname = symtab_to_fullname (sal.symtab); | |
4723 | ||
4724 | if (fullname) | |
4725 | ui_out_field_string (uiout, "fullname", fullname); | |
4726 | } | |
4727 | ||
4728 | ui_out_field_int (uiout, "line", b->line_number); | |
4729 | } | |
859825b8 | 4730 | else if (loc) |
0d381245 | 4731 | { |
170b53b2 UW |
4732 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4733 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4734 | ||
22e722e1 DJ |
4735 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4736 | demangle, ""); | |
0d381245 | 4737 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4738 | |
4739 | do_cleanups (stb_chain); | |
0d381245 | 4740 | } |
859825b8 JK |
4741 | else |
4742 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4743 | |
4744 | do_cleanups (old_chain); | |
0d381245 VP |
4745 | } |
4746 | ||
269b11a2 PA |
4747 | static const char * |
4748 | bptype_string (enum bptype type) | |
c906108c | 4749 | { |
c4093a6a JM |
4750 | struct ep_type_description |
4751 | { | |
4752 | enum bptype type; | |
4753 | char *description; | |
4754 | }; | |
4755 | static struct ep_type_description bptypes[] = | |
c906108c | 4756 | { |
c5aa993b JM |
4757 | {bp_none, "?deleted?"}, |
4758 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4759 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4760 | {bp_until, "until"}, |
4761 | {bp_finish, "finish"}, | |
4762 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4763 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4764 | {bp_read_watchpoint, "read watchpoint"}, |
4765 | {bp_access_watchpoint, "acc watchpoint"}, | |
4766 | {bp_longjmp, "longjmp"}, | |
4767 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4768 | {bp_exception, "exception"}, |
4769 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4770 | {bp_step_resume, "step resume"}, |
2c03e5be | 4771 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4772 | {bp_watchpoint_scope, "watchpoint scope"}, |
4773 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4774 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4775 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4776 | {bp_thread_event, "thread events"}, |
1900040c | 4777 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4778 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4779 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4780 | {bp_exception_master, "exception master"}, |
ce78b96d | 4781 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4782 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4783 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4784 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4785 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4786 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4787 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4788 | }; |
269b11a2 PA |
4789 | |
4790 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4791 | || ((int) type != bptypes[(int) type].type)) | |
4792 | internal_error (__FILE__, __LINE__, | |
4793 | _("bptypes table does not describe type #%d."), | |
4794 | (int) type); | |
4795 | ||
4796 | return bptypes[(int) type].description; | |
4797 | } | |
4798 | ||
4799 | /* Print B to gdb_stdout. */ | |
4800 | ||
4801 | static void | |
4802 | print_one_breakpoint_location (struct breakpoint *b, | |
4803 | struct bp_location *loc, | |
4804 | int loc_number, | |
4805 | struct bp_location **last_loc, | |
269b11a2 PA |
4806 | int allflag) |
4807 | { | |
4808 | struct command_line *l; | |
c2c6d25f | 4809 | static char bpenables[] = "nynny"; |
c906108c | 4810 | |
0d381245 VP |
4811 | int header_of_multiple = 0; |
4812 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4813 | struct value_print_options opts; |
4814 | ||
4815 | get_user_print_options (&opts); | |
0d381245 VP |
4816 | |
4817 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4818 | /* See comment in print_one_breakpoint concerning treatment of |
4819 | breakpoints with single disabled location. */ | |
0d381245 VP |
4820 | if (loc == NULL |
4821 | && (b->loc != NULL | |
4822 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4823 | header_of_multiple = 1; | |
4824 | if (loc == NULL) | |
4825 | loc = b->loc; | |
4826 | ||
c4093a6a JM |
4827 | annotate_record (); |
4828 | ||
4829 | /* 1 */ | |
4830 | annotate_field (0); | |
0d381245 VP |
4831 | if (part_of_multiple) |
4832 | { | |
4833 | char *formatted; | |
0c6773c1 | 4834 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4835 | ui_out_field_string (uiout, "number", formatted); |
4836 | xfree (formatted); | |
4837 | } | |
4838 | else | |
4839 | { | |
4840 | ui_out_field_int (uiout, "number", b->number); | |
4841 | } | |
c4093a6a JM |
4842 | |
4843 | /* 2 */ | |
4844 | annotate_field (1); | |
0d381245 VP |
4845 | if (part_of_multiple) |
4846 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4847 | else |
4848 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4849 | |
4850 | /* 3 */ | |
4851 | annotate_field (2); | |
0d381245 VP |
4852 | if (part_of_multiple) |
4853 | ui_out_field_skip (uiout, "disp"); | |
4854 | else | |
2cec12e5 | 4855 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4856 | |
c4093a6a JM |
4857 | |
4858 | /* 4 */ | |
4859 | annotate_field (3); | |
0d381245 | 4860 | if (part_of_multiple) |
54e52265 | 4861 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4862 | else |
4a64f543 MS |
4863 | ui_out_field_fmt (uiout, "enabled", "%c", |
4864 | bpenables[(int) b->enable_state]); | |
54e52265 | 4865 | ui_out_spaces (uiout, 2); |
0d381245 | 4866 | |
c4093a6a JM |
4867 | |
4868 | /* 5 and 6 */ | |
3086aeae | 4869 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4870 | { |
4a64f543 MS |
4871 | /* Although the print_one can possibly print all locations, |
4872 | calling it here is not likely to get any nice result. So, | |
4873 | make sure there's just one location. */ | |
0d381245 | 4874 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4875 | b->ops->print_one (b, last_loc); |
0d381245 | 4876 | } |
3086aeae DJ |
4877 | else |
4878 | switch (b->type) | |
4879 | { | |
4880 | case bp_none: | |
4881 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4882 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4883 | break; |
c906108c | 4884 | |
3086aeae DJ |
4885 | case bp_watchpoint: |
4886 | case bp_hardware_watchpoint: | |
4887 | case bp_read_watchpoint: | |
4888 | case bp_access_watchpoint: | |
4889 | /* Field 4, the address, is omitted (which makes the columns | |
4890 | not line up too nicely with the headers, but the effect | |
4891 | is relatively readable). */ | |
79a45b7d | 4892 | if (opts.addressprint) |
3086aeae DJ |
4893 | ui_out_field_skip (uiout, "addr"); |
4894 | annotate_field (5); | |
fa8a61dc | 4895 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4896 | break; |
4897 | ||
3086aeae DJ |
4898 | case bp_breakpoint: |
4899 | case bp_hardware_breakpoint: | |
4900 | case bp_until: | |
4901 | case bp_finish: | |
4902 | case bp_longjmp: | |
4903 | case bp_longjmp_resume: | |
186c406b TT |
4904 | case bp_exception: |
4905 | case bp_exception_resume: | |
3086aeae | 4906 | case bp_step_resume: |
2c03e5be | 4907 | case bp_hp_step_resume: |
3086aeae DJ |
4908 | case bp_watchpoint_scope: |
4909 | case bp_call_dummy: | |
aa7d318d | 4910 | case bp_std_terminate: |
3086aeae DJ |
4911 | case bp_shlib_event: |
4912 | case bp_thread_event: | |
4913 | case bp_overlay_event: | |
0fd8e87f | 4914 | case bp_longjmp_master: |
aa7d318d | 4915 | case bp_std_terminate_master: |
186c406b | 4916 | case bp_exception_master: |
1042e4c0 | 4917 | case bp_tracepoint: |
7a697b8d | 4918 | case bp_fast_tracepoint: |
0fb4aa4b | 4919 | case bp_static_tracepoint: |
4efc6507 | 4920 | case bp_jit_event: |
0e30163f JK |
4921 | case bp_gnu_ifunc_resolver: |
4922 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4923 | if (opts.addressprint) |
3086aeae DJ |
4924 | { |
4925 | annotate_field (4); | |
54e52265 | 4926 | if (header_of_multiple) |
0d381245 | 4927 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4928 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4929 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4930 | else |
5af949e3 UW |
4931 | ui_out_field_core_addr (uiout, "addr", |
4932 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4933 | } |
4934 | annotate_field (5); | |
0d381245 | 4935 | if (!header_of_multiple) |
170b53b2 | 4936 | print_breakpoint_location (b, loc); |
0d381245 | 4937 | if (b->loc) |
a6d9a66e | 4938 | *last_loc = b->loc; |
3086aeae DJ |
4939 | break; |
4940 | } | |
c906108c | 4941 | |
6c95b8df PA |
4942 | |
4943 | /* For backward compatibility, don't display inferiors unless there | |
4944 | are several. */ | |
4945 | if (loc != NULL | |
4946 | && !header_of_multiple | |
4947 | && (allflag | |
4948 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4949 | && (number_of_program_spaces () > 1 | |
4950 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4951 | /* LOC is for existing B, it cannot be in |
4952 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4953 | && loc->owner->type != bp_catchpoint))) |
4954 | { | |
4955 | struct inferior *inf; | |
4956 | int first = 1; | |
4957 | ||
4958 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4959 | { | |
4960 | if (inf->pspace == loc->pspace) | |
4961 | { | |
4962 | if (first) | |
4963 | { | |
4964 | first = 0; | |
4965 | ui_out_text (uiout, " inf "); | |
4966 | } | |
4967 | else | |
4968 | ui_out_text (uiout, ", "); | |
4969 | ui_out_text (uiout, plongest (inf->num)); | |
4970 | } | |
4971 | } | |
4972 | } | |
4973 | ||
4a306c9a | 4974 | if (!part_of_multiple) |
c4093a6a | 4975 | { |
4a306c9a JB |
4976 | if (b->thread != -1) |
4977 | { | |
4978 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4979 | "stop only in" line a little further down. */ |
4a306c9a JB |
4980 | ui_out_text (uiout, " thread "); |
4981 | ui_out_field_int (uiout, "thread", b->thread); | |
4982 | } | |
4983 | else if (b->task != 0) | |
4984 | { | |
4985 | ui_out_text (uiout, " task "); | |
4986 | ui_out_field_int (uiout, "task", b->task); | |
4987 | } | |
c4093a6a | 4988 | } |
f1310107 | 4989 | |
8b93c638 | 4990 | ui_out_text (uiout, "\n"); |
f1310107 TJB |
4991 | |
4992 | if (!part_of_multiple && b->ops && b->ops->print_one_detail) | |
4993 | b->ops->print_one_detail (b, uiout); | |
4994 | ||
0fb4aa4b PA |
4995 | if (!part_of_multiple && b->static_trace_marker_id) |
4996 | { | |
4997 | gdb_assert (b->type == bp_static_tracepoint); | |
4998 | ||
4999 | ui_out_text (uiout, "\tmarker id is "); | |
5000 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
5001 | b->static_trace_marker_id); | |
5002 | ui_out_text (uiout, "\n"); | |
5003 | } | |
5004 | ||
0d381245 | 5005 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
5006 | { |
5007 | annotate_field (6); | |
8b93c638 | 5008 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
5009 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
5010 | the frame ID. */ | |
5af949e3 UW |
5011 | ui_out_field_core_addr (uiout, "frame", |
5012 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 5013 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
5014 | } |
5015 | ||
0d381245 | 5016 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 5017 | { |
f7f9143b JB |
5018 | /* We do not print the condition for Ada exception catchpoints |
5019 | because the condition is an internal implementation detail | |
5020 | that we do not want to expose to the user. */ | |
c4093a6a | 5021 | annotate_field (7); |
d77f58be | 5022 | if (is_tracepoint (b)) |
1042e4c0 SS |
5023 | ui_out_text (uiout, "\ttrace only if "); |
5024 | else | |
5025 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
5026 | ui_out_field_string (uiout, "cond", b->cond_string); |
5027 | ui_out_text (uiout, "\n"); | |
5028 | } | |
5029 | ||
0d381245 | 5030 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 5031 | { |
4a64f543 | 5032 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5033 | ui_out_text (uiout, "\tstop only in thread "); |
5034 | ui_out_field_int (uiout, "thread", b->thread); | |
5035 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
5036 | } |
5037 | ||
63c715c6 | 5038 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 5039 | { |
4a64f543 | 5040 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5041 | if (ep_is_catchpoint (b)) |
5042 | ui_out_text (uiout, "\tcatchpoint"); | |
5043 | else | |
5044 | ui_out_text (uiout, "\tbreakpoint"); | |
5045 | ui_out_text (uiout, " already hit "); | |
5046 | ui_out_field_int (uiout, "times", b->hit_count); | |
5047 | if (b->hit_count == 1) | |
5048 | ui_out_text (uiout, " time\n"); | |
5049 | else | |
5050 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
5051 | } |
5052 | ||
4a64f543 MS |
5053 | /* Output the count also if it is zero, but only if this is mi. |
5054 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 5055 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 5056 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 5057 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 5058 | |
0d381245 | 5059 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
5060 | { |
5061 | annotate_field (8); | |
8b93c638 JM |
5062 | ui_out_text (uiout, "\tignore next "); |
5063 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
5064 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 5065 | } |
059fb39f | 5066 | |
9add0f1b | 5067 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 5068 | if (!part_of_multiple && l) |
c4093a6a | 5069 | { |
3b31d625 EZ |
5070 | struct cleanup *script_chain; |
5071 | ||
c4093a6a | 5072 | annotate_field (9); |
3b31d625 | 5073 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 5074 | print_command_lines (uiout, l, 4); |
3b31d625 | 5075 | do_cleanups (script_chain); |
c4093a6a | 5076 | } |
d24317b4 | 5077 | |
1042e4c0 SS |
5078 | if (!part_of_multiple && b->pass_count) |
5079 | { | |
5080 | annotate_field (10); | |
5081 | ui_out_text (uiout, "\tpass count "); | |
5082 | ui_out_field_int (uiout, "pass", b->pass_count); | |
5083 | ui_out_text (uiout, " \n"); | |
5084 | } | |
5085 | ||
d24317b4 VP |
5086 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5087 | { | |
5088 | if (b->addr_string) | |
5089 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
5090 | else if (b->exp_string) | |
5091 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
5092 | } | |
c4093a6a | 5093 | } |
c5aa993b | 5094 | |
0d381245 VP |
5095 | static void |
5096 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5097 | struct bp_location **last_loc, |
6c95b8df | 5098 | int allflag) |
0d381245 | 5099 | { |
8d3788bd VP |
5100 | struct cleanup *bkpt_chain; |
5101 | ||
5102 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
5103 | ||
12c5a436 | 5104 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 5105 | do_cleanups (bkpt_chain); |
0d381245 VP |
5106 | |
5107 | /* If this breakpoint has custom print function, | |
5108 | it's already printed. Otherwise, print individual | |
5109 | locations, if any. */ | |
5110 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5111 | { | |
4a64f543 MS |
5112 | /* If breakpoint has a single location that is disabled, we |
5113 | print it as if it had several locations, since otherwise it's | |
5114 | hard to represent "breakpoint enabled, location disabled" | |
5115 | situation. | |
5116 | ||
5117 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5118 | internally, that's not a property exposed to user. */ |
0d381245 | 5119 | if (b->loc |
a5606eee | 5120 | && !is_hardware_watchpoint (b) |
8d3788bd | 5121 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
5122 | { |
5123 | struct bp_location *loc; | |
5124 | int n = 1; | |
8d3788bd | 5125 | |
0d381245 | 5126 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5127 | { |
5128 | struct cleanup *inner2 = | |
5129 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5130 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5131 | do_cleanups (inner2); | |
5132 | } | |
0d381245 VP |
5133 | } |
5134 | } | |
5135 | } | |
5136 | ||
a6d9a66e UW |
5137 | static int |
5138 | breakpoint_address_bits (struct breakpoint *b) | |
5139 | { | |
5140 | int print_address_bits = 0; | |
5141 | struct bp_location *loc; | |
5142 | ||
5143 | for (loc = b->loc; loc; loc = loc->next) | |
5144 | { | |
c7437ca6 PA |
5145 | int addr_bit; |
5146 | ||
5147 | /* Software watchpoints that aren't watching memory don't have | |
5148 | an address to print. */ | |
5149 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5150 | continue; | |
5151 | ||
5152 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5153 | if (addr_bit > print_address_bits) |
5154 | print_address_bits = addr_bit; | |
5155 | } | |
5156 | ||
5157 | return print_address_bits; | |
5158 | } | |
0d381245 | 5159 | |
c4093a6a JM |
5160 | struct captured_breakpoint_query_args |
5161 | { | |
5162 | int bnum; | |
5163 | }; | |
c5aa993b | 5164 | |
c4093a6a | 5165 | static int |
2b65245e | 5166 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5167 | { |
5168 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5169 | struct breakpoint *b; |
a6d9a66e | 5170 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5171 | |
c4093a6a JM |
5172 | ALL_BREAKPOINTS (b) |
5173 | { | |
5174 | if (args->bnum == b->number) | |
c5aa993b | 5175 | { |
12c5a436 | 5176 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5177 | return GDB_RC_OK; |
c5aa993b | 5178 | } |
c4093a6a JM |
5179 | } |
5180 | return GDB_RC_NONE; | |
5181 | } | |
c5aa993b | 5182 | |
c4093a6a | 5183 | enum gdb_rc |
4a64f543 MS |
5184 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5185 | char **error_message) | |
c4093a6a JM |
5186 | { |
5187 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5188 | |
c4093a6a JM |
5189 | args.bnum = bnum; |
5190 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5191 | an error. */ |
b0b13bb4 DJ |
5192 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5193 | error_message, RETURN_MASK_ALL) < 0) | |
5194 | return GDB_RC_FAIL; | |
5195 | else | |
5196 | return GDB_RC_OK; | |
c4093a6a | 5197 | } |
c5aa993b | 5198 | |
09d682a4 TT |
5199 | /* Return true if this breakpoint was set by the user, false if it is |
5200 | internal or momentary. */ | |
5201 | ||
5202 | int | |
5203 | user_breakpoint_p (struct breakpoint *b) | |
5204 | { | |
46c6471b | 5205 | return b->number > 0; |
09d682a4 TT |
5206 | } |
5207 | ||
7f3b0473 | 5208 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5209 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5210 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5211 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5212 | ones for which it returns non-zero. Return the total number of | |
5213 | breakpoints listed. */ | |
c906108c | 5214 | |
d77f58be | 5215 | static int |
e5a67952 | 5216 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5217 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5218 | { |
52f0bd74 | 5219 | struct breakpoint *b; |
a6d9a66e | 5220 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5221 | int nr_printable_breakpoints; |
3b31d625 | 5222 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5223 | struct value_print_options opts; |
a6d9a66e | 5224 | int print_address_bits = 0; |
269b11a2 PA |
5225 | int print_type_col_width = 14; |
5226 | ||
79a45b7d TT |
5227 | get_user_print_options (&opts); |
5228 | ||
4a64f543 MS |
5229 | /* Compute the number of rows in the table, as well as the size |
5230 | required for address fields. */ | |
7f3b0473 AC |
5231 | nr_printable_breakpoints = 0; |
5232 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5233 | { |
5234 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5235 | if (filter && !filter (b)) | |
5236 | continue; | |
5237 | ||
5238 | /* If we have an "args" string, it is a list of breakpoints to | |
5239 | accept. Skip the others. */ | |
5240 | if (args != NULL && *args != '\0') | |
5241 | { | |
5242 | if (allflag && parse_and_eval_long (args) != b->number) | |
5243 | continue; | |
5244 | if (!allflag && !number_is_in_list (args, b->number)) | |
5245 | continue; | |
5246 | } | |
269b11a2 | 5247 | |
e5a67952 MS |
5248 | if (allflag || user_breakpoint_p (b)) |
5249 | { | |
5250 | int addr_bit, type_len; | |
a6d9a66e | 5251 | |
e5a67952 MS |
5252 | addr_bit = breakpoint_address_bits (b); |
5253 | if (addr_bit > print_address_bits) | |
5254 | print_address_bits = addr_bit; | |
269b11a2 | 5255 | |
e5a67952 MS |
5256 | type_len = strlen (bptype_string (b->type)); |
5257 | if (type_len > print_type_col_width) | |
5258 | print_type_col_width = type_len; | |
5259 | ||
5260 | nr_printable_breakpoints++; | |
5261 | } | |
5262 | } | |
7f3b0473 | 5263 | |
79a45b7d | 5264 | if (opts.addressprint) |
3b31d625 | 5265 | bkpttbl_chain |
3e43a32a MS |
5266 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5267 | nr_printable_breakpoints, | |
3b31d625 | 5268 | "BreakpointTable"); |
8b93c638 | 5269 | else |
3b31d625 | 5270 | bkpttbl_chain |
3e43a32a MS |
5271 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5272 | nr_printable_breakpoints, | |
3b31d625 | 5273 | "BreakpointTable"); |
8b93c638 | 5274 | |
7f3b0473 | 5275 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5276 | annotate_breakpoints_headers (); |
5277 | if (nr_printable_breakpoints > 0) | |
5278 | annotate_field (0); | |
4a64f543 | 5279 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5280 | if (nr_printable_breakpoints > 0) |
5281 | annotate_field (1); | |
269b11a2 | 5282 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5283 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5284 | if (nr_printable_breakpoints > 0) |
5285 | annotate_field (2); | |
4a64f543 | 5286 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5287 | if (nr_printable_breakpoints > 0) |
5288 | annotate_field (3); | |
54e52265 | 5289 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5290 | if (opts.addressprint) |
e5a67952 MS |
5291 | { |
5292 | if (nr_printable_breakpoints > 0) | |
5293 | annotate_field (4); | |
5294 | if (print_address_bits <= 32) | |
5295 | ui_out_table_header (uiout, 10, ui_left, | |
5296 | "addr", "Address"); /* 5 */ | |
5297 | else | |
5298 | ui_out_table_header (uiout, 18, ui_left, | |
5299 | "addr", "Address"); /* 5 */ | |
5300 | } | |
d7faa9e7 AC |
5301 | if (nr_printable_breakpoints > 0) |
5302 | annotate_field (5); | |
5303 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5304 | ui_out_table_body (uiout); | |
5305 | if (nr_printable_breakpoints > 0) | |
5306 | annotate_breakpoints_table (); | |
7f3b0473 | 5307 | |
c4093a6a | 5308 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5309 | { |
5310 | QUIT; | |
5311 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5312 | if (filter && !filter (b)) | |
5313 | continue; | |
5314 | ||
5315 | /* If we have an "args" string, it is a list of breakpoints to | |
5316 | accept. Skip the others. */ | |
5317 | ||
5318 | if (args != NULL && *args != '\0') | |
5319 | { | |
5320 | if (allflag) /* maintenance info breakpoint */ | |
5321 | { | |
5322 | if (parse_and_eval_long (args) != b->number) | |
5323 | continue; | |
5324 | } | |
5325 | else /* all others */ | |
5326 | { | |
5327 | if (!number_is_in_list (args, b->number)) | |
5328 | continue; | |
5329 | } | |
5330 | } | |
5331 | /* We only print out user settable breakpoints unless the | |
5332 | allflag is set. */ | |
5333 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5334 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5335 | } |
5336 | ||
3b31d625 | 5337 | do_cleanups (bkpttbl_chain); |
698384cd | 5338 | |
7f3b0473 | 5339 | if (nr_printable_breakpoints == 0) |
c906108c | 5340 | { |
4a64f543 MS |
5341 | /* If there's a filter, let the caller decide how to report |
5342 | empty list. */ | |
d77f58be SS |
5343 | if (!filter) |
5344 | { | |
e5a67952 | 5345 | if (args == NULL || *args == '\0') |
d77f58be SS |
5346 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5347 | else | |
4a64f543 | 5348 | ui_out_message (uiout, 0, |
e5a67952 MS |
5349 | "No breakpoint or watchpoint matching '%s'.\n", |
5350 | args); | |
d77f58be | 5351 | } |
c906108c SS |
5352 | } |
5353 | else | |
c4093a6a | 5354 | { |
a6d9a66e UW |
5355 | if (last_loc && !server_command) |
5356 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5357 | } |
c906108c | 5358 | |
4a64f543 | 5359 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5360 | there have been breakpoints? */ |
c906108c | 5361 | annotate_breakpoints_table_end (); |
d77f58be SS |
5362 | |
5363 | return nr_printable_breakpoints; | |
c906108c SS |
5364 | } |
5365 | ||
ad443146 SS |
5366 | /* Display the value of default-collect in a way that is generally |
5367 | compatible with the breakpoint list. */ | |
5368 | ||
5369 | static void | |
5370 | default_collect_info (void) | |
5371 | { | |
5372 | /* If it has no value (which is frequently the case), say nothing; a | |
5373 | message like "No default-collect." gets in user's face when it's | |
5374 | not wanted. */ | |
5375 | if (!*default_collect) | |
5376 | return; | |
5377 | ||
5378 | /* The following phrase lines up nicely with per-tracepoint collect | |
5379 | actions. */ | |
5380 | ui_out_text (uiout, "default collect "); | |
5381 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5382 | ui_out_text (uiout, " \n"); | |
5383 | } | |
5384 | ||
c906108c | 5385 | static void |
e5a67952 | 5386 | breakpoints_info (char *args, int from_tty) |
c906108c | 5387 | { |
e5a67952 | 5388 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5389 | |
5390 | default_collect_info (); | |
d77f58be SS |
5391 | } |
5392 | ||
5393 | static void | |
e5a67952 | 5394 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5395 | { |
e5a67952 | 5396 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
d77f58be SS |
5397 | |
5398 | if (num_printed == 0) | |
5399 | { | |
e5a67952 | 5400 | if (args == NULL || *args == '\0') |
d77f58be SS |
5401 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5402 | else | |
e5a67952 | 5403 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5404 | } |
c906108c SS |
5405 | } |
5406 | ||
7a292a7a | 5407 | static void |
e5a67952 | 5408 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5409 | { |
e5a67952 | 5410 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5411 | |
5412 | default_collect_info (); | |
c906108c SS |
5413 | } |
5414 | ||
0d381245 | 5415 | static int |
714835d5 | 5416 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5417 | struct program_space *pspace, |
714835d5 | 5418 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5419 | { |
5420 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5421 | |
0d381245 VP |
5422 | for (; bl; bl = bl->next) |
5423 | { | |
6c95b8df PA |
5424 | if (bl->pspace == pspace |
5425 | && bl->address == pc | |
0d381245 VP |
5426 | && (!overlay_debugging || bl->section == section)) |
5427 | return 1; | |
5428 | } | |
5429 | return 0; | |
5430 | } | |
5431 | ||
6c95b8df PA |
5432 | /* Print a message describing any breakpoints set at PC. This |
5433 | concerns with logical breakpoints, so we match program spaces, not | |
5434 | address spaces. */ | |
c906108c SS |
5435 | |
5436 | static void | |
6c95b8df PA |
5437 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5438 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5439 | struct obj_section *section, int thread) |
c906108c | 5440 | { |
52f0bd74 AC |
5441 | int others = 0; |
5442 | struct breakpoint *b; | |
c906108c SS |
5443 | |
5444 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5445 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5446 | if (others > 0) |
5447 | { | |
a3f17187 AC |
5448 | if (others == 1) |
5449 | printf_filtered (_("Note: breakpoint ")); | |
5450 | else /* if (others == ???) */ | |
5451 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5452 | ALL_BREAKPOINTS (b) |
6c95b8df | 5453 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5454 | { |
5455 | others--; | |
5456 | printf_filtered ("%d", b->number); | |
5457 | if (b->thread == -1 && thread != -1) | |
5458 | printf_filtered (" (all threads)"); | |
5459 | else if (b->thread != -1) | |
5460 | printf_filtered (" (thread %d)", b->thread); | |
5461 | printf_filtered ("%s%s ", | |
059fb39f | 5462 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5463 | || b->enable_state == bp_call_disabled |
5464 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5465 | ? " (disabled)" |
5466 | : b->enable_state == bp_permanent | |
5467 | ? " (permanent)" | |
5468 | : ""), | |
5469 | (others > 1) ? "," | |
5470 | : ((others == 1) ? " and" : "")); | |
5471 | } | |
a3f17187 | 5472 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5473 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5474 | printf_filtered (".\n"); |
5475 | } | |
5476 | } | |
5477 | \f | |
5478 | /* Set the default place to put a breakpoint | |
5479 | for the `break' command with no arguments. */ | |
5480 | ||
5481 | void | |
6c95b8df PA |
5482 | set_default_breakpoint (int valid, struct program_space *pspace, |
5483 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5484 | int line) |
c906108c SS |
5485 | { |
5486 | default_breakpoint_valid = valid; | |
6c95b8df | 5487 | default_breakpoint_pspace = pspace; |
c906108c SS |
5488 | default_breakpoint_address = addr; |
5489 | default_breakpoint_symtab = symtab; | |
5490 | default_breakpoint_line = line; | |
5491 | } | |
5492 | ||
e4f237da KB |
5493 | /* Return true iff it is meaningful to use the address member of |
5494 | BPT. For some breakpoint types, the address member is irrelevant | |
5495 | and it makes no sense to attempt to compare it to other addresses | |
5496 | (or use it for any other purpose either). | |
5497 | ||
4a64f543 MS |
5498 | More specifically, each of the following breakpoint types will |
5499 | always have a zero valued address and we don't want to mark | |
5500 | breakpoints of any of these types to be a duplicate of an actual | |
5501 | breakpoint at address zero: | |
e4f237da KB |
5502 | |
5503 | bp_watchpoint | |
2d134ed3 PA |
5504 | bp_catchpoint |
5505 | ||
5506 | */ | |
e4f237da KB |
5507 | |
5508 | static int | |
5509 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5510 | { | |
5511 | enum bptype type = bpt->type; | |
5512 | ||
2d134ed3 PA |
5513 | return (type != bp_watchpoint && type != bp_catchpoint); |
5514 | } | |
5515 | ||
5516 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5517 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5518 | ||
5519 | static int | |
4a64f543 MS |
5520 | watchpoint_locations_match (struct bp_location *loc1, |
5521 | struct bp_location *loc2) | |
2d134ed3 | 5522 | { |
2bdf28a0 JK |
5523 | /* Both of them must not be in moribund_locations. */ |
5524 | gdb_assert (loc1->owner != NULL); | |
5525 | gdb_assert (loc2->owner != NULL); | |
5526 | ||
4a64f543 MS |
5527 | /* If the target can evaluate the condition expression in hardware, |
5528 | then we we need to insert both watchpoints even if they are at | |
5529 | the same place. Otherwise the watchpoint will only trigger when | |
5530 | the condition of whichever watchpoint was inserted evaluates to | |
5531 | true, not giving a chance for GDB to check the condition of the | |
5532 | other watchpoint. */ | |
0cf6dd15 | 5533 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5534 | && target_can_accel_watchpoint_condition (loc1->address, |
5535 | loc1->length, | |
0cf6dd15 TJB |
5536 | loc1->watchpoint_type, |
5537 | loc1->owner->cond_exp)) | |
5538 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5539 | && target_can_accel_watchpoint_condition (loc2->address, |
5540 | loc2->length, | |
0cf6dd15 TJB |
5541 | loc2->watchpoint_type, |
5542 | loc2->owner->cond_exp))) | |
5543 | return 0; | |
5544 | ||
85d721b8 PA |
5545 | /* Note that this checks the owner's type, not the location's. In |
5546 | case the target does not support read watchpoints, but does | |
5547 | support access watchpoints, we'll have bp_read_watchpoint | |
5548 | watchpoints with hw_access locations. Those should be considered | |
5549 | duplicates of hw_read locations. The hw_read locations will | |
5550 | become hw_access locations later. */ | |
2d134ed3 PA |
5551 | return (loc1->owner->type == loc2->owner->type |
5552 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5553 | && loc1->address == loc2->address | |
5554 | && loc1->length == loc2->length); | |
e4f237da KB |
5555 | } |
5556 | ||
6c95b8df PA |
5557 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5558 | same breakpoint location. In most targets, this can only be true | |
5559 | if ASPACE1 matches ASPACE2. On targets that have global | |
5560 | breakpoints, the address space doesn't really matter. */ | |
5561 | ||
5562 | static int | |
5563 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5564 | struct address_space *aspace2, CORE_ADDR addr2) | |
5565 | { | |
5566 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5567 | || aspace1 == aspace2) | |
5568 | && addr1 == addr2); | |
5569 | } | |
5570 | ||
f1310107 TJB |
5571 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5572 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5573 | matches ASPACE2. On targets that have global breakpoints, the address | |
5574 | space doesn't really matter. */ | |
5575 | ||
5576 | static int | |
5577 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5578 | int len1, struct address_space *aspace2, | |
5579 | CORE_ADDR addr2) | |
5580 | { | |
5581 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5582 | || aspace1 == aspace2) | |
5583 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5584 | } | |
5585 | ||
5586 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5587 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5588 | matches the breakpoint's address space. On targets that have global | |
5589 | breakpoints, the address space doesn't really matter. */ | |
5590 | ||
5591 | static int | |
5592 | breakpoint_location_address_match (struct bp_location *bl, | |
5593 | struct address_space *aspace, | |
5594 | CORE_ADDR addr) | |
5595 | { | |
5596 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5597 | aspace, addr) | |
5598 | || (bl->length | |
5599 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5600 | bl->address, bl->length, | |
5601 | aspace, addr))); | |
5602 | } | |
5603 | ||
2d134ed3 PA |
5604 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5605 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5606 | represent the same location. */ | |
5607 | ||
5608 | static int | |
4a64f543 MS |
5609 | breakpoint_locations_match (struct bp_location *loc1, |
5610 | struct bp_location *loc2) | |
2d134ed3 | 5611 | { |
2bdf28a0 JK |
5612 | int hw_point1, hw_point2; |
5613 | ||
5614 | /* Both of them must not be in moribund_locations. */ | |
5615 | gdb_assert (loc1->owner != NULL); | |
5616 | gdb_assert (loc2->owner != NULL); | |
5617 | ||
5618 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5619 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5620 | |
5621 | if (hw_point1 != hw_point2) | |
5622 | return 0; | |
5623 | else if (hw_point1) | |
5624 | return watchpoint_locations_match (loc1, loc2); | |
5625 | else | |
f1310107 TJB |
5626 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5627 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5628 | loc2->pspace->aspace, loc2->address) | |
5629 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5630 | } |
5631 | ||
76897487 KB |
5632 | static void |
5633 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5634 | int bnum, int have_bnum) | |
5635 | { | |
f63fbe86 MS |
5636 | /* The longest string possibly returned by hex_string_custom |
5637 | is 50 chars. These must be at least that big for safety. */ | |
5638 | char astr1[64]; | |
5639 | char astr2[64]; | |
76897487 | 5640 | |
bb599908 PH |
5641 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5642 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5643 | if (have_bnum) |
8a3fe4f8 | 5644 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5645 | bnum, astr1, astr2); |
5646 | else | |
8a3fe4f8 | 5647 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5648 | } |
5649 | ||
4a64f543 MS |
5650 | /* Adjust a breakpoint's address to account for architectural |
5651 | constraints on breakpoint placement. Return the adjusted address. | |
5652 | Note: Very few targets require this kind of adjustment. For most | |
5653 | targets, this function is simply the identity function. */ | |
76897487 KB |
5654 | |
5655 | static CORE_ADDR | |
a6d9a66e UW |
5656 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5657 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5658 | { |
a6d9a66e | 5659 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5660 | { |
5661 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5662 | return bpaddr; | |
5663 | } | |
88f7da05 KB |
5664 | else if (bptype == bp_watchpoint |
5665 | || bptype == bp_hardware_watchpoint | |
5666 | || bptype == bp_read_watchpoint | |
5667 | || bptype == bp_access_watchpoint | |
fe798b75 | 5668 | || bptype == bp_catchpoint) |
88f7da05 KB |
5669 | { |
5670 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5671 | have their addresses modified. */ | |
5672 | return bpaddr; | |
5673 | } | |
76897487 KB |
5674 | else |
5675 | { | |
5676 | CORE_ADDR adjusted_bpaddr; | |
5677 | ||
5678 | /* Some targets have architectural constraints on the placement | |
5679 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5680 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5681 | |
5682 | /* An adjusted breakpoint address can significantly alter | |
5683 | a user's expectations. Print a warning if an adjustment | |
5684 | is required. */ | |
5685 | if (adjusted_bpaddr != bpaddr) | |
5686 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5687 | ||
5688 | return adjusted_bpaddr; | |
5689 | } | |
5690 | } | |
5691 | ||
7cc221ef DJ |
5692 | /* Allocate a struct bp_location. */ |
5693 | ||
26bb91f3 | 5694 | static struct bp_location * |
39d61571 | 5695 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5696 | { |
afe38095 | 5697 | struct bp_location *loc; |
7cc221ef DJ |
5698 | |
5699 | loc = xmalloc (sizeof (struct bp_location)); | |
5700 | memset (loc, 0, sizeof (*loc)); | |
5701 | ||
e049a4b5 | 5702 | loc->owner = bpt; |
511a6cd4 | 5703 | loc->cond = NULL; |
0d381245 VP |
5704 | loc->shlib_disabled = 0; |
5705 | loc->enabled = 1; | |
e049a4b5 | 5706 | |
39d61571 | 5707 | switch (bpt->type) |
e049a4b5 DJ |
5708 | { |
5709 | case bp_breakpoint: | |
5710 | case bp_until: | |
5711 | case bp_finish: | |
5712 | case bp_longjmp: | |
5713 | case bp_longjmp_resume: | |
186c406b TT |
5714 | case bp_exception: |
5715 | case bp_exception_resume: | |
e049a4b5 | 5716 | case bp_step_resume: |
2c03e5be | 5717 | case bp_hp_step_resume: |
e049a4b5 DJ |
5718 | case bp_watchpoint_scope: |
5719 | case bp_call_dummy: | |
aa7d318d | 5720 | case bp_std_terminate: |
e049a4b5 DJ |
5721 | case bp_shlib_event: |
5722 | case bp_thread_event: | |
5723 | case bp_overlay_event: | |
4efc6507 | 5724 | case bp_jit_event: |
0fd8e87f | 5725 | case bp_longjmp_master: |
aa7d318d | 5726 | case bp_std_terminate_master: |
186c406b | 5727 | case bp_exception_master: |
0e30163f JK |
5728 | case bp_gnu_ifunc_resolver: |
5729 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5730 | loc->loc_type = bp_loc_software_breakpoint; |
5731 | break; | |
5732 | case bp_hardware_breakpoint: | |
5733 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5734 | break; | |
5735 | case bp_hardware_watchpoint: | |
5736 | case bp_read_watchpoint: | |
5737 | case bp_access_watchpoint: | |
5738 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5739 | break; | |
5740 | case bp_watchpoint: | |
ce78b96d | 5741 | case bp_catchpoint: |
15c3d785 PA |
5742 | case bp_tracepoint: |
5743 | case bp_fast_tracepoint: | |
0fb4aa4b | 5744 | case bp_static_tracepoint: |
e049a4b5 DJ |
5745 | loc->loc_type = bp_loc_other; |
5746 | break; | |
5747 | default: | |
e2e0b3e5 | 5748 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5749 | } |
5750 | ||
f431efe5 | 5751 | loc->refc = 1; |
7cc221ef DJ |
5752 | return loc; |
5753 | } | |
5754 | ||
f431efe5 PA |
5755 | static void |
5756 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5757 | { |
5758 | if (loc->cond) | |
5759 | xfree (loc->cond); | |
74960c60 VP |
5760 | |
5761 | if (loc->function_name) | |
5762 | xfree (loc->function_name); | |
f431efe5 | 5763 | |
fe3f5fa8 VP |
5764 | xfree (loc); |
5765 | } | |
5766 | ||
f431efe5 PA |
5767 | /* Increment reference count. */ |
5768 | ||
5769 | static void | |
5770 | incref_bp_location (struct bp_location *bl) | |
5771 | { | |
5772 | ++bl->refc; | |
5773 | } | |
5774 | ||
5775 | /* Decrement reference count. If the reference count reaches 0, | |
5776 | destroy the bp_location. Sets *BLP to NULL. */ | |
5777 | ||
5778 | static void | |
5779 | decref_bp_location (struct bp_location **blp) | |
5780 | { | |
0807b50c PA |
5781 | gdb_assert ((*blp)->refc > 0); |
5782 | ||
f431efe5 PA |
5783 | if (--(*blp)->refc == 0) |
5784 | free_bp_location (*blp); | |
5785 | *blp = NULL; | |
5786 | } | |
5787 | ||
346774a9 | 5788 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5789 | |
346774a9 PA |
5790 | static void |
5791 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5792 | { |
346774a9 | 5793 | struct breakpoint *b1; |
c906108c | 5794 | |
346774a9 PA |
5795 | /* Add this breakpoint to the end of the chain so that a list of |
5796 | breakpoints will come out in order of increasing numbers. */ | |
5797 | ||
5798 | b1 = breakpoint_chain; | |
5799 | if (b1 == 0) | |
5800 | breakpoint_chain = b; | |
5801 | else | |
5802 | { | |
5803 | while (b1->next) | |
5804 | b1 = b1->next; | |
5805 | b1->next = b; | |
5806 | } | |
5807 | } | |
5808 | ||
5809 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5810 | ||
5811 | static void | |
5812 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5813 | struct gdbarch *gdbarch, | |
5814 | enum bptype bptype) | |
5815 | { | |
c906108c | 5816 | memset (b, 0, sizeof (*b)); |
2219d63c | 5817 | |
4d28f7a8 | 5818 | b->type = bptype; |
a6d9a66e | 5819 | b->gdbarch = gdbarch; |
c906108c SS |
5820 | b->language = current_language->la_language; |
5821 | b->input_radix = input_radix; | |
5822 | b->thread = -1; | |
b5de0fa7 | 5823 | b->enable_state = bp_enabled; |
c906108c SS |
5824 | b->next = 0; |
5825 | b->silent = 0; | |
5826 | b->ignore_count = 0; | |
5827 | b->commands = NULL; | |
818dd999 | 5828 | b->frame_id = null_frame_id; |
c906108c | 5829 | b->exec_pathname = NULL; |
3086aeae | 5830 | b->ops = NULL; |
0d381245 | 5831 | b->condition_not_parsed = 0; |
84f4c1fe | 5832 | b->py_bp_object = NULL; |
d0fb5eae | 5833 | b->related_breakpoint = b; |
c906108c | 5834 | |
346774a9 PA |
5835 | add_to_breakpoint_chain (b); |
5836 | } | |
5837 | ||
5838 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5839 | that has type BPTYPE and has no locations as yet. */ | |
5840 | /* This function is used in gdbtk sources and thus can not be made | |
5841 | static. */ | |
5842 | ||
5843 | static struct breakpoint * | |
5844 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
5845 | enum bptype bptype) | |
5846 | { | |
5847 | struct breakpoint *b = XNEW (struct breakpoint); | |
5848 | ||
5849 | init_raw_breakpoint_without_location (b, gdbarch, bptype); | |
c906108c | 5850 | |
0d381245 VP |
5851 | return b; |
5852 | } | |
5853 | ||
0e30163f JK |
5854 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5855 | resolutions should be made as the user specified the location explicitly | |
5856 | enough. */ | |
5857 | ||
0d381245 | 5858 | static void |
0e30163f | 5859 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5860 | { |
2bdf28a0 JK |
5861 | gdb_assert (loc->owner != NULL); |
5862 | ||
0d381245 | 5863 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5864 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5865 | || is_tracepoint (loc->owner)) |
0d381245 | 5866 | { |
0e30163f JK |
5867 | int is_gnu_ifunc; |
5868 | ||
5869 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5870 | NULL, NULL, &is_gnu_ifunc); | |
5871 | ||
5872 | if (is_gnu_ifunc && !explicit_loc) | |
5873 | { | |
5874 | struct breakpoint *b = loc->owner; | |
5875 | ||
5876 | gdb_assert (loc->pspace == current_program_space); | |
5877 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5878 | &loc->requested_address)) | |
5879 | { | |
5880 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5881 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5882 | loc->requested_address, | |
5883 | b->type); | |
5884 | } | |
5885 | else if (b->type == bp_breakpoint && b->loc == loc | |
5886 | && loc->next == NULL && b->related_breakpoint == b) | |
5887 | { | |
5888 | /* Create only the whole new breakpoint of this type but do not | |
5889 | mess more complicated breakpoints with multiple locations. */ | |
5890 | b->type = bp_gnu_ifunc_resolver; | |
5891 | } | |
5892 | } | |
5893 | ||
0d381245 VP |
5894 | if (loc->function_name) |
5895 | loc->function_name = xstrdup (loc->function_name); | |
5896 | } | |
5897 | } | |
5898 | ||
a6d9a66e UW |
5899 | /* Attempt to determine architecture of location identified by SAL. */ |
5900 | static struct gdbarch * | |
5901 | get_sal_arch (struct symtab_and_line sal) | |
5902 | { | |
5903 | if (sal.section) | |
5904 | return get_objfile_arch (sal.section->objfile); | |
5905 | if (sal.symtab) | |
5906 | return get_objfile_arch (sal.symtab->objfile); | |
5907 | ||
5908 | return NULL; | |
5909 | } | |
5910 | ||
346774a9 PA |
5911 | /* Low level routine for partially initializing a breakpoint of type |
5912 | BPTYPE. The newly created breakpoint's address, section, source | |
5913 | file name, and line number are provided by SAL. The newly created | |
5914 | and partially initialized breakpoint is added to the breakpoint | |
5915 | chain. | |
0d381245 VP |
5916 | |
5917 | It is expected that the caller will complete the initialization of | |
5918 | the newly created breakpoint struct as well as output any status | |
5919 | information regarding the creation of a new breakpoint. In | |
346774a9 PA |
5920 | particular, init_raw_breakpoint does NOT set the breakpoint number! |
5921 | Care should be taken to not allow an error to occur prior to | |
5922 | completing the initialization of the breakpoint. If this should | |
5923 | happen, a bogus breakpoint will be left on the chain. */ | |
0d381245 | 5924 | |
346774a9 PA |
5925 | static void |
5926 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
5927 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5928 | { |
0d381245 | 5929 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5930 | struct gdbarch *loc_gdbarch; |
5931 | ||
346774a9 PA |
5932 | init_raw_breakpoint_without_location (b, gdbarch, bptype); |
5933 | ||
a6d9a66e UW |
5934 | loc_gdbarch = get_sal_arch (sal); |
5935 | if (!loc_gdbarch) | |
5936 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5937 | |
6c95b8df PA |
5938 | if (bptype != bp_catchpoint) |
5939 | gdb_assert (sal.pspace != NULL); | |
5940 | ||
0d381245 VP |
5941 | /* Adjust the breakpoint's address prior to allocating a location. |
5942 | Once we call allocate_bp_location(), that mostly uninitialized | |
5943 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5944 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5945 | not want its scan of the location chain to find a breakpoint and |
5946 | location that's only been partially initialized. */ | |
4a64f543 MS |
5947 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5948 | sal.pc, b->type); | |
0d381245 | 5949 | |
39d61571 | 5950 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5951 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5952 | b->loc->requested_address = sal.pc; |
5953 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5954 | b->loc->pspace = sal.pspace; |
5955 | ||
5956 | /* Store the program space that was used to set the breakpoint, for | |
5957 | breakpoint resetting. */ | |
5958 | b->pspace = sal.pspace; | |
0d381245 VP |
5959 | |
5960 | if (sal.symtab == NULL) | |
5961 | b->source_file = NULL; | |
5962 | else | |
1b36a34b | 5963 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5964 | b->loc->section = sal.section; |
5965 | b->line_number = sal.line; | |
5966 | ||
0e30163f JK |
5967 | set_breakpoint_location_function (b->loc, |
5968 | sal.explicit_pc || sal.explicit_line); | |
c906108c | 5969 | |
c906108c | 5970 | breakpoints_changed (); |
346774a9 | 5971 | } |
c906108c | 5972 | |
346774a9 PA |
5973 | /* set_raw_breakpoint is a low level routine for allocating and |
5974 | partially initializing a breakpoint of type BPTYPE. The newly | |
5975 | created breakpoint's address, section, source file name, and line | |
5976 | number are provided by SAL. The newly created and partially | |
5977 | initialized breakpoint is added to the breakpoint chain and | |
5978 | is also returned as the value of this function. | |
5979 | ||
5980 | It is expected that the caller will complete the initialization of | |
5981 | the newly created breakpoint struct as well as output any status | |
5982 | information regarding the creation of a new breakpoint. In | |
5983 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5984 | number! Care should be taken to not allow an error to occur | |
5985 | prior to completing the initialization of the breakpoint. If this | |
5986 | should happen, a bogus breakpoint will be left on the chain. */ | |
5987 | ||
5988 | struct breakpoint * | |
5989 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
5990 | struct symtab_and_line sal, enum bptype bptype) | |
5991 | { | |
5992 | struct breakpoint *b = XNEW (struct breakpoint); | |
5993 | ||
5994 | init_raw_breakpoint (b, gdbarch, sal, bptype); | |
c906108c SS |
5995 | return b; |
5996 | } | |
5997 | ||
c2c6d25f JM |
5998 | |
5999 | /* Note that the breakpoint object B describes a permanent breakpoint | |
6000 | instruction, hard-wired into the inferior's code. */ | |
6001 | void | |
6002 | make_breakpoint_permanent (struct breakpoint *b) | |
6003 | { | |
0d381245 | 6004 | struct bp_location *bl; |
cc59ec59 | 6005 | |
b5de0fa7 | 6006 | b->enable_state = bp_permanent; |
c2c6d25f | 6007 | |
4a64f543 MS |
6008 | /* By definition, permanent breakpoints are already present in the |
6009 | code. Mark all locations as inserted. For now, | |
6010 | make_breakpoint_permanent is called in just one place, so it's | |
6011 | hard to say if it's reasonable to have permanent breakpoint with | |
6012 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
6013 | for (bl = b->loc; bl; bl = bl->next) |
6014 | bl->inserted = 1; | |
c2c6d25f JM |
6015 | } |
6016 | ||
53a5351d | 6017 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
6018 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
6019 | initiated the operation. */ | |
c906108c SS |
6020 | |
6021 | void | |
186c406b | 6022 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 6023 | { |
35df4500 | 6024 | struct breakpoint *b, *b_tmp; |
186c406b | 6025 | int thread = tp->num; |
0fd8e87f UW |
6026 | |
6027 | /* To avoid having to rescan all objfile symbols at every step, | |
6028 | we maintain a list of continually-inserted but always disabled | |
6029 | longjmp "master" breakpoints. Here, we simply create momentary | |
6030 | clones of those and enable them for the requested thread. */ | |
35df4500 | 6031 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 6032 | if (b->pspace == current_program_space |
186c406b TT |
6033 | && (b->type == bp_longjmp_master |
6034 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
6035 | { |
6036 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 6037 | |
186c406b | 6038 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
6039 | clone->thread = thread; |
6040 | } | |
186c406b TT |
6041 | |
6042 | tp->initiating_frame = frame; | |
c906108c SS |
6043 | } |
6044 | ||
611c83ae | 6045 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 6046 | void |
611c83ae | 6047 | delete_longjmp_breakpoint (int thread) |
c906108c | 6048 | { |
35df4500 | 6049 | struct breakpoint *b, *b_tmp; |
c906108c | 6050 | |
35df4500 | 6051 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 6052 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
6053 | { |
6054 | if (b->thread == thread) | |
6055 | delete_breakpoint (b); | |
6056 | } | |
c906108c SS |
6057 | } |
6058 | ||
1900040c MS |
6059 | void |
6060 | enable_overlay_breakpoints (void) | |
6061 | { | |
52f0bd74 | 6062 | struct breakpoint *b; |
1900040c MS |
6063 | |
6064 | ALL_BREAKPOINTS (b) | |
6065 | if (b->type == bp_overlay_event) | |
6066 | { | |
6067 | b->enable_state = bp_enabled; | |
b60e7edf | 6068 | update_global_location_list (1); |
c02f5703 | 6069 | overlay_events_enabled = 1; |
1900040c MS |
6070 | } |
6071 | } | |
6072 | ||
6073 | void | |
6074 | disable_overlay_breakpoints (void) | |
6075 | { | |
52f0bd74 | 6076 | struct breakpoint *b; |
1900040c MS |
6077 | |
6078 | ALL_BREAKPOINTS (b) | |
6079 | if (b->type == bp_overlay_event) | |
6080 | { | |
6081 | b->enable_state = bp_disabled; | |
b60e7edf | 6082 | update_global_location_list (0); |
c02f5703 | 6083 | overlay_events_enabled = 0; |
1900040c MS |
6084 | } |
6085 | } | |
6086 | ||
aa7d318d TT |
6087 | /* Set an active std::terminate breakpoint for each std::terminate |
6088 | master breakpoint. */ | |
6089 | void | |
6090 | set_std_terminate_breakpoint (void) | |
6091 | { | |
35df4500 | 6092 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6093 | |
35df4500 | 6094 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6095 | if (b->pspace == current_program_space |
6096 | && b->type == bp_std_terminate_master) | |
6097 | { | |
6098 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
6099 | clone->type = bp_std_terminate; | |
6100 | } | |
6101 | } | |
6102 | ||
6103 | /* Delete all the std::terminate breakpoints. */ | |
6104 | void | |
6105 | delete_std_terminate_breakpoint (void) | |
6106 | { | |
35df4500 | 6107 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6108 | |
35df4500 | 6109 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6110 | if (b->type == bp_std_terminate) |
6111 | delete_breakpoint (b); | |
6112 | } | |
6113 | ||
c4093a6a | 6114 | struct breakpoint * |
a6d9a66e | 6115 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
6116 | { |
6117 | struct breakpoint *b; | |
c4093a6a | 6118 | |
a6d9a66e | 6119 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 6120 | |
b5de0fa7 | 6121 | b->enable_state = bp_enabled; |
c4093a6a | 6122 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
6123 | b->addr_string |
6124 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 6125 | |
b60e7edf | 6126 | update_global_location_list_nothrow (1); |
74960c60 | 6127 | |
c4093a6a JM |
6128 | return b; |
6129 | } | |
6130 | ||
6131 | void | |
6132 | remove_thread_event_breakpoints (void) | |
6133 | { | |
35df4500 | 6134 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6135 | |
35df4500 | 6136 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6137 | if (b->type == bp_thread_event |
6138 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6139 | delete_breakpoint (b); |
6140 | } | |
6141 | ||
0101ce28 JJ |
6142 | struct lang_and_radix |
6143 | { | |
6144 | enum language lang; | |
6145 | int radix; | |
6146 | }; | |
6147 | ||
4efc6507 DE |
6148 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6149 | ||
6150 | struct breakpoint * | |
6151 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6152 | { | |
6153 | struct breakpoint *b; | |
6154 | ||
6155 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
6156 | update_global_location_list_nothrow (1); | |
6157 | return b; | |
6158 | } | |
0101ce28 | 6159 | |
03673fc7 PP |
6160 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6161 | ||
6162 | void | |
6163 | remove_jit_event_breakpoints (void) | |
6164 | { | |
6165 | struct breakpoint *b, *b_tmp; | |
6166 | ||
6167 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6168 | if (b->type == bp_jit_event | |
6169 | && b->loc->pspace == current_program_space) | |
6170 | delete_breakpoint (b); | |
6171 | } | |
6172 | ||
cae688ec JJ |
6173 | void |
6174 | remove_solib_event_breakpoints (void) | |
6175 | { | |
35df4500 | 6176 | struct breakpoint *b, *b_tmp; |
cae688ec | 6177 | |
35df4500 | 6178 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6179 | if (b->type == bp_shlib_event |
6180 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6181 | delete_breakpoint (b); |
6182 | } | |
6183 | ||
6184 | struct breakpoint * | |
a6d9a66e | 6185 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6186 | { |
6187 | struct breakpoint *b; | |
6188 | ||
a6d9a66e | 6189 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 6190 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6191 | return b; |
6192 | } | |
6193 | ||
6194 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6195 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6196 | ||
6197 | void | |
cb851954 | 6198 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6199 | { |
876fa593 | 6200 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6201 | |
876fa593 | 6202 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6203 | { |
2bdf28a0 | 6204 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6205 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6206 | |
4a64f543 MS |
6207 | /* We apply the check to all breakpoints, including disabled for |
6208 | those with loc->duplicate set. This is so that when breakpoint | |
6209 | becomes enabled, or the duplicate is removed, gdb will try to | |
6210 | insert all breakpoints. If we don't set shlib_disabled here, | |
6211 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6212 | if (((b->type == bp_breakpoint) |
508ccb1f | 6213 | || (b->type == bp_jit_event) |
1042e4c0 | 6214 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6215 | || (is_tracepoint (b))) |
6c95b8df | 6216 | && loc->pspace == current_program_space |
0d381245 | 6217 | && !loc->shlib_disabled |
a77053c2 | 6218 | #ifdef PC_SOLIB |
0d381245 | 6219 | && PC_SOLIB (loc->address) |
a77053c2 | 6220 | #else |
6c95b8df | 6221 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6222 | #endif |
6223 | ) | |
0d381245 VP |
6224 | { |
6225 | loc->shlib_disabled = 1; | |
6226 | } | |
cae688ec JJ |
6227 | } |
6228 | } | |
6229 | ||
7a9dd1b2 | 6230 | /* Disable any breakpoints that are in an unloaded shared library. |
4a64f543 MS |
6231 | Only apply to enabled breakpoints, disabled ones can just stay |
6232 | disabled. */ | |
84acb35a | 6233 | |
75149521 | 6234 | static void |
84acb35a JJ |
6235 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6236 | { | |
876fa593 | 6237 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6238 | int disabled_shlib_breaks = 0; |
6239 | ||
c86cf029 VP |
6240 | /* SunOS a.out shared libraries are always mapped, so do not |
6241 | disable breakpoints; they will only be reported as unloaded | |
6242 | through clear_solib when GDB discards its shared library | |
6243 | list. See clear_solib for more information. */ | |
6244 | if (exec_bfd != NULL | |
6245 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6246 | return; | |
6247 | ||
876fa593 | 6248 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6249 | { |
2bdf28a0 | 6250 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6251 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6252 | |
0d381245 VP |
6253 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6254 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6255 | && solib->pspace == loc->pspace |
e2dd7057 | 6256 | && !loc->shlib_disabled |
508ccb1f TT |
6257 | && (b->type == bp_breakpoint |
6258 | || b->type == bp_jit_event | |
6259 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6260 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6261 | { |
e2dd7057 PP |
6262 | loc->shlib_disabled = 1; |
6263 | /* At this point, we cannot rely on remove_breakpoint | |
6264 | succeeding so we must mark the breakpoint as not inserted | |
6265 | to prevent future errors occurring in remove_breakpoints. */ | |
6266 | loc->inserted = 0; | |
8d3788bd VP |
6267 | |
6268 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6269 | observer_notify_breakpoint_modified (b); | |
6270 | ||
e2dd7057 PP |
6271 | if (!disabled_shlib_breaks) |
6272 | { | |
6273 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6274 | warning (_("Temporarily disabling breakpoints " |
6275 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6276 | solib->so_name); |
84acb35a | 6277 | } |
e2dd7057 | 6278 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6279 | } |
6280 | } | |
84acb35a JJ |
6281 | } |
6282 | ||
ce78b96d JB |
6283 | /* FORK & VFORK catchpoints. */ |
6284 | ||
e29a4733 PA |
6285 | /* An instance of this type is used to represent a fork or vfork |
6286 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6287 | class; users downcast to "struct breakpoint *" when needed. A | |
6288 | breakpoint is really of this type iff its ops pointer points to | |
6289 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6290 | ||
6291 | struct fork_catchpoint | |
6292 | { | |
6293 | /* The base class. */ | |
6294 | struct breakpoint base; | |
6295 | ||
6296 | /* Process id of a child process whose forking triggered this | |
6297 | catchpoint. This field is only valid immediately after this | |
6298 | catchpoint has triggered. */ | |
6299 | ptid_t forked_inferior_pid; | |
6300 | }; | |
6301 | ||
4a64f543 MS |
6302 | /* Implement the "insert" breakpoint_ops method for fork |
6303 | catchpoints. */ | |
ce78b96d | 6304 | |
77b06cd7 TJB |
6305 | static int |
6306 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6307 | { |
77b06cd7 | 6308 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6309 | } |
6310 | ||
4a64f543 MS |
6311 | /* Implement the "remove" breakpoint_ops method for fork |
6312 | catchpoints. */ | |
ce78b96d JB |
6313 | |
6314 | static int | |
77b06cd7 | 6315 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6316 | { |
6317 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6318 | } | |
6319 | ||
6320 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6321 | catchpoints. */ | |
6322 | ||
6323 | static int | |
f1310107 TJB |
6324 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6325 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6326 | { |
e29a4733 PA |
6327 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6328 | ||
6329 | return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6330 | } |
6331 | ||
4a64f543 MS |
6332 | /* Implement the "print_it" breakpoint_ops method for fork |
6333 | catchpoints. */ | |
ce78b96d JB |
6334 | |
6335 | static enum print_stop_action | |
6336 | print_it_catch_fork (struct breakpoint *b) | |
6337 | { | |
e29a4733 PA |
6338 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6339 | ||
ce78b96d JB |
6340 | annotate_catchpoint (b->number); |
6341 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
e29a4733 | 6342 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6343 | return PRINT_SRC_AND_LOC; |
6344 | } | |
6345 | ||
4a64f543 MS |
6346 | /* Implement the "print_one" breakpoint_ops method for fork |
6347 | catchpoints. */ | |
ce78b96d JB |
6348 | |
6349 | static void | |
a6d9a66e | 6350 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6351 | { |
e29a4733 | 6352 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d TT |
6353 | struct value_print_options opts; |
6354 | ||
6355 | get_user_print_options (&opts); | |
6356 | ||
4a64f543 MS |
6357 | /* Field 4, the address, is omitted (which makes the columns not |
6358 | line up too nicely with the headers, but the effect is relatively | |
6359 | readable). */ | |
79a45b7d | 6360 | if (opts.addressprint) |
ce78b96d JB |
6361 | ui_out_field_skip (uiout, "addr"); |
6362 | annotate_field (5); | |
6363 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6364 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6365 | { |
6366 | ui_out_text (uiout, ", process "); | |
6367 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6368 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6369 | ui_out_spaces (uiout, 1); |
6370 | } | |
6371 | } | |
6372 | ||
6373 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6374 | catchpoints. */ | |
6375 | ||
6376 | static void | |
6377 | print_mention_catch_fork (struct breakpoint *b) | |
6378 | { | |
6379 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6380 | } | |
6381 | ||
6149aea9 PA |
6382 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6383 | catchpoints. */ | |
6384 | ||
6385 | static void | |
6386 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6387 | { | |
6388 | fprintf_unfiltered (fp, "catch fork"); | |
6389 | } | |
6390 | ||
ce78b96d JB |
6391 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6392 | ||
6393 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6394 | { | |
be5c67c1 | 6395 | NULL, /* dtor */ |
ce78b96d JB |
6396 | insert_catch_fork, |
6397 | remove_catch_fork, | |
6398 | breakpoint_hit_catch_fork, | |
e09342b5 | 6399 | NULL, /* resources_needed */ |
9c06b0b4 | 6400 | NULL, /* works_in_software_mode */ |
ce78b96d JB |
6401 | print_it_catch_fork, |
6402 | print_one_catch_fork, | |
f1310107 | 6403 | NULL, /* print_one_detail */ |
6149aea9 PA |
6404 | print_mention_catch_fork, |
6405 | print_recreate_catch_fork | |
ce78b96d JB |
6406 | }; |
6407 | ||
4a64f543 MS |
6408 | /* Implement the "insert" breakpoint_ops method for vfork |
6409 | catchpoints. */ | |
ce78b96d | 6410 | |
77b06cd7 TJB |
6411 | static int |
6412 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6413 | { |
77b06cd7 | 6414 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6415 | } |
6416 | ||
4a64f543 MS |
6417 | /* Implement the "remove" breakpoint_ops method for vfork |
6418 | catchpoints. */ | |
ce78b96d JB |
6419 | |
6420 | static int | |
77b06cd7 | 6421 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6422 | { |
6423 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6424 | } | |
6425 | ||
6426 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6427 | catchpoints. */ | |
6428 | ||
6429 | static int | |
f1310107 TJB |
6430 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6431 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6432 | { |
e29a4733 PA |
6433 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6434 | ||
6435 | return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6436 | } |
6437 | ||
4a64f543 MS |
6438 | /* Implement the "print_it" breakpoint_ops method for vfork |
6439 | catchpoints. */ | |
ce78b96d JB |
6440 | |
6441 | static enum print_stop_action | |
6442 | print_it_catch_vfork (struct breakpoint *b) | |
6443 | { | |
e29a4733 PA |
6444 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6445 | ||
ce78b96d JB |
6446 | annotate_catchpoint (b->number); |
6447 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
e29a4733 | 6448 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6449 | return PRINT_SRC_AND_LOC; |
6450 | } | |
6451 | ||
4a64f543 MS |
6452 | /* Implement the "print_one" breakpoint_ops method for vfork |
6453 | catchpoints. */ | |
ce78b96d JB |
6454 | |
6455 | static void | |
a6d9a66e | 6456 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6457 | { |
e29a4733 | 6458 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d TT |
6459 | struct value_print_options opts; |
6460 | ||
6461 | get_user_print_options (&opts); | |
4a64f543 MS |
6462 | /* Field 4, the address, is omitted (which makes the columns not |
6463 | line up too nicely with the headers, but the effect is relatively | |
6464 | readable). */ | |
79a45b7d | 6465 | if (opts.addressprint) |
ce78b96d JB |
6466 | ui_out_field_skip (uiout, "addr"); |
6467 | annotate_field (5); | |
6468 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6469 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6470 | { |
6471 | ui_out_text (uiout, ", process "); | |
6472 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6473 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6474 | ui_out_spaces (uiout, 1); |
6475 | } | |
6476 | } | |
6477 | ||
6478 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6479 | catchpoints. */ | |
6480 | ||
6481 | static void | |
6482 | print_mention_catch_vfork (struct breakpoint *b) | |
6483 | { | |
6484 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6485 | } | |
6486 | ||
6149aea9 PA |
6487 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6488 | catchpoints. */ | |
6489 | ||
6490 | static void | |
6491 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6492 | { | |
6493 | fprintf_unfiltered (fp, "catch vfork"); | |
6494 | } | |
6495 | ||
ce78b96d JB |
6496 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6497 | ||
6498 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6499 | { | |
be5c67c1 | 6500 | NULL, /* dtor */ |
ce78b96d JB |
6501 | insert_catch_vfork, |
6502 | remove_catch_vfork, | |
6503 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6504 | NULL, /* resources_needed */ |
9c06b0b4 | 6505 | NULL, /* works_in_software_mode */ |
ce78b96d JB |
6506 | print_it_catch_vfork, |
6507 | print_one_catch_vfork, | |
f1310107 | 6508 | NULL, /* print_one_detail */ |
6149aea9 PA |
6509 | print_mention_catch_vfork, |
6510 | print_recreate_catch_vfork | |
ce78b96d JB |
6511 | }; |
6512 | ||
be5c67c1 PA |
6513 | /* An instance of this type is used to represent a syscall catchpoint. |
6514 | It includes a "struct breakpoint" as a kind of base class; users | |
6515 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6516 | really of this type iff its ops pointer points to | |
6517 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6518 | ||
6519 | struct syscall_catchpoint | |
6520 | { | |
6521 | /* The base class. */ | |
6522 | struct breakpoint base; | |
6523 | ||
6524 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6525 | syscall has been specified for filtering, its value is NULL. | |
6526 | Otherwise, it holds a list of all syscalls to be caught. The | |
6527 | list elements are allocated with xmalloc. */ | |
6528 | VEC(int) *syscalls_to_be_caught; | |
6529 | }; | |
6530 | ||
6531 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6532 | catchpoints. */ | |
6533 | ||
6534 | static void | |
6535 | dtor_catch_syscall (struct breakpoint *b) | |
6536 | { | |
6537 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6538 | ||
6539 | VEC_free (int, c->syscalls_to_be_caught); | |
6540 | } | |
6541 | ||
a96d9b2e SDJ |
6542 | /* Implement the "insert" breakpoint_ops method for syscall |
6543 | catchpoints. */ | |
6544 | ||
77b06cd7 TJB |
6545 | static int |
6546 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6547 | { |
be5c67c1 | 6548 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6549 | struct inferior *inf = current_inferior (); |
6550 | ||
6551 | ++inf->total_syscalls_count; | |
be5c67c1 | 6552 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6553 | ++inf->any_syscall_count; |
6554 | else | |
6555 | { | |
6556 | int i, iter; | |
cc59ec59 | 6557 | |
a96d9b2e | 6558 | for (i = 0; |
be5c67c1 | 6559 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6560 | i++) |
6561 | { | |
6562 | int elem; | |
cc59ec59 | 6563 | |
a96d9b2e SDJ |
6564 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6565 | { | |
6566 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6567 | uintptr_t vec_addr_offset |
6568 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6569 | uintptr_t vec_addr; |
6570 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6571 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6572 | vec_addr_offset; | |
6573 | memset ((void *) vec_addr, 0, | |
6574 | (iter + 1 - old_size) * sizeof (int)); | |
6575 | } | |
6576 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6577 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6578 | } | |
6579 | } | |
6580 | ||
77b06cd7 TJB |
6581 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6582 | inf->total_syscalls_count != 0, | |
6583 | inf->any_syscall_count, | |
6584 | VEC_length (int, inf->syscalls_counts), | |
6585 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6586 | } |
6587 | ||
6588 | /* Implement the "remove" breakpoint_ops method for syscall | |
6589 | catchpoints. */ | |
6590 | ||
6591 | static int | |
77b06cd7 | 6592 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6593 | { |
be5c67c1 | 6594 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6595 | struct inferior *inf = current_inferior (); |
6596 | ||
6597 | --inf->total_syscalls_count; | |
be5c67c1 | 6598 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6599 | --inf->any_syscall_count; |
6600 | else | |
6601 | { | |
6602 | int i, iter; | |
cc59ec59 | 6603 | |
a96d9b2e | 6604 | for (i = 0; |
be5c67c1 | 6605 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6606 | i++) |
6607 | { | |
6608 | int elem; | |
6609 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6610 | /* Shouldn't happen. */ | |
6611 | continue; | |
6612 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6613 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6614 | } | |
6615 | } | |
6616 | ||
6617 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6618 | inf->total_syscalls_count != 0, | |
6619 | inf->any_syscall_count, | |
6620 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6621 | VEC_address (int, |
6622 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6623 | } |
6624 | ||
6625 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6626 | catchpoints. */ | |
6627 | ||
6628 | static int | |
f1310107 TJB |
6629 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6630 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6631 | { |
4a64f543 MS |
6632 | /* We must check if we are catching specific syscalls in this |
6633 | breakpoint. If we are, then we must guarantee that the called | |
6634 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6635 | int syscall_number = 0; |
be5c67c1 PA |
6636 | const struct syscall_catchpoint *c |
6637 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e SDJ |
6638 | |
6639 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6640 | return 0; | |
6641 | ||
6642 | /* Now, checking if the syscall is the same. */ | |
be5c67c1 | 6643 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6644 | { |
6645 | int i, iter; | |
cc59ec59 | 6646 | |
a96d9b2e | 6647 | for (i = 0; |
be5c67c1 | 6648 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6649 | i++) |
6650 | if (syscall_number == iter) | |
6651 | break; | |
6652 | /* Not the same. */ | |
6653 | if (!iter) | |
6654 | return 0; | |
6655 | } | |
6656 | ||
6657 | return 1; | |
6658 | } | |
6659 | ||
6660 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6661 | catchpoints. */ | |
6662 | ||
6663 | static enum print_stop_action | |
6664 | print_it_catch_syscall (struct breakpoint *b) | |
6665 | { | |
6666 | /* These are needed because we want to know in which state a | |
6667 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6668 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6669 | must print "called syscall" or "returned from syscall". */ | |
6670 | ptid_t ptid; | |
6671 | struct target_waitstatus last; | |
6672 | struct syscall s; | |
6673 | struct cleanup *old_chain; | |
6674 | char *syscall_id; | |
6675 | ||
6676 | get_last_target_status (&ptid, &last); | |
6677 | ||
6678 | get_syscall_by_number (last.value.syscall_number, &s); | |
6679 | ||
6680 | annotate_catchpoint (b->number); | |
6681 | ||
6682 | if (s.name == NULL) | |
6683 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6684 | else | |
6685 | syscall_id = xstrprintf ("'%s'", s.name); | |
6686 | ||
6687 | old_chain = make_cleanup (xfree, syscall_id); | |
6688 | ||
6689 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6690 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6691 | b->number, syscall_id); | |
6692 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6693 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6694 | b->number, syscall_id); | |
6695 | ||
6696 | do_cleanups (old_chain); | |
6697 | ||
6698 | return PRINT_SRC_AND_LOC; | |
6699 | } | |
6700 | ||
6701 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6702 | catchpoints. */ | |
6703 | ||
6704 | static void | |
6705 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6706 | struct bp_location **last_loc) |
a96d9b2e | 6707 | { |
be5c67c1 | 6708 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e SDJ |
6709 | struct value_print_options opts; |
6710 | ||
6711 | get_user_print_options (&opts); | |
4a64f543 MS |
6712 | /* Field 4, the address, is omitted (which makes the columns not |
6713 | line up too nicely with the headers, but the effect is relatively | |
6714 | readable). */ | |
a96d9b2e SDJ |
6715 | if (opts.addressprint) |
6716 | ui_out_field_skip (uiout, "addr"); | |
6717 | annotate_field (5); | |
6718 | ||
be5c67c1 PA |
6719 | if (c->syscalls_to_be_caught |
6720 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6721 | ui_out_text (uiout, "syscalls \""); |
6722 | else | |
6723 | ui_out_text (uiout, "syscall \""); | |
6724 | ||
be5c67c1 | 6725 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6726 | { |
6727 | int i, iter; | |
6728 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6729 | |
a96d9b2e | 6730 | for (i = 0; |
be5c67c1 | 6731 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6732 | i++) |
6733 | { | |
6734 | char *x = text; | |
6735 | struct syscall s; | |
6736 | get_syscall_by_number (iter, &s); | |
6737 | ||
6738 | if (s.name != NULL) | |
6739 | text = xstrprintf ("%s%s, ", text, s.name); | |
6740 | else | |
6741 | text = xstrprintf ("%s%d, ", text, iter); | |
6742 | ||
6743 | /* We have to xfree the last 'text' (now stored at 'x') | |
6744 | because xstrprintf dinamically allocates new space for it | |
6745 | on every call. */ | |
6746 | xfree (x); | |
6747 | } | |
6748 | /* Remove the last comma. */ | |
6749 | text[strlen (text) - 2] = '\0'; | |
6750 | ui_out_field_string (uiout, "what", text); | |
6751 | } | |
6752 | else | |
6753 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6754 | ui_out_text (uiout, "\" "); | |
6755 | } | |
6756 | ||
6757 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6758 | catchpoints. */ | |
6759 | ||
6760 | static void | |
6761 | print_mention_catch_syscall (struct breakpoint *b) | |
6762 | { | |
be5c67c1 PA |
6763 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6764 | ||
6765 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
6766 | { |
6767 | int i, iter; | |
6768 | ||
be5c67c1 | 6769 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
6770 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
6771 | else | |
6772 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6773 | ||
6774 | for (i = 0; | |
be5c67c1 | 6775 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6776 | i++) |
6777 | { | |
6778 | struct syscall s; | |
6779 | get_syscall_by_number (iter, &s); | |
6780 | ||
6781 | if (s.name) | |
6782 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6783 | else | |
6784 | printf_filtered (" %d", s.number); | |
6785 | } | |
6786 | printf_filtered (")"); | |
6787 | } | |
6788 | else | |
6789 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6790 | b->number); | |
6791 | } | |
6792 | ||
6149aea9 PA |
6793 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6794 | catchpoints. */ | |
6795 | ||
6796 | static void | |
6797 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6798 | { | |
be5c67c1 PA |
6799 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6800 | ||
6149aea9 PA |
6801 | fprintf_unfiltered (fp, "catch syscall"); |
6802 | ||
be5c67c1 | 6803 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
6804 | { |
6805 | int i, iter; | |
6806 | ||
6807 | for (i = 0; | |
be5c67c1 | 6808 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
6809 | i++) |
6810 | { | |
6811 | struct syscall s; | |
6812 | ||
6813 | get_syscall_by_number (iter, &s); | |
6814 | if (s.name) | |
6815 | fprintf_unfiltered (fp, " %s", s.name); | |
6816 | else | |
6817 | fprintf_unfiltered (fp, " %d", s.number); | |
6818 | } | |
6819 | } | |
6820 | } | |
6821 | ||
a96d9b2e SDJ |
6822 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6823 | ||
6824 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6825 | { | |
be5c67c1 | 6826 | dtor_catch_syscall, |
a96d9b2e SDJ |
6827 | insert_catch_syscall, |
6828 | remove_catch_syscall, | |
6829 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6830 | NULL, /* resources_needed */ |
9c06b0b4 | 6831 | NULL, /* works_in_software_mode */ |
a96d9b2e SDJ |
6832 | print_it_catch_syscall, |
6833 | print_one_catch_syscall, | |
f1310107 | 6834 | NULL, /* print_one_detail */ |
6149aea9 PA |
6835 | print_mention_catch_syscall, |
6836 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6837 | }; |
6838 | ||
6839 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6840 | ||
6841 | static int | |
6842 | syscall_catchpoint_p (struct breakpoint *b) | |
6843 | { | |
6844 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6845 | } | |
6846 | ||
346774a9 PA |
6847 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
6848 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
6849 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
6850 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 6851 | |
346774a9 PA |
6852 | static void |
6853 | init_catchpoint (struct breakpoint *b, | |
6854 | struct gdbarch *gdbarch, int tempflag, | |
6855 | char *cond_string, | |
6856 | struct breakpoint_ops *ops) | |
c906108c | 6857 | { |
c5aa993b | 6858 | struct symtab_and_line sal; |
346774a9 PA |
6859 | |
6860 | memset (b, 0, sizeof (*b)); | |
c5aa993b | 6861 | |
fe39c653 | 6862 | init_sal (&sal); |
6c95b8df | 6863 | sal.pspace = current_program_space; |
c5aa993b | 6864 | |
346774a9 | 6865 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint); |
c906108c SS |
6866 | set_breakpoint_count (breakpoint_count + 1); |
6867 | b->number = breakpoint_count; | |
ce78b96d | 6868 | |
1b36a34b | 6869 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6870 | b->thread = -1; |
c906108c | 6871 | b->addr_string = NULL; |
b5de0fa7 EZ |
6872 | b->enable_state = bp_enabled; |
6873 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6874 | b->ops = ops; |
346774a9 PA |
6875 | } |
6876 | ||
6877 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6878 | but does NOT mention it nor update the global location list. | |
6879 | This is useful if you need to fill more fields in the | |
6880 | struct breakpoint before calling mention. | |
6881 | ||
6882 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6883 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6884 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6885 | to the catchpoint. */ | |
6886 | ||
6887 | static struct breakpoint * | |
6888 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, | |
6889 | char *cond_string, | |
6890 | struct breakpoint_ops *ops) | |
6891 | { | |
6892 | struct breakpoint *b = XNEW (struct breakpoint); | |
c5aa993b | 6893 | |
346774a9 | 6894 | init_catchpoint (b, gdbarch, tempflag, cond_string, ops); |
a96d9b2e SDJ |
6895 | return b; |
6896 | } | |
6897 | ||
6898 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6899 | ||
6900 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6901 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6902 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6903 | to the catchpoint. */ | |
6904 | ||
6905 | static struct breakpoint * | |
6906 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6907 | char *cond_string, struct breakpoint_ops *ops) | |
6908 | { | |
6909 | struct breakpoint *b = | |
6910 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6911 | ||
c906108c | 6912 | mention (b); |
8d3788bd | 6913 | observer_notify_breakpoint_created (b); |
ce78b96d | 6914 | update_global_location_list (1); |
c906108c | 6915 | |
ce78b96d | 6916 | return b; |
c906108c | 6917 | } |
c5aa993b | 6918 | |
9b70b993 | 6919 | static void |
a6d9a66e UW |
6920 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6921 | int tempflag, char *cond_string, | |
ce78b96d | 6922 | struct breakpoint_ops *ops) |
c906108c | 6923 | { |
e29a4733 | 6924 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 6925 | |
e29a4733 PA |
6926 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
6927 | ||
6928 | c->forked_inferior_pid = null_ptid; | |
6929 | ||
6930 | mention (&c->base); | |
6931 | observer_notify_breakpoint_created (&c->base); | |
6932 | update_global_location_list (1); | |
c906108c SS |
6933 | } |
6934 | ||
fe798b75 JB |
6935 | /* Exec catchpoints. */ |
6936 | ||
77b06cd7 TJB |
6937 | static int |
6938 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6939 | { |
77b06cd7 | 6940 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6941 | } |
c906108c | 6942 | |
fe798b75 | 6943 | static int |
77b06cd7 | 6944 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6945 | { |
6946 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6947 | } | |
c906108c | 6948 | |
fe798b75 | 6949 | static int |
f1310107 TJB |
6950 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6951 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6952 | { |
f1310107 | 6953 | return inferior_has_execd (inferior_ptid, &bl->owner->exec_pathname); |
fe798b75 | 6954 | } |
c906108c | 6955 | |
fe798b75 JB |
6956 | static enum print_stop_action |
6957 | print_it_catch_exec (struct breakpoint *b) | |
6958 | { | |
6959 | annotate_catchpoint (b->number); | |
6960 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6961 | b->exec_pathname); | |
6962 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6963 | } |
6964 | ||
fe798b75 | 6965 | static void |
a6d9a66e | 6966 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6967 | { |
6968 | struct value_print_options opts; | |
6969 | ||
6970 | get_user_print_options (&opts); | |
6971 | ||
6972 | /* Field 4, the address, is omitted (which makes the columns | |
6973 | not line up too nicely with the headers, but the effect | |
6974 | is relatively readable). */ | |
6975 | if (opts.addressprint) | |
6976 | ui_out_field_skip (uiout, "addr"); | |
6977 | annotate_field (5); | |
6978 | ui_out_text (uiout, "exec"); | |
6979 | if (b->exec_pathname != NULL) | |
6980 | { | |
6981 | ui_out_text (uiout, ", program \""); | |
6982 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6983 | ui_out_text (uiout, "\" "); | |
6984 | } | |
6985 | } | |
6986 | ||
6987 | static void | |
6988 | print_mention_catch_exec (struct breakpoint *b) | |
6989 | { | |
6990 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6991 | } | |
6992 | ||
6149aea9 PA |
6993 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6994 | catchpoints. */ | |
6995 | ||
6996 | static void | |
6997 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6998 | { | |
6999 | fprintf_unfiltered (fp, "catch exec"); | |
7000 | } | |
7001 | ||
fe798b75 JB |
7002 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
7003 | { | |
be5c67c1 | 7004 | NULL, /* dtor */ |
fe798b75 JB |
7005 | insert_catch_exec, |
7006 | remove_catch_exec, | |
7007 | breakpoint_hit_catch_exec, | |
e09342b5 | 7008 | NULL, /* resources_needed */ |
9c06b0b4 | 7009 | NULL, /* works_in_software_mode */ |
fe798b75 JB |
7010 | print_it_catch_exec, |
7011 | print_one_catch_exec, | |
f1310107 | 7012 | NULL, /* print_one_detail */ |
6149aea9 PA |
7013 | print_mention_catch_exec, |
7014 | print_recreate_catch_exec | |
fe798b75 JB |
7015 | }; |
7016 | ||
a96d9b2e SDJ |
7017 | static void |
7018 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
7019 | struct breakpoint_ops *ops) | |
7020 | { | |
be5c67c1 | 7021 | struct syscall_catchpoint *c; |
a96d9b2e | 7022 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 7023 | |
be5c67c1 PA |
7024 | c = XNEW (struct syscall_catchpoint); |
7025 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
7026 | c->syscalls_to_be_caught = filter; | |
a96d9b2e SDJ |
7027 | |
7028 | /* Now, we have to mention the breakpoint and update the global | |
7029 | location list. */ | |
be5c67c1 PA |
7030 | mention (&c->base); |
7031 | observer_notify_breakpoint_created (&c->base); | |
a96d9b2e SDJ |
7032 | update_global_location_list (1); |
7033 | } | |
7034 | ||
c906108c | 7035 | static int |
fba45db2 | 7036 | hw_breakpoint_used_count (void) |
c906108c | 7037 | { |
c906108c | 7038 | int i = 0; |
f1310107 TJB |
7039 | struct breakpoint *b; |
7040 | struct bp_location *bl; | |
c906108c SS |
7041 | |
7042 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7043 | { |
d6b74ac4 | 7044 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
7045 | for (bl = b->loc; bl; bl = bl->next) |
7046 | { | |
7047 | /* Special types of hardware breakpoints may use more than | |
7048 | one register. */ | |
7049 | if (b->ops && b->ops->resources_needed) | |
7050 | i += b->ops->resources_needed (bl); | |
7051 | else | |
7052 | i++; | |
7053 | } | |
c5aa993b | 7054 | } |
c906108c SS |
7055 | |
7056 | return i; | |
7057 | } | |
7058 | ||
7059 | static int | |
fba45db2 | 7060 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 7061 | { |
c906108c | 7062 | int i = 0; |
e09342b5 TJB |
7063 | struct breakpoint *b; |
7064 | struct bp_location *bl; | |
c906108c SS |
7065 | |
7066 | *other_type_used = 0; | |
7067 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
7068 | { |
7069 | if (!breakpoint_enabled (b)) | |
7070 | continue; | |
7071 | ||
c5aa993b | 7072 | if (b->type == type) |
e09342b5 TJB |
7073 | for (bl = b->loc; bl; bl = bl->next) |
7074 | { | |
7075 | /* Special types of hardware watchpoints may use more than | |
7076 | one register. */ | |
7077 | if (b->ops && b->ops->resources_needed) | |
7078 | i += b->ops->resources_needed (bl); | |
7079 | else | |
7080 | i++; | |
7081 | } | |
cc60f2e3 | 7082 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 7083 | *other_type_used = 1; |
e09342b5 TJB |
7084 | } |
7085 | ||
c906108c SS |
7086 | return i; |
7087 | } | |
7088 | ||
c906108c | 7089 | void |
fba45db2 | 7090 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 7091 | { |
c5aa993b | 7092 | struct breakpoint *b; |
c906108c SS |
7093 | |
7094 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7095 | { |
cc60f2e3 | 7096 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 7097 | { |
b5de0fa7 | 7098 | b->enable_state = bp_call_disabled; |
b60e7edf | 7099 | update_global_location_list (0); |
c5aa993b JM |
7100 | } |
7101 | } | |
c906108c SS |
7102 | } |
7103 | ||
7104 | void | |
fba45db2 | 7105 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 7106 | { |
c5aa993b | 7107 | struct breakpoint *b; |
c906108c SS |
7108 | |
7109 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7110 | { |
cc60f2e3 | 7111 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 7112 | { |
b5de0fa7 | 7113 | b->enable_state = bp_enabled; |
b60e7edf | 7114 | update_global_location_list (1); |
c5aa993b JM |
7115 | } |
7116 | } | |
c906108c SS |
7117 | } |
7118 | ||
8bea4e01 UW |
7119 | void |
7120 | disable_breakpoints_before_startup (void) | |
7121 | { | |
7122 | struct breakpoint *b; | |
7123 | int found = 0; | |
7124 | ||
7125 | ALL_BREAKPOINTS (b) | |
7126 | { | |
6c95b8df PA |
7127 | if (b->pspace != current_program_space) |
7128 | continue; | |
7129 | ||
8bea4e01 UW |
7130 | if ((b->type == bp_breakpoint |
7131 | || b->type == bp_hardware_breakpoint) | |
7132 | && breakpoint_enabled (b)) | |
7133 | { | |
7134 | b->enable_state = bp_startup_disabled; | |
7135 | found = 1; | |
7136 | } | |
7137 | } | |
7138 | ||
7139 | if (found) | |
7140 | update_global_location_list (0); | |
7141 | ||
6c95b8df | 7142 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
7143 | } |
7144 | ||
7145 | void | |
7146 | enable_breakpoints_after_startup (void) | |
7147 | { | |
7148 | struct breakpoint *b; | |
7149 | int found = 0; | |
7150 | ||
6c95b8df | 7151 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
7152 | |
7153 | ALL_BREAKPOINTS (b) | |
7154 | { | |
6c95b8df PA |
7155 | if (b->pspace != current_program_space) |
7156 | continue; | |
7157 | ||
8bea4e01 UW |
7158 | if ((b->type == bp_breakpoint |
7159 | || b->type == bp_hardware_breakpoint) | |
7160 | && b->enable_state == bp_startup_disabled) | |
7161 | { | |
7162 | b->enable_state = bp_enabled; | |
7163 | found = 1; | |
7164 | } | |
7165 | } | |
7166 | ||
7167 | if (found) | |
7168 | breakpoint_re_set (); | |
7169 | } | |
7170 | ||
c906108c SS |
7171 | |
7172 | /* Set a breakpoint that will evaporate an end of command | |
7173 | at address specified by SAL. | |
7174 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
7175 | ||
7176 | struct breakpoint * | |
a6d9a66e UW |
7177 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
7178 | struct frame_id frame_id, enum bptype type) | |
c906108c | 7179 | { |
52f0bd74 | 7180 | struct breakpoint *b; |
edb3359d DJ |
7181 | |
7182 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
7183 | one. */ | |
7184 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
7185 | ||
a6d9a66e | 7186 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
7187 | b->enable_state = bp_enabled; |
7188 | b->disposition = disp_donttouch; | |
818dd999 | 7189 | b->frame_id = frame_id; |
c906108c | 7190 | |
4a64f543 MS |
7191 | /* If we're debugging a multi-threaded program, then we want |
7192 | momentary breakpoints to be active in only a single thread of | |
7193 | control. */ | |
39f77062 KB |
7194 | if (in_thread_list (inferior_ptid)) |
7195 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 7196 | |
b60e7edf | 7197 | update_global_location_list_nothrow (1); |
74960c60 | 7198 | |
c906108c SS |
7199 | return b; |
7200 | } | |
611c83ae | 7201 | |
e58b0e63 PA |
7202 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7203 | ORIG is NULL. */ | |
7204 | ||
7205 | struct breakpoint * | |
7206 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7207 | { | |
7208 | struct breakpoint *copy; | |
7209 | ||
7210 | /* If there's nothing to clone, then return nothing. */ | |
7211 | if (orig == NULL) | |
7212 | return NULL; | |
7213 | ||
a6d9a66e | 7214 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 | 7215 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7216 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7217 | |
a6d9a66e | 7218 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7219 | copy->loc->requested_address = orig->loc->requested_address; |
7220 | copy->loc->address = orig->loc->address; | |
7221 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7222 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
7223 | |
7224 | if (orig->source_file == NULL) | |
7225 | copy->source_file = NULL; | |
7226 | else | |
7227 | copy->source_file = xstrdup (orig->source_file); | |
7228 | ||
7229 | copy->line_number = orig->line_number; | |
7230 | copy->frame_id = orig->frame_id; | |
7231 | copy->thread = orig->thread; | |
6c95b8df | 7232 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7233 | |
7234 | copy->enable_state = bp_enabled; | |
7235 | copy->disposition = disp_donttouch; | |
7236 | copy->number = internal_breakpoint_number--; | |
7237 | ||
7238 | update_global_location_list_nothrow (0); | |
7239 | return copy; | |
7240 | } | |
7241 | ||
611c83ae | 7242 | struct breakpoint * |
a6d9a66e UW |
7243 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7244 | enum bptype type) | |
611c83ae PA |
7245 | { |
7246 | struct symtab_and_line sal; | |
7247 | ||
7248 | sal = find_pc_line (pc, 0); | |
7249 | sal.pc = pc; | |
7250 | sal.section = find_pc_overlay (pc); | |
7251 | sal.explicit_pc = 1; | |
7252 | ||
a6d9a66e | 7253 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7254 | } |
c906108c | 7255 | \f |
c5aa993b | 7256 | |
c906108c SS |
7257 | /* Tell the user we have just set a breakpoint B. */ |
7258 | ||
7259 | static void | |
fba45db2 | 7260 | mention (struct breakpoint *b) |
c906108c SS |
7261 | { |
7262 | int say_where = 0; | |
fa8a61dc | 7263 | struct cleanup *ui_out_chain; |
79a45b7d TT |
7264 | struct value_print_options opts; |
7265 | ||
7266 | get_user_print_options (&opts); | |
8b93c638 | 7267 | |
3086aeae DJ |
7268 | if (b->ops != NULL && b->ops->print_mention != NULL) |
7269 | b->ops->print_mention (b); | |
7270 | else | |
7271 | switch (b->type) | |
7272 | { | |
7273 | case bp_none: | |
3e43a32a MS |
7274 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
7275 | b->number); | |
3086aeae DJ |
7276 | break; |
7277 | case bp_watchpoint: | |
7278 | ui_out_text (uiout, "Watchpoint "); | |
7279 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7280 | ui_out_field_int (uiout, "number", b->number); | |
7281 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7282 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7283 | do_cleanups (ui_out_chain); |
7284 | break; | |
7285 | case bp_hardware_watchpoint: | |
7286 | ui_out_text (uiout, "Hardware watchpoint "); | |
7287 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7288 | ui_out_field_int (uiout, "number", b->number); | |
7289 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7290 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7291 | do_cleanups (ui_out_chain); |
7292 | break; | |
7293 | case bp_read_watchpoint: | |
7294 | ui_out_text (uiout, "Hardware read watchpoint "); | |
7295 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
7296 | ui_out_field_int (uiout, "number", b->number); | |
7297 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7298 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7299 | do_cleanups (ui_out_chain); |
7300 | break; | |
7301 | case bp_access_watchpoint: | |
7302 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
7303 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
7304 | ui_out_field_int (uiout, "number", b->number); | |
7305 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7306 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7307 | do_cleanups (ui_out_chain); |
7308 | break; | |
7309 | case bp_breakpoint: | |
0e30163f | 7310 | case bp_gnu_ifunc_resolver: |
3086aeae DJ |
7311 | if (ui_out_is_mi_like_p (uiout)) |
7312 | { | |
7313 | say_where = 0; | |
7314 | break; | |
7315 | } | |
2cec12e5 AR |
7316 | if (b->disposition == disp_del) |
7317 | printf_filtered (_("Temporary breakpoint")); | |
7318 | else | |
7319 | printf_filtered (_("Breakpoint")); | |
7320 | printf_filtered (_(" %d"), b->number); | |
0e30163f JK |
7321 | if (b->type == bp_gnu_ifunc_resolver) |
7322 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
3086aeae DJ |
7323 | say_where = 1; |
7324 | break; | |
7325 | case bp_hardware_breakpoint: | |
7326 | if (ui_out_is_mi_like_p (uiout)) | |
7327 | { | |
7328 | say_where = 0; | |
7329 | break; | |
7330 | } | |
a3f17187 | 7331 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
7332 | say_where = 1; |
7333 | break; | |
1042e4c0 SS |
7334 | case bp_tracepoint: |
7335 | if (ui_out_is_mi_like_p (uiout)) | |
7336 | { | |
7337 | say_where = 0; | |
7338 | break; | |
7339 | } | |
7340 | printf_filtered (_("Tracepoint")); | |
7341 | printf_filtered (_(" %d"), b->number); | |
7342 | say_where = 1; | |
7343 | break; | |
7a697b8d SS |
7344 | case bp_fast_tracepoint: |
7345 | if (ui_out_is_mi_like_p (uiout)) | |
7346 | { | |
7347 | say_where = 0; | |
7348 | break; | |
7349 | } | |
7350 | printf_filtered (_("Fast tracepoint")); | |
7351 | printf_filtered (_(" %d"), b->number); | |
7352 | say_where = 1; | |
7353 | break; | |
0fb4aa4b PA |
7354 | case bp_static_tracepoint: |
7355 | if (ui_out_is_mi_like_p (uiout)) | |
7356 | { | |
7357 | say_where = 0; | |
7358 | break; | |
7359 | } | |
7360 | printf_filtered (_("Static tracepoint")); | |
7361 | printf_filtered (_(" %d"), b->number); | |
7362 | say_where = 1; | |
7363 | break; | |
3086aeae DJ |
7364 | |
7365 | case bp_until: | |
7366 | case bp_finish: | |
7367 | case bp_longjmp: | |
7368 | case bp_longjmp_resume: | |
186c406b TT |
7369 | case bp_exception: |
7370 | case bp_exception_resume: | |
3086aeae | 7371 | case bp_step_resume: |
2c03e5be | 7372 | case bp_hp_step_resume: |
3086aeae | 7373 | case bp_call_dummy: |
aa7d318d | 7374 | case bp_std_terminate: |
3086aeae DJ |
7375 | case bp_watchpoint_scope: |
7376 | case bp_shlib_event: | |
7377 | case bp_thread_event: | |
7378 | case bp_overlay_event: | |
4efc6507 | 7379 | case bp_jit_event: |
0fd8e87f | 7380 | case bp_longjmp_master: |
aa7d318d | 7381 | case bp_std_terminate_master: |
186c406b | 7382 | case bp_exception_master: |
0e30163f | 7383 | case bp_gnu_ifunc_resolver_return: |
3086aeae DJ |
7384 | break; |
7385 | } | |
c906108c | 7386 | |
c906108c SS |
7387 | if (say_where) |
7388 | { | |
a3f17187 AC |
7389 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7390 | single string. */ | |
0d381245 | 7391 | if (b->loc == NULL) |
c906108c | 7392 | { |
a3f17187 | 7393 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7394 | } |
7395 | else | |
7396 | { | |
79a45b7d | 7397 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7398 | { |
7399 | printf_filtered (" at "); | |
5af949e3 UW |
7400 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7401 | gdb_stdout); | |
0101ce28 JJ |
7402 | } |
7403 | if (b->source_file) | |
7404 | printf_filtered (": file %s, line %d.", | |
7405 | b->source_file, b->line_number); | |
0d381245 VP |
7406 | |
7407 | if (b->loc->next) | |
7408 | { | |
7409 | struct bp_location *loc = b->loc; | |
7410 | int n = 0; | |
7411 | for (; loc; loc = loc->next) | |
7412 | ++n; | |
7413 | printf_filtered (" (%d locations)", n); | |
7414 | } | |
7415 | ||
c906108c | 7416 | } |
c906108c | 7417 | } |
9dc5e2a9 | 7418 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7419 | return; |
c906108c SS |
7420 | printf_filtered ("\n"); |
7421 | } | |
c906108c | 7422 | \f |
c5aa993b | 7423 | |
0d381245 | 7424 | static struct bp_location * |
39d61571 | 7425 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7426 | const struct symtab_and_line *sal) |
7427 | { | |
7428 | struct bp_location *loc, **tmp; | |
7429 | ||
39d61571 | 7430 | loc = allocate_bp_location (b); |
0d381245 VP |
7431 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7432 | ; | |
7433 | *tmp = loc; | |
a6d9a66e UW |
7434 | loc->gdbarch = get_sal_arch (*sal); |
7435 | if (!loc->gdbarch) | |
7436 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7437 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7438 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7439 | loc->requested_address, b->type); | |
6c95b8df PA |
7440 | loc->pspace = sal->pspace; |
7441 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7442 | loc->section = sal->section; |
7443 | ||
0e30163f JK |
7444 | set_breakpoint_location_function (loc, |
7445 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7446 | return loc; |
7447 | } | |
514f746b AR |
7448 | \f |
7449 | ||
7450 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7451 | return 0 otherwise. */ | |
7452 | ||
7453 | static int | |
7454 | bp_loc_is_permanent (struct bp_location *loc) | |
7455 | { | |
7456 | int len; | |
7457 | CORE_ADDR addr; | |
7458 | const gdb_byte *brk; | |
7459 | gdb_byte *target_mem; | |
939c61fa JK |
7460 | struct cleanup *cleanup; |
7461 | int retval = 0; | |
514f746b AR |
7462 | |
7463 | gdb_assert (loc != NULL); | |
7464 | ||
7465 | addr = loc->address; | |
a6d9a66e | 7466 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7467 | |
939c61fa JK |
7468 | /* Software breakpoints unsupported? */ |
7469 | if (brk == NULL) | |
7470 | return 0; | |
7471 | ||
514f746b AR |
7472 | target_mem = alloca (len); |
7473 | ||
939c61fa JK |
7474 | /* Enable the automatic memory restoration from breakpoints while |
7475 | we read the memory. Otherwise we could say about our temporary | |
7476 | breakpoints they are permanent. */ | |
6c95b8df PA |
7477 | cleanup = save_current_space_and_thread (); |
7478 | ||
7479 | switch_to_program_space_and_thread (loc->pspace); | |
7480 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7481 | |
514f746b AR |
7482 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7483 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7484 | retval = 1; |
514f746b | 7485 | |
939c61fa JK |
7486 | do_cleanups (cleanup); |
7487 | ||
7488 | return retval; | |
514f746b AR |
7489 | } |
7490 | ||
7491 | ||
c3f6f71d | 7492 | |
018d34a4 VP |
7493 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7494 | as textual description of the location, and COND_STRING | |
db107f19 | 7495 | as condition expression. */ |
018d34a4 VP |
7496 | |
7497 | static void | |
8cdf0e15 VP |
7498 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7499 | struct symtabs_and_lines sals, char *addr_string, | |
7500 | char *cond_string, | |
7501 | enum bptype type, enum bpdisp disposition, | |
7502 | int thread, int task, int ignore_count, | |
84f4c1fe | 7503 | struct breakpoint_ops *ops, int from_tty, |
56435ebe | 7504 | int enabled, int internal, int display_canonical) |
018d34a4 | 7505 | { |
0d381245 VP |
7506 | struct breakpoint *b = NULL; |
7507 | int i; | |
018d34a4 VP |
7508 | |
7509 | if (type == bp_hardware_breakpoint) | |
7510 | { | |
7511 | int i = hw_breakpoint_used_count (); | |
7512 | int target_resources_ok = | |
d92524f1 | 7513 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7514 | i + 1, 0); |
7515 | if (target_resources_ok == 0) | |
7516 | error (_("No hardware breakpoint support in the target.")); | |
7517 | else if (target_resources_ok < 0) | |
7518 | error (_("Hardware breakpoints used exceeds limit.")); | |
7519 | } | |
7520 | ||
6c95b8df PA |
7521 | gdb_assert (sals.nelts > 0); |
7522 | ||
0d381245 VP |
7523 | for (i = 0; i < sals.nelts; ++i) |
7524 | { | |
7525 | struct symtab_and_line sal = sals.sals[i]; | |
7526 | struct bp_location *loc; | |
7527 | ||
7528 | if (from_tty) | |
5af949e3 UW |
7529 | { |
7530 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7531 | if (!loc_gdbarch) | |
7532 | loc_gdbarch = gdbarch; | |
7533 | ||
7534 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7535 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7536 | } |
0d381245 VP |
7537 | |
7538 | if (i == 0) | |
7539 | { | |
a6d9a66e | 7540 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7541 | set_breakpoint_number (internal, b); |
0d381245 | 7542 | b->thread = thread; |
4a306c9a | 7543 | b->task = task; |
018d34a4 | 7544 | |
0d381245 VP |
7545 | b->cond_string = cond_string; |
7546 | b->ignore_count = ignore_count; | |
41447f92 | 7547 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7548 | b->disposition = disposition; |
6c95b8df PA |
7549 | b->pspace = sals.sals[0].pspace; |
7550 | ||
0fb4aa4b PA |
7551 | if (type == bp_static_tracepoint) |
7552 | { | |
7553 | struct static_tracepoint_marker marker; | |
7554 | ||
7555 | if (is_marker_spec (addr_string)) | |
7556 | { | |
7557 | /* We already know the marker exists, otherwise, we | |
7558 | wouldn't see a sal for it. */ | |
7559 | char *p = &addr_string[3]; | |
7560 | char *endp; | |
7561 | char *marker_str; | |
7562 | int i; | |
7563 | ||
e9cafbcc | 7564 | p = skip_spaces (p); |
0fb4aa4b | 7565 | |
e9cafbcc | 7566 | endp = skip_to_space (p); |
0fb4aa4b PA |
7567 | |
7568 | marker_str = savestring (p, endp - p); | |
7569 | b->static_trace_marker_id = marker_str; | |
7570 | ||
3e43a32a MS |
7571 | printf_filtered (_("Probed static tracepoint " |
7572 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7573 | b->static_trace_marker_id); |
7574 | } | |
7575 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7576 | { | |
7577 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7578 | release_static_tracepoint_marker (&marker); | |
7579 | ||
3e43a32a MS |
7580 | printf_filtered (_("Probed static tracepoint " |
7581 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7582 | b->static_trace_marker_id); |
7583 | } | |
7584 | else | |
3e43a32a MS |
7585 | warning (_("Couldn't determine the static " |
7586 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7587 | } |
7588 | ||
6c95b8df | 7589 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7590 | && (b->type == bp_breakpoint |
7591 | || b->type == bp_hardware_breakpoint)) | |
7592 | b->enable_state = bp_startup_disabled; | |
7593 | ||
0d381245 VP |
7594 | loc = b->loc; |
7595 | } | |
7596 | else | |
018d34a4 | 7597 | { |
39d61571 | 7598 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7599 | } |
7600 | ||
514f746b AR |
7601 | if (bp_loc_is_permanent (loc)) |
7602 | make_breakpoint_permanent (b); | |
7603 | ||
0d381245 VP |
7604 | if (b->cond_string) |
7605 | { | |
7606 | char *arg = b->cond_string; | |
d32a6982 | 7607 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7608 | if (*arg) |
db107f19 | 7609 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7610 | } |
0d381245 | 7611 | } |
018d34a4 | 7612 | |
56435ebe | 7613 | b->display_canonical = display_canonical; |
018d34a4 VP |
7614 | if (addr_string) |
7615 | b->addr_string = addr_string; | |
7616 | else | |
7617 | /* addr_string has to be used or breakpoint_re_set will delete | |
7618 | me. */ | |
5af949e3 UW |
7619 | b->addr_string |
7620 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7621 | |
604133b5 | 7622 | b->ops = ops; |
8d3788bd VP |
7623 | /* Do not mention breakpoints with a negative number, but do |
7624 | notify observers. */ | |
7625 | if (!internal) | |
84f4c1fe | 7626 | mention (b); |
8d3788bd | 7627 | observer_notify_breakpoint_created (b); |
018d34a4 VP |
7628 | } |
7629 | ||
ed0616c6 VP |
7630 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7631 | elements to fill the void space. */ | |
2c0b251b PA |
7632 | static void |
7633 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7634 | { |
7635 | int i = index_to_remove+1; | |
7636 | int last_index = sal->nelts-1; | |
7637 | ||
7638 | for (;i <= last_index; ++i) | |
7639 | sal->sals[i-1] = sal->sals[i]; | |
7640 | ||
7641 | --(sal->nelts); | |
7642 | } | |
7643 | ||
6c95b8df PA |
7644 | /* If appropriate, obtains all sals that correspond to the same file |
7645 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7646 | will want to set a breakpoint at foo.c:line, and not really care | |
7647 | about program spaces. This is done only if SAL does not have | |
7648 | explicit PC and has line and file information. If we got just a | |
7649 | single expanded sal, return the original. | |
ed0616c6 | 7650 | |
6c95b8df PA |
7651 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7652 | which the name of enclosing function is different from SAL. This | |
7653 | makes sure that if we have breakpoint originally set in template | |
7654 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7655 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7656 | |
2c0b251b | 7657 | static struct symtabs_and_lines |
ed0616c6 VP |
7658 | expand_line_sal_maybe (struct symtab_and_line sal) |
7659 | { | |
7660 | struct symtabs_and_lines expanded; | |
7661 | CORE_ADDR original_pc = sal.pc; | |
7662 | char *original_function = NULL; | |
7663 | int found; | |
7664 | int i; | |
6c95b8df | 7665 | struct cleanup *old_chain; |
ed0616c6 VP |
7666 | |
7667 | /* If we have explicit pc, don't expand. | |
7668 | If we have no line number, we can't expand. */ | |
7669 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7670 | { | |
7671 | expanded.nelts = 1; | |
7672 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7673 | expanded.sals[0] = sal; | |
7674 | return expanded; | |
7675 | } | |
7676 | ||
7677 | sal.pc = 0; | |
6c95b8df PA |
7678 | |
7679 | old_chain = save_current_space_and_thread (); | |
7680 | ||
7681 | switch_to_program_space_and_thread (sal.pspace); | |
7682 | ||
ed0616c6 | 7683 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7684 | |
7685 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7686 | expanded = expand_line_sal (sal); |
6c95b8df | 7687 | |
ed0616c6 VP |
7688 | if (expanded.nelts == 1) |
7689 | { | |
3dba1c98 JB |
7690 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7691 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7692 | xfree (expanded.sals); |
7693 | expanded.nelts = 1; | |
7694 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7695 | sal.pc = original_pc; | |
7696 | expanded.sals[0] = sal; | |
3dba1c98 | 7697 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7698 | do_cleanups (old_chain); |
ed0616c6 VP |
7699 | return expanded; |
7700 | } | |
7701 | ||
7702 | if (!sal.explicit_line) | |
7703 | { | |
7704 | CORE_ADDR func_addr, func_end; | |
7705 | for (i = 0; i < expanded.nelts; ++i) | |
7706 | { | |
7707 | CORE_ADDR pc = expanded.sals[i].pc; | |
7708 | char *this_function; | |
6c95b8df PA |
7709 | |
7710 | /* We need to switch threads as well since we're about to | |
7711 | read memory. */ | |
7712 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7713 | ||
ed0616c6 VP |
7714 | if (find_pc_partial_function (pc, &this_function, |
7715 | &func_addr, &func_end)) | |
7716 | { | |
059fb39f PM |
7717 | if (this_function |
7718 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7719 | { |
7720 | remove_sal (&expanded, i); | |
7721 | --i; | |
7722 | } | |
ed0616c6 VP |
7723 | } |
7724 | } | |
7725 | } | |
059acae7 UW |
7726 | |
7727 | /* Skip the function prologue if necessary. */ | |
7728 | for (i = 0; i < expanded.nelts; ++i) | |
7729 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7730 | |
6c95b8df PA |
7731 | do_cleanups (old_chain); |
7732 | ||
ed0616c6 VP |
7733 | if (expanded.nelts <= 1) |
7734 | { | |
4a64f543 MS |
7735 | /* This is un ugly workaround. If we get zero expanded sals |
7736 | then something is really wrong. Fix that by returning the | |
7737 | original sal. */ | |
7738 | ||
ed0616c6 VP |
7739 | xfree (expanded.sals); |
7740 | expanded.nelts = 1; | |
7741 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7742 | sal.pc = original_pc; | |
7743 | expanded.sals[0] = sal; | |
7744 | return expanded; | |
7745 | } | |
7746 | ||
7747 | if (original_pc) | |
7748 | { | |
7749 | found = 0; | |
7750 | for (i = 0; i < expanded.nelts; ++i) | |
7751 | if (expanded.sals[i].pc == original_pc) | |
7752 | { | |
7753 | found = 1; | |
7754 | break; | |
7755 | } | |
7756 | gdb_assert (found); | |
7757 | } | |
7758 | ||
7759 | return expanded; | |
7760 | } | |
7761 | ||
018d34a4 VP |
7762 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7763 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7764 | value. COND_STRING, if not NULL, specified the condition to be | |
7765 | used for all breakpoints. Essentially the only case where | |
7766 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7767 | function. In that case, it's still not possible to specify | |
7768 | separate conditions for different overloaded functions, so | |
7769 | we take just a single condition string. | |
7770 | ||
c3f6f71d | 7771 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7772 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7773 | array contents). If the function fails (error() is called), the |
7774 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7775 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7776 | |
7777 | static void | |
8cdf0e15 | 7778 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7779 | struct symtabs_and_lines sals, |
7780 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7781 | char *cond_string, |
7782 | enum bptype type, enum bpdisp disposition, | |
7783 | int thread, int task, int ignore_count, | |
7784 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7785 | int enabled, int internal) |
c906108c | 7786 | { |
018d34a4 | 7787 | int i; |
cc59ec59 | 7788 | |
018d34a4 | 7789 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7790 | { |
ed0616c6 VP |
7791 | struct symtabs_and_lines expanded = |
7792 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7793 | |
7efd8fc2 | 7794 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7795 | cond_string, type, disposition, |
84f4c1fe | 7796 | thread, task, ignore_count, ops, |
56435ebe TT |
7797 | from_tty, enabled, internal, |
7798 | canonical->special_display); | |
c3f6f71d | 7799 | } |
c3f6f71d | 7800 | } |
c906108c | 7801 | |
9998af43 | 7802 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7803 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7804 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7805 | address strings. ADDRESS points to the end of the SAL. |
7806 | ||
7807 | The array and the line spec strings are allocated on the heap, it is | |
7808 | the caller's responsibility to free them. */ | |
c906108c | 7809 | |
b9362cc7 | 7810 | static void |
c3f6f71d JM |
7811 | parse_breakpoint_sals (char **address, |
7812 | struct symtabs_and_lines *sals, | |
58438ac1 | 7813 | struct linespec_result *canonical) |
c3f6f71d JM |
7814 | { |
7815 | char *addr_start = *address; | |
cc59ec59 | 7816 | |
c3f6f71d | 7817 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7818 | breakpoint. */ |
c3f6f71d JM |
7819 | if ((*address) == NULL |
7820 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7821 | { |
7822 | if (default_breakpoint_valid) | |
7823 | { | |
c3f6f71d | 7824 | struct symtab_and_line sal; |
cc59ec59 | 7825 | |
4a64f543 | 7826 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7827 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7828 | xmalloc (sizeof (struct symtab_and_line)); |
7829 | sal.pc = default_breakpoint_address; | |
7830 | sal.line = default_breakpoint_line; | |
7831 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7832 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7833 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7834 | |
4a64f543 MS |
7835 | /* "break" without arguments is equivalent to "break *PC" |
7836 | where PC is the default_breakpoint_address. So make sure | |
7837 | to set sal.explicit_pc to prevent GDB from trying to | |
7838 | expand the list of sals to include all other instances | |
7839 | with the same symtab and line. */ | |
00903456 JK |
7840 | sal.explicit_pc = 1; |
7841 | ||
c3f6f71d JM |
7842 | sals->sals[0] = sal; |
7843 | sals->nelts = 1; | |
c906108c SS |
7844 | } |
7845 | else | |
8a3fe4f8 | 7846 | error (_("No default breakpoint address now.")); |
c906108c SS |
7847 | } |
7848 | else | |
7849 | { | |
c906108c | 7850 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7851 | current_source_symtab (which is decode_line_1's default). |
7852 | This should produce the results we want almost all of the | |
7853 | time while leaving default_breakpoint_* alone. | |
7854 | ||
1aeae86e AF |
7855 | ObjC: However, don't match an Objective-C method name which |
7856 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7857 | |
c214a6fd | 7858 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7859 | |
c906108c | 7860 | if (default_breakpoint_valid |
0378c332 | 7861 | && (!cursal.symtab |
1aeae86e AF |
7862 | || ((strchr ("+-", (*address)[0]) != NULL) |
7863 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7864 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
58438ac1 | 7865 | default_breakpoint_line, canonical); |
c906108c | 7866 | else |
0101ce28 | 7867 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7868 | canonical); |
c906108c | 7869 | } |
4a64f543 | 7870 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7871 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7872 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7873 | if (addr_start != (*address)) |
c906108c | 7874 | { |
c3f6f71d | 7875 | int i; |
cc59ec59 | 7876 | |
c3f6f71d | 7877 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7878 | { |
4a64f543 | 7879 | /* Add the string if not present. */ |
7efd8fc2 TT |
7880 | if (canonical->canonical[i] == NULL) |
7881 | canonical->canonical[i] = savestring (addr_start, | |
7882 | (*address) - addr_start); | |
c906108c SS |
7883 | } |
7884 | } | |
c3f6f71d | 7885 | } |
c906108c | 7886 | |
c906108c | 7887 | |
c3f6f71d | 7888 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7889 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7890 | |
b9362cc7 | 7891 | static void |
23e7acfb | 7892 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7893 | { |
7894 | int i; | |
cc59ec59 | 7895 | |
c3f6f71d | 7896 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7897 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7898 | } |
7899 | ||
7a697b8d SS |
7900 | /* Fast tracepoints may have restrictions on valid locations. For |
7901 | instance, a fast tracepoint using a jump instead of a trap will | |
7902 | likely have to overwrite more bytes than a trap would, and so can | |
7903 | only be placed where the instruction is longer than the jump, or a | |
7904 | multi-instruction sequence does not have a jump into the middle of | |
7905 | it, etc. */ | |
7906 | ||
7907 | static void | |
7908 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7909 | struct symtabs_and_lines *sals) | |
7910 | { | |
7911 | int i, rslt; | |
7912 | struct symtab_and_line *sal; | |
7913 | char *msg; | |
7914 | struct cleanup *old_chain; | |
7915 | ||
7916 | for (i = 0; i < sals->nelts; i++) | |
7917 | { | |
7918 | sal = &sals->sals[i]; | |
7919 | ||
7920 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7921 | NULL, &msg); | |
7922 | old_chain = make_cleanup (xfree, msg); | |
7923 | ||
7924 | if (!rslt) | |
7925 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7926 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7927 | ||
7928 | do_cleanups (old_chain); | |
7929 | } | |
7930 | } | |
7931 | ||
018d34a4 VP |
7932 | /* Given TOK, a string specification of condition and thread, as |
7933 | accepted by the 'break' command, extract the condition | |
7934 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7935 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7936 | If no condition is found, *COND_STRING is set to NULL. |
7937 | If no thread is found, *THREAD is set to -1. */ | |
7938 | static void | |
7939 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7940 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7941 | { |
7942 | *cond_string = NULL; | |
7943 | *thread = -1; | |
7944 | while (tok && *tok) | |
7945 | { | |
7946 | char *end_tok; | |
7947 | int toklen; | |
7948 | char *cond_start = NULL; | |
7949 | char *cond_end = NULL; | |
cc59ec59 | 7950 | |
e9cafbcc | 7951 | tok = skip_spaces (tok); |
018d34a4 | 7952 | |
e9cafbcc | 7953 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7954 | |
7955 | toklen = end_tok - tok; | |
7956 | ||
7957 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7958 | { | |
f7545552 TT |
7959 | struct expression *expr; |
7960 | ||
018d34a4 | 7961 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7962 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7963 | xfree (expr); | |
018d34a4 VP |
7964 | cond_end = tok; |
7965 | *cond_string = savestring (cond_start, | |
7966 | cond_end - cond_start); | |
7967 | } | |
7968 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7969 | { | |
7970 | char *tmptok; | |
7971 | ||
7972 | tok = end_tok + 1; | |
7973 | tmptok = tok; | |
7974 | *thread = strtol (tok, &tok, 0); | |
7975 | if (tok == tmptok) | |
7976 | error (_("Junk after thread keyword.")); | |
7977 | if (!valid_thread_id (*thread)) | |
7978 | error (_("Unknown thread %d."), *thread); | |
7979 | } | |
4a306c9a JB |
7980 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7981 | { | |
7982 | char *tmptok; | |
7983 | ||
7984 | tok = end_tok + 1; | |
7985 | tmptok = tok; | |
7986 | *task = strtol (tok, &tok, 0); | |
7987 | if (tok == tmptok) | |
7988 | error (_("Junk after task keyword.")); | |
7989 | if (!valid_task_id (*task)) | |
b6199126 | 7990 | error (_("Unknown task %d."), *task); |
4a306c9a | 7991 | } |
018d34a4 VP |
7992 | else |
7993 | error (_("Junk at end of arguments.")); | |
7994 | } | |
7995 | } | |
7996 | ||
0fb4aa4b PA |
7997 | /* Decode a static tracepoint marker spec. */ |
7998 | ||
7999 | static struct symtabs_and_lines | |
8000 | decode_static_tracepoint_spec (char **arg_p) | |
8001 | { | |
8002 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
8003 | struct symtabs_and_lines sals; | |
8004 | struct symtab_and_line sal; | |
8005 | struct symbol *sym; | |
8006 | struct cleanup *old_chain; | |
8007 | char *p = &(*arg_p)[3]; | |
8008 | char *endp; | |
8009 | char *marker_str; | |
8010 | int i; | |
8011 | ||
e9cafbcc | 8012 | p = skip_spaces (p); |
0fb4aa4b | 8013 | |
e9cafbcc | 8014 | endp = skip_to_space (p); |
0fb4aa4b PA |
8015 | |
8016 | marker_str = savestring (p, endp - p); | |
8017 | old_chain = make_cleanup (xfree, marker_str); | |
8018 | ||
8019 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
8020 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
8021 | error (_("No known static tracepoint marker named %s"), marker_str); | |
8022 | ||
8023 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8024 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
8025 | ||
8026 | for (i = 0; i < sals.nelts; i++) | |
8027 | { | |
8028 | struct static_tracepoint_marker *marker; | |
8029 | ||
8030 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
8031 | ||
8032 | init_sal (&sals.sals[i]); | |
8033 | ||
8034 | sals.sals[i] = find_pc_line (marker->address, 0); | |
8035 | sals.sals[i].pc = marker->address; | |
8036 | ||
8037 | release_static_tracepoint_marker (marker); | |
8038 | } | |
8039 | ||
8040 | do_cleanups (old_chain); | |
8041 | ||
8042 | *arg_p = endp; | |
8043 | return sals; | |
8044 | } | |
8045 | ||
fd9b8c24 PA |
8046 | /* Set a breakpoint. This function is shared between CLI and MI |
8047 | functions for setting a breakpoint. This function has two major | |
8048 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
8049 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
8050 | breakpoint location, address and thread. Otherwise, ARG is just |
8051 | the location of breakpoint, with condition and thread specified by | |
8052 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
8053 | the breakpoint number will be allocated from the internal | |
8054 | breakpoint count. Returns true if any breakpoint was created; | |
8055 | false otherwise. */ | |
0101ce28 | 8056 | |
8cdf0e15 VP |
8057 | int |
8058 | create_breakpoint (struct gdbarch *gdbarch, | |
8059 | char *arg, char *cond_string, int thread, | |
8060 | int parse_condition_and_thread, | |
0fb4aa4b | 8061 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
8062 | int ignore_count, |
8063 | enum auto_boolean pending_break_support, | |
8064 | struct breakpoint_ops *ops, | |
84f4c1fe | 8065 | int from_tty, int enabled, int internal) |
c3f6f71d | 8066 | { |
b78a6381 | 8067 | volatile struct gdb_exception e; |
c3f6f71d | 8068 | struct symtabs_and_lines sals; |
0101ce28 | 8069 | struct symtab_and_line pending_sal; |
0101ce28 | 8070 | char *copy_arg; |
c3f6f71d | 8071 | char *addr_start = arg; |
7efd8fc2 | 8072 | struct linespec_result canonical; |
c3f6f71d | 8073 | struct cleanup *old_chain; |
80c99de1 | 8074 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 8075 | int i; |
0101ce28 | 8076 | int pending = 0; |
4a306c9a | 8077 | int task = 0; |
86b17b60 | 8078 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 8079 | |
c3f6f71d JM |
8080 | sals.sals = NULL; |
8081 | sals.nelts = 0; | |
7efd8fc2 | 8082 | init_linespec_result (&canonical); |
c3f6f71d | 8083 | |
0fb4aa4b PA |
8084 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
8085 | { | |
8086 | int i; | |
8087 | ||
8088 | sals = decode_static_tracepoint_spec (&arg); | |
8089 | ||
8090 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 8091 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 8092 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 8093 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
8094 | goto done; |
8095 | } | |
8096 | ||
b78a6381 TT |
8097 | TRY_CATCH (e, RETURN_MASK_ALL) |
8098 | { | |
58438ac1 | 8099 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 8100 | } |
0101ce28 JJ |
8101 | |
8102 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 8103 | switch (e.reason) |
0101ce28 | 8104 | { |
05ff989b | 8105 | case RETURN_QUIT: |
98deb0da | 8106 | throw_exception (e); |
05ff989b AC |
8107 | case RETURN_ERROR: |
8108 | switch (e.error) | |
0101ce28 | 8109 | { |
05ff989b | 8110 | case NOT_FOUND_ERROR: |
0101ce28 | 8111 | |
05ff989b AC |
8112 | /* If pending breakpoint support is turned off, throw |
8113 | error. */ | |
fa8d40ab JJ |
8114 | |
8115 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
8116 | throw_exception (e); |
8117 | ||
8118 | exception_print (gdb_stderr, e); | |
fa8d40ab | 8119 | |
05ff989b AC |
8120 | /* If pending breakpoint support is auto query and the user |
8121 | selects no, then simply return the error code. */ | |
059fb39f | 8122 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
8123 | && !nquery (_("Make breakpoint pending on " |
8124 | "future shared library load? "))) | |
fd9b8c24 | 8125 | return 0; |
fa8d40ab | 8126 | |
05ff989b AC |
8127 | /* At this point, either the user was queried about setting |
8128 | a pending breakpoint and selected yes, or pending | |
8129 | breakpoint behavior is on and thus a pending breakpoint | |
8130 | is defaulted on behalf of the user. */ | |
0101ce28 | 8131 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 8132 | canonical.canonical = ©_arg; |
0101ce28 JJ |
8133 | sals.nelts = 1; |
8134 | sals.sals = &pending_sal; | |
8135 | pending_sal.pc = 0; | |
8136 | pending = 1; | |
05ff989b AC |
8137 | break; |
8138 | default: | |
98deb0da | 8139 | throw_exception (e); |
0101ce28 | 8140 | } |
2abae994 | 8141 | break; |
05ff989b AC |
8142 | default: |
8143 | if (!sals.nelts) | |
fd9b8c24 | 8144 | return 0; |
0101ce28 | 8145 | } |
c3f6f71d | 8146 | |
0fb4aa4b PA |
8147 | done: |
8148 | ||
4a64f543 | 8149 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
8150 | old_chain = make_cleanup (null_cleanup, 0); |
8151 | ||
0101ce28 JJ |
8152 | if (!pending) |
8153 | { | |
8154 | /* Make sure that all storage allocated to SALS gets freed. */ | |
8155 | make_cleanup (xfree, sals.sals); | |
8156 | ||
7efd8fc2 TT |
8157 | /* Cleanup the canonical array but not its contents. */ |
8158 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 8159 | } |
c3f6f71d | 8160 | |
c3f6f71d JM |
8161 | /* ----------------------------- SNIP ----------------------------- |
8162 | Anything added to the cleanup chain beyond this point is assumed | |
8163 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
8164 | then the memory is not reclaimed. */ |
8165 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 8166 | |
7efd8fc2 | 8167 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 8168 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
8169 | for (i = 0; i < sals.nelts; i++) |
8170 | { | |
7efd8fc2 TT |
8171 | if (canonical.canonical[i] != NULL) |
8172 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
8173 | } |
8174 | ||
8175 | /* Resolve all line numbers to PC's and verify that the addresses | |
8176 | are ok for the target. */ | |
0101ce28 | 8177 | if (!pending) |
23e7acfb | 8178 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 8179 | |
7a697b8d SS |
8180 | /* Fast tracepoints may have additional restrictions on location. */ |
8181 | if (type_wanted == bp_fast_tracepoint) | |
8182 | check_fast_tracepoint_sals (gdbarch, &sals); | |
8183 | ||
c3f6f71d JM |
8184 | /* Verify that condition can be parsed, before setting any |
8185 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 8186 | breakpoint. */ |
0101ce28 | 8187 | if (!pending) |
c3f6f71d | 8188 | { |
2f069f6f | 8189 | if (parse_condition_and_thread) |
72b2ff0e VP |
8190 | { |
8191 | /* Here we only parse 'arg' to separate condition | |
8192 | from thread number, so parsing in context of first | |
8193 | sal is OK. When setting the breakpoint we'll | |
8194 | re-parse it in context of each sal. */ | |
8195 | cond_string = NULL; | |
8196 | thread = -1; | |
4a306c9a JB |
8197 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
8198 | &thread, &task); | |
72b2ff0e VP |
8199 | if (cond_string) |
8200 | make_cleanup (xfree, cond_string); | |
8201 | } | |
2f069f6f | 8202 | else |
72b2ff0e VP |
8203 | { |
8204 | /* Create a private copy of condition string. */ | |
8205 | if (cond_string) | |
8206 | { | |
8207 | cond_string = xstrdup (cond_string); | |
8208 | make_cleanup (xfree, cond_string); | |
8209 | } | |
8210 | } | |
0fb4aa4b PA |
8211 | |
8212 | /* If the user is creating a static tracepoint by marker id | |
8213 | (strace -m MARKER_ID), then store the sals index, so that | |
8214 | breakpoint_re_set can try to match up which of the newly | |
8215 | found markers corresponds to this one, and, don't try to | |
8216 | expand multiple locations for each sal, given than SALS | |
8217 | already should contain all sals for MARKER_ID. */ | |
8218 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 8219 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
8220 | { |
8221 | int i; | |
8222 | ||
8223 | for (i = 0; i < sals.nelts; ++i) | |
8224 | { | |
8225 | struct symtabs_and_lines expanded; | |
8226 | struct breakpoint *tp; | |
8227 | struct cleanup *old_chain; | |
8228 | ||
8229 | expanded.nelts = 1; | |
8230 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
8231 | expanded.sals[0] = sals.sals[i]; | |
8232 | old_chain = make_cleanup (xfree, expanded.sals); | |
8233 | ||
7efd8fc2 | 8234 | create_breakpoint_sal (gdbarch, expanded, canonical.canonical[i], |
0fb4aa4b PA |
8235 | cond_string, type_wanted, |
8236 | tempflag ? disp_del : disp_donttouch, | |
8237 | thread, task, ignore_count, ops, | |
56435ebe TT |
8238 | from_tty, enabled, internal, |
8239 | canonical.special_display); | |
0fb4aa4b PA |
8240 | |
8241 | do_cleanups (old_chain); | |
8242 | ||
8243 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
8244 | if (internal) |
8245 | tp = get_breakpoint (internal_breakpoint_number); | |
8246 | else | |
8247 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
8248 | gdb_assert (tp != NULL); |
8249 | ||
8250 | /* Given that its possible to have multiple markers with | |
8251 | the same string id, if the user is creating a static | |
8252 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
8253 | store the sals index, so that breakpoint_re_set can | |
8254 | try to match up which of the newly found markers | |
8255 | corresponds to this one */ | |
8256 | tp->static_trace_marker_id_idx = i; | |
8257 | } | |
8258 | } | |
8259 | else | |
7efd8fc2 | 8260 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
8261 | type_wanted, |
8262 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 8263 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 8264 | enabled, internal); |
c906108c | 8265 | } |
0101ce28 JJ |
8266 | else |
8267 | { | |
0101ce28 JJ |
8268 | struct breakpoint *b; |
8269 | ||
0101ce28 JJ |
8270 | make_cleanup (xfree, copy_arg); |
8271 | ||
a6d9a66e | 8272 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 8273 | set_breakpoint_number (internal, b); |
72b2ff0e | 8274 | b->thread = -1; |
7efd8fc2 | 8275 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 8276 | b->cond_string = NULL; |
0101ce28 | 8277 | b->ignore_count = ignore_count; |
0101ce28 | 8278 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8279 | b->condition_not_parsed = 1; |
604133b5 | 8280 | b->ops = ops; |
41447f92 | 8281 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8282 | b->pspace = current_program_space; |
84f4c1fe | 8283 | b->py_bp_object = NULL; |
74960c60 | 8284 | |
6c95b8df | 8285 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8286 | && (b->type == bp_breakpoint |
8287 | || b->type == bp_hardware_breakpoint)) | |
8288 | b->enable_state = bp_startup_disabled; | |
8289 | ||
8d3788bd | 8290 | if (!internal) |
84f4c1fe PM |
8291 | /* Do not mention breakpoints with a negative number, |
8292 | but do notify observers. */ | |
8d3788bd VP |
8293 | mention (b); |
8294 | observer_notify_breakpoint_created (b); | |
0101ce28 JJ |
8295 | } |
8296 | ||
c3f6f71d | 8297 | if (sals.nelts > 1) |
95a42b64 | 8298 | { |
3e43a32a MS |
8299 | warning (_("Multiple breakpoints were set.\nUse the " |
8300 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8301 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8302 | } |
8303 | ||
80c99de1 PA |
8304 | /* That's it. Discard the cleanups for data inserted into the |
8305 | breakpoint. */ | |
8306 | discard_cleanups (bkpt_chain); | |
8307 | /* But cleanup everything else. */ | |
c3f6f71d | 8308 | do_cleanups (old_chain); |
217dc9e2 | 8309 | |
80c99de1 | 8310 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8311 | update_global_location_list (1); |
fd9b8c24 PA |
8312 | |
8313 | return 1; | |
c3f6f71d | 8314 | } |
c906108c | 8315 | |
72b2ff0e VP |
8316 | /* Set a breakpoint. |
8317 | ARG is a string describing breakpoint address, | |
8318 | condition, and thread. | |
8319 | FLAG specifies if a breakpoint is hardware on, | |
8320 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8321 | and BP_TEMPFLAG. */ | |
8322 | ||
98deb0da | 8323 | static void |
72b2ff0e | 8324 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8325 | { |
72b2ff0e | 8326 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8327 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8328 | ? bp_hardware_breakpoint | |
8329 | : bp_breakpoint); | |
c3f6f71d | 8330 | |
8cdf0e15 VP |
8331 | create_breakpoint (get_current_arch (), |
8332 | arg, | |
8333 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8334 | tempflag, type_wanted, |
8cdf0e15 VP |
8335 | 0 /* Ignore count */, |
8336 | pending_break_support, | |
8337 | NULL /* breakpoint_ops */, | |
8338 | from_tty, | |
84f4c1fe PM |
8339 | 1 /* enabled */, |
8340 | 0 /* internal */); | |
c906108c SS |
8341 | } |
8342 | ||
72b2ff0e | 8343 | |
c906108c SS |
8344 | /* Helper function for break_command_1 and disassemble_command. */ |
8345 | ||
8346 | void | |
fba45db2 | 8347 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8348 | { |
8349 | CORE_ADDR pc; | |
8350 | ||
8351 | if (sal->pc == 0 && sal->symtab != NULL) | |
8352 | { | |
8353 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8354 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8355 | sal->line, sal->symtab->filename); |
8356 | sal->pc = pc; | |
6a048695 | 8357 | |
4a64f543 MS |
8358 | /* If this SAL corresponds to a breakpoint inserted using a line |
8359 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8360 | if (sal->explicit_line) |
059acae7 | 8361 | skip_prologue_sal (sal); |
c906108c SS |
8362 | } |
8363 | ||
8364 | if (sal->section == 0 && sal->symtab != NULL) | |
8365 | { | |
8366 | struct blockvector *bv; | |
c5aa993b JM |
8367 | struct block *b; |
8368 | struct symbol *sym; | |
c906108c | 8369 | |
801e3a5b | 8370 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8371 | if (bv != NULL) |
8372 | { | |
7f0df278 | 8373 | sym = block_linkage_function (b); |
c906108c SS |
8374 | if (sym != NULL) |
8375 | { | |
8376 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8377 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8378 | } |
8379 | else | |
8380 | { | |
4a64f543 MS |
8381 | /* It really is worthwhile to have the section, so we'll |
8382 | just have to look harder. This case can be executed | |
8383 | if we have line numbers but no functions (as can | |
8384 | happen in assembly source). */ | |
c906108c | 8385 | |
c5aa993b | 8386 | struct minimal_symbol *msym; |
6c95b8df PA |
8387 | struct cleanup *old_chain = save_current_space_and_thread (); |
8388 | ||
8389 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8390 | |
8391 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8392 | if (msym) | |
714835d5 | 8393 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8394 | |
8395 | do_cleanups (old_chain); | |
c906108c SS |
8396 | } |
8397 | } | |
8398 | } | |
8399 | } | |
8400 | ||
8401 | void | |
fba45db2 | 8402 | break_command (char *arg, int from_tty) |
c906108c | 8403 | { |
db107f19 | 8404 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8405 | } |
8406 | ||
c906108c | 8407 | void |
fba45db2 | 8408 | tbreak_command (char *arg, int from_tty) |
c906108c | 8409 | { |
db107f19 | 8410 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8411 | } |
8412 | ||
c906108c | 8413 | static void |
fba45db2 | 8414 | hbreak_command (char *arg, int from_tty) |
c906108c | 8415 | { |
db107f19 | 8416 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8417 | } |
8418 | ||
8419 | static void | |
fba45db2 | 8420 | thbreak_command (char *arg, int from_tty) |
c906108c | 8421 | { |
db107f19 | 8422 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8423 | } |
8424 | ||
8425 | static void | |
fba45db2 | 8426 | stop_command (char *arg, int from_tty) |
c906108c | 8427 | { |
a3f17187 | 8428 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8429 | Usage: stop in <function | address>\n\ |
a3f17187 | 8430 | stop at <line>\n")); |
c906108c SS |
8431 | } |
8432 | ||
8433 | static void | |
fba45db2 | 8434 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8435 | { |
8436 | int badInput = 0; | |
8437 | ||
c5aa993b | 8438 | if (arg == (char *) NULL) |
c906108c SS |
8439 | badInput = 1; |
8440 | else if (*arg != '*') | |
8441 | { | |
8442 | char *argptr = arg; | |
8443 | int hasColon = 0; | |
8444 | ||
4a64f543 | 8445 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8446 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8447 | function/method name. */ |
c906108c | 8448 | while (*argptr && !hasColon) |
c5aa993b JM |
8449 | { |
8450 | hasColon = (*argptr == ':'); | |
8451 | argptr++; | |
8452 | } | |
c906108c SS |
8453 | |
8454 | if (hasColon) | |
c5aa993b | 8455 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8456 | else |
c5aa993b | 8457 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8458 | } |
8459 | ||
8460 | if (badInput) | |
a3f17187 | 8461 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8462 | else |
db107f19 | 8463 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8464 | } |
8465 | ||
8466 | static void | |
fba45db2 | 8467 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8468 | { |
8469 | int badInput = 0; | |
8470 | ||
c5aa993b | 8471 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8472 | badInput = 1; |
8473 | else | |
8474 | { | |
8475 | char *argptr = arg; | |
8476 | int hasColon = 0; | |
8477 | ||
4a64f543 MS |
8478 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8479 | it is probably a line number. */ | |
c906108c | 8480 | while (*argptr && !hasColon) |
c5aa993b JM |
8481 | { |
8482 | hasColon = (*argptr == ':'); | |
8483 | argptr++; | |
8484 | } | |
c906108c SS |
8485 | |
8486 | if (hasColon) | |
c5aa993b | 8487 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8488 | else |
c5aa993b | 8489 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8490 | } |
8491 | ||
8492 | if (badInput) | |
a3f17187 | 8493 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8494 | else |
db107f19 | 8495 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8496 | } |
8497 | ||
f1310107 TJB |
8498 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8499 | ranged breakpoints. */ | |
8500 | ||
8501 | static int | |
8502 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8503 | struct address_space *aspace, | |
8504 | CORE_ADDR bp_addr) | |
8505 | { | |
8506 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8507 | bl->length, aspace, bp_addr); | |
8508 | } | |
8509 | ||
8510 | /* Implement the "resources_needed" breakpoint_ops method for | |
8511 | ranged breakpoints. */ | |
8512 | ||
8513 | static int | |
8514 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8515 | { | |
8516 | return target_ranged_break_num_registers (); | |
8517 | } | |
8518 | ||
8519 | /* Implement the "print_it" breakpoint_ops method for | |
8520 | ranged breakpoints. */ | |
8521 | ||
8522 | static enum print_stop_action | |
8523 | print_it_ranged_breakpoint (struct breakpoint *b) | |
8524 | { | |
8525 | struct bp_location *bl = b->loc; | |
8526 | ||
8527 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8528 | ||
8529 | /* Ranged breakpoints have only one location. */ | |
8530 | gdb_assert (bl && bl->next == NULL); | |
8531 | ||
8532 | annotate_breakpoint (b->number); | |
8533 | if (b->disposition == disp_del) | |
8534 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8535 | else | |
8536 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8537 | if (ui_out_is_mi_like_p (uiout)) | |
8538 | { | |
8539 | ui_out_field_string (uiout, "reason", | |
8540 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8541 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8542 | } | |
8543 | ui_out_field_int (uiout, "bkptno", b->number); | |
8544 | ui_out_text (uiout, ", "); | |
8545 | ||
8546 | return PRINT_SRC_AND_LOC; | |
8547 | } | |
8548 | ||
8549 | /* Implement the "print_one" breakpoint_ops method for | |
8550 | ranged breakpoints. */ | |
8551 | ||
8552 | static void | |
8553 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8554 | struct bp_location **last_loc) | |
8555 | { | |
8556 | struct bp_location *bl = b->loc; | |
8557 | struct value_print_options opts; | |
8558 | ||
8559 | /* Ranged breakpoints have only one location. */ | |
8560 | gdb_assert (bl && bl->next == NULL); | |
8561 | ||
8562 | get_user_print_options (&opts); | |
8563 | ||
8564 | if (opts.addressprint) | |
8565 | /* We don't print the address range here, it will be printed later | |
8566 | by print_one_detail_ranged_breakpoint. */ | |
8567 | ui_out_field_skip (uiout, "addr"); | |
8568 | annotate_field (5); | |
8569 | print_breakpoint_location (b, bl); | |
8570 | *last_loc = bl; | |
8571 | } | |
8572 | ||
8573 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8574 | ranged breakpoints. */ | |
8575 | ||
8576 | static void | |
8577 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8578 | struct ui_out *uiout) | |
8579 | { | |
8580 | CORE_ADDR address_start, address_end; | |
8581 | struct bp_location *bl = b->loc; | |
8582 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8583 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8584 | ||
8585 | gdb_assert (bl); | |
8586 | ||
8587 | address_start = bl->address; | |
8588 | address_end = address_start + bl->length - 1; | |
8589 | ||
8590 | ui_out_text (uiout, "\taddress range: "); | |
8591 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8592 | print_core_address (bl->gdbarch, address_start), | |
8593 | print_core_address (bl->gdbarch, address_end)); | |
8594 | ui_out_field_stream (uiout, "addr", stb); | |
8595 | ui_out_text (uiout, "\n"); | |
8596 | ||
8597 | do_cleanups (cleanup); | |
8598 | } | |
8599 | ||
8600 | /* Implement the "print_mention" breakpoint_ops method for | |
8601 | ranged breakpoints. */ | |
8602 | ||
8603 | static void | |
8604 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8605 | { | |
8606 | struct bp_location *bl = b->loc; | |
8607 | ||
8608 | gdb_assert (bl); | |
8609 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8610 | ||
8611 | if (ui_out_is_mi_like_p (uiout)) | |
8612 | return; | |
8613 | ||
8614 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8615 | b->number, paddress (bl->gdbarch, bl->address), | |
8616 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8617 | } | |
8618 | ||
8619 | /* Implement the "print_recreate" breakpoint_ops method for | |
8620 | ranged breakpoints. */ | |
8621 | ||
8622 | static void | |
8623 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8624 | { | |
8625 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8626 | b->addr_string_range_end); | |
8627 | } | |
8628 | ||
8629 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8630 | ||
8631 | static struct breakpoint_ops ranged_breakpoint_ops = | |
8632 | { | |
be5c67c1 | 8633 | NULL, /* dtor */ |
f1310107 TJB |
8634 | NULL, /* insert */ |
8635 | NULL, /* remove */ | |
8636 | breakpoint_hit_ranged_breakpoint, | |
8637 | resources_needed_ranged_breakpoint, | |
9c06b0b4 | 8638 | NULL, /* works_in_software_mode */ |
f1310107 TJB |
8639 | print_it_ranged_breakpoint, |
8640 | print_one_ranged_breakpoint, | |
8641 | print_one_detail_ranged_breakpoint, | |
8642 | print_mention_ranged_breakpoint, | |
8643 | print_recreate_ranged_breakpoint | |
8644 | }; | |
8645 | ||
8646 | /* Find the address where the end of the breakpoint range should be | |
8647 | placed, given the SAL of the end of the range. This is so that if | |
8648 | the user provides a line number, the end of the range is set to the | |
8649 | last instruction of the given line. */ | |
8650 | ||
8651 | static CORE_ADDR | |
8652 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8653 | { | |
8654 | CORE_ADDR end; | |
8655 | ||
8656 | /* If the user provided a PC value, use it. Otherwise, | |
8657 | find the address of the end of the given location. */ | |
8658 | if (sal.explicit_pc) | |
8659 | end = sal.pc; | |
8660 | else | |
8661 | { | |
8662 | int ret; | |
8663 | CORE_ADDR start; | |
8664 | ||
8665 | ret = find_line_pc_range (sal, &start, &end); | |
8666 | if (!ret) | |
8667 | error (_("Could not find location of the end of the range.")); | |
8668 | ||
8669 | /* find_line_pc_range returns the start of the next line. */ | |
8670 | end--; | |
8671 | } | |
8672 | ||
8673 | return end; | |
8674 | } | |
8675 | ||
8676 | /* Implement the "break-range" CLI command. */ | |
8677 | ||
8678 | static void | |
8679 | break_range_command (char *arg, int from_tty) | |
8680 | { | |
8681 | char *arg_start, *addr_string_start, *addr_string_end; | |
8682 | struct linespec_result canonical_start, canonical_end; | |
8683 | int bp_count, can_use_bp, length; | |
8684 | CORE_ADDR end; | |
8685 | struct breakpoint *b; | |
8686 | struct symtab_and_line sal_start, sal_end; | |
8687 | struct symtabs_and_lines sals_start, sals_end; | |
8688 | struct cleanup *cleanup_bkpt; | |
8689 | ||
8690 | /* We don't support software ranged breakpoints. */ | |
8691 | if (target_ranged_break_num_registers () < 0) | |
8692 | error (_("This target does not support hardware ranged breakpoints.")); | |
8693 | ||
8694 | bp_count = hw_breakpoint_used_count (); | |
8695 | bp_count += target_ranged_break_num_registers (); | |
8696 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8697 | bp_count, 0); | |
8698 | if (can_use_bp < 0) | |
8699 | error (_("Hardware breakpoints used exceeds limit.")); | |
8700 | ||
8701 | if (arg == NULL || arg[0] == '\0') | |
8702 | error(_("No address range specified.")); | |
8703 | ||
8704 | sals_start.sals = NULL; | |
8705 | sals_start.nelts = 0; | |
8706 | init_linespec_result (&canonical_start); | |
8707 | ||
8708 | while (*arg == ' ' || *arg == '\t') | |
8709 | arg++; | |
8710 | ||
58438ac1 | 8711 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8712 | |
8713 | sal_start = sals_start.sals[0]; | |
8714 | addr_string_start = canonical_start.canonical[0]; | |
8715 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8716 | xfree (sals_start.sals); | |
8717 | xfree (canonical_start.canonical); | |
8718 | ||
8719 | if (arg[0] != ',') | |
8720 | error (_("Too few arguments.")); | |
8721 | else if (sals_start.nelts == 0) | |
8722 | error (_("Could not find location of the beginning of the range.")); | |
8723 | else if (sals_start.nelts != 1) | |
8724 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8725 | ||
8726 | resolve_sal_pc (&sal_start); | |
8727 | ||
8728 | arg++; /* Skip the comma. */ | |
8729 | while (*arg == ' ' || *arg == '\t') | |
8730 | arg++; | |
8731 | ||
8732 | /* Parse the end location. */ | |
8733 | ||
8734 | sals_end.sals = NULL; | |
8735 | sals_end.nelts = 0; | |
8736 | init_linespec_result (&canonical_end); | |
8737 | arg_start = arg; | |
8738 | ||
423f41a5 | 8739 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8740 | parse_breakpoint_sals because we need to specify the start location's |
8741 | symtab and line as the default symtab and line for the end of the | |
8742 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8743 | where +14 means 14 lines from the start location. */ | |
8744 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8745 | &canonical_end); |
f1310107 TJB |
8746 | |
8747 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8748 | if (canonical_end.canonical == NULL) | |
38a714bb | 8749 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8750 | /* Add the string if not present. */ |
8751 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8752 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8753 | ||
8754 | sal_end = sals_end.sals[0]; | |
8755 | addr_string_end = canonical_end.canonical[0]; | |
8756 | make_cleanup (xfree, addr_string_end); | |
8757 | xfree (sals_end.sals); | |
8758 | xfree (canonical_end.canonical); | |
8759 | ||
8760 | if (sals_end.nelts == 0) | |
8761 | error (_("Could not find location of the end of the range.")); | |
8762 | else if (sals_end.nelts != 1) | |
8763 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8764 | ||
8765 | resolve_sal_pc (&sal_end); | |
8766 | ||
8767 | end = find_breakpoint_range_end (sal_end); | |
8768 | if (sal_start.pc > end) | |
8769 | error (_("Invalid address range, end preceeds start.")); | |
8770 | ||
8771 | length = end - sal_start.pc + 1; | |
8772 | if (length < 0) | |
8773 | /* Length overflowed. */ | |
8774 | error (_("Address range too large.")); | |
8775 | else if (length == 1) | |
8776 | { | |
8777 | /* This range is simple enough to be handled by | |
8778 | the `hbreak' command. */ | |
8779 | hbreak_command (addr_string_start, 1); | |
8780 | ||
8781 | do_cleanups (cleanup_bkpt); | |
8782 | ||
8783 | return; | |
8784 | } | |
8785 | ||
8786 | /* Now set up the breakpoint. */ | |
8787 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
8788 | bp_hardware_breakpoint); | |
8789 | set_breakpoint_count (breakpoint_count + 1); | |
8790 | b->number = breakpoint_count; | |
8791 | b->disposition = disp_donttouch; | |
8792 | b->addr_string = addr_string_start; | |
8793 | b->addr_string_range_end = addr_string_end; | |
8794 | b->ops = &ranged_breakpoint_ops; | |
8795 | b->loc->length = length; | |
8796 | ||
8797 | discard_cleanups (cleanup_bkpt); | |
8798 | ||
8799 | mention (b); | |
8d3788bd | 8800 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8801 | update_global_location_list (1); |
8802 | } | |
8803 | ||
4a64f543 MS |
8804 | /* Return non-zero if EXP is verified as constant. Returned zero |
8805 | means EXP is variable. Also the constant detection may fail for | |
8806 | some constant expressions and in such case still falsely return | |
8807 | zero. */ | |
65d79d4b SDJ |
8808 | static int |
8809 | watchpoint_exp_is_const (const struct expression *exp) | |
8810 | { | |
8811 | int i = exp->nelts; | |
8812 | ||
8813 | while (i > 0) | |
8814 | { | |
8815 | int oplenp, argsp; | |
8816 | ||
8817 | /* We are only interested in the descriptor of each element. */ | |
8818 | operator_length (exp, i, &oplenp, &argsp); | |
8819 | i -= oplenp; | |
8820 | ||
8821 | switch (exp->elts[i].opcode) | |
8822 | { | |
8823 | case BINOP_ADD: | |
8824 | case BINOP_SUB: | |
8825 | case BINOP_MUL: | |
8826 | case BINOP_DIV: | |
8827 | case BINOP_REM: | |
8828 | case BINOP_MOD: | |
8829 | case BINOP_LSH: | |
8830 | case BINOP_RSH: | |
8831 | case BINOP_LOGICAL_AND: | |
8832 | case BINOP_LOGICAL_OR: | |
8833 | case BINOP_BITWISE_AND: | |
8834 | case BINOP_BITWISE_IOR: | |
8835 | case BINOP_BITWISE_XOR: | |
8836 | case BINOP_EQUAL: | |
8837 | case BINOP_NOTEQUAL: | |
8838 | case BINOP_LESS: | |
8839 | case BINOP_GTR: | |
8840 | case BINOP_LEQ: | |
8841 | case BINOP_GEQ: | |
8842 | case BINOP_REPEAT: | |
8843 | case BINOP_COMMA: | |
8844 | case BINOP_EXP: | |
8845 | case BINOP_MIN: | |
8846 | case BINOP_MAX: | |
8847 | case BINOP_INTDIV: | |
8848 | case BINOP_CONCAT: | |
8849 | case BINOP_IN: | |
8850 | case BINOP_RANGE: | |
8851 | case TERNOP_COND: | |
8852 | case TERNOP_SLICE: | |
8853 | case TERNOP_SLICE_COUNT: | |
8854 | ||
8855 | case OP_LONG: | |
8856 | case OP_DOUBLE: | |
8857 | case OP_DECFLOAT: | |
8858 | case OP_LAST: | |
8859 | case OP_COMPLEX: | |
8860 | case OP_STRING: | |
8861 | case OP_BITSTRING: | |
8862 | case OP_ARRAY: | |
8863 | case OP_TYPE: | |
8864 | case OP_NAME: | |
8865 | case OP_OBJC_NSSTRING: | |
8866 | ||
8867 | case UNOP_NEG: | |
8868 | case UNOP_LOGICAL_NOT: | |
8869 | case UNOP_COMPLEMENT: | |
8870 | case UNOP_ADDR: | |
8871 | case UNOP_HIGH: | |
4a64f543 MS |
8872 | /* Unary, binary and ternary operators: We have to check |
8873 | their operands. If they are constant, then so is the | |
8874 | result of that operation. For instance, if A and B are | |
8875 | determined to be constants, then so is "A + B". | |
8876 | ||
8877 | UNOP_IND is one exception to the rule above, because the | |
8878 | value of *ADDR is not necessarily a constant, even when | |
8879 | ADDR is. */ | |
65d79d4b SDJ |
8880 | break; |
8881 | ||
8882 | case OP_VAR_VALUE: | |
8883 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8884 | |
65d79d4b | 8885 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8886 | possible that a buggy compiler could mark a variable as |
8887 | constant even when it is not, and TYPE_CONST would return | |
8888 | true in this case, while SYMBOL_CLASS wouldn't. | |
8889 | ||
8890 | We also have to check for function symbols because they | |
8891 | are always constant. */ | |
65d79d4b SDJ |
8892 | { |
8893 | struct symbol *s = exp->elts[i + 2].symbol; | |
8894 | ||
8895 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8896 | && SYMBOL_CLASS (s) != LOC_CONST | |
8897 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8898 | return 0; | |
8899 | break; | |
8900 | } | |
8901 | ||
8902 | /* The default action is to return 0 because we are using | |
8903 | the optimistic approach here: If we don't know something, | |
8904 | then it is not a constant. */ | |
8905 | default: | |
8906 | return 0; | |
8907 | } | |
8908 | } | |
8909 | ||
8910 | return 1; | |
8911 | } | |
8912 | ||
77b06cd7 TJB |
8913 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8914 | ||
8915 | static int | |
8916 | insert_watchpoint (struct bp_location *bl) | |
8917 | { | |
e09342b5 TJB |
8918 | int length = bl->owner->exact? 1 : bl->length; |
8919 | ||
8920 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8921 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8922 | } |
8923 | ||
8924 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8925 | ||
8926 | static int | |
8927 | remove_watchpoint (struct bp_location *bl) | |
8928 | { | |
e09342b5 TJB |
8929 | int length = bl->owner->exact? 1 : bl->length; |
8930 | ||
8931 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8932 | bl->owner->cond_exp); | |
8933 | } | |
8934 | ||
8935 | /* Implement the "resources_needed" breakpoint_ops method for | |
8936 | hardware watchpoints. */ | |
8937 | ||
8938 | static int | |
8939 | resources_needed_watchpoint (const struct bp_location *bl) | |
8940 | { | |
90e4670f | 8941 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8942 | |
90e4670f | 8943 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8944 | } |
8945 | ||
9c06b0b4 TJB |
8946 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
8947 | hardware watchpoints. */ | |
8948 | ||
8949 | int | |
8950 | works_in_software_mode_watchpoint (const struct breakpoint *b) | |
8951 | { | |
8952 | return b->type == bp_hardware_watchpoint; | |
8953 | } | |
8954 | ||
77b06cd7 TJB |
8955 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
8956 | ||
8957 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8958 | { | |
be5c67c1 | 8959 | NULL, /* dtor */ |
77b06cd7 TJB |
8960 | insert_watchpoint, |
8961 | remove_watchpoint, | |
8962 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8963 | resources_needed_watchpoint, |
9c06b0b4 | 8964 | works_in_software_mode_watchpoint, |
77b06cd7 TJB |
8965 | NULL, /* print_it */ |
8966 | NULL, /* print_one */ | |
f1310107 | 8967 | NULL, /* print_one_detail */ |
77b06cd7 TJB |
8968 | NULL, /* print_mention */ |
8969 | NULL /* print_recreate */ | |
8970 | }; | |
8971 | ||
9c06b0b4 TJB |
8972 | /* Implement the "insert" breakpoint_ops method for |
8973 | masked hardware watchpoints. */ | |
8974 | ||
8975 | static int | |
8976 | insert_masked_watchpoint (struct bp_location *bl) | |
8977 | { | |
8978 | return target_insert_mask_watchpoint (bl->address, bl->owner->hw_wp_mask, | |
8979 | bl->watchpoint_type); | |
8980 | } | |
8981 | ||
8982 | /* Implement the "remove" breakpoint_ops method for | |
8983 | masked hardware watchpoints. */ | |
8984 | ||
8985 | static int | |
8986 | remove_masked_watchpoint (struct bp_location *bl) | |
8987 | { | |
8988 | return target_remove_mask_watchpoint (bl->address, bl->owner->hw_wp_mask, | |
8989 | bl->watchpoint_type); | |
8990 | } | |
8991 | ||
8992 | /* Implement the "resources_needed" breakpoint_ops method for | |
8993 | masked hardware watchpoints. */ | |
8994 | ||
8995 | static int | |
8996 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8997 | { | |
8998 | return target_masked_watch_num_registers (bl->address, | |
8999 | bl->owner->hw_wp_mask); | |
9000 | } | |
9001 | ||
9002 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
9003 | masked hardware watchpoints. */ | |
9004 | ||
9005 | static int | |
9006 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
9007 | { | |
9008 | return 0; | |
9009 | } | |
9010 | ||
9011 | /* Implement the "print_it" breakpoint_ops method for | |
9012 | masked hardware watchpoints. */ | |
9013 | ||
9014 | static enum print_stop_action | |
9015 | print_it_masked_watchpoint (struct breakpoint *b) | |
9016 | { | |
9017 | /* Masked watchpoints have only one location. */ | |
9018 | gdb_assert (b->loc && b->loc->next == NULL); | |
9019 | ||
9020 | switch (b->type) | |
9021 | { | |
9022 | case bp_hardware_watchpoint: | |
9023 | annotate_watchpoint (b->number); | |
9024 | if (ui_out_is_mi_like_p (uiout)) | |
9025 | ui_out_field_string | |
9026 | (uiout, "reason", | |
9027 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
9028 | break; | |
9029 | ||
9030 | case bp_read_watchpoint: | |
9031 | if (ui_out_is_mi_like_p (uiout)) | |
9032 | ui_out_field_string | |
9033 | (uiout, "reason", | |
9034 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
9035 | break; | |
9036 | ||
9037 | case bp_access_watchpoint: | |
9038 | if (ui_out_is_mi_like_p (uiout)) | |
9039 | ui_out_field_string | |
9040 | (uiout, "reason", | |
9041 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
9042 | break; | |
9043 | default: | |
9044 | internal_error (__FILE__, __LINE__, | |
9045 | _("Invalid hardware watchpoint type.")); | |
9046 | } | |
9047 | ||
9048 | mention (b); | |
9049 | ui_out_text (uiout, _("\n\ | |
9050 | Check the underlying instruction at PC for the memory\n\ | |
9051 | address and value which triggered this watchpoint.\n")); | |
9052 | ui_out_text (uiout, "\n"); | |
9053 | ||
9054 | /* More than one watchpoint may have been triggered. */ | |
9055 | return PRINT_UNKNOWN; | |
9056 | } | |
9057 | ||
9058 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9059 | masked hardware watchpoints. */ | |
9060 | ||
9061 | static void | |
9062 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
9063 | struct ui_out *uiout) | |
9064 | { | |
9065 | /* Masked watchpoints have only one location. */ | |
9066 | gdb_assert (b->loc && b->loc->next == NULL); | |
9067 | ||
9068 | ui_out_text (uiout, "\tmask "); | |
9069 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, b->hw_wp_mask); | |
9070 | ui_out_text (uiout, "\n"); | |
9071 | } | |
9072 | ||
9073 | /* Implement the "print_mention" breakpoint_ops method for | |
9074 | masked hardware watchpoints. */ | |
9075 | ||
9076 | static void | |
9077 | print_mention_masked_watchpoint (struct breakpoint *b) | |
9078 | { | |
9079 | struct cleanup *ui_out_chain; | |
9080 | ||
9081 | switch (b->type) | |
9082 | { | |
9083 | case bp_hardware_watchpoint: | |
9084 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
9085 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
9086 | break; | |
9087 | case bp_read_watchpoint: | |
9088 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
9089 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
9090 | break; | |
9091 | case bp_access_watchpoint: | |
9092 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
9093 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
9094 | break; | |
9095 | default: | |
9096 | internal_error (__FILE__, __LINE__, | |
9097 | _("Invalid hardware watchpoint type.")); | |
9098 | } | |
9099 | ||
9100 | ui_out_field_int (uiout, "number", b->number); | |
9101 | ui_out_text (uiout, ": "); | |
9102 | ui_out_field_string (uiout, "exp", b->exp_string); | |
9103 | do_cleanups (ui_out_chain); | |
9104 | } | |
9105 | ||
9106 | /* Implement the "print_recreate" breakpoint_ops method for | |
9107 | masked hardware watchpoints. */ | |
9108 | ||
9109 | static void | |
9110 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9111 | { | |
9112 | char tmp[40]; | |
9113 | ||
9114 | switch (b->type) | |
9115 | { | |
9116 | case bp_hardware_watchpoint: | |
9117 | fprintf_unfiltered (fp, "watch"); | |
9118 | break; | |
9119 | case bp_read_watchpoint: | |
9120 | fprintf_unfiltered (fp, "rwatch"); | |
9121 | break; | |
9122 | case bp_access_watchpoint: | |
9123 | fprintf_unfiltered (fp, "awatch"); | |
9124 | break; | |
9125 | default: | |
9126 | internal_error (__FILE__, __LINE__, | |
9127 | _("Invalid hardware watchpoint type.")); | |
9128 | } | |
9129 | ||
9130 | sprintf_vma (tmp, b->hw_wp_mask); | |
9131 | fprintf_unfiltered (fp, " %s mask 0x%s", b->exp_string, tmp); | |
9132 | } | |
9133 | ||
9134 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9135 | ||
9136 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops = | |
9137 | { | |
be5c67c1 | 9138 | NULL, /* dtor */ |
9c06b0b4 TJB |
9139 | insert_masked_watchpoint, |
9140 | remove_masked_watchpoint, | |
9141 | NULL, /* breakpoint_hit */ | |
9142 | resources_needed_masked_watchpoint, | |
9143 | works_in_software_mode_masked_watchpoint, | |
9144 | print_it_masked_watchpoint, | |
9145 | NULL, /* print_one */ | |
9146 | print_one_detail_masked_watchpoint, | |
9147 | print_mention_masked_watchpoint, | |
9148 | print_recreate_masked_watchpoint | |
9149 | }; | |
9150 | ||
9151 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9152 | ||
9153 | static int | |
9154 | is_masked_watchpoint (const struct breakpoint *b) | |
9155 | { | |
9156 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9157 | } | |
9158 | ||
53a5351d JM |
9159 | /* accessflag: hw_write: watch write, |
9160 | hw_read: watch read, | |
9161 | hw_access: watch access (read or write) */ | |
c906108c | 9162 | static void |
84f4c1fe PM |
9163 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9164 | int just_location, int internal) | |
c906108c | 9165 | { |
a9634178 | 9166 | volatile struct gdb_exception e; |
d983da9c | 9167 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9168 | struct expression *exp; |
60e1c644 | 9169 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9170 | struct value *val, *mark, *result; |
c906108c | 9171 | struct frame_info *frame; |
c906108c SS |
9172 | char *exp_start = NULL; |
9173 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9174 | char *tok, *end_tok; |
9175 | int toklen = -1; | |
c906108c SS |
9176 | char *cond_start = NULL; |
9177 | char *cond_end = NULL; | |
c906108c | 9178 | enum bptype bp_type; |
37e4754d | 9179 | int thread = -1; |
0cf6dd15 | 9180 | int pc = 0; |
9c06b0b4 TJB |
9181 | /* Flag to indicate whether we are going to use masks for |
9182 | the hardware watchpoint. */ | |
9183 | int use_mask = 0; | |
9184 | CORE_ADDR mask = 0; | |
c906108c | 9185 | |
37e4754d LM |
9186 | /* Make sure that we actually have parameters to parse. */ |
9187 | if (arg != NULL && arg[0] != '\0') | |
9188 | { | |
9c06b0b4 | 9189 | char *value_start; |
37e4754d | 9190 | |
9c06b0b4 TJB |
9191 | /* Look for "parameter value" pairs at the end |
9192 | of the arguments string. */ | |
9193 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9194 | { | |
9195 | /* Skip whitespace at the end of the argument list. */ | |
9196 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9197 | tok--; | |
9198 | ||
9199 | /* Find the beginning of the last token. | |
9200 | This is the value of the parameter. */ | |
9201 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9202 | tok--; | |
9203 | value_start = tok + 1; | |
9204 | ||
9205 | /* Skip whitespace. */ | |
9206 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9207 | tok--; | |
9208 | ||
9209 | end_tok = tok; | |
9210 | ||
9211 | /* Find the beginning of the second to last token. | |
9212 | This is the parameter itself. */ | |
9213 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9214 | tok--; | |
9215 | tok++; | |
9216 | toklen = end_tok - tok + 1; | |
9217 | ||
9218 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9219 | { | |
9220 | /* At this point we've found a "thread" token, which means | |
9221 | the user is trying to set a watchpoint that triggers | |
9222 | only in a specific thread. */ | |
9223 | char *endp; | |
37e4754d | 9224 | |
9c06b0b4 TJB |
9225 | if (thread != -1) |
9226 | error(_("You can specify only one thread.")); | |
37e4754d | 9227 | |
9c06b0b4 TJB |
9228 | /* Extract the thread ID from the next token. */ |
9229 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9230 | |
9c06b0b4 TJB |
9231 | /* Check if the user provided a valid numeric value for the |
9232 | thread ID. */ | |
9233 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9234 | error (_("Invalid thread ID specification %s."), value_start); | |
9235 | ||
9236 | /* Check if the thread actually exists. */ | |
9237 | if (!valid_thread_id (thread)) | |
9238 | error (_("Unknown thread %d."), thread); | |
9239 | } | |
9240 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9241 | { | |
9242 | /* We've found a "mask" token, which means the user wants to | |
9243 | create a hardware watchpoint that is going to have the mask | |
9244 | facility. */ | |
9245 | struct value *mask_value, *mark; | |
37e4754d | 9246 | |
9c06b0b4 TJB |
9247 | if (use_mask) |
9248 | error(_("You can specify only one mask.")); | |
37e4754d | 9249 | |
9c06b0b4 | 9250 | use_mask = just_location = 1; |
37e4754d | 9251 | |
9c06b0b4 TJB |
9252 | mark = value_mark (); |
9253 | mask_value = parse_to_comma_and_eval (&value_start); | |
9254 | mask = value_as_address (mask_value); | |
9255 | value_free_to_mark (mark); | |
9256 | } | |
9257 | else | |
9258 | /* We didn't recognize what we found. We should stop here. */ | |
9259 | break; | |
37e4754d | 9260 | |
9c06b0b4 TJB |
9261 | /* Truncate the string and get rid of the "parameter value" pair before |
9262 | the arguments string is parsed by the parse_exp_1 function. */ | |
9263 | *tok = '\0'; | |
9264 | } | |
37e4754d LM |
9265 | } |
9266 | ||
9267 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9268 | innermost_block = NULL; |
9269 | exp_start = arg; | |
9270 | exp = parse_exp_1 (&arg, 0, 0); | |
9271 | exp_end = arg; | |
fa8a61dc TT |
9272 | /* Remove trailing whitespace from the expression before saving it. |
9273 | This makes the eventual display of the expression string a bit | |
9274 | prettier. */ | |
9275 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9276 | --exp_end; | |
9277 | ||
65d79d4b SDJ |
9278 | /* Checking if the expression is not constant. */ |
9279 | if (watchpoint_exp_is_const (exp)) | |
9280 | { | |
9281 | int len; | |
9282 | ||
9283 | len = exp_end - exp_start; | |
9284 | while (len > 0 && isspace (exp_start[len - 1])) | |
9285 | len--; | |
9286 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9287 | } | |
9288 | ||
c906108c SS |
9289 | exp_valid_block = innermost_block; |
9290 | mark = value_mark (); | |
a1442452 | 9291 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9292 | |
9293 | if (just_location) | |
9294 | { | |
9c06b0b4 TJB |
9295 | int ret; |
9296 | ||
06a64a0b | 9297 | exp_valid_block = NULL; |
a1442452 | 9298 | val = value_addr (result); |
06a64a0b TT |
9299 | release_value (val); |
9300 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9301 | |
9302 | if (use_mask) | |
9303 | { | |
9304 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9305 | mask); | |
9306 | if (ret == -1) | |
9307 | error (_("This target does not support masked watchpoints.")); | |
9308 | else if (ret == -2) | |
9309 | error (_("Invalid mask or memory region.")); | |
9310 | } | |
06a64a0b TT |
9311 | } |
9312 | else if (val != NULL) | |
fa4727a6 | 9313 | release_value (val); |
c906108c | 9314 | |
e9cafbcc TT |
9315 | tok = skip_spaces (arg); |
9316 | end_tok = skip_to_space (tok); | |
c906108c SS |
9317 | |
9318 | toklen = end_tok - tok; | |
9319 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9320 | { | |
2d134ed3 PA |
9321 | struct expression *cond; |
9322 | ||
60e1c644 | 9323 | innermost_block = NULL; |
c906108c SS |
9324 | tok = cond_start = end_tok + 1; |
9325 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9326 | |
9327 | /* The watchpoint expression may not be local, but the condition | |
9328 | may still be. E.g.: `watch global if local > 0'. */ | |
9329 | cond_exp_valid_block = innermost_block; | |
9330 | ||
2d134ed3 | 9331 | xfree (cond); |
c906108c SS |
9332 | cond_end = tok; |
9333 | } | |
9334 | if (*tok) | |
8a3fe4f8 | 9335 | error (_("Junk at end of command.")); |
c906108c | 9336 | |
53a5351d | 9337 | if (accessflag == hw_read) |
c5aa993b | 9338 | bp_type = bp_read_watchpoint; |
53a5351d | 9339 | else if (accessflag == hw_access) |
c5aa993b JM |
9340 | bp_type = bp_access_watchpoint; |
9341 | else | |
9342 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9343 | |
d983da9c | 9344 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9345 | |
9346 | /* If the expression is "local", then set up a "watchpoint scope" | |
9347 | breakpoint at the point where we've left the scope of the watchpoint | |
9348 | expression. Create the scope breakpoint before the watchpoint, so | |
9349 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9350 | if (exp_valid_block && frame) |
d983da9c | 9351 | { |
edb3359d DJ |
9352 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9353 | { | |
9354 | scope_breakpoint | |
a6d9a66e UW |
9355 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9356 | frame_unwind_caller_pc (frame), | |
edb3359d | 9357 | bp_watchpoint_scope); |
d983da9c | 9358 | |
edb3359d | 9359 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9360 | |
edb3359d DJ |
9361 | /* Automatically delete the breakpoint when it hits. */ |
9362 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9363 | |
edb3359d DJ |
9364 | /* Only break in the proper frame (help with recursion). */ |
9365 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9366 | |
edb3359d | 9367 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9368 | scope_breakpoint->loc->gdbarch |
9369 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9370 | scope_breakpoint->loc->requested_address |
9371 | = frame_unwind_caller_pc (frame); | |
9372 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9373 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9374 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9375 | scope_breakpoint->type); |
9376 | } | |
d983da9c DJ |
9377 | } |
9378 | ||
c906108c | 9379 | /* Now set up the breakpoint. */ |
2d134ed3 | 9380 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
37e4754d | 9381 | b->thread = thread; |
b5de0fa7 | 9382 | b->disposition = disp_donttouch; |
c906108c SS |
9383 | b->exp = exp; |
9384 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 9385 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
9386 | if (just_location) |
9387 | { | |
9388 | struct type *t = value_type (val); | |
9389 | CORE_ADDR addr = value_as_address (val); | |
9390 | char *name; | |
9391 | ||
9392 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9393 | name = type_to_string (t); | |
9394 | ||
d63d0675 JK |
9395 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
9396 | core_addr_to_string (addr)); | |
06a64a0b TT |
9397 | xfree (name); |
9398 | ||
4a4106ca | 9399 | b->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9400 | (int) (exp_end - exp_start), exp_start); |
9401 | ||
06a64a0b TT |
9402 | /* The above expression is in C. */ |
9403 | b->language = language_c; | |
9404 | } | |
9405 | else | |
9406 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
9c06b0b4 TJB |
9407 | |
9408 | if (use_mask) | |
9409 | { | |
9410 | b->hw_wp_mask = mask; | |
9411 | b->ops = &masked_watchpoint_breakpoint_ops; | |
9412 | } | |
9413 | else | |
9414 | { | |
9415 | b->val = val; | |
9416 | b->val_valid = 1; | |
9417 | b->ops = &watchpoint_breakpoint_ops; | |
9418 | } | |
77b06cd7 | 9419 | |
c906108c SS |
9420 | if (cond_start) |
9421 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9422 | else | |
9423 | b->cond_string = 0; | |
c5aa993b | 9424 | |
c906108c | 9425 | if (frame) |
f6bc2008 PA |
9426 | { |
9427 | b->watchpoint_frame = get_frame_id (frame); | |
9428 | b->watchpoint_thread = inferior_ptid; | |
9429 | } | |
c906108c | 9430 | else |
f6bc2008 PA |
9431 | { |
9432 | b->watchpoint_frame = null_frame_id; | |
9433 | b->watchpoint_thread = null_ptid; | |
9434 | } | |
c906108c | 9435 | |
d983da9c | 9436 | if (scope_breakpoint != NULL) |
c906108c | 9437 | { |
d983da9c DJ |
9438 | /* The scope breakpoint is related to the watchpoint. We will |
9439 | need to act on them together. */ | |
9440 | b->related_breakpoint = scope_breakpoint; | |
9441 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9442 | } |
d983da9c | 9443 | |
06a64a0b TT |
9444 | if (!just_location) |
9445 | value_free_to_mark (mark); | |
2d134ed3 | 9446 | |
a9634178 TJB |
9447 | TRY_CATCH (e, RETURN_MASK_ALL) |
9448 | { | |
9449 | /* Finally update the new watchpoint. This creates the locations | |
9450 | that should be inserted. */ | |
9451 | update_watchpoint (b, 1); | |
9452 | } | |
9453 | if (e.reason < 0) | |
9454 | { | |
9455 | delete_breakpoint (b); | |
9456 | throw_exception (e); | |
9457 | } | |
9458 | ||
9459 | set_breakpoint_number (internal, b); | |
8d3788bd VP |
9460 | |
9461 | /* Do not mention breakpoints with a negative number, but do | |
a9634178 | 9462 | notify observers. */ |
8d3788bd | 9463 | if (!internal) |
84f4c1fe | 9464 | mention (b); |
8d3788bd VP |
9465 | observer_notify_breakpoint_created (b); |
9466 | ||
b60e7edf | 9467 | update_global_location_list (1); |
c906108c SS |
9468 | } |
9469 | ||
e09342b5 | 9470 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9471 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9472 | |
c906108c | 9473 | static int |
a9634178 | 9474 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9475 | { |
9476 | int found_memory_cnt = 0; | |
2e70b7b9 | 9477 | struct value *head = v; |
c906108c SS |
9478 | |
9479 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9480 | if (!can_use_hw_watchpoints) |
c906108c | 9481 | return 0; |
c5aa993b | 9482 | |
5c44784c JM |
9483 | /* Make sure that the value of the expression depends only upon |
9484 | memory contents, and values computed from them within GDB. If we | |
9485 | find any register references or function calls, we can't use a | |
9486 | hardware watchpoint. | |
9487 | ||
9488 | The idea here is that evaluating an expression generates a series | |
9489 | of values, one holding the value of every subexpression. (The | |
9490 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9491 | a*b+c.) GDB's values hold almost enough information to establish | |
9492 | the criteria given above --- they identify memory lvalues, | |
9493 | register lvalues, computed values, etcetera. So we can evaluate | |
9494 | the expression, and then scan the chain of values that leaves | |
9495 | behind to decide whether we can detect any possible change to the | |
9496 | expression's final value using only hardware watchpoints. | |
9497 | ||
9498 | However, I don't think that the values returned by inferior | |
9499 | function calls are special in any way. So this function may not | |
9500 | notice that an expression involving an inferior function call | |
9501 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9502 | for (; v; v = value_next (v)) |
c906108c | 9503 | { |
5c44784c | 9504 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9505 | { |
8464be76 DJ |
9506 | if (v != head && value_lazy (v)) |
9507 | /* A lazy memory lvalue in the chain is one that GDB never | |
9508 | needed to fetch; we either just used its address (e.g., | |
9509 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9510 | in `a,b'). This doesn't apply to HEAD; if that is | |
9511 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9512 | ; |
53a5351d | 9513 | else |
5c44784c JM |
9514 | { |
9515 | /* Ahh, memory we actually used! Check if we can cover | |
9516 | it with hardware watchpoints. */ | |
df407dfe | 9517 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9518 | |
9519 | /* We only watch structs and arrays if user asked for it | |
9520 | explicitly, never if they just happen to appear in a | |
9521 | middle of some value chain. */ | |
9522 | if (v == head | |
9523 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9524 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9525 | { | |
42ae5230 | 9526 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9527 | int len; |
9528 | int num_regs; | |
9529 | ||
a9634178 | 9530 | len = (target_exact_watchpoints |
e09342b5 TJB |
9531 | && is_scalar_type_recursive (vtype))? |
9532 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9533 | |
e09342b5 TJB |
9534 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9535 | if (!num_regs) | |
2e70b7b9 MS |
9536 | return 0; |
9537 | else | |
e09342b5 | 9538 | found_memory_cnt += num_regs; |
2e70b7b9 | 9539 | } |
5c44784c | 9540 | } |
c5aa993b | 9541 | } |
5086187c AC |
9542 | else if (VALUE_LVAL (v) != not_lval |
9543 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9544 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9545 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9546 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9547 | } |
9548 | ||
9549 | /* The expression itself looks suitable for using a hardware | |
9550 | watchpoint, but give the target machine a chance to reject it. */ | |
9551 | return found_memory_cnt; | |
9552 | } | |
9553 | ||
8b93c638 | 9554 | void |
84f4c1fe | 9555 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9556 | { |
84f4c1fe | 9557 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9558 | } |
9559 | ||
9560 | /* A helper function that looks for an argument at the start of a | |
9561 | string. The argument must also either be at the end of the string, | |
9562 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9563 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9564 | ||
9565 | static int | |
9566 | check_for_argument (char **str, char *arg, int arg_len) | |
9567 | { | |
9568 | if (strncmp (*str, arg, arg_len) == 0 | |
9569 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9570 | { | |
9571 | *str += arg_len; | |
9572 | return 1; | |
9573 | } | |
9574 | return 0; | |
9575 | } | |
9576 | ||
9577 | /* A helper function that looks for the "-location" argument and then | |
9578 | calls watch_command_1. */ | |
9579 | ||
9580 | static void | |
9581 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9582 | { | |
9583 | int just_location = 0; | |
9584 | ||
9585 | if (arg | |
9586 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9587 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9588 | { | |
e9cafbcc | 9589 | arg = skip_spaces (arg); |
06a64a0b TT |
9590 | just_location = 1; |
9591 | } | |
9592 | ||
84f4c1fe | 9593 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9594 | } |
8926118c | 9595 | |
c5aa993b | 9596 | static void |
fba45db2 | 9597 | watch_command (char *arg, int from_tty) |
c906108c | 9598 | { |
06a64a0b | 9599 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9600 | } |
9601 | ||
8b93c638 | 9602 | void |
84f4c1fe | 9603 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9604 | { |
84f4c1fe | 9605 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9606 | } |
8926118c | 9607 | |
c5aa993b | 9608 | static void |
fba45db2 | 9609 | rwatch_command (char *arg, int from_tty) |
c906108c | 9610 | { |
06a64a0b | 9611 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9612 | } |
9613 | ||
8b93c638 | 9614 | void |
84f4c1fe | 9615 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9616 | { |
84f4c1fe | 9617 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9618 | } |
8926118c | 9619 | |
c5aa993b | 9620 | static void |
fba45db2 | 9621 | awatch_command (char *arg, int from_tty) |
c906108c | 9622 | { |
06a64a0b | 9623 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9624 | } |
c906108c | 9625 | \f |
c5aa993b | 9626 | |
43ff13b4 | 9627 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9628 | because it uses the mechanisms of breakpoints. */ |
9629 | ||
bfec99b2 PA |
9630 | struct until_break_command_continuation_args |
9631 | { | |
9632 | struct breakpoint *breakpoint; | |
9633 | struct breakpoint *breakpoint2; | |
186c406b | 9634 | int thread_num; |
bfec99b2 PA |
9635 | }; |
9636 | ||
43ff13b4 | 9637 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9638 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9639 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9640 | command. */ |
c2c6d25f | 9641 | static void |
fa4cd53f | 9642 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9643 | { |
bfec99b2 PA |
9644 | struct until_break_command_continuation_args *a = arg; |
9645 | ||
9646 | delete_breakpoint (a->breakpoint); | |
9647 | if (a->breakpoint2) | |
9648 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9649 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9650 | } |
9651 | ||
c906108c | 9652 | void |
ae66c1fc | 9653 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9654 | { |
9655 | struct symtabs_and_lines sals; | |
9656 | struct symtab_and_line sal; | |
206415a3 | 9657 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9658 | struct breakpoint *breakpoint; |
f107f563 | 9659 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9660 | struct cleanup *old_chain; |
186c406b TT |
9661 | int thread; |
9662 | struct thread_info *tp; | |
c906108c SS |
9663 | |
9664 | clear_proceed_status (); | |
9665 | ||
9666 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9667 | this function. */ |
c5aa993b | 9668 | |
c906108c SS |
9669 | if (default_breakpoint_valid) |
9670 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
58438ac1 | 9671 | default_breakpoint_line, NULL); |
c906108c | 9672 | else |
58438ac1 | 9673 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9674 | |
c906108c | 9675 | if (sals.nelts != 1) |
8a3fe4f8 | 9676 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9677 | |
c906108c | 9678 | sal = sals.sals[0]; |
4a64f543 | 9679 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9680 | |
c906108c | 9681 | if (*arg) |
8a3fe4f8 | 9682 | error (_("Junk at end of arguments.")); |
c5aa993b | 9683 | |
c906108c | 9684 | resolve_sal_pc (&sal); |
c5aa993b | 9685 | |
ae66c1fc EZ |
9686 | if (anywhere) |
9687 | /* If the user told us to continue until a specified location, | |
9688 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9689 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9690 | null_frame_id, bp_until); | |
ae66c1fc | 9691 | else |
4a64f543 MS |
9692 | /* Otherwise, specify the selected frame, because we want to stop |
9693 | only at the very same frame. */ | |
a6d9a66e UW |
9694 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9695 | get_stack_frame_id (frame), | |
ae66c1fc | 9696 | bp_until); |
c5aa993b | 9697 | |
f107f563 | 9698 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9699 | |
186c406b TT |
9700 | tp = inferior_thread (); |
9701 | thread = tp->num; | |
9702 | ||
ae66c1fc EZ |
9703 | /* Keep within the current frame, or in frames called by the current |
9704 | one. */ | |
edb3359d DJ |
9705 | |
9706 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9707 | { |
edb3359d DJ |
9708 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9709 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9710 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9711 | sal, | |
edb3359d | 9712 | frame_unwind_caller_id (frame), |
f107f563 VP |
9713 | bp_until); |
9714 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9715 | |
9716 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9717 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9718 | } |
c5aa993b | 9719 | |
c906108c | 9720 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9721 | |
4a64f543 MS |
9722 | /* If we are running asynchronously, and proceed call above has |
9723 | actually managed to start the target, arrange for breakpoints to | |
9724 | be deleted when the target stops. Otherwise, we're already | |
9725 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9726 | |
8ea051c5 | 9727 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9728 | { |
bfec99b2 PA |
9729 | struct until_break_command_continuation_args *args; |
9730 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9731 | |
bfec99b2 PA |
9732 | args->breakpoint = breakpoint; |
9733 | args->breakpoint2 = breakpoint2; | |
186c406b | 9734 | args->thread_num = thread; |
f107f563 VP |
9735 | |
9736 | discard_cleanups (old_chain); | |
95e54da7 PA |
9737 | add_continuation (inferior_thread (), |
9738 | until_break_command_continuation, args, | |
604ead4a | 9739 | xfree); |
f107f563 VP |
9740 | } |
9741 | else | |
c5aa993b | 9742 | do_cleanups (old_chain); |
c906108c | 9743 | } |
ae66c1fc | 9744 | |
c906108c SS |
9745 | /* This function attempts to parse an optional "if <cond>" clause |
9746 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9747 | |
c906108c SS |
9748 | Else, it returns a pointer to the condition string. (It does not |
9749 | attempt to evaluate the string against a particular block.) And, | |
9750 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9751 | if clause in the arg string. */ |
53a5351d | 9752 | |
c906108c | 9753 | static char * |
fba45db2 | 9754 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9755 | { |
c5aa993b JM |
9756 | char *cond_string; |
9757 | ||
9758 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9759 | return NULL; |
c5aa993b | 9760 | |
4a64f543 | 9761 | /* Skip the "if" keyword. */ |
c906108c | 9762 | (*arg) += 2; |
c5aa993b | 9763 | |
c906108c | 9764 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9765 | condition string. */ |
e9cafbcc | 9766 | *arg = skip_spaces (*arg); |
c906108c | 9767 | cond_string = *arg; |
c5aa993b | 9768 | |
4a64f543 MS |
9769 | /* Assume that the condition occupies the remainder of the arg |
9770 | string. */ | |
c906108c | 9771 | (*arg) += strlen (cond_string); |
c5aa993b | 9772 | |
c906108c SS |
9773 | return cond_string; |
9774 | } | |
c5aa993b | 9775 | |
c906108c SS |
9776 | /* Commands to deal with catching events, such as signals, exceptions, |
9777 | process start/exit, etc. */ | |
c5aa993b JM |
9778 | |
9779 | typedef enum | |
9780 | { | |
44feb3ce TT |
9781 | catch_fork_temporary, catch_vfork_temporary, |
9782 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9783 | } |
9784 | catch_fork_kind; | |
9785 | ||
c906108c | 9786 | static void |
cc59ec59 MS |
9787 | catch_fork_command_1 (char *arg, int from_tty, |
9788 | struct cmd_list_element *command) | |
c906108c | 9789 | { |
a6d9a66e | 9790 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9791 | char *cond_string = NULL; |
44feb3ce TT |
9792 | catch_fork_kind fork_kind; |
9793 | int tempflag; | |
9794 | ||
9795 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9796 | tempflag = (fork_kind == catch_fork_temporary | |
9797 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9798 | |
44feb3ce TT |
9799 | if (!arg) |
9800 | arg = ""; | |
e9cafbcc | 9801 | arg = skip_spaces (arg); |
c5aa993b | 9802 | |
c906108c | 9803 | /* The allowed syntax is: |
c5aa993b JM |
9804 | catch [v]fork |
9805 | catch [v]fork if <cond> | |
9806 | ||
4a64f543 | 9807 | First, check if there's an if clause. */ |
c906108c | 9808 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9809 | |
c906108c | 9810 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9811 | error (_("Junk at end of arguments.")); |
c5aa993b | 9812 | |
c906108c | 9813 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9814 | and enable reporting of such events. */ |
c5aa993b JM |
9815 | switch (fork_kind) |
9816 | { | |
44feb3ce TT |
9817 | case catch_fork_temporary: |
9818 | case catch_fork_permanent: | |
a6d9a66e | 9819 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9820 | &catch_fork_breakpoint_ops); |
c906108c | 9821 | break; |
44feb3ce TT |
9822 | case catch_vfork_temporary: |
9823 | case catch_vfork_permanent: | |
a6d9a66e | 9824 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9825 | &catch_vfork_breakpoint_ops); |
c906108c | 9826 | break; |
c5aa993b | 9827 | default: |
8a3fe4f8 | 9828 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9829 | break; |
c5aa993b | 9830 | } |
c906108c SS |
9831 | } |
9832 | ||
9833 | static void | |
cc59ec59 MS |
9834 | catch_exec_command_1 (char *arg, int from_tty, |
9835 | struct cmd_list_element *command) | |
c906108c | 9836 | { |
a6d9a66e | 9837 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9838 | int tempflag; |
c5aa993b | 9839 | char *cond_string = NULL; |
c906108c | 9840 | |
44feb3ce TT |
9841 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9842 | ||
9843 | if (!arg) | |
9844 | arg = ""; | |
e9cafbcc | 9845 | arg = skip_spaces (arg); |
c906108c SS |
9846 | |
9847 | /* The allowed syntax is: | |
c5aa993b JM |
9848 | catch exec |
9849 | catch exec if <cond> | |
c906108c | 9850 | |
4a64f543 | 9851 | First, check if there's an if clause. */ |
c906108c SS |
9852 | cond_string = ep_parse_optional_if_clause (&arg); |
9853 | ||
9854 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9855 | error (_("Junk at end of arguments.")); |
c906108c SS |
9856 | |
9857 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 9858 | and enable reporting of such events. */ |
a6d9a66e UW |
9859 | create_catchpoint (gdbarch, tempflag, cond_string, |
9860 | &catch_exec_breakpoint_ops); | |
c906108c | 9861 | } |
c5aa993b | 9862 | |
3086aeae | 9863 | static enum print_stop_action |
ba770c9c | 9864 | print_it_exception_catchpoint (struct breakpoint *b) |
3086aeae | 9865 | { |
ade92717 | 9866 | int bp_temp, bp_throw; |
3086aeae | 9867 | |
ade92717 | 9868 | annotate_catchpoint (b->number); |
3086aeae | 9869 | |
ade92717 AR |
9870 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9871 | if (b->loc->address != b->loc->requested_address) | |
9872 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9873 | b->loc->address, | |
9874 | b->number, 1); | |
df2b6d2d | 9875 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9876 | ui_out_text (uiout, |
9877 | bp_temp ? "Temporary catchpoint " | |
9878 | : "Catchpoint "); | |
9879 | if (!ui_out_is_mi_like_p (uiout)) | |
9880 | ui_out_field_int (uiout, "bkptno", b->number); | |
9881 | ui_out_text (uiout, | |
c0b37c48 AR |
9882 | bp_throw ? " (exception thrown), " |
9883 | : " (exception caught), "); | |
ade92717 AR |
9884 | if (ui_out_is_mi_like_p (uiout)) |
9885 | { | |
9886 | ui_out_field_string (uiout, "reason", | |
9887 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9888 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9889 | ui_out_field_int (uiout, "bkptno", b->number); | |
9890 | } | |
3086aeae DJ |
9891 | return PRINT_SRC_AND_LOC; |
9892 | } | |
9893 | ||
9894 | static void | |
cc59ec59 MS |
9895 | print_one_exception_catchpoint (struct breakpoint *b, |
9896 | struct bp_location **last_loc) | |
3086aeae | 9897 | { |
79a45b7d | 9898 | struct value_print_options opts; |
cc59ec59 | 9899 | |
79a45b7d TT |
9900 | get_user_print_options (&opts); |
9901 | if (opts.addressprint) | |
3086aeae DJ |
9902 | { |
9903 | annotate_field (4); | |
604133b5 AR |
9904 | if (b->loc == NULL || b->loc->shlib_disabled) |
9905 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9906 | else | |
5af949e3 UW |
9907 | ui_out_field_core_addr (uiout, "addr", |
9908 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9909 | } |
9910 | annotate_field (5); | |
604133b5 | 9911 | if (b->loc) |
a6d9a66e | 9912 | *last_loc = b->loc; |
3086aeae DJ |
9913 | if (strstr (b->addr_string, "throw") != NULL) |
9914 | ui_out_field_string (uiout, "what", "exception throw"); | |
9915 | else | |
9916 | ui_out_field_string (uiout, "what", "exception catch"); | |
9917 | } | |
9918 | ||
9919 | static void | |
9920 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9921 | { | |
ade92717 AR |
9922 | int bp_temp; |
9923 | int bp_throw; | |
9924 | ||
df2b6d2d | 9925 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9926 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9927 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9928 | : _("Catchpoint ")); | |
9929 | ui_out_field_int (uiout, "bkptno", b->number); | |
9930 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9931 | : _(" (catch)")); | |
3086aeae DJ |
9932 | } |
9933 | ||
6149aea9 PA |
9934 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9935 | catch catchpoints. */ | |
9936 | ||
9937 | static void | |
4a64f543 MS |
9938 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9939 | struct ui_file *fp) | |
6149aea9 PA |
9940 | { |
9941 | int bp_temp; | |
9942 | int bp_throw; | |
9943 | ||
9944 | bp_temp = b->disposition == disp_del; | |
9945 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9946 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9947 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9948 | } | |
9949 | ||
3086aeae | 9950 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
be5c67c1 | 9951 | NULL, /* dtor */ |
ce78b96d JB |
9952 | NULL, /* insert */ |
9953 | NULL, /* remove */ | |
9954 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9955 | NULL, /* resources_needed */ |
9c06b0b4 | 9956 | NULL, /* works_in_software_mode */ |
ba770c9c | 9957 | print_it_exception_catchpoint, |
3086aeae | 9958 | print_one_exception_catchpoint, |
f1310107 | 9959 | NULL, /* print_one_detail */ |
6149aea9 PA |
9960 | print_mention_exception_catchpoint, |
9961 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9962 | }; |
9963 | ||
9964 | static int | |
9965 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9966 | enum exception_event_kind ex_event, int from_tty) | |
9967 | { | |
604133b5 AR |
9968 | char *trigger_func_name; |
9969 | ||
3086aeae | 9970 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9971 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9972 | else |
604133b5 | 9973 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9974 | |
8cdf0e15 VP |
9975 | create_breakpoint (get_current_arch (), |
9976 | trigger_func_name, cond_string, -1, | |
9977 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9978 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9979 | 0, |
9980 | AUTO_BOOLEAN_TRUE /* pending */, | |
9981 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9982 | 1 /* enabled */, |
9983 | 0 /* internal */); | |
3086aeae | 9984 | |
3086aeae DJ |
9985 | return 1; |
9986 | } | |
9987 | ||
4a64f543 | 9988 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9989 | |
9990 | static void | |
fba45db2 KB |
9991 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9992 | int tempflag, int from_tty) | |
c906108c | 9993 | { |
c5aa993b | 9994 | char *cond_string = NULL; |
c5aa993b | 9995 | |
44feb3ce TT |
9996 | if (!arg) |
9997 | arg = ""; | |
e9cafbcc | 9998 | arg = skip_spaces (arg); |
c5aa993b | 9999 | |
c906108c SS |
10000 | cond_string = ep_parse_optional_if_clause (&arg); |
10001 | ||
10002 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 10003 | error (_("Junk at end of arguments.")); |
c906108c | 10004 | |
059fb39f PM |
10005 | if (ex_event != EX_EVENT_THROW |
10006 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 10007 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 10008 | |
3086aeae DJ |
10009 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
10010 | return; | |
10011 | ||
8a3fe4f8 | 10012 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
10013 | } |
10014 | ||
44feb3ce TT |
10015 | /* Implementation of "catch catch" command. */ |
10016 | ||
10017 | static void | |
10018 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10019 | { | |
10020 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10021 | |
44feb3ce TT |
10022 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
10023 | } | |
10024 | ||
10025 | /* Implementation of "catch throw" command. */ | |
10026 | ||
10027 | static void | |
10028 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
10029 | { | |
10030 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 10031 | |
44feb3ce TT |
10032 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
10033 | } | |
10034 | ||
f7f9143b JB |
10035 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
10036 | ||
10037 | static void | |
a6d9a66e UW |
10038 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
10039 | struct symtab_and_line sal, | |
f7f9143b JB |
10040 | char *addr_string, |
10041 | char *exp_string, | |
10042 | char *cond_string, | |
10043 | struct expression *cond, | |
10044 | struct breakpoint_ops *ops, | |
10045 | int tempflag, | |
10046 | int from_tty) | |
10047 | { | |
10048 | struct breakpoint *b; | |
10049 | ||
10050 | if (from_tty) | |
10051 | { | |
5af949e3 UW |
10052 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
10053 | if (!loc_gdbarch) | |
10054 | loc_gdbarch = gdbarch; | |
10055 | ||
6c95b8df PA |
10056 | describe_other_breakpoints (loc_gdbarch, |
10057 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
10058 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
10059 | version for exception catchpoints, because two catchpoints | |
10060 | used for different exception names will use the same address. | |
10061 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 10062 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
10063 | inapropriate, we should use the word catchpoint, and tell |
10064 | the user what type of catchpoint it is. The above is good | |
10065 | enough for now, though. */ | |
10066 | } | |
10067 | ||
a6d9a66e | 10068 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
10069 | set_breakpoint_count (breakpoint_count + 1); |
10070 | ||
10071 | b->enable_state = bp_enabled; | |
10072 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
10073 | b->number = breakpoint_count; | |
10074 | b->ignore_count = 0; | |
511a6cd4 | 10075 | b->loc->cond = cond; |
f7f9143b JB |
10076 | b->addr_string = addr_string; |
10077 | b->language = language_ada; | |
10078 | b->cond_string = cond_string; | |
10079 | b->exp_string = exp_string; | |
10080 | b->thread = -1; | |
10081 | b->ops = ops; | |
f7f9143b JB |
10082 | |
10083 | mention (b); | |
8d3788bd | 10084 | observer_notify_breakpoint_created (b); |
b60e7edf | 10085 | update_global_location_list (1); |
f7f9143b JB |
10086 | } |
10087 | ||
10088 | /* Implement the "catch exception" command. */ | |
10089 | ||
10090 | static void | |
44feb3ce TT |
10091 | catch_ada_exception_command (char *arg, int from_tty, |
10092 | struct cmd_list_element *command) | |
f7f9143b | 10093 | { |
a6d9a66e | 10094 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 10095 | int tempflag; |
f7f9143b | 10096 | struct symtab_and_line sal; |
f7f9143b JB |
10097 | char *addr_string = NULL; |
10098 | char *exp_string = NULL; | |
10099 | char *cond_string = NULL; | |
10100 | struct expression *cond = NULL; | |
10101 | struct breakpoint_ops *ops = NULL; | |
10102 | ||
44feb3ce TT |
10103 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
10104 | ||
10105 | if (!arg) | |
10106 | arg = ""; | |
f7f9143b JB |
10107 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
10108 | &cond_string, &cond, &ops); | |
a6d9a66e | 10109 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
10110 | cond_string, cond, ops, tempflag, |
10111 | from_tty); | |
10112 | } | |
10113 | ||
a96d9b2e SDJ |
10114 | /* Cleanup function for a syscall filter list. */ |
10115 | static void | |
10116 | clean_up_filters (void *arg) | |
10117 | { | |
10118 | VEC(int) *iter = *(VEC(int) **) arg; | |
10119 | VEC_free (int, iter); | |
10120 | } | |
10121 | ||
10122 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
10123 | filter list, or NULL if no filtering is required. */ | |
10124 | static VEC(int) * | |
10125 | catch_syscall_split_args (char *arg) | |
10126 | { | |
10127 | VEC(int) *result = NULL; | |
10128 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
10129 | ||
10130 | while (*arg != '\0') | |
10131 | { | |
10132 | int i, syscall_number; | |
10133 | char *endptr; | |
10134 | char cur_name[128]; | |
10135 | struct syscall s; | |
10136 | ||
10137 | /* Skip whitespace. */ | |
10138 | while (isspace (*arg)) | |
10139 | arg++; | |
10140 | ||
10141 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10142 | cur_name[i] = arg[i]; | |
10143 | cur_name[i] = '\0'; | |
10144 | arg += i; | |
10145 | ||
10146 | /* Check if the user provided a syscall name or a number. */ | |
10147 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10148 | if (*endptr == '\0') | |
bccd0dd2 | 10149 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10150 | else |
10151 | { | |
10152 | /* We have a name. Let's check if it's valid and convert it | |
10153 | to a number. */ | |
10154 | get_syscall_by_name (cur_name, &s); | |
10155 | ||
10156 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10157 | /* Here we have to issue an error instead of a warning, |
10158 | because GDB cannot do anything useful if there's no | |
10159 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10160 | error (_("Unknown syscall name '%s'."), cur_name); |
10161 | } | |
10162 | ||
10163 | /* Ok, it's valid. */ | |
10164 | VEC_safe_push (int, result, s.number); | |
10165 | } | |
10166 | ||
10167 | discard_cleanups (cleanup); | |
10168 | return result; | |
10169 | } | |
10170 | ||
10171 | /* Implement the "catch syscall" command. */ | |
10172 | ||
10173 | static void | |
cc59ec59 MS |
10174 | catch_syscall_command_1 (char *arg, int from_tty, |
10175 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10176 | { |
10177 | int tempflag; | |
10178 | VEC(int) *filter; | |
10179 | struct syscall s; | |
10180 | struct gdbarch *gdbarch = get_current_arch (); | |
10181 | ||
10182 | /* Checking if the feature if supported. */ | |
10183 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10184 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10185 | this architecture yet.")); |
a96d9b2e SDJ |
10186 | |
10187 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10188 | ||
e9cafbcc | 10189 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10190 | |
10191 | /* We need to do this first "dummy" translation in order | |
10192 | to get the syscall XML file loaded or, most important, | |
10193 | to display a warning to the user if there's no XML file | |
10194 | for his/her architecture. */ | |
10195 | get_syscall_by_number (0, &s); | |
10196 | ||
10197 | /* The allowed syntax is: | |
10198 | catch syscall | |
10199 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10200 | ||
10201 | Let's check if there's a syscall name. */ | |
10202 | ||
10203 | if (arg != NULL) | |
10204 | filter = catch_syscall_split_args (arg); | |
10205 | else | |
10206 | filter = NULL; | |
10207 | ||
10208 | create_syscall_event_catchpoint (tempflag, filter, | |
10209 | &catch_syscall_breakpoint_ops); | |
10210 | } | |
10211 | ||
f7f9143b JB |
10212 | /* Implement the "catch assert" command. */ |
10213 | ||
10214 | static void | |
3e43a32a MS |
10215 | catch_assert_command (char *arg, int from_tty, |
10216 | struct cmd_list_element *command) | |
f7f9143b | 10217 | { |
a6d9a66e | 10218 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 10219 | int tempflag; |
f7f9143b JB |
10220 | struct symtab_and_line sal; |
10221 | char *addr_string = NULL; | |
10222 | struct breakpoint_ops *ops = NULL; | |
10223 | ||
44feb3ce TT |
10224 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
10225 | ||
10226 | if (!arg) | |
10227 | arg = ""; | |
f7f9143b | 10228 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
10229 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
10230 | ops, tempflag, from_tty); | |
f7f9143b JB |
10231 | } |
10232 | ||
c906108c | 10233 | static void |
fba45db2 | 10234 | catch_command (char *arg, int from_tty) |
c906108c | 10235 | { |
44feb3ce | 10236 | error (_("Catch requires an event name.")); |
c906108c SS |
10237 | } |
10238 | \f | |
10239 | ||
10240 | static void | |
fba45db2 | 10241 | tcatch_command (char *arg, int from_tty) |
c906108c | 10242 | { |
44feb3ce | 10243 | error (_("Catch requires an event name.")); |
c906108c SS |
10244 | } |
10245 | ||
80f8a6eb | 10246 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10247 | |
10248 | static void | |
fba45db2 | 10249 | clear_command (char *arg, int from_tty) |
c906108c | 10250 | { |
d6e956e5 VP |
10251 | struct breakpoint *b; |
10252 | VEC(breakpoint_p) *found = 0; | |
10253 | int ix; | |
c906108c SS |
10254 | int default_match; |
10255 | struct symtabs_and_lines sals; | |
10256 | struct symtab_and_line sal; | |
c906108c SS |
10257 | int i; |
10258 | ||
10259 | if (arg) | |
10260 | { | |
10261 | sals = decode_line_spec (arg, 1); | |
10262 | default_match = 0; | |
10263 | } | |
10264 | else | |
10265 | { | |
c5aa993b | 10266 | sals.sals = (struct symtab_and_line *) |
c906108c | 10267 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10268 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10269 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
10270 | sal.line = default_breakpoint_line; |
10271 | sal.symtab = default_breakpoint_symtab; | |
10272 | sal.pc = default_breakpoint_address; | |
6c95b8df | 10273 | sal.pspace = default_breakpoint_pspace; |
c906108c | 10274 | if (sal.symtab == 0) |
8a3fe4f8 | 10275 | error (_("No source file specified.")); |
c906108c SS |
10276 | |
10277 | sals.sals[0] = sal; | |
10278 | sals.nelts = 1; | |
10279 | ||
10280 | default_match = 1; | |
10281 | } | |
10282 | ||
4a64f543 MS |
10283 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10284 | seems, because all existing breakpoints typically have both | |
10285 | file/line and pc set. So, if clear is given file/line, we can | |
10286 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10287 | |
10288 | We only support clearing given the address explicitly | |
10289 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10290 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10291 | due to optimization, all in one block. |
4a64f543 MS |
10292 | |
10293 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10294 | PC corresponding to the same file:line, the breakpoint won't |
10295 | be cleared. We probably can still clear the breakpoint, but | |
10296 | since the other PC value is never presented to user, user | |
10297 | can only find it by guessing, and it does not seem important | |
10298 | to support that. */ | |
10299 | ||
4a64f543 MS |
10300 | /* For each line spec given, delete bps which correspond to it. Do |
10301 | it in two passes, solely to preserve the current behavior that | |
10302 | from_tty is forced true if we delete more than one | |
10303 | breakpoint. */ | |
c906108c | 10304 | |
80f8a6eb | 10305 | found = NULL; |
c906108c SS |
10306 | for (i = 0; i < sals.nelts; i++) |
10307 | { | |
10308 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10309 | If line given (pc == 0), clear all bpts on specified line. |
10310 | If defaulting, clear all bpts on default line | |
c906108c | 10311 | or at default pc. |
c5aa993b JM |
10312 | |
10313 | defaulting sal.pc != 0 tests to do | |
10314 | ||
10315 | 0 1 pc | |
10316 | 1 1 pc _and_ line | |
10317 | 0 0 line | |
10318 | 1 0 <can't happen> */ | |
c906108c SS |
10319 | |
10320 | sal = sals.sals[i]; | |
c906108c | 10321 | |
4a64f543 | 10322 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10323 | ALL_BREAKPOINTS (b) |
c5aa993b | 10324 | { |
0d381245 | 10325 | int match = 0; |
4a64f543 | 10326 | /* Are we going to delete b? */ |
cc60f2e3 | 10327 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10328 | { |
10329 | struct bp_location *loc = b->loc; | |
10330 | for (; loc; loc = loc->next) | |
10331 | { | |
6c95b8df PA |
10332 | int pc_match = sal.pc |
10333 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10334 | && (loc->address == sal.pc) |
10335 | && (!section_is_overlay (loc->section) | |
10336 | || loc->section == sal.section); | |
10337 | int line_match = ((default_match || (0 == sal.pc)) | |
10338 | && b->source_file != NULL | |
10339 | && sal.symtab != NULL | |
6c95b8df | 10340 | && sal.pspace == loc->pspace |
0ba1096a KT |
10341 | && filename_cmp (b->source_file, |
10342 | sal.symtab->filename) == 0 | |
0d381245 VP |
10343 | && b->line_number == sal.line); |
10344 | if (pc_match || line_match) | |
10345 | { | |
10346 | match = 1; | |
10347 | break; | |
10348 | } | |
10349 | } | |
10350 | } | |
10351 | ||
10352 | if (match) | |
d6e956e5 | 10353 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10354 | } |
80f8a6eb MS |
10355 | } |
10356 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10357 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10358 | { |
10359 | if (arg) | |
8a3fe4f8 | 10360 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10361 | else |
8a3fe4f8 | 10362 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10363 | } |
c906108c | 10364 | |
d6e956e5 | 10365 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10366 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10367 | if (from_tty) |
a3f17187 | 10368 | { |
d6e956e5 | 10369 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10370 | printf_unfiltered (_("Deleted breakpoint ")); |
10371 | else | |
10372 | printf_unfiltered (_("Deleted breakpoints ")); | |
10373 | } | |
80f8a6eb | 10374 | breakpoints_changed (); |
d6e956e5 VP |
10375 | |
10376 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10377 | { |
c5aa993b | 10378 | if (from_tty) |
d6e956e5 VP |
10379 | printf_unfiltered ("%d ", b->number); |
10380 | delete_breakpoint (b); | |
c906108c | 10381 | } |
80f8a6eb MS |
10382 | if (from_tty) |
10383 | putchar_unfiltered ('\n'); | |
c906108c SS |
10384 | } |
10385 | \f | |
10386 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10387 | all breakpoints that are marked for deletion, whether hit or not. | |
10388 | This is called after any breakpoint is hit, or after errors. */ | |
10389 | ||
10390 | void | |
fba45db2 | 10391 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10392 | { |
35df4500 | 10393 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10394 | |
10395 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10396 | if (bs->breakpoint_at |
10397 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10398 | && bs->stop) |
f431efe5 | 10399 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10400 | |
35df4500 | 10401 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10402 | { |
b5de0fa7 | 10403 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10404 | delete_breakpoint (b); |
10405 | } | |
c906108c SS |
10406 | } |
10407 | ||
4a64f543 MS |
10408 | /* A comparison function for bp_location AP and BP being interfaced to |
10409 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10410 | does breakpoint_address_is_meaningful say for its OWNER), | |
10411 | secondarily by ordering first bp_permanent OWNERed elements and | |
10412 | terciarily just ensuring the array is sorted stable way despite | |
10413 | qsort being an instable algorithm. */ | |
876fa593 JK |
10414 | |
10415 | static int | |
494cfb0f | 10416 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10417 | { |
494cfb0f JK |
10418 | struct bp_location *a = *(void **) ap; |
10419 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10420 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10421 | int a_perm = a->owner->enable_state == bp_permanent; |
10422 | int b_perm = b->owner->enable_state == bp_permanent; | |
10423 | ||
10424 | if (a->address != b->address) | |
10425 | return (a->address > b->address) - (a->address < b->address); | |
10426 | ||
10427 | /* Sort permanent breakpoints first. */ | |
10428 | if (a_perm != b_perm) | |
10429 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10430 | ||
4a64f543 MS |
10431 | /* Make the user-visible order stable across GDB runs. Locations of |
10432 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10433 | |
10434 | if (a->owner->number != b->owner->number) | |
10435 | return (a->owner->number > b->owner->number) | |
10436 | - (a->owner->number < b->owner->number); | |
10437 | ||
10438 | return (a > b) - (a < b); | |
10439 | } | |
10440 | ||
876fa593 | 10441 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10442 | bp_location_shadow_len_after_address_max according to the current |
10443 | content of the bp_location array. */ | |
f7545552 TT |
10444 | |
10445 | static void | |
876fa593 | 10446 | bp_location_target_extensions_update (void) |
f7545552 | 10447 | { |
876fa593 JK |
10448 | struct bp_location *bl, **blp_tmp; |
10449 | ||
10450 | bp_location_placed_address_before_address_max = 0; | |
10451 | bp_location_shadow_len_after_address_max = 0; | |
10452 | ||
10453 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10454 | { | |
10455 | CORE_ADDR start, end, addr; | |
10456 | ||
10457 | if (!bp_location_has_shadow (bl)) | |
10458 | continue; | |
10459 | ||
10460 | start = bl->target_info.placed_address; | |
10461 | end = start + bl->target_info.shadow_len; | |
10462 | ||
10463 | gdb_assert (bl->address >= start); | |
10464 | addr = bl->address - start; | |
10465 | if (addr > bp_location_placed_address_before_address_max) | |
10466 | bp_location_placed_address_before_address_max = addr; | |
10467 | ||
10468 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10469 | ||
10470 | gdb_assert (bl->address < end); | |
10471 | addr = end - bl->address; | |
10472 | if (addr > bp_location_shadow_len_after_address_max) | |
10473 | bp_location_shadow_len_after_address_max = addr; | |
10474 | } | |
f7545552 TT |
10475 | } |
10476 | ||
4cd9bd08 | 10477 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10478 | into the inferior, only remove already-inserted locations that no |
10479 | longer should be inserted. Functions that delete a breakpoint or | |
10480 | breakpoints should pass false, so that deleting a breakpoint | |
10481 | doesn't have the side effect of inserting the locations of other | |
10482 | breakpoints that are marked not-inserted, but should_be_inserted | |
10483 | returns true on them. | |
10484 | ||
10485 | This behaviour is useful is situations close to tear-down -- e.g., | |
10486 | after an exec, while the target still has execution, but breakpoint | |
10487 | shadows of the previous executable image should *NOT* be restored | |
10488 | to the new image; or before detaching, where the target still has | |
10489 | execution and wants to delete breakpoints from GDB's lists, and all | |
10490 | breakpoints had already been removed from the inferior. */ | |
10491 | ||
0d381245 | 10492 | static void |
b60e7edf | 10493 | update_global_location_list (int should_insert) |
0d381245 | 10494 | { |
74960c60 | 10495 | struct breakpoint *b; |
876fa593 | 10496 | struct bp_location **locp, *loc; |
f7545552 TT |
10497 | struct cleanup *cleanups; |
10498 | ||
2d134ed3 PA |
10499 | /* Used in the duplicates detection below. When iterating over all |
10500 | bp_locations, points to the first bp_location of a given address. | |
10501 | Breakpoints and watchpoints of different types are never | |
10502 | duplicates of each other. Keep one pointer for each type of | |
10503 | breakpoint/watchpoint, so we only need to loop over all locations | |
10504 | once. */ | |
10505 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10506 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10507 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10508 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10509 | |
4a64f543 MS |
10510 | /* Saved former bp_location array which we compare against the newly |
10511 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10512 | struct bp_location **old_location, **old_locp; |
10513 | unsigned old_location_count; | |
10514 | ||
10515 | old_location = bp_location; | |
10516 | old_location_count = bp_location_count; | |
10517 | bp_location = NULL; | |
10518 | bp_location_count = 0; | |
10519 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10520 | |
74960c60 | 10521 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10522 | for (loc = b->loc; loc; loc = loc->next) |
10523 | bp_location_count++; | |
10524 | ||
10525 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10526 | locp = bp_location; | |
10527 | ALL_BREAKPOINTS (b) | |
10528 | for (loc = b->loc; loc; loc = loc->next) | |
10529 | *locp++ = loc; | |
10530 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10531 | bp_location_compare); |
876fa593 JK |
10532 | |
10533 | bp_location_target_extensions_update (); | |
74960c60 | 10534 | |
4a64f543 MS |
10535 | /* Identify bp_location instances that are no longer present in the |
10536 | new list, and therefore should be freed. Note that it's not | |
10537 | necessary that those locations should be removed from inferior -- | |
10538 | if there's another location at the same address (previously | |
10539 | marked as duplicate), we don't need to remove/insert the | |
10540 | location. | |
876fa593 | 10541 | |
4a64f543 MS |
10542 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10543 | and former bp_location array state respectively. */ | |
876fa593 JK |
10544 | |
10545 | locp = bp_location; | |
10546 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10547 | old_locp++) | |
74960c60 | 10548 | { |
876fa593 | 10549 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10550 | struct bp_location **loc2p; |
876fa593 | 10551 | |
4a64f543 MS |
10552 | /* Tells if 'old_loc' is found amoung the new locations. If |
10553 | not, we have to free it. */ | |
c7d46a38 | 10554 | int found_object = 0; |
20874c92 VP |
10555 | /* Tells if the location should remain inserted in the target. */ |
10556 | int keep_in_target = 0; | |
10557 | int removed = 0; | |
876fa593 | 10558 | |
4a64f543 MS |
10559 | /* Skip LOCP entries which will definitely never be needed. |
10560 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10561 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10562 | && (*locp)->address < old_loc->address) |
876fa593 | 10563 | locp++; |
c7d46a38 PA |
10564 | |
10565 | for (loc2p = locp; | |
10566 | (loc2p < bp_location + bp_location_count | |
10567 | && (*loc2p)->address == old_loc->address); | |
10568 | loc2p++) | |
10569 | { | |
10570 | if (*loc2p == old_loc) | |
10571 | { | |
10572 | found_object = 1; | |
10573 | break; | |
10574 | } | |
10575 | } | |
74960c60 | 10576 | |
4a64f543 MS |
10577 | /* If this location is no longer present, and inserted, look if |
10578 | there's maybe a new location at the same address. If so, | |
10579 | mark that one inserted, and don't remove this one. This is | |
10580 | needed so that we don't have a time window where a breakpoint | |
10581 | at certain location is not inserted. */ | |
74960c60 | 10582 | |
876fa593 | 10583 | if (old_loc->inserted) |
0d381245 | 10584 | { |
4a64f543 MS |
10585 | /* If the location is inserted now, we might have to remove |
10586 | it. */ | |
74960c60 | 10587 | |
876fa593 | 10588 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10589 | { |
4a64f543 MS |
10590 | /* The location is still present in the location list, |
10591 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10592 | keep_in_target = 1; |
74960c60 VP |
10593 | } |
10594 | else | |
10595 | { | |
4a64f543 MS |
10596 | /* The location is either no longer present, or got |
10597 | disabled. See if there's another location at the | |
10598 | same address, in which case we don't need to remove | |
10599 | this one from the target. */ | |
876fa593 | 10600 | |
2bdf28a0 | 10601 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10602 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10603 | { | |
876fa593 | 10604 | for (loc2p = locp; |
c7d46a38 PA |
10605 | (loc2p < bp_location + bp_location_count |
10606 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10607 | loc2p++) |
10608 | { | |
10609 | struct bp_location *loc2 = *loc2p; | |
10610 | ||
2d134ed3 | 10611 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
10612 | { |
10613 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
10614 | Duplicates check below will fix up this |
10615 | later. */ | |
c7d46a38 | 10616 | loc2->duplicate = 0; |
85d721b8 PA |
10617 | |
10618 | /* Read watchpoint locations are switched to | |
10619 | access watchpoints, if the former are not | |
10620 | supported, but the latter are. */ | |
10621 | if (is_hardware_watchpoint (old_loc->owner)) | |
10622 | { | |
10623 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10624 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10625 | } | |
10626 | ||
c7d46a38 PA |
10627 | if (loc2 != old_loc && should_be_inserted (loc2)) |
10628 | { | |
10629 | loc2->inserted = 1; | |
10630 | loc2->target_info = old_loc->target_info; | |
10631 | keep_in_target = 1; | |
10632 | break; | |
10633 | } | |
876fa593 JK |
10634 | } |
10635 | } | |
10636 | } | |
74960c60 VP |
10637 | } |
10638 | ||
20874c92 VP |
10639 | if (!keep_in_target) |
10640 | { | |
876fa593 | 10641 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10642 | { |
4a64f543 MS |
10643 | /* This is just about all we can do. We could keep |
10644 | this location on the global list, and try to | |
10645 | remove it next time, but there's no particular | |
10646 | reason why we will succeed next time. | |
20874c92 | 10647 | |
4a64f543 MS |
10648 | Note that at this point, old_loc->owner is still |
10649 | valid, as delete_breakpoint frees the breakpoint | |
10650 | only after calling us. */ | |
3e43a32a MS |
10651 | printf_filtered (_("warning: Error removing " |
10652 | "breakpoint %d\n"), | |
876fa593 | 10653 | old_loc->owner->number); |
20874c92 VP |
10654 | } |
10655 | removed = 1; | |
10656 | } | |
0d381245 | 10657 | } |
74960c60 VP |
10658 | |
10659 | if (!found_object) | |
1c5cfe86 | 10660 | { |
db82e815 PA |
10661 | if (removed && non_stop |
10662 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10663 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10664 | { |
db82e815 PA |
10665 | /* This location was removed from the target. In |
10666 | non-stop mode, a race condition is possible where | |
10667 | we've removed a breakpoint, but stop events for that | |
10668 | breakpoint are already queued and will arrive later. | |
10669 | We apply an heuristic to be able to distinguish such | |
10670 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10671 | breakpoint location for a bit, and will retire it | |
10672 | after we see some number of events. The theory here | |
10673 | is that reporting of events should, "on the average", | |
10674 | be fair, so after a while we'll see events from all | |
10675 | threads that have anything of interest, and no longer | |
10676 | need to keep this breakpoint location around. We | |
10677 | don't hold locations forever so to reduce chances of | |
10678 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10679 | SIGTRAP. | |
10680 | ||
10681 | The heuristic failing can be disastrous on | |
10682 | decr_pc_after_break targets. | |
10683 | ||
10684 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10685 | if we fail to recognize a late breakpoint SIGTRAP, | |
10686 | because events_till_retirement has reached 0 too | |
10687 | soon, we'll fail to do the PC adjustment, and report | |
10688 | a random SIGTRAP to the user. When the user resumes | |
10689 | the inferior, it will most likely immediately crash | |
2dec564e | 10690 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10691 | corrupted, because of being resumed e.g., in the |
10692 | middle of a multi-byte instruction, or skipped a | |
10693 | one-byte instruction. This was actually seen happen | |
10694 | on native x86-linux, and should be less rare on | |
10695 | targets that do not support new thread events, like | |
10696 | remote, due to the heuristic depending on | |
10697 | thread_count. | |
10698 | ||
10699 | Mistaking a random SIGTRAP for a breakpoint trap | |
10700 | causes similar symptoms (PC adjustment applied when | |
10701 | it shouldn't), but then again, playing with SIGTRAPs | |
10702 | behind the debugger's back is asking for trouble. | |
10703 | ||
10704 | Since hardware watchpoint traps are always | |
10705 | distinguishable from other traps, so we don't need to | |
10706 | apply keep hardware watchpoint moribund locations | |
10707 | around. We simply always ignore hardware watchpoint | |
10708 | traps we can no longer explain. */ | |
10709 | ||
876fa593 JK |
10710 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10711 | old_loc->owner = NULL; | |
20874c92 | 10712 | |
876fa593 | 10713 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10714 | } |
10715 | else | |
f431efe5 PA |
10716 | { |
10717 | old_loc->owner = NULL; | |
10718 | decref_bp_location (&old_loc); | |
10719 | } | |
20874c92 | 10720 | } |
74960c60 | 10721 | } |
1c5cfe86 | 10722 | |
2d134ed3 PA |
10723 | /* Rescan breakpoints at the same address and section, marking the |
10724 | first one as "first" and any others as "duplicates". This is so | |
10725 | that the bpt instruction is only inserted once. If we have a | |
10726 | permanent breakpoint at the same place as BPT, make that one the | |
10727 | official one, and the rest as duplicates. Permanent breakpoints | |
10728 | are sorted first for the same address. | |
10729 | ||
10730 | Do the same for hardware watchpoints, but also considering the | |
10731 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 10732 | |
2d134ed3 PA |
10733 | bp_loc_first = NULL; |
10734 | wp_loc_first = NULL; | |
10735 | awp_loc_first = NULL; | |
10736 | rwp_loc_first = NULL; | |
876fa593 | 10737 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 10738 | { |
4a64f543 MS |
10739 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
10740 | non-NULL. */ | |
876fa593 | 10741 | struct breakpoint *b = loc->owner; |
2d134ed3 | 10742 | struct bp_location **loc_first_p; |
876fa593 JK |
10743 | |
10744 | if (b->enable_state == bp_disabled | |
10745 | || b->enable_state == bp_call_disabled | |
10746 | || b->enable_state == bp_startup_disabled | |
10747 | || !loc->enabled | |
10748 | || loc->shlib_disabled | |
15c3d785 | 10749 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 10750 | || is_tracepoint (b)) |
876fa593 JK |
10751 | continue; |
10752 | ||
10753 | /* Permanent breakpoint should always be inserted. */ | |
10754 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10755 | internal_error (__FILE__, __LINE__, | |
10756 | _("allegedly permanent breakpoint is not " | |
10757 | "actually inserted")); | |
10758 | ||
2d134ed3 PA |
10759 | if (b->type == bp_hardware_watchpoint) |
10760 | loc_first_p = &wp_loc_first; | |
10761 | else if (b->type == bp_read_watchpoint) | |
10762 | loc_first_p = &rwp_loc_first; | |
10763 | else if (b->type == bp_access_watchpoint) | |
10764 | loc_first_p = &awp_loc_first; | |
10765 | else | |
10766 | loc_first_p = &bp_loc_first; | |
10767 | ||
10768 | if (*loc_first_p == NULL | |
10769 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10770 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 10771 | { |
2d134ed3 | 10772 | *loc_first_p = loc; |
876fa593 JK |
10773 | loc->duplicate = 0; |
10774 | continue; | |
10775 | } | |
10776 | ||
10777 | loc->duplicate = 1; | |
10778 | ||
2d134ed3 PA |
10779 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
10780 | && b->enable_state != bp_permanent) | |
876fa593 JK |
10781 | internal_error (__FILE__, __LINE__, |
10782 | _("another breakpoint was inserted on top of " | |
10783 | "a permanent breakpoint")); | |
0d381245 | 10784 | } |
74960c60 | 10785 | |
50c71eaf | 10786 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 10787 | && (have_live_inferiors () |
2567c7d9 | 10788 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 10789 | insert_breakpoint_locations (); |
f7545552 TT |
10790 | |
10791 | do_cleanups (cleanups); | |
74960c60 VP |
10792 | } |
10793 | ||
20874c92 VP |
10794 | void |
10795 | breakpoint_retire_moribund (void) | |
10796 | { | |
10797 | struct bp_location *loc; | |
10798 | int ix; | |
10799 | ||
10800 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10801 | if (--(loc->events_till_retirement) == 0) | |
10802 | { | |
f431efe5 | 10803 | decref_bp_location (&loc); |
20874c92 VP |
10804 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
10805 | --ix; | |
10806 | } | |
10807 | } | |
10808 | ||
74960c60 | 10809 | static void |
b60e7edf | 10810 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
10811 | { |
10812 | struct gdb_exception e; | |
cc59ec59 | 10813 | |
74960c60 | 10814 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 10815 | update_global_location_list (inserting); |
0d381245 VP |
10816 | } |
10817 | ||
f431efe5 PA |
10818 | /* Clear BKP from a BPS. */ |
10819 | ||
a474d7c2 | 10820 | static void |
f431efe5 | 10821 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
10822 | { |
10823 | bpstat bs; | |
cc59ec59 | 10824 | |
a474d7c2 | 10825 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 10826 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
10827 | { |
10828 | bs->breakpoint_at = NULL; | |
10829 | bs->old_val = NULL; | |
10830 | /* bs->commands will be freed later. */ | |
10831 | } | |
10832 | } | |
10833 | ||
10834 | /* Callback for iterate_over_threads. */ | |
10835 | static int | |
f431efe5 | 10836 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 10837 | { |
f431efe5 | 10838 | struct breakpoint *bpt = data; |
cc59ec59 | 10839 | |
16c381f0 | 10840 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
10841 | return 0; |
10842 | } | |
10843 | ||
53a5351d | 10844 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 10845 | structures. */ |
c906108c SS |
10846 | |
10847 | void | |
fba45db2 | 10848 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 10849 | { |
52f0bd74 | 10850 | struct breakpoint *b; |
c906108c | 10851 | |
8a3fe4f8 | 10852 | gdb_assert (bpt != NULL); |
c906108c | 10853 | |
4a64f543 MS |
10854 | /* Has this bp already been deleted? This can happen because |
10855 | multiple lists can hold pointers to bp's. bpstat lists are | |
10856 | especial culprits. | |
10857 | ||
10858 | One example of this happening is a watchpoint's scope bp. When | |
10859 | the scope bp triggers, we notice that the watchpoint is out of | |
10860 | scope, and delete it. We also delete its scope bp. But the | |
10861 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
10862 | That bpstat is then checked for auto-deleting bp's, which are | |
10863 | deleted. | |
10864 | ||
10865 | A real solution to this problem might involve reference counts in | |
10866 | bp's, and/or giving them pointers back to their referencing | |
10867 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
10868 | storage when no more references were extent. A cheaper bandaid | |
10869 | was chosen. */ | |
c906108c SS |
10870 | if (bpt->type == bp_none) |
10871 | return; | |
10872 | ||
4a64f543 MS |
10873 | /* At least avoid this stale reference until the reference counting |
10874 | of breakpoints gets resolved. */ | |
d0fb5eae | 10875 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 10876 | { |
d0fb5eae JK |
10877 | struct breakpoint *related; |
10878 | ||
10879 | if (bpt->type == bp_watchpoint_scope) | |
10880 | watchpoint_del_at_next_stop (bpt->related_breakpoint); | |
10881 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) | |
10882 | watchpoint_del_at_next_stop (bpt); | |
10883 | ||
10884 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
10885 | for (related = bpt; related->related_breakpoint != bpt; | |
10886 | related = related->related_breakpoint); | |
10887 | related->related_breakpoint = bpt->related_breakpoint; | |
10888 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
10889 | } |
10890 | ||
a9634178 TJB |
10891 | /* watch_command_1 creates a watchpoint but only sets its number if |
10892 | update_watchpoint succeeds in creating its bp_locations. If there's | |
10893 | a problem in that process, we'll be asked to delete the half-created | |
10894 | watchpoint. In that case, don't announce the deletion. */ | |
10895 | if (bpt->number) | |
10896 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 10897 | |
c906108c SS |
10898 | if (breakpoint_chain == bpt) |
10899 | breakpoint_chain = bpt->next; | |
10900 | ||
c906108c SS |
10901 | ALL_BREAKPOINTS (b) |
10902 | if (b->next == bpt) | |
c5aa993b JM |
10903 | { |
10904 | b->next = bpt->next; | |
10905 | break; | |
10906 | } | |
c906108c | 10907 | |
be5c67c1 PA |
10908 | if (bpt->ops != NULL && bpt->ops->dtor != NULL) |
10909 | bpt->ops->dtor (bpt); | |
10910 | ||
9add0f1b | 10911 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10912 | xfree (bpt->cond_string); |
10913 | xfree (bpt->cond_exp); | |
10914 | xfree (bpt->addr_string); | |
f1310107 | 10915 | xfree (bpt->addr_string_range_end); |
60e1c644 PA |
10916 | xfree (bpt->exp); |
10917 | xfree (bpt->exp_string); | |
d63d0675 | 10918 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10919 | value_free (bpt->val); |
10920 | xfree (bpt->source_file); | |
10921 | xfree (bpt->exec_pathname); | |
c906108c | 10922 | |
f431efe5 PA |
10923 | |
10924 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10925 | been freed. */ | |
10926 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10927 | in all threeds for now. Note that we cannot just remove bpstats | |
10928 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10929 | commands are associated with the bpstat; if we remove it here, | |
10930 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10931 | event-top.c won't do anything, and temporary breakpoints with | |
10932 | commands won't work. */ | |
10933 | ||
10934 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10935 | ||
4a64f543 MS |
10936 | /* Now that breakpoint is removed from breakpoint list, update the |
10937 | global location list. This will remove locations that used to | |
10938 | belong to this breakpoint. Do this before freeing the breakpoint | |
10939 | itself, since remove_breakpoint looks at location's owner. It | |
10940 | might be better design to have location completely | |
10941 | self-contained, but it's not the case now. */ | |
b60e7edf | 10942 | update_global_location_list (0); |
74960c60 VP |
10943 | |
10944 | ||
4a64f543 MS |
10945 | /* On the chance that someone will soon try again to delete this |
10946 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10947 | bpt->type = bp_none; |
10948 | ||
b8c9b27d | 10949 | xfree (bpt); |
c906108c SS |
10950 | } |
10951 | ||
4d6140d9 AC |
10952 | static void |
10953 | do_delete_breakpoint_cleanup (void *b) | |
10954 | { | |
10955 | delete_breakpoint (b); | |
10956 | } | |
10957 | ||
10958 | struct cleanup * | |
10959 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10960 | { | |
10961 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10962 | } | |
10963 | ||
51be5b68 PA |
10964 | /* Iterator function to call a user-provided callback function once |
10965 | for each of B and its related breakpoints. */ | |
10966 | ||
10967 | static void | |
10968 | iterate_over_related_breakpoints (struct breakpoint *b, | |
10969 | void (*function) (struct breakpoint *, | |
10970 | void *), | |
10971 | void *data) | |
10972 | { | |
10973 | struct breakpoint *related; | |
10974 | ||
10975 | related = b; | |
10976 | do | |
10977 | { | |
10978 | struct breakpoint *next; | |
10979 | ||
10980 | /* FUNCTION may delete RELATED. */ | |
10981 | next = related->related_breakpoint; | |
10982 | ||
10983 | if (next == related) | |
10984 | { | |
10985 | /* RELATED is the last ring entry. */ | |
10986 | function (related, data); | |
10987 | ||
10988 | /* FUNCTION may have deleted it, so we'd never reach back to | |
10989 | B. There's nothing left to do anyway, so just break | |
10990 | out. */ | |
10991 | break; | |
10992 | } | |
10993 | else | |
10994 | function (related, data); | |
10995 | ||
10996 | related = next; | |
10997 | } | |
10998 | while (related != b); | |
10999 | } | |
95a42b64 TT |
11000 | |
11001 | static void | |
11002 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11003 | { | |
11004 | delete_breakpoint (b); | |
11005 | } | |
11006 | ||
51be5b68 PA |
11007 | /* A callback for map_breakpoint_numbers that calls |
11008 | delete_breakpoint. */ | |
11009 | ||
11010 | static void | |
11011 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11012 | { | |
11013 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
11014 | } | |
11015 | ||
c906108c | 11016 | void |
fba45db2 | 11017 | delete_command (char *arg, int from_tty) |
c906108c | 11018 | { |
35df4500 | 11019 | struct breakpoint *b, *b_tmp; |
c906108c | 11020 | |
ea9365bb TT |
11021 | dont_repeat (); |
11022 | ||
c906108c SS |
11023 | if (arg == 0) |
11024 | { | |
11025 | int breaks_to_delete = 0; | |
11026 | ||
46c6471b PA |
11027 | /* Delete all breakpoints if no argument. Do not delete |
11028 | internal breakpoints, these have to be deleted with an | |
11029 | explicit breakpoint number argument. */ | |
c5aa993b | 11030 | ALL_BREAKPOINTS (b) |
46c6471b | 11031 | if (user_breakpoint_p (b)) |
973d738b DJ |
11032 | { |
11033 | breaks_to_delete = 1; | |
11034 | break; | |
11035 | } | |
c906108c SS |
11036 | |
11037 | /* Ask user only if there are some breakpoints to delete. */ | |
11038 | if (!from_tty | |
e2e0b3e5 | 11039 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 11040 | { |
35df4500 | 11041 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 11042 | if (user_breakpoint_p (b)) |
c5aa993b | 11043 | delete_breakpoint (b); |
c906108c SS |
11044 | } |
11045 | } | |
11046 | else | |
51be5b68 | 11047 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
11048 | } |
11049 | ||
0d381245 VP |
11050 | static int |
11051 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 11052 | { |
0d381245 VP |
11053 | for (; loc; loc = loc->next) |
11054 | if (!loc->shlib_disabled) | |
11055 | return 0; | |
11056 | return 1; | |
fe3f5fa8 VP |
11057 | } |
11058 | ||
776592bf DE |
11059 | /* Subroutine of update_breakpoint_locations to simplify it. |
11060 | Return non-zero if multiple fns in list LOC have the same name. | |
11061 | Null names are ignored. */ | |
11062 | ||
11063 | static int | |
11064 | ambiguous_names_p (struct bp_location *loc) | |
11065 | { | |
11066 | struct bp_location *l; | |
11067 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
11068 | (int (*) (const void *, |
11069 | const void *)) streq, | |
776592bf DE |
11070 | NULL, xcalloc, xfree); |
11071 | ||
11072 | for (l = loc; l != NULL; l = l->next) | |
11073 | { | |
11074 | const char **slot; | |
11075 | const char *name = l->function_name; | |
11076 | ||
11077 | /* Allow for some names to be NULL, ignore them. */ | |
11078 | if (name == NULL) | |
11079 | continue; | |
11080 | ||
11081 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
11082 | INSERT); | |
4a64f543 MS |
11083 | /* NOTE: We can assume slot != NULL here because xcalloc never |
11084 | returns NULL. */ | |
776592bf DE |
11085 | if (*slot != NULL) |
11086 | { | |
11087 | htab_delete (htab); | |
11088 | return 1; | |
11089 | } | |
11090 | *slot = name; | |
11091 | } | |
11092 | ||
11093 | htab_delete (htab); | |
11094 | return 0; | |
11095 | } | |
11096 | ||
0fb4aa4b PA |
11097 | /* When symbols change, it probably means the sources changed as well, |
11098 | and it might mean the static tracepoint markers are no longer at | |
11099 | the same address or line numbers they used to be at last we | |
11100 | checked. Losing your static tracepoints whenever you rebuild is | |
11101 | undesirable. This function tries to resync/rematch gdb static | |
11102 | tracepoints with the markers on the target, for static tracepoints | |
11103 | that have not been set by marker id. Static tracepoint that have | |
11104 | been set by marker id are reset by marker id in breakpoint_re_set. | |
11105 | The heuristic is: | |
11106 | ||
11107 | 1) For a tracepoint set at a specific address, look for a marker at | |
11108 | the old PC. If one is found there, assume to be the same marker. | |
11109 | If the name / string id of the marker found is different from the | |
11110 | previous known name, assume that means the user renamed the marker | |
11111 | in the sources, and output a warning. | |
11112 | ||
11113 | 2) For a tracepoint set at a given line number, look for a marker | |
11114 | at the new address of the old line number. If one is found there, | |
11115 | assume to be the same marker. If the name / string id of the | |
11116 | marker found is different from the previous known name, assume that | |
11117 | means the user renamed the marker in the sources, and output a | |
11118 | warning. | |
11119 | ||
11120 | 3) If a marker is no longer found at the same address or line, it | |
11121 | may mean the marker no longer exists. But it may also just mean | |
11122 | the code changed a bit. Maybe the user added a few lines of code | |
11123 | that made the marker move up or down (in line number terms). Ask | |
11124 | the target for info about the marker with the string id as we knew | |
11125 | it. If found, update line number and address in the matching | |
11126 | static tracepoint. This will get confused if there's more than one | |
11127 | marker with the same ID (possible in UST, although unadvised | |
11128 | precisely because it confuses tools). */ | |
11129 | ||
11130 | static struct symtab_and_line | |
11131 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
11132 | { | |
11133 | struct static_tracepoint_marker marker; | |
11134 | CORE_ADDR pc; | |
11135 | int i; | |
11136 | ||
11137 | pc = sal.pc; | |
11138 | if (sal.line) | |
11139 | find_line_pc (sal.symtab, sal.line, &pc); | |
11140 | ||
11141 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11142 | { | |
11143 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
11144 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
11145 | b->number, | |
11146 | b->static_trace_marker_id, marker.str_id); | |
11147 | ||
11148 | xfree (b->static_trace_marker_id); | |
11149 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
11150 | release_static_tracepoint_marker (&marker); | |
11151 | ||
11152 | return sal; | |
11153 | } | |
11154 | ||
11155 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11156 | by string ID. */ | |
11157 | if (!sal.explicit_pc | |
11158 | && sal.line != 0 | |
11159 | && sal.symtab != NULL | |
11160 | && b->static_trace_marker_id != NULL) | |
11161 | { | |
11162 | VEC(static_tracepoint_marker_p) *markers; | |
11163 | ||
11164 | markers | |
11165 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
11166 | ||
11167 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11168 | { | |
11169 | struct symtab_and_line sal; | |
11170 | struct symbol *sym; | |
11171 | struct static_tracepoint_marker *marker; | |
11172 | ||
11173 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
11174 | ||
11175 | xfree (b->static_trace_marker_id); | |
11176 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
11177 | ||
11178 | warning (_("marker for static tracepoint %d (%s) not " | |
11179 | "found at previous line number"), | |
11180 | b->number, b->static_trace_marker_id); | |
11181 | ||
11182 | init_sal (&sal); | |
11183 | ||
11184 | sal.pc = marker->address; | |
11185 | ||
11186 | sal = find_pc_line (marker->address, 0); | |
11187 | sym = find_pc_sect_function (marker->address, NULL); | |
11188 | ui_out_text (uiout, "Now in "); | |
11189 | if (sym) | |
11190 | { | |
11191 | ui_out_field_string (uiout, "func", | |
11192 | SYMBOL_PRINT_NAME (sym)); | |
11193 | ui_out_text (uiout, " at "); | |
11194 | } | |
11195 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11196 | ui_out_text (uiout, ":"); | |
11197 | ||
11198 | if (ui_out_is_mi_like_p (uiout)) | |
11199 | { | |
11200 | char *fullname = symtab_to_fullname (sal.symtab); | |
11201 | ||
11202 | if (fullname) | |
11203 | ui_out_field_string (uiout, "fullname", fullname); | |
11204 | } | |
11205 | ||
11206 | ui_out_field_int (uiout, "line", sal.line); | |
11207 | ui_out_text (uiout, "\n"); | |
11208 | ||
11209 | b->line_number = sal.line; | |
11210 | ||
11211 | xfree (b->source_file); | |
11212 | if (sym) | |
11213 | b->source_file = xstrdup (sal.symtab->filename); | |
11214 | else | |
11215 | b->source_file = NULL; | |
11216 | ||
11217 | xfree (b->addr_string); | |
11218 | b->addr_string = xstrprintf ("%s:%d", | |
11219 | sal.symtab->filename, b->line_number); | |
11220 | ||
11221 | /* Might be nice to check if function changed, and warn if | |
11222 | so. */ | |
11223 | ||
11224 | release_static_tracepoint_marker (marker); | |
11225 | } | |
11226 | } | |
11227 | return sal; | |
11228 | } | |
11229 | ||
8d3788bd VP |
11230 | /* Returns 1 iff locations A and B are sufficiently same that |
11231 | we don't need to report breakpoint as changed. */ | |
11232 | ||
11233 | static int | |
11234 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11235 | { | |
11236 | while (a && b) | |
11237 | { | |
11238 | if (a->address != b->address) | |
11239 | return 0; | |
11240 | ||
11241 | if (a->shlib_disabled != b->shlib_disabled) | |
11242 | return 0; | |
11243 | ||
11244 | if (a->enabled != b->enabled) | |
11245 | return 0; | |
11246 | ||
11247 | a = a->next; | |
11248 | b = b->next; | |
11249 | } | |
11250 | ||
11251 | if ((a == NULL) != (b == NULL)) | |
11252 | return 0; | |
11253 | ||
11254 | return 1; | |
11255 | } | |
11256 | ||
f1310107 TJB |
11257 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11258 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11259 | a ranged breakpoint. */ | |
11260 | ||
0e30163f | 11261 | void |
0d381245 | 11262 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11263 | struct symtabs_and_lines sals, |
11264 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11265 | { |
11266 | int i; | |
0d381245 VP |
11267 | struct bp_location *existing_locations = b->loc; |
11268 | ||
f1310107 TJB |
11269 | /* Ranged breakpoints have only one start location and one end location. */ |
11270 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11271 | ||
4a64f543 MS |
11272 | /* If there's no new locations, and all existing locations are |
11273 | pending, don't do anything. This optimizes the common case where | |
11274 | all locations are in the same shared library, that was unloaded. | |
11275 | We'd like to retain the location, so that when the library is | |
11276 | loaded again, we don't loose the enabled/disabled status of the | |
11277 | individual locations. */ | |
0d381245 | 11278 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11279 | return; |
11280 | ||
fe3f5fa8 VP |
11281 | b->loc = NULL; |
11282 | ||
0d381245 | 11283 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11284 | { |
0d381245 | 11285 | struct bp_location *new_loc = |
39d61571 | 11286 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11287 | |
0d381245 VP |
11288 | /* Reparse conditions, they might contain references to the |
11289 | old symtab. */ | |
11290 | if (b->cond_string != NULL) | |
11291 | { | |
f1310107 | 11292 | char *s; |
0d381245 | 11293 | struct gdb_exception e; |
fe3f5fa8 | 11294 | |
0d381245 VP |
11295 | s = b->cond_string; |
11296 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11297 | { | |
11298 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11299 | 0); | |
11300 | } | |
11301 | if (e.reason < 0) | |
11302 | { | |
3e43a32a MS |
11303 | warning (_("failed to reevaluate condition " |
11304 | "for breakpoint %d: %s"), | |
0d381245 VP |
11305 | b->number, e.message); |
11306 | new_loc->enabled = 0; | |
11307 | } | |
11308 | } | |
fe3f5fa8 | 11309 | |
0d381245 VP |
11310 | if (b->source_file != NULL) |
11311 | xfree (b->source_file); | |
11312 | if (sals.sals[i].symtab == NULL) | |
11313 | b->source_file = NULL; | |
11314 | else | |
1b36a34b | 11315 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11316 | |
0d381245 VP |
11317 | if (b->line_number == 0) |
11318 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11319 | |
11320 | if (sals_end.nelts) | |
11321 | { | |
11322 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11323 | ||
11324 | new_loc->length = end - sals.sals[0].pc + 1; | |
11325 | } | |
0d381245 | 11326 | } |
fe3f5fa8 | 11327 | |
514f746b AR |
11328 | /* Update locations of permanent breakpoints. */ |
11329 | if (b->enable_state == bp_permanent) | |
11330 | make_breakpoint_permanent (b); | |
11331 | ||
4a64f543 MS |
11332 | /* If possible, carry over 'disable' status from existing |
11333 | breakpoints. */ | |
0d381245 VP |
11334 | { |
11335 | struct bp_location *e = existing_locations; | |
776592bf DE |
11336 | /* If there are multiple breakpoints with the same function name, |
11337 | e.g. for inline functions, comparing function names won't work. | |
11338 | Instead compare pc addresses; this is just a heuristic as things | |
11339 | may have moved, but in practice it gives the correct answer | |
11340 | often enough until a better solution is found. */ | |
11341 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11342 | ||
0d381245 VP |
11343 | for (; e; e = e->next) |
11344 | { | |
11345 | if (!e->enabled && e->function_name) | |
11346 | { | |
11347 | struct bp_location *l = b->loc; | |
776592bf DE |
11348 | if (have_ambiguous_names) |
11349 | { | |
11350 | for (; l; l = l->next) | |
f1310107 | 11351 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11352 | { |
11353 | l->enabled = 0; | |
11354 | break; | |
11355 | } | |
11356 | } | |
11357 | else | |
11358 | { | |
11359 | for (; l; l = l->next) | |
11360 | if (l->function_name | |
11361 | && strcmp (e->function_name, l->function_name) == 0) | |
11362 | { | |
11363 | l->enabled = 0; | |
11364 | break; | |
11365 | } | |
11366 | } | |
0d381245 VP |
11367 | } |
11368 | } | |
11369 | } | |
fe3f5fa8 | 11370 | |
8d3788bd VP |
11371 | if (!locations_are_equal (existing_locations, b->loc)) |
11372 | observer_notify_breakpoint_modified (b); | |
11373 | ||
b60e7edf | 11374 | update_global_location_list (1); |
fe3f5fa8 VP |
11375 | } |
11376 | ||
ef23e705 TJB |
11377 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11378 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11379 | ||
11380 | static struct symtabs_and_lines | |
11381 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11382 | { | |
11383 | char *s; | |
58438ac1 | 11384 | int marker_spec; |
02d20e4a | 11385 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11386 | struct gdb_exception e; |
11387 | ||
11388 | s = addr_string; | |
11389 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11390 | ||
11391 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11392 | { | |
11393 | if (marker_spec) | |
11394 | { | |
11395 | sals = decode_static_tracepoint_spec (&s); | |
11396 | if (sals.nelts > b->static_trace_marker_id_idx) | |
11397 | { | |
11398 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
11399 | sals.nelts = 1; | |
11400 | } | |
11401 | else | |
11402 | error (_("marker %s not found"), b->static_trace_marker_id); | |
11403 | } | |
11404 | else | |
58438ac1 | 11405 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11406 | } |
11407 | if (e.reason < 0) | |
11408 | { | |
11409 | int not_found_and_ok = 0; | |
11410 | /* For pending breakpoints, it's expected that parsing will | |
11411 | fail until the right shared library is loaded. User has | |
11412 | already told to create pending breakpoints and don't need | |
11413 | extra messages. If breakpoint is in bp_shlib_disabled | |
11414 | state, then user already saw the message about that | |
11415 | breakpoint being disabled, and don't want to see more | |
11416 | errors. */ | |
58438ac1 | 11417 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11418 | && (b->condition_not_parsed |
11419 | || (b->loc && b->loc->shlib_disabled) | |
11420 | || b->enable_state == bp_disabled)) | |
11421 | not_found_and_ok = 1; | |
11422 | ||
11423 | if (!not_found_and_ok) | |
11424 | { | |
11425 | /* We surely don't want to warn about the same breakpoint | |
11426 | 10 times. One solution, implemented here, is disable | |
11427 | the breakpoint on error. Another solution would be to | |
11428 | have separate 'warning emitted' flag. Since this | |
11429 | happens only when a binary has changed, I don't know | |
11430 | which approach is better. */ | |
11431 | b->enable_state = bp_disabled; | |
11432 | throw_exception (e); | |
11433 | } | |
11434 | } | |
11435 | ||
58438ac1 | 11436 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11437 | { |
11438 | gdb_assert (sals.nelts == 1); | |
11439 | ||
11440 | resolve_sal_pc (&sals.sals[0]); | |
11441 | if (b->condition_not_parsed && s && s[0]) | |
11442 | { | |
11443 | char *cond_string = 0; | |
11444 | int thread = -1; | |
11445 | int task = 0; | |
11446 | ||
11447 | find_condition_and_thread (s, sals.sals[0].pc, | |
11448 | &cond_string, &thread, &task); | |
11449 | if (cond_string) | |
11450 | b->cond_string = cond_string; | |
11451 | b->thread = thread; | |
11452 | b->task = task; | |
11453 | b->condition_not_parsed = 0; | |
11454 | } | |
11455 | ||
11456 | if (b->type == bp_static_tracepoint && !marker_spec) | |
11457 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 11458 | |
58438ac1 TT |
11459 | *found = 1; |
11460 | } | |
11461 | else | |
11462 | *found = 0; | |
ef23e705 TJB |
11463 | |
11464 | return sals; | |
11465 | } | |
11466 | ||
11467 | /* Reevaluate a hardware or software breakpoint and recreate its locations. | |
11468 | This is necessary after symbols are read (e.g., an executable or DSO | |
11469 | was loaded, or the inferior just started). */ | |
11470 | ||
11471 | static void | |
11472 | re_set_breakpoint (struct breakpoint *b) | |
11473 | { | |
11474 | int found; | |
f1310107 | 11475 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 11476 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 11477 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
11478 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
11479 | ||
11480 | input_radix = b->input_radix; | |
11481 | save_current_space_and_thread (); | |
11482 | switch_to_program_space_and_thread (b->pspace); | |
11483 | set_language (b->language); | |
11484 | ||
11485 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
11486 | if (found) | |
11487 | { | |
11488 | make_cleanup (xfree, sals.sals); | |
11489 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
11490 | } | |
11491 | ||
f1310107 TJB |
11492 | if (b->addr_string_range_end) |
11493 | { | |
11494 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
11495 | if (found) | |
11496 | { | |
11497 | make_cleanup (xfree, sals_end.sals); | |
11498 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
11499 | } | |
11500 | } | |
11501 | ||
11502 | update_breakpoint_locations (b, expanded, expanded_end); | |
ef23e705 TJB |
11503 | do_cleanups (cleanups); |
11504 | } | |
11505 | ||
c906108c SS |
11506 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
11507 | The value we return ends up being the return value from catch_errors. | |
11508 | Unused in this case. */ | |
11509 | ||
11510 | static int | |
4efb68b1 | 11511 | breakpoint_re_set_one (void *bint) |
c906108c | 11512 | { |
4a64f543 | 11513 | /* Get past catch_errs. */ |
53a5351d | 11514 | struct breakpoint *b = (struct breakpoint *) bint; |
c906108c SS |
11515 | |
11516 | switch (b->type) | |
11517 | { | |
11518 | case bp_none: | |
8a3fe4f8 | 11519 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 11520 | b->number); |
c906108c SS |
11521 | return 0; |
11522 | case bp_breakpoint: | |
11523 | case bp_hardware_breakpoint: | |
1042e4c0 | 11524 | case bp_tracepoint: |
7a697b8d | 11525 | case bp_fast_tracepoint: |
0fb4aa4b | 11526 | case bp_static_tracepoint: |
0e30163f | 11527 | case bp_gnu_ifunc_resolver: |
8bea4e01 UW |
11528 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
11529 | if (b->enable_state == bp_startup_disabled) | |
11530 | return 0; | |
11531 | ||
c906108c SS |
11532 | if (b->addr_string == NULL) |
11533 | { | |
4a64f543 | 11534 | /* Anything without a string can't be re-set. */ |
c906108c SS |
11535 | delete_breakpoint (b); |
11536 | return 0; | |
11537 | } | |
c906108c | 11538 | |
ef23e705 | 11539 | re_set_breakpoint (b); |
c906108c SS |
11540 | break; |
11541 | ||
11542 | case bp_watchpoint: | |
11543 | case bp_hardware_watchpoint: | |
11544 | case bp_read_watchpoint: | |
11545 | case bp_access_watchpoint: | |
4a64f543 MS |
11546 | /* Watchpoint can be either on expression using entirely global |
11547 | variables, or it can be on local variables. | |
11548 | ||
11549 | Watchpoints of the first kind are never auto-deleted, and | |
11550 | even persist across program restarts. Since they can use | |
11551 | variables from shared libraries, we need to reparse | |
11552 | expression as libraries are loaded and unloaded. | |
11553 | ||
11554 | Watchpoints on local variables can also change meaning as | |
11555 | result of solib event. For example, if a watchpoint uses | |
11556 | both a local and a global variables in expression, it's a | |
11557 | local watchpoint, but unloading of a shared library will make | |
11558 | the expression invalid. This is not a very common use case, | |
11559 | but we still re-evaluate expression, to avoid surprises to | |
11560 | the user. | |
0b3de036 VP |
11561 | |
11562 | Note that for local watchpoints, we re-evaluate it only if | |
11563 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
11564 | the watchpoint is out of scope and will be deleted soon. In |
11565 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
11566 | |
11567 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 11568 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
11569 | |
11570 | Don't do anything about disabled watchpoints, since they will | |
11571 | be reevaluated again when enabled. */ | |
a5606eee | 11572 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 11573 | break; |
c5aa993b JM |
11574 | /* We needn't really do anything to reset these, since the mask |
11575 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 11576 | loaded. */ |
ce78b96d | 11577 | case bp_catchpoint: |
c906108c | 11578 | break; |
c5aa993b | 11579 | |
c906108c | 11580 | default: |
a3f17187 | 11581 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 11582 | /* fall through */ |
0fd8e87f UW |
11583 | /* Delete overlay event and longjmp master breakpoints; they will be |
11584 | reset later by breakpoint_re_set. */ | |
1900040c | 11585 | case bp_overlay_event: |
0fd8e87f | 11586 | case bp_longjmp_master: |
aa7d318d | 11587 | case bp_std_terminate_master: |
186c406b | 11588 | case bp_exception_master: |
c906108c SS |
11589 | delete_breakpoint (b); |
11590 | break; | |
11591 | ||
c5aa993b JM |
11592 | /* This breakpoint is special, it's set up when the inferior |
11593 | starts and we really don't want to touch it. */ | |
c906108c SS |
11594 | case bp_shlib_event: |
11595 | ||
c4093a6a JM |
11596 | /* Like bp_shlib_event, this breakpoint type is special. |
11597 | Once it is set up, we do not want to touch it. */ | |
11598 | case bp_thread_event: | |
11599 | ||
4a64f543 MS |
11600 | /* Keep temporary breakpoints, which can be encountered when we |
11601 | step over a dlopen call and SOLIB_ADD is resetting the | |
11602 | breakpoints. Otherwise these should have been blown away via | |
11603 | the cleanup chain or by breakpoint_init_inferior when we | |
11604 | rerun the executable. */ | |
c906108c SS |
11605 | case bp_until: |
11606 | case bp_finish: | |
11607 | case bp_watchpoint_scope: | |
11608 | case bp_call_dummy: | |
aa7d318d | 11609 | case bp_std_terminate: |
c906108c | 11610 | case bp_step_resume: |
2c03e5be | 11611 | case bp_hp_step_resume: |
611c83ae PA |
11612 | case bp_longjmp: |
11613 | case bp_longjmp_resume: | |
186c406b TT |
11614 | case bp_exception: |
11615 | case bp_exception_resume: | |
4efc6507 | 11616 | case bp_jit_event: |
0e30163f | 11617 | case bp_gnu_ifunc_resolver_return: |
c906108c SS |
11618 | break; |
11619 | } | |
11620 | ||
11621 | return 0; | |
11622 | } | |
11623 | ||
69de3c6a | 11624 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 11625 | void |
69de3c6a | 11626 | breakpoint_re_set (void) |
c906108c | 11627 | { |
35df4500 | 11628 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11629 | enum language save_language; |
11630 | int save_input_radix; | |
6c95b8df | 11631 | struct cleanup *old_chain; |
c5aa993b | 11632 | |
c906108c SS |
11633 | save_language = current_language->la_language; |
11634 | save_input_radix = input_radix; | |
6c95b8df PA |
11635 | old_chain = save_current_program_space (); |
11636 | ||
35df4500 | 11637 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11638 | { |
4a64f543 | 11639 | /* Format possible error msg. */ |
fe3f5fa8 | 11640 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
11641 | b->number); |
11642 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 11643 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 11644 | do_cleanups (cleanups); |
c5aa993b | 11645 | } |
c906108c SS |
11646 | set_language (save_language); |
11647 | input_radix = save_input_radix; | |
e62c965a | 11648 | |
0756c555 | 11649 | jit_breakpoint_re_set (); |
4efc6507 | 11650 | |
6c95b8df PA |
11651 | do_cleanups (old_chain); |
11652 | ||
af02033e PP |
11653 | create_overlay_event_breakpoint (); |
11654 | create_longjmp_master_breakpoint (); | |
11655 | create_std_terminate_master_breakpoint (); | |
186c406b | 11656 | create_exception_master_breakpoint (); |
c906108c SS |
11657 | } |
11658 | \f | |
c906108c SS |
11659 | /* Reset the thread number of this breakpoint: |
11660 | ||
11661 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 11662 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 11663 | void |
fba45db2 | 11664 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
11665 | { |
11666 | if (b->thread != -1) | |
11667 | { | |
39f77062 KB |
11668 | if (in_thread_list (inferior_ptid)) |
11669 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
11670 | |
11671 | /* We're being called after following a fork. The new fork is | |
11672 | selected as current, and unless this was a vfork will have a | |
11673 | different program space from the original thread. Reset that | |
11674 | as well. */ | |
11675 | b->loc->pspace = current_program_space; | |
c906108c SS |
11676 | } |
11677 | } | |
11678 | ||
03ac34d5 MS |
11679 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11680 | If from_tty is nonzero, it prints a message to that effect, | |
11681 | which ends with a period (no newline). */ | |
11682 | ||
c906108c | 11683 | void |
fba45db2 | 11684 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 11685 | { |
52f0bd74 | 11686 | struct breakpoint *b; |
c906108c SS |
11687 | |
11688 | if (count < 0) | |
11689 | count = 0; | |
11690 | ||
11691 | ALL_BREAKPOINTS (b) | |
11692 | if (b->number == bptnum) | |
c5aa993b | 11693 | { |
d77f58be SS |
11694 | if (is_tracepoint (b)) |
11695 | { | |
11696 | if (from_tty && count != 0) | |
11697 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
11698 | bptnum); | |
11699 | return; | |
11700 | } | |
11701 | ||
c5aa993b | 11702 | b->ignore_count = count; |
221ea385 KS |
11703 | if (from_tty) |
11704 | { | |
11705 | if (count == 0) | |
3e43a32a MS |
11706 | printf_filtered (_("Will stop next time " |
11707 | "breakpoint %d is reached."), | |
221ea385 KS |
11708 | bptnum); |
11709 | else if (count == 1) | |
a3f17187 | 11710 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
11711 | bptnum); |
11712 | else | |
3e43a32a MS |
11713 | printf_filtered (_("Will ignore next %d " |
11714 | "crossings of breakpoint %d."), | |
221ea385 KS |
11715 | count, bptnum); |
11716 | } | |
c5aa993b | 11717 | breakpoints_changed (); |
8d3788bd | 11718 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
11719 | return; |
11720 | } | |
c906108c | 11721 | |
8a3fe4f8 | 11722 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
11723 | } |
11724 | ||
c906108c SS |
11725 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
11726 | ||
11727 | static void | |
fba45db2 | 11728 | ignore_command (char *args, int from_tty) |
c906108c SS |
11729 | { |
11730 | char *p = args; | |
52f0bd74 | 11731 | int num; |
c906108c SS |
11732 | |
11733 | if (p == 0) | |
e2e0b3e5 | 11734 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 11735 | |
c906108c | 11736 | num = get_number (&p); |
5c44784c | 11737 | if (num == 0) |
8a3fe4f8 | 11738 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 11739 | if (*p == 0) |
8a3fe4f8 | 11740 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
11741 | |
11742 | set_ignore_count (num, | |
11743 | longest_to_int (value_as_long (parse_and_eval (p))), | |
11744 | from_tty); | |
221ea385 KS |
11745 | if (from_tty) |
11746 | printf_filtered ("\n"); | |
c906108c SS |
11747 | } |
11748 | \f | |
11749 | /* Call FUNCTION on each of the breakpoints | |
11750 | whose numbers are given in ARGS. */ | |
11751 | ||
11752 | static void | |
95a42b64 TT |
11753 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
11754 | void *), | |
11755 | void *data) | |
c906108c | 11756 | { |
52f0bd74 AC |
11757 | int num; |
11758 | struct breakpoint *b, *tmp; | |
11cf8741 | 11759 | int match; |
197f0a60 | 11760 | struct get_number_or_range_state state; |
c906108c | 11761 | |
197f0a60 | 11762 | if (args == 0) |
e2e0b3e5 | 11763 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 11764 | |
197f0a60 TT |
11765 | init_number_or_range (&state, args); |
11766 | ||
11767 | while (!state.finished) | |
c906108c | 11768 | { |
197f0a60 TT |
11769 | char *p = state.string; |
11770 | ||
11cf8741 | 11771 | match = 0; |
c5aa993b | 11772 | |
197f0a60 | 11773 | num = get_number_or_range (&state); |
5c44784c | 11774 | if (num == 0) |
c5aa993b | 11775 | { |
8a3fe4f8 | 11776 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
11777 | } |
11778 | else | |
11779 | { | |
11780 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
11781 | if (b->number == num) | |
11782 | { | |
11cf8741 | 11783 | match = 1; |
cdac0397 | 11784 | function (b, data); |
11cf8741 | 11785 | break; |
5c44784c | 11786 | } |
11cf8741 | 11787 | if (match == 0) |
a3f17187 | 11788 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 11789 | } |
c906108c SS |
11790 | } |
11791 | } | |
11792 | ||
0d381245 VP |
11793 | static struct bp_location * |
11794 | find_location_by_number (char *number) | |
11795 | { | |
11796 | char *dot = strchr (number, '.'); | |
11797 | char *p1; | |
11798 | int bp_num; | |
11799 | int loc_num; | |
11800 | struct breakpoint *b; | |
11801 | struct bp_location *loc; | |
11802 | ||
11803 | *dot = '\0'; | |
11804 | ||
11805 | p1 = number; | |
197f0a60 | 11806 | bp_num = get_number (&p1); |
0d381245 VP |
11807 | if (bp_num == 0) |
11808 | error (_("Bad breakpoint number '%s'"), number); | |
11809 | ||
11810 | ALL_BREAKPOINTS (b) | |
11811 | if (b->number == bp_num) | |
11812 | { | |
11813 | break; | |
11814 | } | |
11815 | ||
11816 | if (!b || b->number != bp_num) | |
11817 | error (_("Bad breakpoint number '%s'"), number); | |
11818 | ||
11819 | p1 = dot+1; | |
197f0a60 | 11820 | loc_num = get_number (&p1); |
0d381245 VP |
11821 | if (loc_num == 0) |
11822 | error (_("Bad breakpoint location number '%s'"), number); | |
11823 | ||
11824 | --loc_num; | |
11825 | loc = b->loc; | |
11826 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
11827 | ; | |
11828 | if (!loc) | |
11829 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
11830 | ||
11831 | return loc; | |
11832 | } | |
11833 | ||
11834 | ||
1900040c MS |
11835 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11836 | If from_tty is nonzero, it prints a message to that effect, | |
11837 | which ends with a period (no newline). */ | |
11838 | ||
c906108c | 11839 | void |
fba45db2 | 11840 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
11841 | { |
11842 | /* Never disable a watchpoint scope breakpoint; we want to | |
11843 | hit them when we leave scope so we can delete both the | |
11844 | watchpoint and its scope breakpoint at that time. */ | |
11845 | if (bpt->type == bp_watchpoint_scope) | |
11846 | return; | |
11847 | ||
c2c6d25f | 11848 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 11849 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
11850 | return; |
11851 | ||
b5de0fa7 | 11852 | bpt->enable_state = bp_disabled; |
c906108c | 11853 | |
d248b706 KY |
11854 | if (target_supports_enable_disable_tracepoint () |
11855 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
11856 | { | |
11857 | struct bp_location *location; | |
11858 | ||
11859 | for (location = bpt->loc; location; location = location->next) | |
11860 | target_disable_tracepoint (location); | |
11861 | } | |
11862 | ||
b60e7edf | 11863 | update_global_location_list (0); |
c906108c | 11864 | |
8d3788bd | 11865 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
11866 | } |
11867 | ||
51be5b68 PA |
11868 | /* A callback for iterate_over_related_breakpoints. */ |
11869 | ||
11870 | static void | |
11871 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
11872 | { | |
11873 | disable_breakpoint (b); | |
11874 | } | |
11875 | ||
95a42b64 TT |
11876 | /* A callback for map_breakpoint_numbers that calls |
11877 | disable_breakpoint. */ | |
11878 | ||
11879 | static void | |
11880 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
11881 | { | |
51be5b68 | 11882 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
11883 | } |
11884 | ||
c906108c | 11885 | static void |
fba45db2 | 11886 | disable_command (char *args, int from_tty) |
c906108c | 11887 | { |
c906108c | 11888 | if (args == 0) |
46c6471b PA |
11889 | { |
11890 | struct breakpoint *bpt; | |
11891 | ||
11892 | ALL_BREAKPOINTS (bpt) | |
11893 | if (user_breakpoint_p (bpt)) | |
11894 | disable_breakpoint (bpt); | |
11895 | } | |
0d381245 VP |
11896 | else if (strchr (args, '.')) |
11897 | { | |
11898 | struct bp_location *loc = find_location_by_number (args); | |
11899 | if (loc) | |
d248b706 KY |
11900 | { |
11901 | loc->enabled = 0; | |
11902 | if (target_supports_enable_disable_tracepoint () | |
11903 | && current_trace_status ()->running && loc->owner | |
11904 | && is_tracepoint (loc->owner)) | |
11905 | target_disable_tracepoint (loc); | |
11906 | } | |
b60e7edf | 11907 | update_global_location_list (0); |
0d381245 | 11908 | } |
c906108c | 11909 | else |
95a42b64 | 11910 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
11911 | } |
11912 | ||
11913 | static void | |
51be5b68 | 11914 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 11915 | { |
afe38095 | 11916 | int target_resources_ok; |
c906108c SS |
11917 | |
11918 | if (bpt->type == bp_hardware_breakpoint) | |
11919 | { | |
11920 | int i; | |
c5aa993b | 11921 | i = hw_breakpoint_used_count (); |
53a5351d | 11922 | target_resources_ok = |
d92524f1 | 11923 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 11924 | i + 1, 0); |
c906108c | 11925 | if (target_resources_ok == 0) |
8a3fe4f8 | 11926 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 11927 | else if (target_resources_ok < 0) |
8a3fe4f8 | 11928 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
11929 | } |
11930 | ||
cc60f2e3 | 11931 | if (is_watchpoint (bpt)) |
c906108c | 11932 | { |
d07205c2 JK |
11933 | /* Initialize it just to avoid a GCC false warning. */ |
11934 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
11935 | struct gdb_exception e; |
11936 | ||
11937 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 11938 | { |
1e718ff1 TJB |
11939 | orig_enable_state = bpt->enable_state; |
11940 | bpt->enable_state = bp_enabled; | |
dde02812 | 11941 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 11942 | } |
dde02812 | 11943 | if (e.reason < 0) |
c5aa993b | 11944 | { |
1e718ff1 | 11945 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
11946 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
11947 | bpt->number); | |
11948 | return; | |
c5aa993b | 11949 | } |
c906108c | 11950 | } |
0101ce28 | 11951 | |
b4c291bb KH |
11952 | if (bpt->enable_state != bp_permanent) |
11953 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
11954 | |
11955 | if (target_supports_enable_disable_tracepoint () | |
11956 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
11957 | { | |
11958 | struct bp_location *location; | |
11959 | ||
11960 | for (location = bpt->loc; location; location = location->next) | |
11961 | target_enable_tracepoint (location); | |
11962 | } | |
11963 | ||
b4c291bb | 11964 | bpt->disposition = disposition; |
b60e7edf | 11965 | update_global_location_list (1); |
b4c291bb KH |
11966 | breakpoints_changed (); |
11967 | ||
8d3788bd | 11968 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
11969 | } |
11970 | ||
fe3f5fa8 | 11971 | |
c906108c | 11972 | void |
fba45db2 | 11973 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 11974 | { |
51be5b68 PA |
11975 | enable_breakpoint_disp (bpt, bpt->disposition); |
11976 | } | |
11977 | ||
11978 | static void | |
11979 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
11980 | { | |
11981 | enable_breakpoint (bpt); | |
c906108c SS |
11982 | } |
11983 | ||
95a42b64 TT |
11984 | /* A callback for map_breakpoint_numbers that calls |
11985 | enable_breakpoint. */ | |
11986 | ||
11987 | static void | |
11988 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
11989 | { | |
51be5b68 | 11990 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
11991 | } |
11992 | ||
c906108c SS |
11993 | /* The enable command enables the specified breakpoints (or all defined |
11994 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 11995 | in stopping the inferior. */ |
c906108c | 11996 | |
c906108c | 11997 | static void |
fba45db2 | 11998 | enable_command (char *args, int from_tty) |
c906108c | 11999 | { |
c906108c | 12000 | if (args == 0) |
46c6471b PA |
12001 | { |
12002 | struct breakpoint *bpt; | |
12003 | ||
12004 | ALL_BREAKPOINTS (bpt) | |
12005 | if (user_breakpoint_p (bpt)) | |
12006 | enable_breakpoint (bpt); | |
12007 | } | |
0d381245 VP |
12008 | else if (strchr (args, '.')) |
12009 | { | |
12010 | struct bp_location *loc = find_location_by_number (args); | |
12011 | if (loc) | |
d248b706 KY |
12012 | { |
12013 | loc->enabled = 1; | |
12014 | if (target_supports_enable_disable_tracepoint () | |
12015 | && current_trace_status ()->running && loc->owner | |
12016 | && is_tracepoint (loc->owner)) | |
12017 | target_enable_tracepoint (loc); | |
12018 | } | |
b60e7edf | 12019 | update_global_location_list (1); |
0d381245 | 12020 | } |
c906108c | 12021 | else |
95a42b64 | 12022 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12023 | } |
12024 | ||
12025 | static void | |
51be5b68 PA |
12026 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
12027 | { | |
12028 | enum bpdisp disp = *(enum bpdisp *) arg; | |
12029 | ||
12030 | enable_breakpoint_disp (bpt, disp); | |
12031 | } | |
12032 | ||
12033 | static void | |
12034 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 12035 | { |
51be5b68 PA |
12036 | enum bpdisp disp = disp_disable; |
12037 | ||
12038 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12039 | } |
12040 | ||
c906108c | 12041 | static void |
fba45db2 | 12042 | enable_once_command (char *args, int from_tty) |
c906108c | 12043 | { |
51be5b68 | 12044 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
12045 | } |
12046 | ||
12047 | static void | |
51be5b68 | 12048 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 12049 | { |
51be5b68 PA |
12050 | enum bpdisp disp = disp_del; |
12051 | ||
12052 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12053 | } |
12054 | ||
c906108c | 12055 | static void |
fba45db2 | 12056 | enable_delete_command (char *args, int from_tty) |
c906108c | 12057 | { |
51be5b68 | 12058 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
12059 | } |
12060 | \f | |
fa8d40ab JJ |
12061 | static void |
12062 | set_breakpoint_cmd (char *args, int from_tty) | |
12063 | { | |
12064 | } | |
12065 | ||
12066 | static void | |
12067 | show_breakpoint_cmd (char *args, int from_tty) | |
12068 | { | |
12069 | } | |
12070 | ||
1f3b5d1b PP |
12071 | /* Invalidate last known value of any hardware watchpoint if |
12072 | the memory which that value represents has been written to by | |
12073 | GDB itself. */ | |
12074 | ||
12075 | static void | |
12076 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
12077 | const bfd_byte *data) | |
12078 | { | |
12079 | struct breakpoint *bp; | |
12080 | ||
12081 | ALL_BREAKPOINTS (bp) | |
12082 | if (bp->enable_state == bp_enabled | |
12083 | && bp->type == bp_hardware_watchpoint | |
12084 | && bp->val_valid && bp->val) | |
12085 | { | |
12086 | struct bp_location *loc; | |
12087 | ||
12088 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
12089 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
12090 | && loc->address + loc->length > addr | |
12091 | && addr + len > loc->address) | |
12092 | { | |
12093 | value_free (bp->val); | |
12094 | bp->val = NULL; | |
12095 | bp->val_valid = 0; | |
12096 | } | |
12097 | } | |
12098 | } | |
12099 | ||
c906108c SS |
12100 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
12101 | ||
12102 | struct symtabs_and_lines | |
fba45db2 | 12103 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
12104 | { |
12105 | struct symtabs_and_lines sals; | |
cc59ec59 | 12106 | |
c906108c | 12107 | if (string == 0) |
8a3fe4f8 | 12108 | error (_("Empty line specification.")); |
c906108c SS |
12109 | if (default_breakpoint_valid) |
12110 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
12111 | default_breakpoint_symtab, |
12112 | default_breakpoint_line, | |
58438ac1 | 12113 | NULL); |
c906108c SS |
12114 | else |
12115 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 12116 | (struct symtab *) NULL, 0, NULL); |
c906108c | 12117 | if (*string) |
8a3fe4f8 | 12118 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
12119 | return sals; |
12120 | } | |
8181d85f DJ |
12121 | |
12122 | /* Create and insert a raw software breakpoint at PC. Return an | |
12123 | identifier, which should be used to remove the breakpoint later. | |
12124 | In general, places which call this should be using something on the | |
12125 | breakpoint chain instead; this function should be eliminated | |
12126 | someday. */ | |
12127 | ||
12128 | void * | |
6c95b8df PA |
12129 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
12130 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
12131 | { |
12132 | struct bp_target_info *bp_tgt; | |
12133 | ||
6c95b8df | 12134 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12135 | |
6c95b8df | 12136 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12137 | bp_tgt->placed_address = pc; |
6c95b8df | 12138 | |
a6d9a66e | 12139 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12140 | { |
12141 | /* Could not insert the breakpoint. */ | |
12142 | xfree (bp_tgt); | |
12143 | return NULL; | |
12144 | } | |
12145 | ||
12146 | return bp_tgt; | |
12147 | } | |
12148 | ||
4a64f543 MS |
12149 | /* Remove a breakpoint BP inserted by |
12150 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12151 | |
12152 | int | |
a6d9a66e | 12153 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12154 | { |
12155 | struct bp_target_info *bp_tgt = bp; | |
12156 | int ret; | |
12157 | ||
a6d9a66e | 12158 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12159 | xfree (bp_tgt); |
12160 | ||
12161 | return ret; | |
12162 | } | |
12163 | ||
4a64f543 MS |
12164 | /* One (or perhaps two) breakpoints used for software single |
12165 | stepping. */ | |
8181d85f DJ |
12166 | |
12167 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12168 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12169 | |
12170 | /* Create and insert a breakpoint for software single step. */ | |
12171 | ||
12172 | void | |
6c95b8df | 12173 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12174 | struct address_space *aspace, |
12175 | CORE_ADDR next_pc) | |
8181d85f DJ |
12176 | { |
12177 | void **bpt_p; | |
12178 | ||
12179 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12180 | { |
12181 | bpt_p = &single_step_breakpoints[0]; | |
12182 | single_step_gdbarch[0] = gdbarch; | |
12183 | } | |
8181d85f DJ |
12184 | else |
12185 | { | |
12186 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12187 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12188 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12189 | } |
12190 | ||
4a64f543 MS |
12191 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12192 | be to only create the breakpoints once, and actually put them on | |
12193 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12194 | We could adjust the addresses each time they were needed. Doing | |
12195 | this requires corresponding changes elsewhere where single step | |
12196 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12197 | |
6c95b8df | 12198 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12199 | if (*bpt_p == NULL) |
5af949e3 UW |
12200 | error (_("Could not insert single-step breakpoint at %s"), |
12201 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12202 | } |
12203 | ||
f02253f1 HZ |
12204 | /* Check if the breakpoints used for software single stepping |
12205 | were inserted or not. */ | |
12206 | ||
12207 | int | |
12208 | single_step_breakpoints_inserted (void) | |
12209 | { | |
12210 | return (single_step_breakpoints[0] != NULL | |
12211 | || single_step_breakpoints[1] != NULL); | |
12212 | } | |
12213 | ||
8181d85f DJ |
12214 | /* Remove and delete any breakpoints used for software single step. */ |
12215 | ||
12216 | void | |
12217 | remove_single_step_breakpoints (void) | |
12218 | { | |
12219 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12220 | ||
12221 | /* See insert_single_step_breakpoint for more about this deprecated | |
12222 | call. */ | |
a6d9a66e UW |
12223 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12224 | single_step_breakpoints[0]); | |
12225 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12226 | single_step_breakpoints[0] = NULL; |
12227 | ||
12228 | if (single_step_breakpoints[1] != NULL) | |
12229 | { | |
a6d9a66e UW |
12230 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12231 | single_step_breakpoints[1]); | |
12232 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12233 | single_step_breakpoints[1] = NULL; |
12234 | } | |
12235 | } | |
12236 | ||
d03285ec UW |
12237 | /* Delete software single step breakpoints without removing them from |
12238 | the inferior. This is intended to be used if the inferior's address | |
12239 | space where they were inserted is already gone, e.g. after exit or | |
12240 | exec. */ | |
12241 | ||
12242 | void | |
12243 | cancel_single_step_breakpoints (void) | |
12244 | { | |
12245 | int i; | |
12246 | ||
12247 | for (i = 0; i < 2; i++) | |
12248 | if (single_step_breakpoints[i]) | |
12249 | { | |
12250 | xfree (single_step_breakpoints[i]); | |
12251 | single_step_breakpoints[i] = NULL; | |
12252 | single_step_gdbarch[i] = NULL; | |
12253 | } | |
12254 | } | |
12255 | ||
12256 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12257 | removing them. */ | |
12258 | ||
12259 | static void | |
12260 | detach_single_step_breakpoints (void) | |
12261 | { | |
12262 | int i; | |
12263 | ||
12264 | for (i = 0; i < 2; i++) | |
12265 | if (single_step_breakpoints[i]) | |
12266 | target_remove_breakpoint (single_step_gdbarch[i], | |
12267 | single_step_breakpoints[i]); | |
12268 | } | |
12269 | ||
4a64f543 MS |
12270 | /* Check whether a software single-step breakpoint is inserted at |
12271 | PC. */ | |
1aafd4da UW |
12272 | |
12273 | static int | |
cc59ec59 MS |
12274 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12275 | CORE_ADDR pc) | |
1aafd4da UW |
12276 | { |
12277 | int i; | |
12278 | ||
12279 | for (i = 0; i < 2; i++) | |
12280 | { | |
12281 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12282 | if (bp_tgt |
12283 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12284 | bp_tgt->placed_address, | |
12285 | aspace, pc)) | |
1aafd4da UW |
12286 | return 1; |
12287 | } | |
12288 | ||
12289 | return 0; | |
12290 | } | |
12291 | ||
a96d9b2e SDJ |
12292 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12293 | non-zero otherwise. */ | |
12294 | static int | |
12295 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12296 | { | |
12297 | if (syscall_catchpoint_p (bp) | |
12298 | && bp->enable_state != bp_disabled | |
12299 | && bp->enable_state != bp_call_disabled) | |
12300 | return 1; | |
12301 | else | |
12302 | return 0; | |
12303 | } | |
12304 | ||
12305 | int | |
12306 | catch_syscall_enabled (void) | |
12307 | { | |
12308 | struct inferior *inf = current_inferior (); | |
12309 | ||
12310 | return inf->total_syscalls_count != 0; | |
12311 | } | |
12312 | ||
12313 | int | |
12314 | catching_syscall_number (int syscall_number) | |
12315 | { | |
12316 | struct breakpoint *bp; | |
12317 | ||
12318 | ALL_BREAKPOINTS (bp) | |
12319 | if (is_syscall_catchpoint_enabled (bp)) | |
12320 | { | |
be5c67c1 PA |
12321 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
12322 | ||
12323 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
12324 | { |
12325 | int i, iter; | |
12326 | for (i = 0; | |
be5c67c1 | 12327 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
12328 | i++) |
12329 | if (syscall_number == iter) | |
12330 | return 1; | |
12331 | } | |
12332 | else | |
12333 | return 1; | |
12334 | } | |
12335 | ||
12336 | return 0; | |
12337 | } | |
12338 | ||
12339 | /* Complete syscall names. Used by "catch syscall". */ | |
12340 | static char ** | |
12341 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12342 | char *text, char *word) | |
12343 | { | |
12344 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12345 | char **retlist |
12346 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12347 | |
c38eea1a MS |
12348 | xfree (list); |
12349 | return retlist; | |
a96d9b2e SDJ |
12350 | } |
12351 | ||
1042e4c0 SS |
12352 | /* Tracepoint-specific operations. */ |
12353 | ||
12354 | /* Set tracepoint count to NUM. */ | |
12355 | static void | |
12356 | set_tracepoint_count (int num) | |
12357 | { | |
12358 | tracepoint_count = num; | |
4fa62494 | 12359 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12360 | } |
12361 | ||
12362 | void | |
12363 | trace_command (char *arg, int from_tty) | |
12364 | { | |
8cdf0e15 VP |
12365 | if (create_breakpoint (get_current_arch (), |
12366 | arg, | |
12367 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12368 | 0 /* tempflag */, |
12369 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12370 | 0 /* Ignore count */, |
12371 | pending_break_support, | |
12372 | NULL, | |
12373 | from_tty, | |
84f4c1fe PM |
12374 | 1 /* enabled */, |
12375 | 0 /* internal */)) | |
fd9b8c24 | 12376 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12377 | } |
12378 | ||
7a697b8d SS |
12379 | void |
12380 | ftrace_command (char *arg, int from_tty) | |
12381 | { | |
8cdf0e15 VP |
12382 | if (create_breakpoint (get_current_arch (), |
12383 | arg, | |
12384 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12385 | 0 /* tempflag */, |
12386 | bp_fast_tracepoint /* type_wanted */, | |
12387 | 0 /* Ignore count */, | |
12388 | pending_break_support, | |
12389 | NULL, | |
12390 | from_tty, | |
84f4c1fe PM |
12391 | 1 /* enabled */, |
12392 | 0 /* internal */)) | |
0fb4aa4b PA |
12393 | set_tracepoint_count (breakpoint_count); |
12394 | } | |
12395 | ||
12396 | /* strace command implementation. Creates a static tracepoint. */ | |
12397 | ||
12398 | void | |
12399 | strace_command (char *arg, int from_tty) | |
12400 | { | |
12401 | if (create_breakpoint (get_current_arch (), | |
12402 | arg, | |
12403 | NULL, 0, 1 /* parse arg */, | |
12404 | 0 /* tempflag */, | |
12405 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12406 | 0 /* Ignore count */, |
12407 | pending_break_support, | |
12408 | NULL, | |
12409 | from_tty, | |
84f4c1fe PM |
12410 | 1 /* enabled */, |
12411 | 0 /* internal */)) | |
fd9b8c24 | 12412 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12413 | } |
12414 | ||
409873ef SS |
12415 | /* Set up a fake reader function that gets command lines from a linked |
12416 | list that was acquired during tracepoint uploading. */ | |
12417 | ||
12418 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12419 | static int next_cmd; |
409873ef SS |
12420 | |
12421 | static char * | |
12422 | read_uploaded_action (void) | |
12423 | { | |
12424 | char *rslt; | |
12425 | ||
3149d8c1 | 12426 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12427 | |
3149d8c1 | 12428 | next_cmd++; |
409873ef SS |
12429 | |
12430 | return rslt; | |
12431 | } | |
12432 | ||
00bf0b85 SS |
12433 | /* Given information about a tracepoint as recorded on a target (which |
12434 | can be either a live system or a trace file), attempt to create an | |
12435 | equivalent GDB tracepoint. This is not a reliable process, since | |
12436 | the target does not necessarily have all the information used when | |
12437 | the tracepoint was originally defined. */ | |
12438 | ||
12439 | struct breakpoint * | |
12440 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 12441 | { |
409873ef | 12442 | char *addr_str, small_buf[100]; |
d5551862 | 12443 | struct breakpoint *tp; |
fd9b8c24 | 12444 | |
409873ef SS |
12445 | if (utp->at_string) |
12446 | addr_str = utp->at_string; | |
12447 | else | |
12448 | { | |
12449 | /* In the absence of a source location, fall back to raw | |
12450 | address. Since there is no way to confirm that the address | |
12451 | means the same thing as when the trace was started, warn the | |
12452 | user. */ | |
3e43a32a MS |
12453 | warning (_("Uploaded tracepoint %d has no " |
12454 | "source location, using raw address"), | |
409873ef SS |
12455 | utp->number); |
12456 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12457 | addr_str = small_buf; | |
12458 | } | |
12459 | ||
12460 | /* There's not much we can do with a sequence of bytecodes. */ | |
12461 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12462 | warning (_("Uploaded tracepoint %d condition " |
12463 | "has no source form, ignoring it"), | |
409873ef | 12464 | utp->number); |
d5551862 | 12465 | |
8cdf0e15 | 12466 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12467 | addr_str, |
12468 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12469 | 0 /* tempflag */, |
0fb4aa4b | 12470 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12471 | 0 /* Ignore count */, |
12472 | pending_break_support, | |
12473 | NULL, | |
12474 | 0 /* from_tty */, | |
84f4c1fe PM |
12475 | utp->enabled /* enabled */, |
12476 | 0 /* internal */)) | |
fd9b8c24 PA |
12477 | return NULL; |
12478 | ||
00bf0b85 SS |
12479 | set_tracepoint_count (breakpoint_count); |
12480 | ||
409873ef | 12481 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12482 | tp = get_tracepoint (tracepoint_count); |
12483 | gdb_assert (tp != NULL); | |
d5551862 | 12484 | |
00bf0b85 SS |
12485 | if (utp->pass > 0) |
12486 | { | |
409873ef | 12487 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 12488 | |
409873ef | 12489 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12490 | } |
12491 | ||
409873ef SS |
12492 | /* If we have uploaded versions of the original commands, set up a |
12493 | special-purpose "reader" function and call the usual command line | |
12494 | reader, then pass the result to the breakpoint command-setting | |
12495 | function. */ | |
3149d8c1 | 12496 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12497 | { |
409873ef | 12498 | struct command_line *cmd_list; |
00bf0b85 | 12499 | |
409873ef | 12500 | this_utp = utp; |
3149d8c1 | 12501 | next_cmd = 0; |
d5551862 | 12502 | |
409873ef SS |
12503 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12504 | ||
12505 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 12506 | } |
3149d8c1 SS |
12507 | else if (!VEC_empty (char_ptr, utp->actions) |
12508 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12509 | warning (_("Uploaded tracepoint %d actions " |
12510 | "have no source form, ignoring them"), | |
409873ef | 12511 | utp->number); |
00bf0b85 SS |
12512 | |
12513 | return tp; | |
12514 | } | |
12515 | ||
1042e4c0 SS |
12516 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12517 | omitted. */ | |
12518 | ||
12519 | static void | |
e5a67952 | 12520 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 12521 | { |
e5a67952 | 12522 | int num_printed; |
1042e4c0 | 12523 | |
e5a67952 | 12524 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
12525 | |
12526 | if (num_printed == 0) | |
1042e4c0 | 12527 | { |
e5a67952 | 12528 | if (args == NULL || *args == '\0') |
d77f58be SS |
12529 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
12530 | else | |
e5a67952 | 12531 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 12532 | } |
ad443146 SS |
12533 | |
12534 | default_collect_info (); | |
1042e4c0 SS |
12535 | } |
12536 | ||
4a64f543 | 12537 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
12538 | Not supported by all targets. */ |
12539 | static void | |
12540 | enable_trace_command (char *args, int from_tty) | |
12541 | { | |
12542 | enable_command (args, from_tty); | |
12543 | } | |
12544 | ||
4a64f543 | 12545 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
12546 | Not supported by all targets. */ |
12547 | static void | |
12548 | disable_trace_command (char *args, int from_tty) | |
12549 | { | |
12550 | disable_command (args, from_tty); | |
12551 | } | |
12552 | ||
4a64f543 | 12553 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
12554 | static void |
12555 | delete_trace_command (char *arg, int from_tty) | |
12556 | { | |
35df4500 | 12557 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
12558 | |
12559 | dont_repeat (); | |
12560 | ||
12561 | if (arg == 0) | |
12562 | { | |
12563 | int breaks_to_delete = 0; | |
12564 | ||
12565 | /* Delete all breakpoints if no argument. | |
12566 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
12567 | have to be deleted with an explicit breakpoint number |
12568 | argument. */ | |
1042e4c0 | 12569 | ALL_TRACEPOINTS (b) |
46c6471b | 12570 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
12571 | { |
12572 | breaks_to_delete = 1; | |
12573 | break; | |
12574 | } | |
1042e4c0 SS |
12575 | |
12576 | /* Ask user only if there are some breakpoints to delete. */ | |
12577 | if (!from_tty | |
12578 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
12579 | { | |
35df4500 | 12580 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12581 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 12582 | delete_breakpoint (b); |
1042e4c0 SS |
12583 | } |
12584 | } | |
12585 | else | |
51be5b68 | 12586 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
12587 | } |
12588 | ||
197f0a60 TT |
12589 | /* Helper function for trace_pass_command. */ |
12590 | ||
12591 | static void | |
12592 | trace_pass_set_count (struct breakpoint *bp, int count, int from_tty) | |
12593 | { | |
12594 | bp->pass_count = count; | |
12595 | observer_notify_tracepoint_modified (bp->number); | |
12596 | if (from_tty) | |
12597 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
12598 | bp->number, count); | |
12599 | } | |
12600 | ||
1042e4c0 SS |
12601 | /* Set passcount for tracepoint. |
12602 | ||
12603 | First command argument is passcount, second is tracepoint number. | |
12604 | If tracepoint number omitted, apply to most recently defined. | |
12605 | Also accepts special argument "all". */ | |
12606 | ||
12607 | static void | |
12608 | trace_pass_command (char *args, int from_tty) | |
12609 | { | |
197f0a60 | 12610 | struct breakpoint *t1; |
1042e4c0 | 12611 | unsigned int count; |
1042e4c0 SS |
12612 | |
12613 | if (args == 0 || *args == 0) | |
3e43a32a MS |
12614 | error (_("passcount command requires an " |
12615 | "argument (count + optional TP num)")); | |
1042e4c0 | 12616 | |
4a64f543 | 12617 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
12618 | |
12619 | while (*args && isspace ((int) *args)) | |
12620 | args++; | |
12621 | ||
12622 | if (*args && strncasecmp (args, "all", 3) == 0) | |
12623 | { | |
12624 | args += 3; /* Skip special argument "all". */ | |
1042e4c0 SS |
12625 | if (*args) |
12626 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 12627 | |
197f0a60 TT |
12628 | ALL_TRACEPOINTS (t1) |
12629 | { | |
12630 | trace_pass_set_count (t1, count, from_tty); | |
12631 | } | |
12632 | } | |
12633 | else if (*args == '\0') | |
1042e4c0 | 12634 | { |
197f0a60 | 12635 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 12636 | if (t1) |
197f0a60 TT |
12637 | trace_pass_set_count (t1, count, from_tty); |
12638 | } | |
12639 | else | |
12640 | { | |
12641 | struct get_number_or_range_state state; | |
12642 | ||
12643 | init_number_or_range (&state, args); | |
12644 | while (!state.finished) | |
1042e4c0 | 12645 | { |
197f0a60 TT |
12646 | t1 = get_tracepoint_by_number (&args, &state, 1); |
12647 | if (t1) | |
12648 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
12649 | } |
12650 | } | |
1042e4c0 SS |
12651 | } |
12652 | ||
12653 | struct breakpoint * | |
12654 | get_tracepoint (int num) | |
12655 | { | |
12656 | struct breakpoint *t; | |
12657 | ||
12658 | ALL_TRACEPOINTS (t) | |
12659 | if (t->number == num) | |
12660 | return t; | |
12661 | ||
12662 | return NULL; | |
12663 | } | |
12664 | ||
d5551862 SS |
12665 | /* Find the tracepoint with the given target-side number (which may be |
12666 | different from the tracepoint number after disconnecting and | |
12667 | reconnecting). */ | |
12668 | ||
12669 | struct breakpoint * | |
12670 | get_tracepoint_by_number_on_target (int num) | |
12671 | { | |
12672 | struct breakpoint *t; | |
12673 | ||
12674 | ALL_TRACEPOINTS (t) | |
12675 | if (t->number_on_target == num) | |
12676 | return t; | |
12677 | ||
12678 | return NULL; | |
12679 | } | |
12680 | ||
1042e4c0 | 12681 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
12682 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
12683 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 SS |
12684 | recent tracepoint (tracepoint_count) is returned. */ |
12685 | struct breakpoint * | |
197f0a60 TT |
12686 | get_tracepoint_by_number (char **arg, |
12687 | struct get_number_or_range_state *state, | |
12688 | int optional_p) | |
1042e4c0 SS |
12689 | { |
12690 | extern int tracepoint_count; | |
12691 | struct breakpoint *t; | |
12692 | int tpnum; | |
12693 | char *instring = arg == NULL ? NULL : *arg; | |
12694 | ||
197f0a60 TT |
12695 | if (state) |
12696 | { | |
12697 | gdb_assert (!state->finished); | |
12698 | tpnum = get_number_or_range (state); | |
12699 | } | |
12700 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
12701 | { |
12702 | if (optional_p) | |
12703 | tpnum = tracepoint_count; | |
12704 | else | |
12705 | error_no_arg (_("tracepoint number")); | |
12706 | } | |
12707 | else | |
197f0a60 | 12708 | tpnum = get_number (arg); |
1042e4c0 SS |
12709 | |
12710 | if (tpnum <= 0) | |
12711 | { | |
12712 | if (instring && *instring) | |
12713 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
12714 | instring); | |
12715 | else | |
3e43a32a MS |
12716 | printf_filtered (_("Tracepoint argument missing " |
12717 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
12718 | return NULL; |
12719 | } | |
12720 | ||
12721 | ALL_TRACEPOINTS (t) | |
12722 | if (t->number == tpnum) | |
12723 | { | |
12724 | return t; | |
12725 | } | |
12726 | ||
1042e4c0 SS |
12727 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
12728 | return NULL; | |
12729 | } | |
12730 | ||
6149aea9 PA |
12731 | /* Save information on user settable breakpoints (watchpoints, etc) to |
12732 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
12733 | on each breakpoint and only include the ones for which it returns | |
12734 | non-zero. */ | |
12735 | ||
1042e4c0 | 12736 | static void |
6149aea9 PA |
12737 | save_breakpoints (char *filename, int from_tty, |
12738 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
12739 | { |
12740 | struct breakpoint *tp; | |
6149aea9 | 12741 | int any = 0; |
a7bdde9e | 12742 | char *pathname; |
1042e4c0 | 12743 | struct cleanup *cleanup; |
a7bdde9e | 12744 | struct ui_file *fp; |
6149aea9 | 12745 | int extra_trace_bits = 0; |
1042e4c0 | 12746 | |
6149aea9 PA |
12747 | if (filename == 0 || *filename == 0) |
12748 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
12749 | |
12750 | /* See if we have anything to save. */ | |
6149aea9 | 12751 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 12752 | { |
6149aea9 | 12753 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 12754 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
12755 | continue; |
12756 | ||
12757 | /* If we have a filter, only save the breakpoints it accepts. */ | |
12758 | if (filter && !filter (tp)) | |
12759 | continue; | |
12760 | ||
12761 | any = 1; | |
12762 | ||
12763 | if (is_tracepoint (tp)) | |
12764 | { | |
12765 | extra_trace_bits = 1; | |
12766 | ||
12767 | /* We can stop searching. */ | |
12768 | break; | |
12769 | } | |
1042e4c0 | 12770 | } |
6149aea9 PA |
12771 | |
12772 | if (!any) | |
1042e4c0 | 12773 | { |
6149aea9 | 12774 | warning (_("Nothing to save.")); |
1042e4c0 SS |
12775 | return; |
12776 | } | |
12777 | ||
6149aea9 | 12778 | pathname = tilde_expand (filename); |
1042e4c0 | 12779 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 12780 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 12781 | if (!fp) |
6149aea9 PA |
12782 | error (_("Unable to open file '%s' for saving (%s)"), |
12783 | filename, safe_strerror (errno)); | |
a7bdde9e | 12784 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 12785 | |
6149aea9 PA |
12786 | if (extra_trace_bits) |
12787 | save_trace_state_variables (fp); | |
8bf6485c | 12788 | |
6149aea9 | 12789 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 12790 | { |
6149aea9 | 12791 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 12792 | if (!user_breakpoint_p (tp)) |
6149aea9 | 12793 | continue; |
8bf6485c | 12794 | |
6149aea9 PA |
12795 | /* If we have a filter, only save the breakpoints it accepts. */ |
12796 | if (filter && !filter (tp)) | |
12797 | continue; | |
12798 | ||
26063d49 | 12799 | if (tp->ops != NULL && tp->ops->print_recreate != NULL) |
6149aea9 | 12800 | (tp->ops->print_recreate) (tp, fp); |
1042e4c0 SS |
12801 | else |
12802 | { | |
6149aea9 PA |
12803 | if (tp->type == bp_fast_tracepoint) |
12804 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
12805 | if (tp->type == bp_static_tracepoint) |
12806 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
12807 | else if (tp->type == bp_tracepoint) |
12808 | fprintf_unfiltered (fp, "trace"); | |
12809 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12810 | fprintf_unfiltered (fp, "tbreak"); | |
12811 | else if (tp->type == bp_breakpoint) | |
12812 | fprintf_unfiltered (fp, "break"); | |
12813 | else if (tp->type == bp_hardware_breakpoint | |
12814 | && tp->disposition == disp_del) | |
12815 | fprintf_unfiltered (fp, "thbreak"); | |
12816 | else if (tp->type == bp_hardware_breakpoint) | |
12817 | fprintf_unfiltered (fp, "hbreak"); | |
12818 | else if (tp->type == bp_watchpoint) | |
12819 | fprintf_unfiltered (fp, "watch"); | |
12820 | else if (tp->type == bp_hardware_watchpoint) | |
12821 | fprintf_unfiltered (fp, "watch"); | |
12822 | else if (tp->type == bp_read_watchpoint) | |
12823 | fprintf_unfiltered (fp, "rwatch"); | |
12824 | else if (tp->type == bp_access_watchpoint) | |
12825 | fprintf_unfiltered (fp, "awatch"); | |
12826 | else | |
12827 | internal_error (__FILE__, __LINE__, | |
12828 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12829 | ||
12830 | if (tp->exp_string) | |
12831 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
12832 | else if (tp->addr_string) | |
12833 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
12834 | else | |
12835 | { | |
12836 | char tmp[40]; | |
12837 | ||
12838 | sprintf_vma (tmp, tp->loc->address); | |
12839 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
12840 | } | |
1042e4c0 SS |
12841 | } |
12842 | ||
6149aea9 PA |
12843 | if (tp->thread != -1) |
12844 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
12845 | ||
12846 | if (tp->task != 0) | |
12847 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
12848 | |
12849 | fprintf_unfiltered (fp, "\n"); | |
12850 | ||
6149aea9 PA |
12851 | /* Note, we can't rely on tp->number for anything, as we can't |
12852 | assume the recreated breakpoint numbers will match. Use $bpnum | |
12853 | instead. */ | |
12854 | ||
12855 | if (tp->cond_string) | |
12856 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
12857 | ||
12858 | if (tp->ignore_count) | |
12859 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
12860 | ||
1042e4c0 | 12861 | if (tp->pass_count) |
a7bdde9e | 12862 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 12863 | |
a7bdde9e | 12864 | if (tp->commands) |
1042e4c0 | 12865 | { |
a7bdde9e VP |
12866 | volatile struct gdb_exception ex; |
12867 | ||
6149aea9 | 12868 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
12869 | |
12870 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 12871 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 12872 | { |
9add0f1b | 12873 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
12874 | } |
12875 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 12876 | |
a7bdde9e VP |
12877 | if (ex.reason < 0) |
12878 | throw_exception (ex); | |
1042e4c0 | 12879 | |
a7bdde9e | 12880 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 12881 | } |
6149aea9 PA |
12882 | |
12883 | if (tp->enable_state == bp_disabled) | |
12884 | fprintf_unfiltered (fp, "disable\n"); | |
12885 | ||
12886 | /* If this is a multi-location breakpoint, check if the locations | |
12887 | should be individually disabled. Watchpoint locations are | |
12888 | special, and not user visible. */ | |
12889 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
12890 | { | |
12891 | struct bp_location *loc; | |
12892 | int n = 1; | |
12893 | ||
12894 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
12895 | if (!loc->enabled) | |
12896 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
12897 | } | |
1042e4c0 | 12898 | } |
8bf6485c | 12899 | |
6149aea9 | 12900 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
12901 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
12902 | ||
1042e4c0 SS |
12903 | do_cleanups (cleanup); |
12904 | if (from_tty) | |
6149aea9 PA |
12905 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
12906 | } | |
12907 | ||
12908 | /* The `save breakpoints' command. */ | |
12909 | ||
12910 | static void | |
12911 | save_breakpoints_command (char *args, int from_tty) | |
12912 | { | |
12913 | save_breakpoints (args, from_tty, NULL); | |
12914 | } | |
12915 | ||
12916 | /* The `save tracepoints' command. */ | |
12917 | ||
12918 | static void | |
12919 | save_tracepoints_command (char *args, int from_tty) | |
12920 | { | |
12921 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
12922 | } |
12923 | ||
12924 | /* Create a vector of all tracepoints. */ | |
12925 | ||
12926 | VEC(breakpoint_p) * | |
eeae04df | 12927 | all_tracepoints (void) |
1042e4c0 SS |
12928 | { |
12929 | VEC(breakpoint_p) *tp_vec = 0; | |
12930 | struct breakpoint *tp; | |
12931 | ||
12932 | ALL_TRACEPOINTS (tp) | |
12933 | { | |
12934 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
12935 | } | |
12936 | ||
12937 | return tp_vec; | |
12938 | } | |
12939 | ||
c906108c | 12940 | \f |
4a64f543 MS |
12941 | /* This help string is used for the break, hbreak, tbreak and thbreak |
12942 | commands. It is defined as a macro to prevent duplication. | |
12943 | COMMAND should be a string constant containing the name of the | |
12944 | command. */ | |
31e2b00f AS |
12945 | #define BREAK_ARGS_HELP(command) \ |
12946 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
12947 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
12948 | If a line number is specified, break at start of code for that line.\n\ | |
12949 | If a function is specified, break at start of code for that function.\n\ | |
12950 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
12951 | With no LOCATION, uses current execution address of the selected\n\ |
12952 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
12953 | \n\ |
12954 | THREADNUM is the number from \"info threads\".\n\ | |
12955 | CONDITION is a boolean expression.\n\ | |
12956 | \n\ | |
d41c0fc8 PA |
12957 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
12958 | conditions are different.\n\ | |
31e2b00f AS |
12959 | \n\ |
12960 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
12961 | ||
44feb3ce TT |
12962 | /* List of subcommands for "catch". */ |
12963 | static struct cmd_list_element *catch_cmdlist; | |
12964 | ||
12965 | /* List of subcommands for "tcatch". */ | |
12966 | static struct cmd_list_element *tcatch_cmdlist; | |
12967 | ||
12968 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
12969 | lists, and pass some additional user data to the command function. */ | |
12970 | static void | |
12971 | add_catch_command (char *name, char *docstring, | |
12972 | void (*sfunc) (char *args, int from_tty, | |
12973 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
12974 | char **(*completer) (struct cmd_list_element *cmd, |
12975 | char *text, char *word), | |
44feb3ce TT |
12976 | void *user_data_catch, |
12977 | void *user_data_tcatch) | |
12978 | { | |
12979 | struct cmd_list_element *command; | |
12980 | ||
12981 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12982 | &catch_cmdlist); | |
12983 | set_cmd_sfunc (command, sfunc); | |
12984 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 12985 | set_cmd_completer (command, completer); |
44feb3ce TT |
12986 | |
12987 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12988 | &tcatch_cmdlist); | |
12989 | set_cmd_sfunc (command, sfunc); | |
12990 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 12991 | set_cmd_completer (command, completer); |
44feb3ce TT |
12992 | } |
12993 | ||
6c95b8df | 12994 | static void |
a79b8f6e | 12995 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 12996 | { |
6c95b8df PA |
12997 | inf->total_syscalls_count = 0; |
12998 | inf->any_syscall_count = 0; | |
12999 | VEC_free (int, inf->syscalls_counts); | |
13000 | } | |
13001 | ||
6149aea9 PA |
13002 | static void |
13003 | save_command (char *arg, int from_tty) | |
13004 | { | |
3e43a32a MS |
13005 | printf_unfiltered (_("\"save\" must be followed by " |
13006 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13007 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13008 | } | |
13009 | ||
84f4c1fe PM |
13010 | struct breakpoint * |
13011 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13012 | void *data) | |
13013 | { | |
35df4500 | 13014 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13015 | |
35df4500 | 13016 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13017 | { |
13018 | if ((*callback) (b, data)) | |
13019 | return b; | |
13020 | } | |
13021 | ||
13022 | return NULL; | |
13023 | } | |
13024 | ||
c906108c | 13025 | void |
fba45db2 | 13026 | _initialize_breakpoint (void) |
c906108c SS |
13027 | { |
13028 | struct cmd_list_element *c; | |
13029 | ||
84acb35a | 13030 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 13031 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 13032 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 13033 | |
17450429 PP |
13034 | breakpoint_objfile_key = register_objfile_data (); |
13035 | ||
c906108c SS |
13036 | breakpoint_chain = 0; |
13037 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
13038 | before a breakpoint is set. */ | |
13039 | breakpoint_count = 0; | |
13040 | ||
1042e4c0 SS |
13041 | tracepoint_count = 0; |
13042 | ||
1bedd215 AC |
13043 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
13044 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
13045 | Usage is `ignore N COUNT'.")); | |
c906108c | 13046 | if (xdb_commands) |
c5aa993b | 13047 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 13048 | |
1bedd215 AC |
13049 | add_com ("commands", class_breakpoint, commands_command, _("\ |
13050 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
13051 | Give breakpoint number as argument after \"commands\".\n\ |
13052 | With no argument, the targeted breakpoint is the last one set.\n\ | |
13053 | The commands themselves follow starting on the next line.\n\ | |
13054 | Type a line containing \"end\" to indicate the end of them.\n\ | |
13055 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 13056 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 13057 | |
1bedd215 AC |
13058 | add_com ("condition", class_breakpoint, condition_command, _("\ |
13059 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 13060 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 13061 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 13062 | |
1bedd215 | 13063 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 13064 | Set a temporary breakpoint.\n\ |
c906108c SS |
13065 | Like \"break\" except the breakpoint is only temporary,\n\ |
13066 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
13067 | by using \"enable delete\" on the breakpoint number.\n\ |
13068 | \n" | |
13069 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 13070 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13071 | |
1bedd215 | 13072 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 13073 | Set a hardware assisted breakpoint.\n\ |
c906108c | 13074 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
13075 | some target hardware may not have this support.\n\ |
13076 | \n" | |
13077 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 13078 | set_cmd_completer (c, location_completer); |
c906108c | 13079 | |
1bedd215 | 13080 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 13081 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 13082 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
13083 | so it will be deleted when hit.\n\ |
13084 | \n" | |
13085 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 13086 | set_cmd_completer (c, location_completer); |
c906108c | 13087 | |
1bedd215 AC |
13088 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
13089 | Enable some breakpoints.\n\ | |
c906108c SS |
13090 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13091 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13092 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13093 | With a subcommand you can enable temporarily."), |
c906108c SS |
13094 | &enablelist, "enable ", 1, &cmdlist); |
13095 | if (xdb_commands) | |
1bedd215 AC |
13096 | add_com ("ab", class_breakpoint, enable_command, _("\ |
13097 | Enable some breakpoints.\n\ | |
c906108c SS |
13098 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13099 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13100 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13101 | With a subcommand you can enable temporarily.")); |
c906108c SS |
13102 | |
13103 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
13104 | ||
84951ab5 | 13105 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 13106 | Enable some breakpoints.\n\ |
c906108c SS |
13107 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13108 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13109 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 13110 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 13111 | |
1a966eab AC |
13112 | add_cmd ("once", no_class, enable_once_command, _("\ |
13113 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13114 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13115 | &enablebreaklist); |
13116 | ||
1a966eab AC |
13117 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13118 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13119 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13120 | &enablebreaklist); |
13121 | ||
1a966eab AC |
13122 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13123 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13124 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13125 | &enablelist); |
13126 | ||
1a966eab AC |
13127 | add_cmd ("once", no_class, enable_once_command, _("\ |
13128 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13129 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13130 | &enablelist); |
13131 | ||
1bedd215 AC |
13132 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
13133 | Disable some breakpoints.\n\ | |
c906108c SS |
13134 | Arguments are breakpoint numbers with spaces in between.\n\ |
13135 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13136 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
13137 | &disablelist, "disable ", 1, &cmdlist); |
13138 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13139 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13140 | if (xdb_commands) | |
1bedd215 AC |
13141 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13142 | Disable some breakpoints.\n\ | |
c906108c SS |
13143 | Arguments are breakpoint numbers with spaces in between.\n\ |
13144 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13145 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 13146 | |
1a966eab AC |
13147 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13148 | Disable some breakpoints.\n\ | |
c906108c SS |
13149 | Arguments are breakpoint numbers with spaces in between.\n\ |
13150 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13151 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 13152 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13153 | &disablelist); |
13154 | ||
1bedd215 AC |
13155 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13156 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13157 | Arguments are breakpoint numbers with spaces in between.\n\ |
13158 | To delete all breakpoints, give no argument.\n\ | |
13159 | \n\ | |
13160 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13161 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13162 | &deletelist, "delete ", 1, &cmdlist); |
13163 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13164 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13165 | if (xdb_commands) |
1bedd215 AC |
13166 | add_com ("db", class_breakpoint, delete_command, _("\ |
13167 | Delete some breakpoints.\n\ | |
c906108c | 13168 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13169 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13170 | |
1a966eab AC |
13171 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13172 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13173 | Arguments are breakpoint numbers with spaces in between.\n\ |
13174 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13175 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13176 | &deletelist); |
13177 | ||
1bedd215 AC |
13178 | add_com ("clear", class_breakpoint, clear_command, _("\ |
13179 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
13180 | Argument may be line number, function name, or \"*\" and an address.\n\ |
13181 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
13182 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
13183 | If an address is specified, breakpoints at that address are cleared.\n\ |
13184 | \n\ | |
13185 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
13186 | is executing in.\n\ |
13187 | \n\ | |
1bedd215 | 13188 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 13189 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 13190 | |
1bedd215 | 13191 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
13192 | Set breakpoint at specified line or function.\n" |
13193 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13194 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13195 | |
c906108c SS |
13196 | add_com_alias ("b", "break", class_run, 1); |
13197 | add_com_alias ("br", "break", class_run, 1); | |
13198 | add_com_alias ("bre", "break", class_run, 1); | |
13199 | add_com_alias ("brea", "break", class_run, 1); | |
13200 | ||
7681d515 PM |
13201 | if (xdb_commands) |
13202 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13203 | |
13204 | if (dbx_commands) | |
13205 | { | |
1bedd215 AC |
13206 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13207 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13208 | &stoplist, "stop ", 1, &cmdlist); |
13209 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13210 | _("Break in function or address."), &stoplist); |
c5aa993b | 13211 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13212 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13213 | add_com ("status", class_info, breakpoints_info, _("\ |
13214 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13215 | The \"Type\" column indicates one of:\n\ |
13216 | \tbreakpoint - normal breakpoint\n\ | |
13217 | \twatchpoint - watchpoint\n\ | |
13218 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13219 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13220 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13221 | address and file/line number respectively.\n\ |
13222 | \n\ | |
13223 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13224 | are set to the address of the last breakpoint listed unless the command\n\ |
13225 | is prefixed with \"server \".\n\n\ | |
c906108c | 13226 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13227 | breakpoint set.")); |
c906108c SS |
13228 | } |
13229 | ||
1bedd215 | 13230 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13231 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
13232 | The \"Type\" column indicates one of:\n\ |
13233 | \tbreakpoint - normal breakpoint\n\ | |
13234 | \twatchpoint - watchpoint\n\ | |
13235 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13236 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13237 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13238 | address and file/line number respectively.\n\ |
13239 | \n\ | |
13240 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13241 | are set to the address of the last breakpoint listed unless the command\n\ |
13242 | is prefixed with \"server \".\n\n\ | |
c906108c | 13243 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13244 | breakpoint set.")); |
c906108c | 13245 | |
6b04bdb7 MS |
13246 | add_info_alias ("b", "breakpoints", 1); |
13247 | ||
c906108c | 13248 | if (xdb_commands) |
1bedd215 AC |
13249 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13250 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13251 | The \"Type\" column indicates one of:\n\ |
13252 | \tbreakpoint - normal breakpoint\n\ | |
13253 | \twatchpoint - watchpoint\n\ | |
13254 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13255 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13256 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13257 | address and file/line number respectively.\n\ |
13258 | \n\ | |
13259 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13260 | are set to the address of the last breakpoint listed unless the command\n\ |
13261 | is prefixed with \"server \".\n\n\ | |
c906108c | 13262 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13263 | breakpoint set.")); |
c906108c | 13264 | |
1a966eab AC |
13265 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13266 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13267 | The \"Type\" column indicates one of:\n\ |
13268 | \tbreakpoint - normal breakpoint\n\ | |
13269 | \twatchpoint - watchpoint\n\ | |
13270 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13271 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13272 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13273 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13274 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13275 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13276 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13277 | address and file/line number respectively.\n\ |
13278 | \n\ | |
13279 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13280 | are set to the address of the last breakpoint listed unless the command\n\ |
13281 | is prefixed with \"server \".\n\n\ | |
c906108c | 13282 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13283 | breakpoint set."), |
c906108c SS |
13284 | &maintenanceinfolist); |
13285 | ||
44feb3ce TT |
13286 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13287 | Set catchpoints to catch events."), | |
13288 | &catch_cmdlist, "catch ", | |
13289 | 0/*allow-unknown*/, &cmdlist); | |
13290 | ||
13291 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13292 | Set temporary catchpoints to catch events."), | |
13293 | &tcatch_cmdlist, "tcatch ", | |
13294 | 0/*allow-unknown*/, &cmdlist); | |
13295 | ||
13296 | /* Add catch and tcatch sub-commands. */ | |
13297 | add_catch_command ("catch", _("\ | |
13298 | Catch an exception, when caught.\n\ | |
13299 | With an argument, catch only exceptions with the given name."), | |
13300 | catch_catch_command, | |
a96d9b2e | 13301 | NULL, |
44feb3ce TT |
13302 | CATCH_PERMANENT, |
13303 | CATCH_TEMPORARY); | |
13304 | add_catch_command ("throw", _("\ | |
13305 | Catch an exception, when thrown.\n\ | |
13306 | With an argument, catch only exceptions with the given name."), | |
13307 | catch_throw_command, | |
a96d9b2e | 13308 | NULL, |
44feb3ce TT |
13309 | CATCH_PERMANENT, |
13310 | CATCH_TEMPORARY); | |
13311 | add_catch_command ("fork", _("Catch calls to fork."), | |
13312 | catch_fork_command_1, | |
a96d9b2e | 13313 | NULL, |
44feb3ce TT |
13314 | (void *) (uintptr_t) catch_fork_permanent, |
13315 | (void *) (uintptr_t) catch_fork_temporary); | |
13316 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13317 | catch_fork_command_1, | |
a96d9b2e | 13318 | NULL, |
44feb3ce TT |
13319 | (void *) (uintptr_t) catch_vfork_permanent, |
13320 | (void *) (uintptr_t) catch_vfork_temporary); | |
13321 | add_catch_command ("exec", _("Catch calls to exec."), | |
13322 | catch_exec_command_1, | |
a96d9b2e SDJ |
13323 | NULL, |
13324 | CATCH_PERMANENT, | |
13325 | CATCH_TEMPORARY); | |
13326 | add_catch_command ("syscall", _("\ | |
13327 | Catch system calls by their names and/or numbers.\n\ | |
13328 | Arguments say which system calls to catch. If no arguments\n\ | |
13329 | are given, every system call will be caught.\n\ | |
13330 | Arguments, if given, should be one or more system call names\n\ | |
13331 | (if your system supports that), or system call numbers."), | |
13332 | catch_syscall_command_1, | |
13333 | catch_syscall_completer, | |
44feb3ce TT |
13334 | CATCH_PERMANENT, |
13335 | CATCH_TEMPORARY); | |
44feb3ce TT |
13336 | add_catch_command ("exception", _("\ |
13337 | Catch Ada exceptions, when raised.\n\ | |
13338 | With an argument, catch only exceptions with the given name."), | |
13339 | catch_ada_exception_command, | |
a96d9b2e | 13340 | NULL, |
44feb3ce TT |
13341 | CATCH_PERMANENT, |
13342 | CATCH_TEMPORARY); | |
13343 | add_catch_command ("assert", _("\ | |
13344 | Catch failed Ada assertions, when raised.\n\ | |
13345 | With an argument, catch only exceptions with the given name."), | |
13346 | catch_assert_command, | |
a96d9b2e | 13347 | NULL, |
44feb3ce TT |
13348 | CATCH_PERMANENT, |
13349 | CATCH_TEMPORARY); | |
c5aa993b | 13350 | |
1bedd215 AC |
13351 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13352 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13353 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13354 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13355 | an expression changes.\n\ |
13356 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13357 | the memory to which it refers.")); | |
65d12d83 | 13358 | set_cmd_completer (c, expression_completer); |
c906108c | 13359 | |
1bedd215 AC |
13360 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13361 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13362 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13363 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13364 | an expression is read.\n\ |
13365 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13366 | the memory to which it refers.")); | |
65d12d83 | 13367 | set_cmd_completer (c, expression_completer); |
c906108c | 13368 | |
1bedd215 AC |
13369 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13370 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13371 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13372 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13373 | an expression is either read or written.\n\ |
13374 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13375 | the memory to which it refers.")); | |
65d12d83 | 13376 | set_cmd_completer (c, expression_completer); |
c906108c | 13377 | |
d77f58be | 13378 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13379 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 13380 | |
920d2a44 AC |
13381 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
13382 | respond to changes - contrary to the description. */ | |
85c07804 AC |
13383 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
13384 | &can_use_hw_watchpoints, _("\ | |
13385 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
13386 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
13387 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
13388 | such is available. (However, any hardware watchpoints that were\n\ | |
13389 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
13390 | hardware.)"), |
13391 | NULL, | |
920d2a44 | 13392 | show_can_use_hw_watchpoints, |
85c07804 | 13393 | &setlist, &showlist); |
c906108c SS |
13394 | |
13395 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 13396 | |
1042e4c0 SS |
13397 | /* Tracepoint manipulation commands. */ |
13398 | ||
13399 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
13400 | Set a tracepoint at specified line or function.\n\ | |
13401 | \n" | |
13402 | BREAK_ARGS_HELP ("trace") "\n\ | |
13403 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13404 | set_cmd_completer (c, location_completer); | |
13405 | ||
13406 | add_com_alias ("tp", "trace", class_alias, 0); | |
13407 | add_com_alias ("tr", "trace", class_alias, 1); | |
13408 | add_com_alias ("tra", "trace", class_alias, 1); | |
13409 | add_com_alias ("trac", "trace", class_alias, 1); | |
13410 | ||
7a697b8d SS |
13411 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
13412 | Set a fast tracepoint at specified line or function.\n\ | |
13413 | \n" | |
13414 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
13415 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13416 | set_cmd_completer (c, location_completer); | |
13417 | ||
0fb4aa4b PA |
13418 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
13419 | Set a static tracepoint at specified line, function or marker.\n\ | |
13420 | \n\ | |
13421 | strace [LOCATION] [if CONDITION]\n\ | |
13422 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
13423 | or -m MARKER_ID.\n\ | |
13424 | If a line number is specified, probe the marker at start of code\n\ | |
13425 | for that line. If a function is specified, probe the marker at start\n\ | |
13426 | of code for that function. If an address is specified, probe the marker\n\ | |
13427 | at that exact address. If a marker id is specified, probe the marker\n\ | |
13428 | with that name. With no LOCATION, uses current execution address of\n\ | |
13429 | the selected stack frame.\n\ | |
13430 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
13431 | This collects arbitrary user data passed in the probe point call to the\n\ | |
13432 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
13433 | by printing the $_sdata variable like any other convenience variable.\n\ | |
13434 | \n\ | |
13435 | CONDITION is a boolean expression.\n\ | |
13436 | \n\ | |
d41c0fc8 PA |
13437 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
13438 | conditions are different.\n\ | |
0fb4aa4b PA |
13439 | \n\ |
13440 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
13441 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13442 | set_cmd_completer (c, location_completer); | |
13443 | ||
1042e4c0 | 13444 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 13445 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
13446 | Convenience variable \"$tpnum\" contains the number of the\n\ |
13447 | last tracepoint set.")); | |
13448 | ||
13449 | add_info_alias ("tp", "tracepoints", 1); | |
13450 | ||
13451 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
13452 | Delete specified tracepoints.\n\ | |
13453 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13454 | No argument means delete all tracepoints."), | |
13455 | &deletelist); | |
13456 | ||
13457 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
13458 | Disable specified tracepoints.\n\ | |
13459 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13460 | No argument means disable all tracepoints."), | |
13461 | &disablelist); | |
13462 | deprecate_cmd (c, "disable"); | |
13463 | ||
13464 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
13465 | Enable specified tracepoints.\n\ | |
13466 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13467 | No argument means enable all tracepoints."), | |
13468 | &enablelist); | |
13469 | deprecate_cmd (c, "enable"); | |
13470 | ||
13471 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
13472 | Set the passcount for a tracepoint.\n\ | |
13473 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
13474 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
13475 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
13476 | ||
6149aea9 PA |
13477 | add_prefix_cmd ("save", class_breakpoint, save_command, |
13478 | _("Save breakpoint definitions as a script."), | |
13479 | &save_cmdlist, "save ", | |
13480 | 0/*allow-unknown*/, &cmdlist); | |
13481 | ||
13482 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
13483 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 13484 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
13485 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
13486 | session to restore them."), | |
13487 | &save_cmdlist); | |
13488 | set_cmd_completer (c, filename_completer); | |
13489 | ||
13490 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 13491 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
13492 | Use the 'source' command in another debug session to restore them."), |
13493 | &save_cmdlist); | |
1042e4c0 SS |
13494 | set_cmd_completer (c, filename_completer); |
13495 | ||
6149aea9 PA |
13496 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
13497 | deprecate_cmd (c, "save tracepoints"); | |
13498 | ||
1bedd215 | 13499 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13500 | Breakpoint specific settings\n\ |
13501 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13502 | pending breakpoint behavior"), |
fa8d40ab JJ |
13503 | &breakpoint_set_cmdlist, "set breakpoint ", |
13504 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 13505 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13506 | Breakpoint specific settings\n\ |
13507 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13508 | pending breakpoint behavior"), |
fa8d40ab JJ |
13509 | &breakpoint_show_cmdlist, "show breakpoint ", |
13510 | 0/*allow-unknown*/, &showlist); | |
13511 | ||
7915a72c AC |
13512 | add_setshow_auto_boolean_cmd ("pending", no_class, |
13513 | &pending_break_support, _("\ | |
13514 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
13515 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
13516 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
13517 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
13518 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 13519 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 13520 | NULL, |
920d2a44 | 13521 | show_pending_break_support, |
6e1d7d6c AC |
13522 | &breakpoint_set_cmdlist, |
13523 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
13524 | |
13525 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
13526 | |
13527 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
13528 | &automatic_hardware_breakpoints, _("\ | |
13529 | Set automatic usage of hardware breakpoints."), _("\ | |
13530 | Show automatic usage of hardware breakpoints."), _("\ | |
13531 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
13532 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
13533 | a warning will be emitted for such breakpoints."), | |
13534 | NULL, | |
13535 | show_automatic_hardware_breakpoints, | |
13536 | &breakpoint_set_cmdlist, | |
13537 | &breakpoint_show_cmdlist); | |
74960c60 | 13538 | |
33e5cbd6 PA |
13539 | add_setshow_enum_cmd ("always-inserted", class_support, |
13540 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
13541 | Set mode for inserting breakpoints."), _("\ |
13542 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
13543 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
13544 | resumed, and removed when execution stops. When this mode is on,\n\ | |
13545 | breakpoints are inserted immediately and removed only when the user\n\ | |
13546 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
13547 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
13548 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
13549 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
13550 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
13551 | NULL, |
13552 | &show_always_inserted_mode, | |
13553 | &breakpoint_set_cmdlist, | |
13554 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
13555 | |
13556 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
13557 | Set a breakpoint for an address range.\n\ | |
13558 | break-range START-LOCATION, END-LOCATION\n\ | |
13559 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
13560 | LINENUM, for that line in the current file,\n\ | |
13561 | FILE:LINENUM, for that line in that file,\n\ | |
13562 | +OFFSET, for that number of lines after the current line\n\ | |
13563 | or the start of the range\n\ | |
13564 | FUNCTION, for the first line in that function,\n\ | |
13565 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
13566 | *ADDRESS, for the instruction at that address.\n\ | |
13567 | \n\ | |
13568 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
13569 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
13570 | range (including START-LOCATION and END-LOCATION).")); | |
13571 | ||
765dc015 | 13572 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
13573 | |
13574 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 13575 | } |