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" | |
42 | #include "annotate.h" | |
43 | #include "symfile.h" | |
44 | #include "objfiles.h" | |
0378c332 | 45 | #include "source.h" |
c5f0f3d0 | 46 | #include "linespec.h" |
c94fdfd0 | 47 | #include "completer.h" |
5b7f31a4 | 48 | #include "gdb.h" |
8b93c638 | 49 | #include "ui-out.h" |
e1507482 | 50 | #include "cli/cli-script.h" |
0225421b | 51 | #include "gdb_assert.h" |
fe898f56 | 52 | #include "block.h" |
a77053c2 | 53 | #include "solib.h" |
84acb35a JJ |
54 | #include "solist.h" |
55 | #include "observer.h" | |
60250e8b | 56 | #include "exceptions.h" |
765dc015 | 57 | #include "memattr.h" |
f7f9143b | 58 | #include "ada-lang.h" |
d1aa2f50 | 59 | #include "top.h" |
fa4727a6 | 60 | #include "wrapper.h" |
79a45b7d | 61 | #include "valprint.h" |
4efc6507 | 62 | #include "jit.h" |
a96d9b2e | 63 | #include "xml-syscall.h" |
65d79d4b | 64 | #include "parser-defs.h" |
e9cafbcc | 65 | #include "cli/cli-utils.h" |
c906108c | 66 | |
1042e4c0 SS |
67 | /* readline include files */ |
68 | #include "readline/readline.h" | |
69 | #include "readline/history.h" | |
70 | ||
71 | /* readline defines this. */ | |
72 | #undef savestring | |
73 | ||
034dad6f | 74 | #include "mi/mi-common.h" |
7371cf6d | 75 | #include "python/python.h" |
104c1213 | 76 | |
44feb3ce TT |
77 | /* Arguments to pass as context to some catch command handlers. */ |
78 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
79 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 80 | |
4a64f543 | 81 | /* Prototypes for local functions. */ |
c906108c | 82 | |
a14ed312 | 83 | static void enable_delete_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void enable_once_command (char *, int); |
c906108c | 86 | |
a14ed312 | 87 | static void disable_command (char *, int); |
c906108c | 88 | |
a14ed312 | 89 | static void enable_command (char *, int); |
c906108c | 90 | |
95a42b64 TT |
91 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
92 | void *), | |
93 | void *); | |
c906108c | 94 | |
a14ed312 | 95 | static void ignore_command (char *, int); |
c906108c | 96 | |
4efb68b1 | 97 | static int breakpoint_re_set_one (void *); |
c906108c | 98 | |
a14ed312 | 99 | static void clear_command (char *, int); |
c906108c | 100 | |
a14ed312 | 101 | static void catch_command (char *, int); |
c906108c | 102 | |
e09342b5 | 103 | static int can_use_hardware_watchpoint (struct value *, int); |
c906108c | 104 | |
98deb0da | 105 | static void break_command_1 (char *, int, int); |
c906108c | 106 | |
a14ed312 | 107 | static void mention (struct breakpoint *); |
c906108c | 108 | |
4a64f543 MS |
109 | /* This function is used in gdbtk sources and thus can not be made |
110 | static. */ | |
63c252f8 | 111 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
a6d9a66e UW |
112 | struct symtab_and_line, |
113 | enum bptype); | |
c906108c | 114 | |
76897487 KB |
115 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
116 | ||
a6d9a66e UW |
117 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
118 | CORE_ADDR bpaddr, | |
88f7da05 | 119 | enum bptype bptype); |
76897487 | 120 | |
6c95b8df PA |
121 | static void describe_other_breakpoints (struct gdbarch *, |
122 | struct program_space *, CORE_ADDR, | |
5af949e3 | 123 | struct obj_section *, int); |
c906108c | 124 | |
6c95b8df PA |
125 | static int breakpoint_address_match (struct address_space *aspace1, |
126 | CORE_ADDR addr1, | |
127 | struct address_space *aspace2, | |
128 | CORE_ADDR addr2); | |
129 | ||
85d721b8 PA |
130 | static int watchpoint_locations_match (struct bp_location *loc1, |
131 | struct bp_location *loc2); | |
132 | ||
a14ed312 | 133 | static void breakpoints_info (char *, int); |
c906108c | 134 | |
d77f58be SS |
135 | static void watchpoints_info (char *, int); |
136 | ||
e5a67952 MS |
137 | static int breakpoint_1 (char *, int, |
138 | int (*) (const struct breakpoint *)); | |
c906108c | 139 | |
4efb68b1 | 140 | static int breakpoint_cond_eval (void *); |
c906108c | 141 | |
4efb68b1 | 142 | static void cleanup_executing_breakpoints (void *); |
c906108c | 143 | |
a14ed312 | 144 | static void commands_command (char *, int); |
c906108c | 145 | |
a14ed312 | 146 | static void condition_command (char *, int); |
c906108c | 147 | |
c5aa993b JM |
148 | typedef enum |
149 | { | |
150 | mark_inserted, | |
151 | mark_uninserted | |
152 | } | |
153 | insertion_state_t; | |
c906108c | 154 | |
0bde7532 | 155 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 156 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 157 | |
a14ed312 | 158 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
159 | |
160 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 161 | |
4efb68b1 | 162 | static int watchpoint_check (void *); |
c906108c | 163 | |
a14ed312 | 164 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 165 | |
a14ed312 | 166 | static int hw_breakpoint_used_count (void); |
c906108c | 167 | |
a14ed312 | 168 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 169 | |
a14ed312 | 170 | static void hbreak_command (char *, int); |
c906108c | 171 | |
a14ed312 | 172 | static void thbreak_command (char *, int); |
c906108c | 173 | |
a14ed312 | 174 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 175 | |
a14ed312 | 176 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 177 | |
a14ed312 | 178 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 179 | |
a14ed312 | 180 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 181 | |
a14ed312 | 182 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 183 | |
d85310f7 MS |
184 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
185 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 186 | |
a14ed312 | 187 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 188 | |
d03285ec UW |
189 | static void detach_single_step_breakpoints (void); |
190 | ||
6c95b8df PA |
191 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
192 | CORE_ADDR pc); | |
1aafd4da | 193 | |
fe3f5fa8 | 194 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
195 | static void incref_bp_location (struct bp_location *loc); |
196 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 197 | |
39d61571 | 198 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 199 | |
b60e7edf | 200 | static void update_global_location_list (int); |
a5606eee | 201 | |
b60e7edf | 202 | static void update_global_location_list_nothrow (int); |
74960c60 | 203 | |
d77f58be | 204 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 | 205 | |
d77f58be | 206 | static int is_watchpoint (const struct breakpoint *bpt); |
60e1c644 | 207 | |
74960c60 | 208 | static void insert_breakpoint_locations (void); |
a5606eee | 209 | |
a96d9b2e SDJ |
210 | static int syscall_catchpoint_p (struct breakpoint *b); |
211 | ||
1042e4c0 SS |
212 | static void tracepoints_info (char *, int); |
213 | ||
214 | static void delete_trace_command (char *, int); | |
215 | ||
216 | static void enable_trace_command (char *, int); | |
217 | ||
218 | static void disable_trace_command (char *, int); | |
219 | ||
220 | static void trace_pass_command (char *, int); | |
221 | ||
0fb4aa4b PA |
222 | /* Assuming we're creating a static tracepoint, does S look like a |
223 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
224 | #define is_marker_spec(s) \ | |
f5a8e22b | 225 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 226 | |
5cea2a26 PA |
227 | /* A reference-counted struct command_line. This lets multiple |
228 | breakpoints share a single command list. */ | |
229 | struct counted_command_line | |
230 | { | |
231 | /* The reference count. */ | |
232 | int refc; | |
233 | ||
234 | /* The command list. */ | |
235 | struct command_line *commands; | |
236 | }; | |
237 | ||
238 | struct command_line * | |
239 | breakpoint_commands (struct breakpoint *b) | |
240 | { | |
241 | return b->commands ? b->commands->commands : NULL; | |
242 | } | |
3daf8fe5 | 243 | |
f3b1572e PA |
244 | /* Flag indicating that a command has proceeded the inferior past the |
245 | current breakpoint. */ | |
246 | ||
247 | static int breakpoint_proceeded; | |
248 | ||
2cec12e5 AR |
249 | static const char * |
250 | bpdisp_text (enum bpdisp disp) | |
251 | { | |
4a64f543 MS |
252 | /* NOTE: the following values are a part of MI protocol and |
253 | represent values of 'disp' field returned when inferior stops at | |
254 | a breakpoint. */ | |
bc043ef3 | 255 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 256 | |
2cec12e5 AR |
257 | return bpdisps[(int) disp]; |
258 | } | |
c906108c | 259 | |
4a64f543 | 260 | /* Prototypes for exported functions. */ |
c906108c | 261 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 262 | if such is available. */ |
c906108c SS |
263 | static int can_use_hw_watchpoints; |
264 | ||
920d2a44 AC |
265 | static void |
266 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
267 | struct cmd_list_element *c, | |
268 | const char *value) | |
269 | { | |
3e43a32a MS |
270 | fprintf_filtered (file, |
271 | _("Debugger's willingness to use " | |
272 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
273 | value); |
274 | } | |
275 | ||
fa8d40ab JJ |
276 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
277 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 278 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
279 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
280 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
281 | static void |
282 | show_pending_break_support (struct ui_file *file, int from_tty, | |
283 | struct cmd_list_element *c, | |
284 | const char *value) | |
285 | { | |
3e43a32a MS |
286 | fprintf_filtered (file, |
287 | _("Debugger's behavior regarding " | |
288 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
289 | value); |
290 | } | |
fa8d40ab | 291 | |
765dc015 | 292 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 293 | set with "break" but falling in read-only memory. |
765dc015 VP |
294 | If 0, gdb will warn about such breakpoints, but won't automatically |
295 | use hardware breakpoints. */ | |
296 | static int automatic_hardware_breakpoints; | |
297 | static void | |
298 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
299 | struct cmd_list_element *c, | |
300 | const char *value) | |
301 | { | |
3e43a32a MS |
302 | fprintf_filtered (file, |
303 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
304 | value); |
305 | } | |
306 | ||
33e5cbd6 PA |
307 | /* If on, gdb will keep breakpoints inserted even as inferior is |
308 | stopped, and immediately insert any new breakpoints. If off, gdb | |
309 | will insert breakpoints into inferior only when resuming it, and | |
310 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
311 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
312 | ||
313 | static const char always_inserted_auto[] = "auto"; | |
314 | static const char always_inserted_on[] = "on"; | |
315 | static const char always_inserted_off[] = "off"; | |
316 | static const char *always_inserted_enums[] = { | |
317 | always_inserted_auto, | |
318 | always_inserted_off, | |
319 | always_inserted_on, | |
320 | NULL | |
321 | }; | |
322 | static const char *always_inserted_mode = always_inserted_auto; | |
323 | static void | |
74960c60 | 324 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 325 | struct cmd_list_element *c, const char *value) |
74960c60 | 326 | { |
33e5cbd6 | 327 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
328 | fprintf_filtered (file, |
329 | _("Always inserted breakpoint " | |
330 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
331 | value, |
332 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
333 | else | |
3e43a32a MS |
334 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
335 | value); | |
74960c60 VP |
336 | } |
337 | ||
33e5cbd6 PA |
338 | int |
339 | breakpoints_always_inserted_mode (void) | |
340 | { | |
341 | return (always_inserted_mode == always_inserted_on | |
342 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
343 | } | |
765dc015 | 344 | |
a14ed312 | 345 | void _initialize_breakpoint (void); |
c906108c | 346 | |
c906108c SS |
347 | /* Are we executing breakpoint commands? */ |
348 | static int executing_breakpoint_commands; | |
349 | ||
c02f5703 MS |
350 | /* Are overlay event breakpoints enabled? */ |
351 | static int overlay_events_enabled; | |
352 | ||
e09342b5 TJB |
353 | /* See description in breakpoint.h. */ |
354 | int target_exact_watchpoints = 0; | |
355 | ||
c906108c | 356 | /* Walk the following statement or block through all breakpoints. |
4a64f543 MS |
357 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the |
358 | current breakpoint. */ | |
c906108c | 359 | |
5c44784c | 360 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 361 | |
5c44784c JM |
362 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
363 | for (B = breakpoint_chain; \ | |
364 | B ? (TMP=B->next, 1): 0; \ | |
365 | B = TMP) | |
c906108c | 366 | |
4a64f543 MS |
367 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
368 | not provided so update_global_location_list must not be called | |
369 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 370 | |
876fa593 JK |
371 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
372 | for (BP_TMP = bp_location; \ | |
373 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
374 | BP_TMP++) | |
7cc221ef | 375 | |
1042e4c0 SS |
376 | /* Iterator for tracepoints only. */ |
377 | ||
378 | #define ALL_TRACEPOINTS(B) \ | |
379 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 380 | if (is_tracepoint (B)) |
1042e4c0 | 381 | |
7cc221ef | 382 | /* Chains of all breakpoints defined. */ |
c906108c SS |
383 | |
384 | struct breakpoint *breakpoint_chain; | |
385 | ||
876fa593 JK |
386 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
387 | ||
388 | static struct bp_location **bp_location; | |
389 | ||
390 | /* Number of elements of BP_LOCATION. */ | |
391 | ||
392 | static unsigned bp_location_count; | |
393 | ||
4a64f543 MS |
394 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
395 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
396 | result from bp_location_has_shadow. You can use it for roughly | |
397 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
398 | an address you need to read. */ | |
876fa593 JK |
399 | |
400 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
401 | ||
4a64f543 MS |
402 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
403 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
404 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
405 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
406 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
407 | |
408 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 409 | |
4a64f543 MS |
410 | /* The locations that no longer correspond to any breakpoint, unlinked |
411 | from bp_location array, but for which a hit may still be reported | |
412 | by a target. */ | |
20874c92 VP |
413 | VEC(bp_location_p) *moribund_locations = NULL; |
414 | ||
c906108c SS |
415 | /* Number of last breakpoint made. */ |
416 | ||
95a42b64 TT |
417 | static int breakpoint_count; |
418 | ||
86b17b60 PA |
419 | /* The value of `breakpoint_count' before the last command that |
420 | created breakpoints. If the last (break-like) command created more | |
421 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
422 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
423 | static int prev_breakpoint_count; | |
c906108c | 424 | |
1042e4c0 SS |
425 | /* Number of last tracepoint made. */ |
426 | ||
95a42b64 | 427 | static int tracepoint_count; |
1042e4c0 | 428 | |
6149aea9 PA |
429 | static struct cmd_list_element *breakpoint_set_cmdlist; |
430 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 431 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 432 | |
468d015d JJ |
433 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
434 | static int | |
435 | breakpoint_enabled (struct breakpoint *b) | |
436 | { | |
0d381245 | 437 | return (b->enable_state == bp_enabled); |
468d015d JJ |
438 | } |
439 | ||
c906108c SS |
440 | /* Set breakpoint count to NUM. */ |
441 | ||
95a42b64 | 442 | static void |
fba45db2 | 443 | set_breakpoint_count (int num) |
c906108c | 444 | { |
86b17b60 | 445 | prev_breakpoint_count = breakpoint_count; |
c906108c | 446 | breakpoint_count = num; |
4fa62494 | 447 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
448 | } |
449 | ||
86b17b60 PA |
450 | /* Used by `start_rbreak_breakpoints' below, to record the current |
451 | breakpoint count before "rbreak" creates any breakpoint. */ | |
452 | static int rbreak_start_breakpoint_count; | |
453 | ||
95a42b64 TT |
454 | /* Called at the start an "rbreak" command to record the first |
455 | breakpoint made. */ | |
86b17b60 | 456 | |
95a42b64 TT |
457 | void |
458 | start_rbreak_breakpoints (void) | |
459 | { | |
86b17b60 | 460 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
461 | } |
462 | ||
463 | /* Called at the end of an "rbreak" command to record the last | |
464 | breakpoint made. */ | |
86b17b60 | 465 | |
95a42b64 TT |
466 | void |
467 | end_rbreak_breakpoints (void) | |
468 | { | |
86b17b60 | 469 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
470 | } |
471 | ||
4a64f543 | 472 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
473 | |
474 | void | |
fba45db2 | 475 | clear_breakpoint_hit_counts (void) |
c906108c SS |
476 | { |
477 | struct breakpoint *b; | |
478 | ||
479 | ALL_BREAKPOINTS (b) | |
480 | b->hit_count = 0; | |
481 | } | |
482 | ||
9add0f1b TT |
483 | /* Allocate a new counted_command_line with reference count of 1. |
484 | The new structure owns COMMANDS. */ | |
485 | ||
486 | static struct counted_command_line * | |
487 | alloc_counted_command_line (struct command_line *commands) | |
488 | { | |
489 | struct counted_command_line *result | |
490 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 491 | |
9add0f1b TT |
492 | result->refc = 1; |
493 | result->commands = commands; | |
494 | return result; | |
495 | } | |
496 | ||
497 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
498 | ||
499 | static void | |
500 | incref_counted_command_line (struct counted_command_line *cmd) | |
501 | { | |
502 | if (cmd) | |
503 | ++cmd->refc; | |
504 | } | |
505 | ||
506 | /* Decrement reference count. If the reference count reaches 0, | |
507 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
508 | nothing if *CMDP is NULL. */ | |
509 | ||
510 | static void | |
511 | decref_counted_command_line (struct counted_command_line **cmdp) | |
512 | { | |
513 | if (*cmdp) | |
514 | { | |
515 | if (--(*cmdp)->refc == 0) | |
516 | { | |
517 | free_command_lines (&(*cmdp)->commands); | |
518 | xfree (*cmdp); | |
519 | } | |
520 | *cmdp = NULL; | |
521 | } | |
522 | } | |
523 | ||
524 | /* A cleanup function that calls decref_counted_command_line. */ | |
525 | ||
526 | static void | |
527 | do_cleanup_counted_command_line (void *arg) | |
528 | { | |
529 | decref_counted_command_line (arg); | |
530 | } | |
531 | ||
532 | /* Create a cleanup that calls decref_counted_command_line on the | |
533 | argument. */ | |
534 | ||
535 | static struct cleanup * | |
536 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
537 | { | |
538 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
539 | } | |
540 | ||
c906108c SS |
541 | /* Default address, symtab and line to put a breakpoint at |
542 | for "break" command with no arg. | |
4a64f543 | 543 | If default_breakpoint_valid is zero, the other three are |
c906108c SS |
544 | not valid, and "break" with no arg is an error. |
545 | ||
546 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
547 | ||
548 | int default_breakpoint_valid; | |
549 | CORE_ADDR default_breakpoint_address; | |
550 | struct symtab *default_breakpoint_symtab; | |
551 | int default_breakpoint_line; | |
6c95b8df PA |
552 | struct program_space *default_breakpoint_pspace; |
553 | ||
c906108c | 554 | \f |
48cb2d85 VP |
555 | /* Return the breakpoint with the specified number, or NULL |
556 | if the number does not refer to an existing breakpoint. */ | |
557 | ||
558 | struct breakpoint * | |
559 | get_breakpoint (int num) | |
560 | { | |
561 | struct breakpoint *b; | |
562 | ||
563 | ALL_BREAKPOINTS (b) | |
564 | if (b->number == num) | |
565 | return b; | |
566 | ||
567 | return NULL; | |
568 | } | |
5c44784c | 569 | |
c906108c | 570 | \f |
adc36818 PM |
571 | |
572 | void | |
573 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
574 | int from_tty) | |
575 | { | |
576 | struct bp_location *loc = b->loc; | |
577 | ||
578 | for (; loc; loc = loc->next) | |
579 | { | |
580 | xfree (loc->cond); | |
581 | loc->cond = NULL; | |
582 | } | |
583 | xfree (b->cond_string); | |
584 | b->cond_string = NULL; | |
585 | xfree (b->cond_exp); | |
586 | b->cond_exp = NULL; | |
587 | ||
588 | if (*exp == 0) | |
589 | { | |
590 | if (from_tty) | |
591 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
592 | } | |
593 | else | |
594 | { | |
595 | char *arg = exp; | |
cc59ec59 | 596 | |
adc36818 PM |
597 | /* I don't know if it matters whether this is the string the user |
598 | typed in or the decompiled expression. */ | |
599 | b->cond_string = xstrdup (arg); | |
600 | b->condition_not_parsed = 0; | |
601 | ||
602 | if (is_watchpoint (b)) | |
603 | { | |
604 | innermost_block = NULL; | |
605 | arg = exp; | |
606 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
607 | if (*arg) | |
608 | error (_("Junk at end of expression")); | |
609 | b->cond_exp_valid_block = innermost_block; | |
610 | } | |
611 | else | |
612 | { | |
613 | for (loc = b->loc; loc; loc = loc->next) | |
614 | { | |
615 | arg = exp; | |
616 | loc->cond = | |
617 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
618 | if (*arg) | |
619 | error (_("Junk at end of expression")); | |
620 | } | |
621 | } | |
622 | } | |
623 | breakpoints_changed (); | |
624 | observer_notify_breakpoint_modified (b->number); | |
625 | } | |
626 | ||
c906108c SS |
627 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
628 | ||
629 | static void | |
fba45db2 | 630 | condition_command (char *arg, int from_tty) |
c906108c | 631 | { |
52f0bd74 | 632 | struct breakpoint *b; |
c906108c | 633 | char *p; |
52f0bd74 | 634 | int bnum; |
c906108c SS |
635 | |
636 | if (arg == 0) | |
e2e0b3e5 | 637 | error_no_arg (_("breakpoint number")); |
c906108c SS |
638 | |
639 | p = arg; | |
640 | bnum = get_number (&p); | |
5c44784c | 641 | if (bnum == 0) |
8a3fe4f8 | 642 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
643 | |
644 | ALL_BREAKPOINTS (b) | |
645 | if (b->number == bnum) | |
2f069f6f | 646 | { |
7371cf6d PM |
647 | /* Check if this breakpoint has a Python object assigned to |
648 | it, and if it has a definition of the "stop" | |
649 | method. This method and conditions entered into GDB from | |
650 | the CLI are mutually exclusive. */ | |
651 | if (b->py_bp_object | |
652 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
653 | error (_("Cannot set a condition where a Python 'stop' " | |
654 | "method has been defined in the breakpoint.")); | |
2566ad2d | 655 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
656 | return; |
657 | } | |
c906108c | 658 | |
8a3fe4f8 | 659 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
660 | } |
661 | ||
a7bdde9e VP |
662 | /* Check that COMMAND do not contain commands that are suitable |
663 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
664 | Throw if any such commands is found. */ |
665 | ||
a7bdde9e VP |
666 | static void |
667 | check_no_tracepoint_commands (struct command_line *commands) | |
668 | { | |
669 | struct command_line *c; | |
cc59ec59 | 670 | |
a7bdde9e VP |
671 | for (c = commands; c; c = c->next) |
672 | { | |
673 | int i; | |
674 | ||
675 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
676 | error (_("The 'while-stepping' command can " |
677 | "only be used for tracepoints")); | |
a7bdde9e VP |
678 | |
679 | for (i = 0; i < c->body_count; ++i) | |
680 | check_no_tracepoint_commands ((c->body_list)[i]); | |
681 | ||
682 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 683 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
684 | command directly. */ |
685 | if (strstr (c->line, "collect ") == c->line) | |
686 | error (_("The 'collect' command can only be used for tracepoints")); | |
687 | ||
51661e93 VP |
688 | if (strstr (c->line, "teval ") == c->line) |
689 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
690 | } |
691 | } | |
692 | ||
d77f58be SS |
693 | /* Encapsulate tests for different types of tracepoints. */ |
694 | ||
a7bdde9e | 695 | int |
d77f58be | 696 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 697 | { |
0fb4aa4b PA |
698 | return (b->type == bp_tracepoint |
699 | || b->type == bp_fast_tracepoint | |
700 | || b->type == bp_static_tracepoint); | |
a7bdde9e | 701 | } |
d77f58be | 702 | |
95a42b64 TT |
703 | /* A helper function that validsates that COMMANDS are valid for a |
704 | breakpoint. This function will throw an exception if a problem is | |
705 | found. */ | |
48cb2d85 | 706 | |
95a42b64 TT |
707 | static void |
708 | validate_commands_for_breakpoint (struct breakpoint *b, | |
709 | struct command_line *commands) | |
48cb2d85 | 710 | { |
d77f58be | 711 | if (is_tracepoint (b)) |
a7bdde9e | 712 | { |
4a64f543 MS |
713 | /* We need to verify that each top-level element of commands is |
714 | valid for tracepoints, that there's at most one | |
715 | while-stepping element, and that while-stepping's body has | |
716 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
717 | struct command_line *c; |
718 | struct command_line *while_stepping = 0; | |
719 | for (c = commands; c; c = c->next) | |
720 | { | |
a7bdde9e VP |
721 | if (c->control_type == while_stepping_control) |
722 | { | |
723 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
724 | error (_("The 'while-stepping' command " |
725 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 726 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
727 | error (_("The 'while-stepping' command " |
728 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
729 | |
730 | if (while_stepping) | |
3e43a32a MS |
731 | error (_("The 'while-stepping' command " |
732 | "can be used only once")); | |
a7bdde9e VP |
733 | else |
734 | while_stepping = c; | |
735 | } | |
736 | } | |
737 | if (while_stepping) | |
738 | { | |
739 | struct command_line *c2; | |
740 | ||
741 | gdb_assert (while_stepping->body_count == 1); | |
742 | c2 = while_stepping->body_list[0]; | |
743 | for (; c2; c2 = c2->next) | |
744 | { | |
a7bdde9e VP |
745 | if (c2->control_type == while_stepping_control) |
746 | error (_("The 'while-stepping' command cannot be nested")); | |
747 | } | |
748 | } | |
749 | } | |
750 | else | |
751 | { | |
752 | check_no_tracepoint_commands (commands); | |
753 | } | |
95a42b64 TT |
754 | } |
755 | ||
0fb4aa4b PA |
756 | /* Return a vector of all the static tracepoints set at ADDR. The |
757 | caller is responsible for releasing the vector. */ | |
758 | ||
759 | VEC(breakpoint_p) * | |
760 | static_tracepoints_here (CORE_ADDR addr) | |
761 | { | |
762 | struct breakpoint *b; | |
763 | VEC(breakpoint_p) *found = 0; | |
764 | struct bp_location *loc; | |
765 | ||
766 | ALL_BREAKPOINTS (b) | |
767 | if (b->type == bp_static_tracepoint) | |
768 | { | |
769 | for (loc = b->loc; loc; loc = loc->next) | |
770 | if (loc->address == addr) | |
771 | VEC_safe_push(breakpoint_p, found, b); | |
772 | } | |
773 | ||
774 | return found; | |
775 | } | |
776 | ||
95a42b64 | 777 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 778 | validate that only allowed commands are included. */ |
95a42b64 TT |
779 | |
780 | void | |
4a64f543 MS |
781 | breakpoint_set_commands (struct breakpoint *b, |
782 | struct command_line *commands) | |
95a42b64 TT |
783 | { |
784 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 785 | |
9add0f1b TT |
786 | decref_counted_command_line (&b->commands); |
787 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
788 | breakpoints_changed (); |
789 | observer_notify_breakpoint_modified (b->number); | |
790 | } | |
791 | ||
45a43567 TT |
792 | /* Set the internal `silent' flag on the breakpoint. Note that this |
793 | is not the same as the "silent" that may appear in the breakpoint's | |
794 | commands. */ | |
795 | ||
796 | void | |
797 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
798 | { | |
799 | int old_silent = b->silent; | |
800 | ||
801 | b->silent = silent; | |
802 | if (old_silent != silent) | |
803 | observer_notify_breakpoint_modified (b->number); | |
804 | } | |
805 | ||
806 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
807 | breakpoint work for any thread. */ | |
808 | ||
809 | void | |
810 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
811 | { | |
812 | int old_thread = b->thread; | |
813 | ||
814 | b->thread = thread; | |
815 | if (old_thread != thread) | |
816 | observer_notify_breakpoint_modified (b->number); | |
817 | } | |
818 | ||
819 | /* Set the task for this breakpoint. If TASK is 0, make the | |
820 | breakpoint work for any task. */ | |
821 | ||
822 | void | |
823 | breakpoint_set_task (struct breakpoint *b, int task) | |
824 | { | |
825 | int old_task = b->task; | |
826 | ||
827 | b->task = task; | |
828 | if (old_task != task) | |
829 | observer_notify_breakpoint_modified (b->number); | |
830 | } | |
831 | ||
95a42b64 TT |
832 | void |
833 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
834 | { |
835 | struct breakpoint *b = closure; | |
cc59ec59 | 836 | |
a7bdde9e VP |
837 | validate_actionline (&line, b); |
838 | } | |
839 | ||
95a42b64 TT |
840 | /* A structure used to pass information through |
841 | map_breakpoint_numbers. */ | |
842 | ||
843 | struct commands_info | |
844 | { | |
845 | /* True if the command was typed at a tty. */ | |
846 | int from_tty; | |
86b17b60 PA |
847 | |
848 | /* The breakpoint range spec. */ | |
849 | char *arg; | |
850 | ||
95a42b64 TT |
851 | /* Non-NULL if the body of the commands are being read from this |
852 | already-parsed command. */ | |
853 | struct command_line *control; | |
86b17b60 | 854 | |
95a42b64 TT |
855 | /* The command lines read from the user, or NULL if they have not |
856 | yet been read. */ | |
857 | struct counted_command_line *cmd; | |
858 | }; | |
859 | ||
860 | /* A callback for map_breakpoint_numbers that sets the commands for | |
861 | commands_command. */ | |
862 | ||
c906108c | 863 | static void |
95a42b64 | 864 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 865 | { |
95a42b64 | 866 | struct commands_info *info = data; |
c906108c | 867 | |
95a42b64 TT |
868 | if (info->cmd == NULL) |
869 | { | |
870 | struct command_line *l; | |
5c44784c | 871 | |
95a42b64 TT |
872 | if (info->control != NULL) |
873 | l = copy_command_lines (info->control->body_list[0]); | |
874 | else | |
86b17b60 PA |
875 | { |
876 | struct cleanup *old_chain; | |
877 | char *str; | |
c5aa993b | 878 | |
3e43a32a MS |
879 | str = xstrprintf (_("Type commands for breakpoint(s) " |
880 | "%s, one per line."), | |
86b17b60 PA |
881 | info->arg); |
882 | ||
883 | old_chain = make_cleanup (xfree, str); | |
884 | ||
885 | l = read_command_lines (str, | |
886 | info->from_tty, 1, | |
d77f58be | 887 | (is_tracepoint (b) |
86b17b60 PA |
888 | ? check_tracepoint_command : 0), |
889 | b); | |
890 | ||
891 | do_cleanups (old_chain); | |
892 | } | |
a7bdde9e | 893 | |
95a42b64 TT |
894 | info->cmd = alloc_counted_command_line (l); |
895 | } | |
896 | ||
897 | /* If a breakpoint was on the list more than once, we don't need to | |
898 | do anything. */ | |
899 | if (b->commands != info->cmd) | |
900 | { | |
901 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
902 | incref_counted_command_line (info->cmd); | |
903 | decref_counted_command_line (&b->commands); | |
904 | b->commands = info->cmd; | |
905 | breakpoints_changed (); | |
906 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 907 | } |
95a42b64 TT |
908 | } |
909 | ||
910 | static void | |
4a64f543 MS |
911 | commands_command_1 (char *arg, int from_tty, |
912 | struct command_line *control) | |
95a42b64 TT |
913 | { |
914 | struct cleanup *cleanups; | |
915 | struct commands_info info; | |
916 | ||
917 | info.from_tty = from_tty; | |
918 | info.control = control; | |
919 | info.cmd = NULL; | |
920 | /* If we read command lines from the user, then `info' will hold an | |
921 | extra reference to the commands that we must clean up. */ | |
922 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
923 | ||
924 | if (arg == NULL || !*arg) | |
925 | { | |
86b17b60 | 926 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
927 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
928 | breakpoint_count); | |
95a42b64 TT |
929 | else if (breakpoint_count > 0) |
930 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
931 | else |
932 | { | |
933 | /* So that we don't try to free the incoming non-NULL | |
934 | argument in the cleanup below. Mapping breakpoint | |
935 | numbers will fail in this case. */ | |
936 | arg = NULL; | |
937 | } | |
95a42b64 | 938 | } |
9766ced4 SS |
939 | else |
940 | /* The command loop has some static state, so we need to preserve | |
941 | our argument. */ | |
942 | arg = xstrdup (arg); | |
86b17b60 PA |
943 | |
944 | if (arg != NULL) | |
945 | make_cleanup (xfree, arg); | |
946 | ||
947 | info.arg = arg; | |
95a42b64 TT |
948 | |
949 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
950 | ||
951 | if (info.cmd == NULL) | |
952 | error (_("No breakpoints specified.")); | |
953 | ||
954 | do_cleanups (cleanups); | |
955 | } | |
956 | ||
957 | static void | |
958 | commands_command (char *arg, int from_tty) | |
959 | { | |
960 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 961 | } |
40c03ae8 EZ |
962 | |
963 | /* Like commands_command, but instead of reading the commands from | |
964 | input stream, takes them from an already parsed command structure. | |
965 | ||
966 | This is used by cli-script.c to DTRT with breakpoint commands | |
967 | that are part of if and while bodies. */ | |
968 | enum command_control_type | |
969 | commands_from_control_command (char *arg, struct command_line *cmd) | |
970 | { | |
95a42b64 TT |
971 | commands_command_1 (arg, 0, cmd); |
972 | return simple_control; | |
40c03ae8 | 973 | } |
876fa593 JK |
974 | |
975 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
976 | ||
977 | static int | |
978 | bp_location_has_shadow (struct bp_location *bl) | |
979 | { | |
980 | if (bl->loc_type != bp_loc_software_breakpoint) | |
981 | return 0; | |
982 | if (!bl->inserted) | |
983 | return 0; | |
984 | if (bl->target_info.shadow_len == 0) | |
985 | /* bp isn't valid, or doesn't shadow memory. */ | |
986 | return 0; | |
987 | return 1; | |
988 | } | |
989 | ||
8defab1a | 990 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
991 | by replacing any memory breakpoints with their shadowed contents. |
992 | ||
993 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
994 | bl->address - bp_location_placed_address_before_address_max |
995 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
996 | The range we were requested to resolve shadows for is: |
997 | memaddr ... memaddr + len | |
998 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
999 | memaddr + len <= (bl->address |
1000 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1001 | and: |
35df4500 | 1002 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1003 | |
8defab1a DJ |
1004 | void |
1005 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1006 | { |
4a64f543 MS |
1007 | /* Left boundary, right boundary and median element of our binary |
1008 | search. */ | |
876fa593 JK |
1009 | unsigned bc_l, bc_r, bc; |
1010 | ||
4a64f543 MS |
1011 | /* Find BC_L which is a leftmost element which may affect BUF |
1012 | content. It is safe to report lower value but a failure to | |
1013 | report higher one. */ | |
876fa593 JK |
1014 | |
1015 | bc_l = 0; | |
1016 | bc_r = bp_location_count; | |
1017 | while (bc_l + 1 < bc_r) | |
1018 | { | |
35df4500 | 1019 | struct bp_location *bl; |
876fa593 JK |
1020 | |
1021 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1022 | bl = bp_location[bc]; |
876fa593 | 1023 | |
4a64f543 MS |
1024 | /* Check first BL->ADDRESS will not overflow due to the added |
1025 | constant. Then advance the left boundary only if we are sure | |
1026 | the BC element can in no way affect the BUF content (MEMADDR | |
1027 | to MEMADDR + LEN range). | |
876fa593 | 1028 | |
4a64f543 MS |
1029 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1030 | offset so that we cannot miss a breakpoint with its shadow | |
1031 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1032 | |
35df4500 TJB |
1033 | if ((bl->address + bp_location_shadow_len_after_address_max |
1034 | >= bl->address) | |
1035 | && (bl->address + bp_location_shadow_len_after_address_max | |
1036 | <= memaddr)) | |
876fa593 JK |
1037 | bc_l = bc; |
1038 | else | |
1039 | bc_r = bc; | |
1040 | } | |
1041 | ||
128070bb PA |
1042 | /* Due to the binary search above, we need to make sure we pick the |
1043 | first location that's at BC_L's address. E.g., if there are | |
1044 | multiple locations at the same address, BC_L may end up pointing | |
1045 | at a duplicate location, and miss the "master"/"inserted" | |
1046 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1047 | B: | |
1048 | ||
1049 | L1@A, L2@A, L3@B, ... | |
1050 | ||
1051 | BC_L could end up pointing at location L2, while the "master" | |
1052 | location could be L1. Since the `loc->inserted' flag is only set | |
1053 | on "master" locations, we'd forget to restore the shadow of L1 | |
1054 | and L2. */ | |
1055 | while (bc_l > 0 | |
1056 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1057 | bc_l--; | |
1058 | ||
876fa593 JK |
1059 | /* Now do full processing of the found relevant range of elements. */ |
1060 | ||
1061 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1062 | { |
35df4500 | 1063 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1064 | CORE_ADDR bp_addr = 0; |
1065 | int bp_size = 0; | |
1066 | int bptoffset = 0; | |
1067 | ||
35df4500 TJB |
1068 | /* bp_location array has BL->OWNER always non-NULL. */ |
1069 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1070 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1071 | bl->owner->number); |
ffce0d52 | 1072 | |
876fa593 JK |
1073 | /* Performance optimization: any futher element can no longer affect BUF |
1074 | content. */ | |
1075 | ||
35df4500 TJB |
1076 | if (bl->address >= bp_location_placed_address_before_address_max |
1077 | && memaddr + len <= (bl->address | |
1078 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1079 | break; |
1080 | ||
35df4500 | 1081 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1082 | continue; |
35df4500 | 1083 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1084 | current_program_space->aspace, 0)) |
1085 | continue; | |
1086 | ||
c5aa993b JM |
1087 | /* Addresses and length of the part of the breakpoint that |
1088 | we need to copy. */ | |
35df4500 TJB |
1089 | bp_addr = bl->target_info.placed_address; |
1090 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1091 | |
c5aa993b JM |
1092 | if (bp_addr + bp_size <= memaddr) |
1093 | /* The breakpoint is entirely before the chunk of memory we | |
1094 | are reading. */ | |
1095 | continue; | |
8defab1a | 1096 | |
c5aa993b JM |
1097 | if (bp_addr >= memaddr + len) |
1098 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1099 | reading. */ |
c5aa993b | 1100 | continue; |
c5aa993b | 1101 | |
8defab1a DJ |
1102 | /* Offset within shadow_contents. */ |
1103 | if (bp_addr < memaddr) | |
1104 | { | |
1105 | /* Only copy the second part of the breakpoint. */ | |
1106 | bp_size -= memaddr - bp_addr; | |
1107 | bptoffset = memaddr - bp_addr; | |
1108 | bp_addr = memaddr; | |
1109 | } | |
c5aa993b | 1110 | |
8defab1a DJ |
1111 | if (bp_addr + bp_size > memaddr + len) |
1112 | { | |
1113 | /* Only copy the first part of the breakpoint. */ | |
1114 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1115 | } | |
c5aa993b | 1116 | |
8defab1a | 1117 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1118 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1119 | } |
c906108c | 1120 | } |
c906108c | 1121 | \f |
c5aa993b | 1122 | |
60e1c644 PA |
1123 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1124 | ||
a5606eee | 1125 | static int |
d77f58be | 1126 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1127 | { |
1128 | return (bpt->type == bp_hardware_watchpoint | |
1129 | || bpt->type == bp_read_watchpoint | |
1130 | || bpt->type == bp_access_watchpoint); | |
1131 | } | |
7270d8f2 | 1132 | |
60e1c644 PA |
1133 | /* Return true if BPT is of any watchpoint kind, hardware or |
1134 | software. */ | |
1135 | ||
1136 | static int | |
d77f58be | 1137 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1138 | { |
1139 | return (is_hardware_watchpoint (bpt) | |
1140 | || bpt->type == bp_watchpoint); | |
1141 | } | |
1142 | ||
f6bc2008 PA |
1143 | /* Assuming that B is a watchpoint: returns true if the current thread |
1144 | and its running state are safe to evaluate or update watchpoint B. | |
1145 | Watchpoints on local expressions need to be evaluated in the | |
1146 | context of the thread that was current when the watchpoint was | |
1147 | created, and, that thread needs to be stopped to be able to select | |
1148 | the correct frame context. Watchpoints on global expressions can | |
1149 | be evaluated on any thread, and in any state. It is presently left | |
1150 | to the target allowing memory accesses when threads are | |
1151 | running. */ | |
1152 | ||
1153 | static int | |
1154 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1155 | { | |
1156 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1157 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1158 | && !is_executing (inferior_ptid))); | |
1159 | } | |
1160 | ||
567e1b4e JB |
1161 | /* Assuming that B is a watchpoint: |
1162 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1163 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1164 | - Evaluate the condition if there is one, and store the result |
1165 | in b->loc->cond. | |
a5606eee VP |
1166 | - Update the list of values that must be watched in B->loc. |
1167 | ||
4a64f543 MS |
1168 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1169 | nothing. If this is local watchpoint that is out of scope, delete | |
1170 | it. | |
1171 | ||
1172 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1173 | removed + inserted on each stop here. Normal breakpoints must | |
1174 | never be removed because they might be missed by a running thread | |
1175 | when debugging in non-stop mode. On the other hand, hardware | |
1176 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1177 | to each LWP since they are stored in each LWP's hardware debug | |
1178 | registers. Therefore, such LWP must be stopped first in order to | |
1179 | be able to modify its hardware watchpoints. | |
1180 | ||
1181 | Hardware watchpoints must be reset exactly once after being | |
1182 | presented to the user. It cannot be done sooner, because it would | |
1183 | reset the data used to present the watchpoint hit to the user. And | |
1184 | it must not be done later because it could display the same single | |
1185 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1186 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1187 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1188 | not user-visible - its hit is suppressed if the memory content has | |
1189 | not changed. | |
1190 | ||
1191 | The following constraints influence the location where we can reset | |
1192 | hardware watchpoints: | |
1193 | ||
1194 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1195 | called several times when GDB stops. | |
1196 | ||
1197 | [linux] | |
1198 | * Multiple hardware watchpoints can be hit at the same time, | |
1199 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1200 | hit at a time as the reason for stopping, and all the other hits | |
1201 | are presented later, one after the other, each time the user | |
1202 | requests the execution to be resumed. Execution is not resumed | |
1203 | for the threads still having pending hit event stored in | |
1204 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1205 | the inferior on the first stop the thread hit event is kept being | |
1206 | reported from its cached value by linux_nat_stopped_data_address | |
1207 | until the real thread resume happens after the watchpoint gets | |
1208 | presented and thus its LWP_INFO->STATUS gets reset. | |
1209 | ||
1210 | Therefore the hardware watchpoint hit can get safely reset on the | |
1211 | watchpoint removal from inferior. */ | |
a79d3c27 | 1212 | |
b40ce68a | 1213 | static void |
a5606eee | 1214 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1215 | { |
a5606eee | 1216 | int within_current_scope; |
a5606eee | 1217 | struct frame_id saved_frame_id; |
66076460 | 1218 | int frame_saved; |
a5606eee | 1219 | |
f6bc2008 PA |
1220 | /* If this is a local watchpoint, we only want to check if the |
1221 | watchpoint frame is in scope if the current thread is the thread | |
1222 | that was used to create the watchpoint. */ | |
1223 | if (!watchpoint_in_thread_scope (b)) | |
1224 | return; | |
1225 | ||
a5606eee VP |
1226 | if (b->disposition == disp_del_at_next_stop) |
1227 | return; | |
1228 | ||
66076460 | 1229 | frame_saved = 0; |
a5606eee VP |
1230 | |
1231 | /* Determine if the watchpoint is within scope. */ | |
1232 | if (b->exp_valid_block == NULL) | |
1233 | within_current_scope = 1; | |
1234 | else | |
1235 | { | |
b5db5dfc UW |
1236 | struct frame_info *fi = get_current_frame (); |
1237 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1238 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1239 | ||
1240 | /* If we're in a function epilogue, unwinding may not work | |
1241 | properly, so do not attempt to recreate locations at this | |
1242 | point. See similar comments in watchpoint_check. */ | |
1243 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1244 | return; | |
66076460 DJ |
1245 | |
1246 | /* Save the current frame's ID so we can restore it after | |
1247 | evaluating the watchpoint expression on its own frame. */ | |
1248 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1249 | took a frame parameter, so that we didn't have to change the | |
1250 | selected frame. */ | |
1251 | frame_saved = 1; | |
1252 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1253 | ||
a5606eee VP |
1254 | fi = frame_find_by_id (b->watchpoint_frame); |
1255 | within_current_scope = (fi != NULL); | |
1256 | if (within_current_scope) | |
1257 | select_frame (fi); | |
1258 | } | |
1259 | ||
b5db5dfc UW |
1260 | /* We don't free locations. They are stored in the bp_location array |
1261 | and update_global_location_list will eventually delete them and | |
1262 | remove breakpoints if needed. */ | |
1263 | b->loc = NULL; | |
1264 | ||
a5606eee VP |
1265 | if (within_current_scope && reparse) |
1266 | { | |
1267 | char *s; | |
d63d0675 | 1268 | |
a5606eee VP |
1269 | if (b->exp) |
1270 | { | |
1271 | xfree (b->exp); | |
1272 | b->exp = NULL; | |
1273 | } | |
d63d0675 | 1274 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1275 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1276 | /* If the meaning of expression itself changed, the old value is | |
1277 | no longer relevant. We don't want to report a watchpoint hit | |
1278 | to the user when the old value and the new value may actually | |
1279 | be completely different objects. */ | |
1280 | value_free (b->val); | |
fa4727a6 DJ |
1281 | b->val = NULL; |
1282 | b->val_valid = 0; | |
60e1c644 PA |
1283 | |
1284 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1285 | expression is stored in the breakpoint object, not in the | |
1286 | locations (re)created below. */ | |
1287 | if (b->cond_string != NULL) | |
1288 | { | |
1289 | if (b->cond_exp != NULL) | |
1290 | { | |
1291 | xfree (b->cond_exp); | |
1292 | b->cond_exp = NULL; | |
1293 | } | |
1294 | ||
1295 | s = b->cond_string; | |
1296 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1297 | } | |
a5606eee | 1298 | } |
a5606eee VP |
1299 | |
1300 | /* If we failed to parse the expression, for example because | |
1301 | it refers to a global variable in a not-yet-loaded shared library, | |
1302 | don't try to insert watchpoint. We don't automatically delete | |
1303 | such watchpoint, though, since failure to parse expression | |
1304 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1305 | if ( !target_has_execution) |
1306 | { | |
1307 | /* Without execution, memory can't change. No use to try and | |
1308 | set watchpoint locations. The watchpoint will be reset when | |
1309 | the target gains execution, through breakpoint_re_set. */ | |
1310 | } | |
1311 | else if (within_current_scope && b->exp) | |
a5606eee | 1312 | { |
0cf6dd15 | 1313 | int pc = 0; |
fa4727a6 | 1314 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1315 | struct program_space *frame_pspace; |
a5606eee | 1316 | |
0cf6dd15 | 1317 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1318 | |
a5606eee VP |
1319 | /* Avoid setting b->val if it's already set. The meaning of |
1320 | b->val is 'the last value' user saw, and we should update | |
1321 | it only if we reported that last value to user. As it | |
1322 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1323 | if (!b->val_valid) |
1324 | { | |
1325 | b->val = v; | |
1326 | b->val_valid = 1; | |
1327 | } | |
a5606eee | 1328 | |
2d134ed3 PA |
1329 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1330 | ||
a5606eee | 1331 | /* Look at each value on the value chain. */ |
9fa40276 | 1332 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1333 | { |
1334 | /* If it's a memory location, and GDB actually needed | |
1335 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1336 | must watch it. If the first value returned is |
1337 | still lazy, that means an error occurred reading it; | |
1338 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1339 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1340 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1341 | { |
1342 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1343 | |
a5606eee VP |
1344 | /* We only watch structs and arrays if user asked |
1345 | for it explicitly, never if they just happen to | |
1346 | appear in the middle of some value chain. */ | |
fa4727a6 | 1347 | if (v == result |
a5606eee VP |
1348 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1349 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1350 | { | |
1351 | CORE_ADDR addr; | |
1352 | int len, type; | |
1353 | struct bp_location *loc, **tmp; | |
1354 | ||
42ae5230 | 1355 | addr = value_address (v); |
a5606eee VP |
1356 | len = TYPE_LENGTH (value_type (v)); |
1357 | type = hw_write; | |
1358 | if (b->type == bp_read_watchpoint) | |
1359 | type = hw_read; | |
1360 | else if (b->type == bp_access_watchpoint) | |
1361 | type = hw_access; | |
1362 | ||
39d61571 | 1363 | loc = allocate_bp_location (b); |
a5606eee VP |
1364 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1365 | ; | |
1366 | *tmp = loc; | |
a6d9a66e | 1367 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1368 | |
1369 | loc->pspace = frame_pspace; | |
a5606eee VP |
1370 | loc->address = addr; |
1371 | loc->length = len; | |
1372 | loc->watchpoint_type = type; | |
1373 | } | |
1374 | } | |
9fa40276 TJB |
1375 | } |
1376 | ||
1377 | /* Change the type of breakpoint between hardware assisted or | |
1378 | an ordinary watchpoint depending on the hardware support | |
1379 | and free hardware slots. REPARSE is set when the inferior | |
1380 | is started. */ | |
1381 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1382 | && reparse) | |
1383 | { | |
e09342b5 | 1384 | int reg_cnt; |
9fa40276 TJB |
1385 | enum bp_loc_type loc_type; |
1386 | struct bp_location *bl; | |
a5606eee | 1387 | |
e09342b5 TJB |
1388 | reg_cnt = can_use_hardware_watchpoint (val_chain, b->exact); |
1389 | ||
1390 | if (reg_cnt) | |
9fa40276 TJB |
1391 | { |
1392 | int i, target_resources_ok, other_type_used; | |
e09342b5 | 1393 | enum enable_state orig_enable_state; |
9fa40276 TJB |
1394 | |
1395 | /* We need to determine how many resources are already | |
e09342b5 TJB |
1396 | used for all other hardware watchpoints plus this one |
1397 | to see if we still have enough resources to also fit | |
1398 | this watchpoint in as well. To guarantee the | |
1399 | hw_watchpoint_used_count call below counts this | |
1400 | watchpoint, make sure that it is marked as a hardware | |
1401 | watchpoint. */ | |
1402 | b->type = bp_hardware_watchpoint; | |
1403 | ||
1404 | /* hw_watchpoint_used_count ignores disabled watchpoints, | |
1405 | and b might be disabled if we're being called from | |
1406 | do_enable_breakpoint. */ | |
1407 | orig_enable_state = b->enable_state; | |
1408 | b->enable_state = bp_enabled; | |
1409 | ||
9fa40276 TJB |
1410 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1411 | &other_type_used); | |
9fa40276 | 1412 | |
e09342b5 TJB |
1413 | b->enable_state = orig_enable_state; |
1414 | ||
1415 | target_resources_ok = target_can_use_hardware_watchpoint | |
1416 | (bp_hardware_watchpoint, i, other_type_used); | |
1417 | if (target_resources_ok <= 0) | |
1418 | b->type = bp_watchpoint; | |
9fa40276 TJB |
1419 | } |
1420 | else | |
1421 | b->type = bp_watchpoint; | |
1422 | ||
1423 | loc_type = (b->type == bp_watchpoint? bp_loc_other | |
1424 | : bp_loc_hardware_watchpoint); | |
1425 | for (bl = b->loc; bl; bl = bl->next) | |
1426 | bl->loc_type = loc_type; | |
1427 | } | |
1428 | ||
1429 | for (v = val_chain; v; v = next) | |
1430 | { | |
a5606eee VP |
1431 | next = value_next (v); |
1432 | if (v != b->val) | |
1433 | value_free (v); | |
1434 | } | |
1435 | ||
c7437ca6 PA |
1436 | /* If a software watchpoint is not watching any memory, then the |
1437 | above left it without any location set up. But, | |
1438 | bpstat_stop_status requires a location to be able to report | |
1439 | stops, so make sure there's at least a dummy one. */ | |
1440 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1441 | { | |
1442 | b->loc = allocate_bp_location (b); | |
1443 | b->loc->pspace = frame_pspace; | |
1444 | b->loc->address = -1; | |
1445 | b->loc->length = -1; | |
1446 | b->loc->watchpoint_type = -1; | |
1447 | } | |
a5606eee VP |
1448 | } |
1449 | else if (!within_current_scope) | |
7270d8f2 | 1450 | { |
ac74f770 MS |
1451 | printf_filtered (_("\ |
1452 | Watchpoint %d deleted because the program has left the block\n\ | |
1453 | in which its expression is valid.\n"), | |
a5606eee VP |
1454 | b->number); |
1455 | if (b->related_breakpoint) | |
60e1c644 PA |
1456 | { |
1457 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1458 | b->related_breakpoint->related_breakpoint = NULL; | |
1459 | b->related_breakpoint= NULL; | |
1460 | } | |
a5606eee | 1461 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1462 | } |
a5606eee VP |
1463 | |
1464 | /* Restore the selected frame. */ | |
66076460 DJ |
1465 | if (frame_saved) |
1466 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1467 | } |
1468 | ||
a5606eee | 1469 | |
74960c60 VP |
1470 | /* Returns 1 iff breakpoint location should be |
1471 | inserted in the inferior. */ | |
1472 | static int | |
35df4500 | 1473 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1474 | { |
35df4500 | 1475 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1476 | return 0; |
1477 | ||
35df4500 | 1478 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1479 | return 0; |
1480 | ||
35df4500 | 1481 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1482 | return 0; |
1483 | ||
56710373 PA |
1484 | /* This is set for example, when we're attached to the parent of a |
1485 | vfork, and have detached from the child. The child is running | |
1486 | free, and we expect it to do an exec or exit, at which point the | |
1487 | OS makes the parent schedulable again (and the target reports | |
1488 | that the vfork is done). Until the child is done with the shared | |
1489 | memory region, do not insert breakpoints in the parent, otherwise | |
1490 | the child could still trip on the parent's breakpoints. Since | |
1491 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1492 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1493 | return 0; |
1494 | ||
1042e4c0 SS |
1495 | /* Tracepoints are inserted by the target at a time of its choosing, |
1496 | not by us. */ | |
35df4500 | 1497 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1498 | return 0; |
1499 | ||
74960c60 VP |
1500 | return 1; |
1501 | } | |
1502 | ||
35df4500 TJB |
1503 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1504 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
1505 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. | |
879bfdc2 | 1506 | |
4a64f543 MS |
1507 | NOTE drow/2003-09-09: This routine could be broken down to an |
1508 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1509 | static int |
35df4500 | 1510 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1511 | struct ui_file *tmp_error_stream, |
fa3a767f | 1512 | int *disabled_breaks, |
26bb91f3 | 1513 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1514 | { |
1515 | int val = 0; | |
1516 | ||
35df4500 | 1517 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1518 | return 0; |
1519 | ||
8181d85f | 1520 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1521 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1522 | bl->target_info.placed_address = bl->address; | |
1523 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
8181d85f | 1524 | |
35df4500 TJB |
1525 | if (bl->loc_type == bp_loc_software_breakpoint |
1526 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1527 | { |
35df4500 | 1528 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1529 | { |
1530 | /* If the explicitly specified breakpoint type | |
1531 | is not hardware breakpoint, check the memory map to see | |
1532 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1533 | |
765dc015 VP |
1534 | Two important cases are: |
1535 | - location type is not hardware breakpoint, memory | |
1536 | is readonly. We change the type of the location to | |
1537 | hardware breakpoint. | |
4a64f543 MS |
1538 | - location type is hardware breakpoint, memory is |
1539 | read-write. This means we've previously made the | |
1540 | location hardware one, but then the memory map changed, | |
1541 | so we undo. | |
765dc015 | 1542 | |
4a64f543 MS |
1543 | When breakpoints are removed, remove_breakpoints will use |
1544 | location types we've just set here, the only possible | |
1545 | problem is that memory map has changed during running | |
1546 | program, but it's not going to work anyway with current | |
1547 | gdb. */ | |
765dc015 | 1548 | struct mem_region *mr |
35df4500 | 1549 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1550 | |
1551 | if (mr) | |
1552 | { | |
1553 | if (automatic_hardware_breakpoints) | |
1554 | { | |
765dc015 VP |
1555 | enum bp_loc_type new_type; |
1556 | ||
1557 | if (mr->attrib.mode != MEM_RW) | |
1558 | new_type = bp_loc_hardware_breakpoint; | |
1559 | else | |
1560 | new_type = bp_loc_software_breakpoint; | |
1561 | ||
35df4500 | 1562 | if (new_type != bl->loc_type) |
765dc015 VP |
1563 | { |
1564 | static int said = 0; | |
cc59ec59 | 1565 | |
35df4500 | 1566 | bl->loc_type = new_type; |
765dc015 VP |
1567 | if (!said) |
1568 | { | |
3e43a32a MS |
1569 | fprintf_filtered (gdb_stdout, |
1570 | _("Note: automatically using " | |
1571 | "hardware breakpoints for " | |
1572 | "read-only addresses.\n")); | |
765dc015 VP |
1573 | said = 1; |
1574 | } | |
1575 | } | |
1576 | } | |
35df4500 | 1577 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1578 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1579 | warning (_("cannot set software breakpoint " |
1580 | "at readonly address %s"), | |
35df4500 | 1581 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1582 | } |
1583 | } | |
1584 | ||
879bfdc2 DJ |
1585 | /* First check to see if we have to handle an overlay. */ |
1586 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1587 | || bl->section == NULL |
1588 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1589 | { |
1590 | /* No overlay handling: just set the breakpoint. */ | |
1591 | ||
35df4500 TJB |
1592 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1593 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1594 | &bl->target_info); | |
879bfdc2 | 1595 | else |
35df4500 TJB |
1596 | val = target_insert_breakpoint (bl->gdbarch, |
1597 | &bl->target_info); | |
879bfdc2 DJ |
1598 | } |
1599 | else | |
1600 | { | |
4a64f543 | 1601 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1602 | Shall we set a breakpoint at the LMA? */ |
1603 | if (!overlay_events_enabled) | |
1604 | { | |
1605 | /* Yes -- overlay event support is not active, | |
1606 | so we must try to set a breakpoint at the LMA. | |
1607 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1608 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1609 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1610 | bl->owner->number); |
879bfdc2 DJ |
1611 | else |
1612 | { | |
35df4500 TJB |
1613 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1614 | bl->section); | |
879bfdc2 | 1615 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1616 | bl->overlay_target_info = bl->target_info; |
1617 | bl->overlay_target_info.placed_address = addr; | |
1618 | val = target_insert_breakpoint (bl->gdbarch, | |
1619 | &bl->overlay_target_info); | |
879bfdc2 | 1620 | if (val != 0) |
99361f52 | 1621 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1622 | "Overlay breakpoint %d " |
1623 | "failed: in ROM?\n", | |
35df4500 | 1624 | bl->owner->number); |
879bfdc2 DJ |
1625 | } |
1626 | } | |
1627 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1628 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1629 | { |
1630 | /* Yes. This overlay section is mapped into memory. */ | |
35df4500 TJB |
1631 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1632 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1633 | &bl->target_info); | |
879bfdc2 | 1634 | else |
35df4500 TJB |
1635 | val = target_insert_breakpoint (bl->gdbarch, |
1636 | &bl->target_info); | |
879bfdc2 DJ |
1637 | } |
1638 | else | |
1639 | { | |
1640 | /* No. This breakpoint will not be inserted. | |
1641 | No error, but do not mark the bp as 'inserted'. */ | |
1642 | return 0; | |
1643 | } | |
1644 | } | |
1645 | ||
1646 | if (val) | |
1647 | { | |
1648 | /* Can't set the breakpoint. */ | |
35df4500 | 1649 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1650 | { |
4a64f543 | 1651 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1652 | val = 0; |
35df4500 | 1653 | bl->shlib_disabled = 1; |
879bfdc2 DJ |
1654 | if (!*disabled_breaks) |
1655 | { | |
1656 | fprintf_unfiltered (tmp_error_stream, | |
1657 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1658 | bl->owner->number); |
879bfdc2 | 1659 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1660 | "Temporarily disabling shared " |
1661 | "library breakpoints:\n"); | |
879bfdc2 DJ |
1662 | } |
1663 | *disabled_breaks = 1; | |
1664 | fprintf_unfiltered (tmp_error_stream, | |
35df4500 | 1665 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1666 | } |
1667 | else | |
879bfdc2 | 1668 | { |
35df4500 | 1669 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1670 | { |
1671 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1672 | fprintf_unfiltered (tmp_error_stream, |
1673 | "Cannot insert hardware " | |
1674 | "breakpoint %d.\n", | |
35df4500 | 1675 | bl->owner->number); |
879bfdc2 DJ |
1676 | } |
1677 | else | |
1678 | { | |
1679 | fprintf_unfiltered (tmp_error_stream, | |
1680 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1681 | bl->owner->number); |
879bfdc2 DJ |
1682 | fprintf_filtered (tmp_error_stream, |
1683 | "Error accessing memory address "); | |
35df4500 | 1684 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1685 | tmp_error_stream); |
879bfdc2 DJ |
1686 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1687 | safe_strerror (val)); | |
1688 | } | |
1689 | ||
1690 | } | |
1691 | } | |
1692 | else | |
35df4500 | 1693 | bl->inserted = 1; |
879bfdc2 DJ |
1694 | |
1695 | return val; | |
1696 | } | |
1697 | ||
35df4500 | 1698 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1699 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1700 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1701 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1702 | { |
77b06cd7 TJB |
1703 | gdb_assert (bl->owner->ops != NULL |
1704 | && bl->owner->ops->insert_location != NULL); | |
1705 | ||
1706 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1707 | |
1708 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1709 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1710 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1711 | { |
1712 | struct bp_location *loc, **loc_temp; | |
1713 | ||
1714 | /* But don't try to insert it, if there's already another | |
1715 | hw_access location that would be considered a duplicate | |
1716 | of this one. */ | |
1717 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1718 | if (loc != bl |
85d721b8 | 1719 | && loc->watchpoint_type == hw_access |
35df4500 | 1720 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1721 | { |
35df4500 TJB |
1722 | bl->duplicate = 1; |
1723 | bl->inserted = 1; | |
1724 | bl->target_info = loc->target_info; | |
1725 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1726 | val = 0; |
1727 | break; | |
1728 | } | |
1729 | ||
1730 | if (val == 1) | |
1731 | { | |
77b06cd7 TJB |
1732 | bl->watchpoint_type = hw_access; |
1733 | val = bl->owner->ops->insert_location (bl); | |
1734 | ||
1735 | if (val) | |
1736 | /* Back to the original value. */ | |
1737 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1738 | } |
1739 | } | |
1740 | ||
35df4500 | 1741 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1742 | } |
1743 | ||
35df4500 | 1744 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1745 | { |
77b06cd7 TJB |
1746 | gdb_assert (bl->owner->ops != NULL |
1747 | && bl->owner->ops->insert_location != NULL); | |
1748 | ||
1749 | val = bl->owner->ops->insert_location (bl); | |
1750 | if (val) | |
1751 | { | |
1752 | bl->owner->enable_state = bp_disabled; | |
1753 | ||
1754 | if (val == 1) | |
1755 | warning (_("\ | |
1756 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1757 | of catchpoint."), bl->owner->number); | |
1758 | else | |
1759 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1760 | } | |
1761 | ||
1762 | bl->inserted = (val == 0); | |
1640b821 DJ |
1763 | |
1764 | /* We've already printed an error message if there was a problem | |
1765 | inserting this catchpoint, and we've disabled the catchpoint, | |
1766 | so just return success. */ | |
1767 | return 0; | |
879bfdc2 DJ |
1768 | } |
1769 | ||
1770 | return 0; | |
1771 | } | |
1772 | ||
6c95b8df PA |
1773 | /* This function is called when program space PSPACE is about to be |
1774 | deleted. It takes care of updating breakpoints to not reference | |
1775 | PSPACE anymore. */ | |
1776 | ||
1777 | void | |
1778 | breakpoint_program_space_exit (struct program_space *pspace) | |
1779 | { | |
1780 | struct breakpoint *b, *b_temp; | |
876fa593 | 1781 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1782 | |
1783 | /* Remove any breakpoint that was set through this program space. */ | |
1784 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1785 | { | |
1786 | if (b->pspace == pspace) | |
1787 | delete_breakpoint (b); | |
1788 | } | |
1789 | ||
1790 | /* Breakpoints set through other program spaces could have locations | |
1791 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1792 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1793 | { |
1794 | struct bp_location *tmp; | |
1795 | ||
1796 | if (loc->pspace == pspace) | |
1797 | { | |
2bdf28a0 | 1798 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1799 | if (loc->owner->loc == loc) |
1800 | loc->owner->loc = loc->next; | |
1801 | else | |
1802 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1803 | if (tmp->next == loc) | |
1804 | { | |
1805 | tmp->next = loc->next; | |
1806 | break; | |
1807 | } | |
1808 | } | |
1809 | } | |
1810 | ||
1811 | /* Now update the global location list to permanently delete the | |
1812 | removed locations above. */ | |
1813 | update_global_location_list (0); | |
1814 | } | |
1815 | ||
74960c60 VP |
1816 | /* Make sure all breakpoints are inserted in inferior. |
1817 | Throws exception on any error. | |
1818 | A breakpoint that is already inserted won't be inserted | |
1819 | again, so calling this function twice is safe. */ | |
1820 | void | |
1821 | insert_breakpoints (void) | |
1822 | { | |
1823 | struct breakpoint *bpt; | |
1824 | ||
1825 | ALL_BREAKPOINTS (bpt) | |
1826 | if (is_hardware_watchpoint (bpt)) | |
4a64f543 | 1827 | update_watchpoint (bpt, 0 /* don't reparse. */); |
74960c60 | 1828 | |
b60e7edf | 1829 | update_global_location_list (1); |
74960c60 | 1830 | |
c35b1492 PA |
1831 | /* update_global_location_list does not insert breakpoints when |
1832 | always_inserted_mode is not enabled. Explicitly insert them | |
1833 | now. */ | |
1834 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1835 | insert_breakpoint_locations (); |
1836 | } | |
1837 | ||
c906108c SS |
1838 | /* insert_breakpoints is used when starting or continuing the program. |
1839 | remove_breakpoints is used when the program stops. | |
1840 | Both return zero if successful, | |
1841 | or an `errno' value if could not write the inferior. */ | |
1842 | ||
74960c60 VP |
1843 | static void |
1844 | insert_breakpoint_locations (void) | |
c906108c | 1845 | { |
a5606eee | 1846 | struct breakpoint *bpt; |
35df4500 | 1847 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1848 | int error = 0; |
c906108c SS |
1849 | int val = 0; |
1850 | int disabled_breaks = 0; | |
81d0cc19 | 1851 | int hw_breakpoint_error = 0; |
c906108c | 1852 | |
81d0cc19 | 1853 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1854 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1855 | |
81d0cc19 GS |
1856 | /* Explicitly mark the warning -- this will only be printed if |
1857 | there was an error. */ | |
1858 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1859 | |
1860 | save_current_space_and_thread (); | |
1861 | ||
35df4500 | 1862 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1863 | { |
35df4500 | 1864 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1865 | continue; |
1866 | ||
4a64f543 MS |
1867 | /* There is no point inserting thread-specific breakpoints if |
1868 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1869 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1870 | if (bl->owner->thread != -1 |
1871 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1872 | continue; |
1873 | ||
35df4500 | 1874 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1875 | |
1876 | /* For targets that support global breakpoints, there's no need | |
1877 | to select an inferior to insert breakpoint to. In fact, even | |
1878 | if we aren't attached to any process yet, we should still | |
1879 | insert breakpoints. */ | |
1880 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1881 | && ptid_equal (inferior_ptid, null_ptid)) | |
1882 | continue; | |
1883 | ||
35df4500 | 1884 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
879bfdc2 DJ |
1885 | &hw_breakpoint_error); |
1886 | if (val) | |
e236ba44 | 1887 | error = val; |
879bfdc2 | 1888 | } |
c906108c | 1889 | |
4a64f543 MS |
1890 | /* If we failed to insert all locations of a watchpoint, remove |
1891 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1892 | ALL_BREAKPOINTS (bpt) |
1893 | { | |
1894 | int some_failed = 0; | |
1895 | struct bp_location *loc; | |
1896 | ||
1897 | if (!is_hardware_watchpoint (bpt)) | |
1898 | continue; | |
1899 | ||
d6b74ac4 | 1900 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1901 | continue; |
74960c60 VP |
1902 | |
1903 | if (bpt->disposition == disp_del_at_next_stop) | |
1904 | continue; | |
a5606eee VP |
1905 | |
1906 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1907 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1908 | { |
1909 | some_failed = 1; | |
1910 | break; | |
1911 | } | |
1912 | if (some_failed) | |
1913 | { | |
1914 | for (loc = bpt->loc; loc; loc = loc->next) | |
1915 | if (loc->inserted) | |
1916 | remove_breakpoint (loc, mark_uninserted); | |
1917 | ||
1918 | hw_breakpoint_error = 1; | |
1919 | fprintf_unfiltered (tmp_error_stream, | |
1920 | "Could not insert hardware watchpoint %d.\n", | |
1921 | bpt->number); | |
1922 | error = -1; | |
1923 | } | |
1924 | } | |
1925 | ||
e236ba44 | 1926 | if (error) |
81d0cc19 GS |
1927 | { |
1928 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1929 | message about possibly exhausted resources. */ | |
879bfdc2 | 1930 | if (hw_breakpoint_error) |
81d0cc19 | 1931 | { |
c6510018 MS |
1932 | fprintf_unfiltered (tmp_error_stream, |
1933 | "Could not insert hardware breakpoints:\n\ | |
1934 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1935 | } |
81d0cc19 GS |
1936 | target_terminal_ours_for_output (); |
1937 | error_stream (tmp_error_stream); | |
1938 | } | |
f7545552 TT |
1939 | |
1940 | do_cleanups (cleanups); | |
c906108c SS |
1941 | } |
1942 | ||
c906108c | 1943 | int |
fba45db2 | 1944 | remove_breakpoints (void) |
c906108c | 1945 | { |
35df4500 | 1946 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1947 | int val = 0; |
c906108c | 1948 | |
35df4500 | 1949 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 1950 | { |
35df4500 TJB |
1951 | if (bl->inserted) |
1952 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 1953 | } |
3a1bae8e | 1954 | return val; |
c906108c SS |
1955 | } |
1956 | ||
6c95b8df PA |
1957 | /* Remove breakpoints of process PID. */ |
1958 | ||
1959 | int | |
1960 | remove_breakpoints_pid (int pid) | |
1961 | { | |
35df4500 | 1962 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
1963 | int val; |
1964 | struct inferior *inf = find_inferior_pid (pid); | |
1965 | ||
35df4500 | 1966 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 1967 | { |
35df4500 | 1968 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
1969 | continue; |
1970 | ||
35df4500 | 1971 | if (bl->inserted) |
6c95b8df | 1972 | { |
35df4500 | 1973 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
1974 | if (val != 0) |
1975 | return val; | |
1976 | } | |
1977 | } | |
1978 | return 0; | |
1979 | } | |
1980 | ||
692590c1 | 1981 | int |
80ce1ecb | 1982 | remove_hw_watchpoints (void) |
692590c1 | 1983 | { |
35df4500 | 1984 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1985 | int val = 0; |
692590c1 | 1986 | |
35df4500 | 1987 | ALL_BP_LOCATIONS (bl, blp_tmp) |
692590c1 | 1988 | { |
35df4500 TJB |
1989 | if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint) |
1990 | val |= remove_breakpoint (bl, mark_uninserted); | |
692590c1 | 1991 | } |
3a1bae8e | 1992 | return val; |
692590c1 MS |
1993 | } |
1994 | ||
c906108c | 1995 | int |
fba45db2 | 1996 | reattach_breakpoints (int pid) |
c906108c | 1997 | { |
6c95b8df | 1998 | struct cleanup *old_chain; |
35df4500 | 1999 | struct bp_location *bl, **blp_tmp; |
c906108c | 2000 | int val; |
86b887df | 2001 | struct ui_file *tmp_error_stream; |
fa3a767f | 2002 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2003 | struct inferior *inf; |
2004 | struct thread_info *tp; | |
2005 | ||
2006 | tp = any_live_thread_of_process (pid); | |
2007 | if (tp == NULL) | |
2008 | return 1; | |
2009 | ||
2010 | inf = find_inferior_pid (pid); | |
2011 | old_chain = save_inferior_ptid (); | |
2012 | ||
2013 | inferior_ptid = tp->ptid; | |
a4954f26 | 2014 | |
86b887df | 2015 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2016 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2017 | |
35df4500 | 2018 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2019 | { |
35df4500 | 2020 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2021 | continue; |
2022 | ||
35df4500 | 2023 | if (bl->inserted) |
c5aa993b | 2024 | { |
35df4500 TJB |
2025 | bl->inserted = 0; |
2026 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2027 | if (val != 0) |
2028 | { | |
ce696e05 | 2029 | do_cleanups (old_chain); |
c5aa993b JM |
2030 | return val; |
2031 | } | |
2032 | } | |
2033 | } | |
ce696e05 | 2034 | do_cleanups (old_chain); |
c906108c SS |
2035 | return 0; |
2036 | } | |
2037 | ||
e58b0e63 PA |
2038 | static int internal_breakpoint_number = -1; |
2039 | ||
84f4c1fe PM |
2040 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2041 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2042 | from internal_breakpoint_number and that variable decremented. | |
2043 | Otherwis the breakpoint number will be populated from | |
2044 | breakpoint_count and that value incremented. Internal breakpoints | |
2045 | do not set the internal var bpnum. */ | |
2046 | static void | |
2047 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2048 | { | |
2049 | if (internal) | |
2050 | b->number = internal_breakpoint_number--; | |
2051 | else | |
2052 | { | |
2053 | set_breakpoint_count (breakpoint_count + 1); | |
2054 | b->number = breakpoint_count; | |
2055 | } | |
2056 | } | |
2057 | ||
e62c965a | 2058 | static struct breakpoint * |
a6d9a66e UW |
2059 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2060 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2061 | { |
e62c965a PP |
2062 | struct symtab_and_line sal; |
2063 | struct breakpoint *b; | |
2064 | ||
4a64f543 | 2065 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2066 | |
2067 | sal.pc = address; | |
2068 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2069 | sal.pspace = current_program_space; |
e62c965a | 2070 | |
a6d9a66e | 2071 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2072 | b->number = internal_breakpoint_number--; |
2073 | b->disposition = disp_donttouch; | |
2074 | ||
2075 | return b; | |
2076 | } | |
2077 | ||
17450429 PP |
2078 | static const char *const longjmp_names[] = |
2079 | { | |
2080 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2081 | }; | |
2082 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2083 | ||
2084 | /* Per-objfile data private to breakpoint.c. */ | |
2085 | struct breakpoint_objfile_data | |
2086 | { | |
2087 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2088 | struct minimal_symbol *overlay_msym; | |
2089 | ||
2090 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2091 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2092 | ||
2093 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2094 | struct minimal_symbol *terminate_msym; | |
2095 | ||
2096 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2097 | struct minimal_symbol *exception_msym; | |
2098 | }; | |
2099 | ||
2100 | static const struct objfile_data *breakpoint_objfile_key; | |
2101 | ||
2102 | /* Minimal symbol not found sentinel. */ | |
2103 | static struct minimal_symbol msym_not_found; | |
2104 | ||
2105 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2106 | ||
2107 | static int | |
2108 | msym_not_found_p (const struct minimal_symbol *msym) | |
2109 | { | |
2110 | return msym == &msym_not_found; | |
2111 | } | |
2112 | ||
2113 | /* Return per-objfile data needed by breakpoint.c. | |
2114 | Allocate the data if necessary. */ | |
2115 | ||
2116 | static struct breakpoint_objfile_data * | |
2117 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2118 | { | |
2119 | struct breakpoint_objfile_data *bp_objfile_data; | |
2120 | ||
2121 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2122 | if (bp_objfile_data == NULL) | |
2123 | { | |
2124 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2125 | sizeof (*bp_objfile_data)); | |
2126 | ||
2127 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2128 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2129 | } | |
2130 | return bp_objfile_data; | |
2131 | } | |
2132 | ||
e62c965a | 2133 | static void |
af02033e | 2134 | create_overlay_event_breakpoint (void) |
e62c965a | 2135 | { |
69de3c6a | 2136 | struct objfile *objfile; |
af02033e | 2137 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2138 | |
69de3c6a PP |
2139 | ALL_OBJFILES (objfile) |
2140 | { | |
2141 | struct breakpoint *b; | |
17450429 PP |
2142 | struct breakpoint_objfile_data *bp_objfile_data; |
2143 | CORE_ADDR addr; | |
69de3c6a | 2144 | |
17450429 PP |
2145 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2146 | ||
2147 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2148 | continue; | |
2149 | ||
2150 | if (bp_objfile_data->overlay_msym == NULL) | |
2151 | { | |
2152 | struct minimal_symbol *m; | |
2153 | ||
2154 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2155 | if (m == NULL) | |
2156 | { | |
2157 | /* Avoid future lookups in this objfile. */ | |
2158 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2159 | continue; | |
2160 | } | |
2161 | bp_objfile_data->overlay_msym = m; | |
2162 | } | |
e62c965a | 2163 | |
17450429 PP |
2164 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2165 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
69de3c6a PP |
2166 | bp_overlay_event); |
2167 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2168 | |
69de3c6a PP |
2169 | if (overlay_debugging == ovly_auto) |
2170 | { | |
2171 | b->enable_state = bp_enabled; | |
2172 | overlay_events_enabled = 1; | |
2173 | } | |
2174 | else | |
2175 | { | |
2176 | b->enable_state = bp_disabled; | |
2177 | overlay_events_enabled = 0; | |
2178 | } | |
e62c965a PP |
2179 | } |
2180 | update_global_location_list (1); | |
2181 | } | |
2182 | ||
0fd8e87f | 2183 | static void |
af02033e | 2184 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2185 | { |
6c95b8df | 2186 | struct program_space *pspace; |
6c95b8df PA |
2187 | struct cleanup *old_chain; |
2188 | ||
2189 | old_chain = save_current_program_space (); | |
0fd8e87f | 2190 | |
6c95b8df | 2191 | ALL_PSPACES (pspace) |
af02033e PP |
2192 | { |
2193 | struct objfile *objfile; | |
2194 | ||
2195 | set_current_program_space (pspace); | |
2196 | ||
2197 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2198 | { |
af02033e PP |
2199 | int i; |
2200 | struct gdbarch *gdbarch; | |
17450429 | 2201 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2202 | |
af02033e PP |
2203 | gdbarch = get_objfile_arch (objfile); |
2204 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2205 | continue; |
2206 | ||
17450429 PP |
2207 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2208 | ||
2209 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2210 | { |
2211 | struct breakpoint *b; | |
af02033e | 2212 | const char *func_name; |
17450429 | 2213 | CORE_ADDR addr; |
6c95b8df | 2214 | |
17450429 | 2215 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2216 | continue; |
0fd8e87f | 2217 | |
17450429 PP |
2218 | func_name = longjmp_names[i]; |
2219 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2220 | { | |
2221 | struct minimal_symbol *m; | |
2222 | ||
2223 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2224 | if (m == NULL) | |
2225 | { | |
2226 | /* Prevent future lookups in this objfile. */ | |
2227 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2228 | continue; | |
2229 | } | |
2230 | bp_objfile_data->longjmp_msym[i] = m; | |
2231 | } | |
2232 | ||
2233 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
2234 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master); | |
af02033e PP |
2235 | b->addr_string = xstrdup (func_name); |
2236 | b->enable_state = bp_disabled; | |
2237 | } | |
0fd8e87f | 2238 | } |
af02033e | 2239 | } |
0fd8e87f | 2240 | update_global_location_list (1); |
6c95b8df PA |
2241 | |
2242 | do_cleanups (old_chain); | |
0fd8e87f UW |
2243 | } |
2244 | ||
af02033e | 2245 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2246 | static void |
af02033e | 2247 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2248 | { |
2249 | struct program_space *pspace; | |
aa7d318d | 2250 | struct cleanup *old_chain; |
af02033e | 2251 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2252 | |
2253 | old_chain = save_current_program_space (); | |
2254 | ||
2255 | ALL_PSPACES (pspace) | |
17450429 PP |
2256 | { |
2257 | struct objfile *objfile; | |
2258 | CORE_ADDR addr; | |
2259 | ||
2260 | set_current_program_space (pspace); | |
2261 | ||
aa7d318d TT |
2262 | ALL_OBJFILES (objfile) |
2263 | { | |
2264 | struct breakpoint *b; | |
17450429 | 2265 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2266 | |
17450429 | 2267 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2268 | |
17450429 PP |
2269 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2270 | continue; | |
2271 | ||
2272 | if (bp_objfile_data->terminate_msym == NULL) | |
2273 | { | |
2274 | struct minimal_symbol *m; | |
2275 | ||
2276 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2277 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2278 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2279 | { | |
2280 | /* Prevent future lookups in this objfile. */ | |
2281 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2282 | continue; | |
2283 | } | |
2284 | bp_objfile_data->terminate_msym = m; | |
2285 | } | |
aa7d318d | 2286 | |
17450429 PP |
2287 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2288 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
aa7d318d TT |
2289 | bp_std_terminate_master); |
2290 | b->addr_string = xstrdup (func_name); | |
2291 | b->enable_state = bp_disabled; | |
2292 | } | |
17450429 PP |
2293 | } |
2294 | ||
aa7d318d TT |
2295 | update_global_location_list (1); |
2296 | ||
2297 | do_cleanups (old_chain); | |
2298 | } | |
2299 | ||
186c406b TT |
2300 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2301 | ||
2302 | void | |
2303 | create_exception_master_breakpoint (void) | |
2304 | { | |
2305 | struct objfile *objfile; | |
17450429 | 2306 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2307 | |
2308 | ALL_OBJFILES (objfile) | |
2309 | { | |
17450429 PP |
2310 | struct breakpoint *b; |
2311 | struct gdbarch *gdbarch; | |
2312 | struct breakpoint_objfile_data *bp_objfile_data; | |
2313 | CORE_ADDR addr; | |
2314 | ||
2315 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2316 | ||
2317 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2318 | continue; | |
2319 | ||
2320 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2321 | |
17450429 | 2322 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2323 | { |
17450429 | 2324 | struct minimal_symbol *debug_hook; |
186c406b | 2325 | |
17450429 PP |
2326 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2327 | if (debug_hook == NULL) | |
2328 | { | |
2329 | bp_objfile_data->exception_msym = &msym_not_found; | |
2330 | continue; | |
2331 | } | |
2332 | ||
2333 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2334 | } |
17450429 PP |
2335 | |
2336 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2337 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2338 | ¤t_target); | |
2339 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2340 | b->addr_string = xstrdup (func_name); | |
2341 | b->enable_state = bp_disabled; | |
186c406b TT |
2342 | } |
2343 | ||
2344 | update_global_location_list (1); | |
2345 | } | |
2346 | ||
c906108c | 2347 | void |
fba45db2 | 2348 | update_breakpoints_after_exec (void) |
c906108c | 2349 | { |
35df4500 | 2350 | struct breakpoint *b, *b_tmp; |
876fa593 | 2351 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2352 | |
25b22b0a PA |
2353 | /* We're about to delete breakpoints from GDB's lists. If the |
2354 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2355 | writing the breakpoints' "shadow contents" back into memory. The | |
2356 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2357 | do that. Instead, the target is responsible from marking | |
2358 | breakpoints out as soon as it detects an exec. We don't do that | |
2359 | here instead, because there may be other attempts to delete | |
2360 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2361 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2362 | if (bploc->pspace == current_program_space) |
2363 | gdb_assert (!bploc->inserted); | |
c906108c | 2364 | |
35df4500 | 2365 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2366 | { |
6c95b8df PA |
2367 | if (b->pspace != current_program_space) |
2368 | continue; | |
2369 | ||
4a64f543 | 2370 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2371 | if (b->type == bp_shlib_event) |
2372 | { | |
2373 | delete_breakpoint (b); | |
2374 | continue; | |
2375 | } | |
c906108c | 2376 | |
4a64f543 | 2377 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2378 | if (b->type == bp_jit_event) |
2379 | { | |
2380 | delete_breakpoint (b); | |
2381 | continue; | |
2382 | } | |
2383 | ||
1900040c | 2384 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2385 | as must overlay event and longjmp master breakpoints. */ |
2386 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2387 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2388 | || b->type == bp_exception_master) | |
c4093a6a JM |
2389 | { |
2390 | delete_breakpoint (b); | |
2391 | continue; | |
2392 | } | |
2393 | ||
4a64f543 | 2394 | /* Step-resume breakpoints are meaningless after an exec(). */ |
c5aa993b JM |
2395 | if (b->type == bp_step_resume) |
2396 | { | |
2397 | delete_breakpoint (b); | |
2398 | continue; | |
2399 | } | |
2400 | ||
611c83ae PA |
2401 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2402 | after an exec. */ | |
186c406b TT |
2403 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2404 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2405 | { |
2406 | delete_breakpoint (b); | |
2407 | continue; | |
2408 | } | |
2409 | ||
ce78b96d JB |
2410 | if (b->type == bp_catchpoint) |
2411 | { | |
2412 | /* For now, none of the bp_catchpoint breakpoints need to | |
2413 | do anything at this point. In the future, if some of | |
2414 | the catchpoints need to something, we will need to add | |
2415 | a new method, and call this method from here. */ | |
2416 | continue; | |
2417 | } | |
2418 | ||
c5aa993b JM |
2419 | /* bp_finish is a special case. The only way we ought to be able |
2420 | to see one of these when an exec() has happened, is if the user | |
2421 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2422 | carries them to the call-site of the current callee, by setting | |
2423 | a temporary bp there and resuming. But in this case, the finish | |
2424 | will carry them entirely through the vfork & exec. | |
2425 | ||
2426 | We don't want to allow a bp_finish to remain inserted now. But | |
2427 | we can't safely delete it, 'cause finish_command has a handle to | |
2428 | the bp on a bpstat, and will later want to delete it. There's a | |
2429 | chance (and I've seen it happen) that if we delete the bp_finish | |
2430 | here, that its storage will get reused by the time finish_command | |
2431 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2432 | We really must allow finish_command to delete a bp_finish. | |
2433 | ||
53a5351d JM |
2434 | In the absense of a general solution for the "how do we know |
2435 | it's safe to delete something others may have handles to?" | |
2436 | problem, what we'll do here is just uninsert the bp_finish, and | |
2437 | let finish_command delete it. | |
2438 | ||
2439 | (We know the bp_finish is "doomed" in the sense that it's | |
2440 | momentary, and will be deleted as soon as finish_command sees | |
2441 | the inferior stopped. So it doesn't matter that the bp's | |
2442 | address is probably bogus in the new a.out, unlike e.g., the | |
2443 | solib breakpoints.) */ | |
c5aa993b | 2444 | |
c5aa993b JM |
2445 | if (b->type == bp_finish) |
2446 | { | |
2447 | continue; | |
2448 | } | |
2449 | ||
2450 | /* Without a symbolic address, we have little hope of the | |
2451 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2452 | a.out. */ |
c5aa993b JM |
2453 | if (b->addr_string == NULL) |
2454 | { | |
2455 | delete_breakpoint (b); | |
2456 | continue; | |
2457 | } | |
c5aa993b | 2458 | } |
1900040c | 2459 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2460 | create_overlay_event_breakpoint (); |
2461 | create_longjmp_master_breakpoint (); | |
2462 | create_std_terminate_master_breakpoint (); | |
186c406b | 2463 | create_exception_master_breakpoint (); |
c906108c SS |
2464 | } |
2465 | ||
2466 | int | |
fba45db2 | 2467 | detach_breakpoints (int pid) |
c906108c | 2468 | { |
35df4500 | 2469 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2470 | int val = 0; |
ce696e05 | 2471 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2472 | struct inferior *inf = current_inferior (); |
c5aa993b | 2473 | |
39f77062 | 2474 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2475 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2476 | |
6c95b8df | 2477 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2478 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2479 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2480 | { |
35df4500 | 2481 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2482 | continue; |
2483 | ||
35df4500 TJB |
2484 | if (bl->inserted) |
2485 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2486 | } |
d03285ec UW |
2487 | |
2488 | /* Detach single-step breakpoints as well. */ | |
2489 | detach_single_step_breakpoints (); | |
2490 | ||
ce696e05 | 2491 | do_cleanups (old_chain); |
3a1bae8e | 2492 | return val; |
c906108c SS |
2493 | } |
2494 | ||
35df4500 | 2495 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2496 | Note that this is used to detach breakpoints from a child fork. |
2497 | When we get here, the child isn't in the inferior list, and neither | |
2498 | do we have objects to represent its address space --- we should | |
35df4500 | 2499 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2500 | |
c906108c | 2501 | static int |
35df4500 | 2502 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2503 | { |
2504 | int val; | |
c5aa993b | 2505 | |
35df4500 TJB |
2506 | /* BL is never in moribund_locations by our callers. */ |
2507 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2508 | |
35df4500 | 2509 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2510 | /* Permanent breakpoints cannot be inserted or removed. */ |
2511 | return 0; | |
2512 | ||
74960c60 VP |
2513 | /* The type of none suggests that owner is actually deleted. |
2514 | This should not ever happen. */ | |
35df4500 | 2515 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2516 | |
35df4500 TJB |
2517 | if (bl->loc_type == bp_loc_software_breakpoint |
2518 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2519 | { |
c02f5703 MS |
2520 | /* "Normal" instruction breakpoint: either the standard |
2521 | trap-instruction bp (bp_breakpoint), or a | |
2522 | bp_hardware_breakpoint. */ | |
2523 | ||
2524 | /* First check to see if we have to handle an overlay. */ | |
2525 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2526 | || bl->section == NULL |
2527 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2528 | { |
2529 | /* No overlay handling: just remove the breakpoint. */ | |
2530 | ||
35df4500 TJB |
2531 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2532 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2533 | else |
35df4500 | 2534 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2535 | } |
c906108c SS |
2536 | else |
2537 | { | |
4a64f543 | 2538 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2539 | Did we set a breakpoint at the LMA? */ |
2540 | if (!overlay_events_enabled) | |
2541 | { | |
2542 | /* Yes -- overlay event support is not active, so we | |
2543 | should have set a breakpoint at the LMA. Remove it. | |
2544 | */ | |
c02f5703 MS |
2545 | /* Ignore any failures: if the LMA is in ROM, we will |
2546 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2547 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2548 | target_remove_hw_breakpoint (bl->gdbarch, | |
2549 | &bl->overlay_target_info); | |
c02f5703 | 2550 | else |
35df4500 TJB |
2551 | target_remove_breakpoint (bl->gdbarch, |
2552 | &bl->overlay_target_info); | |
c02f5703 MS |
2553 | } |
2554 | /* Did we set a breakpoint at the VMA? | |
2555 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2556 | if (bl->inserted) |
c906108c | 2557 | { |
c02f5703 MS |
2558 | /* Yes -- remove it. Previously we did not bother to |
2559 | remove the breakpoint if the section had been | |
2560 | unmapped, but let's not rely on that being safe. We | |
2561 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2562 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2563 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2564 | &bl->target_info); | |
aa67235e UW |
2565 | |
2566 | /* However, we should remove *software* breakpoints only | |
2567 | if the section is still mapped, or else we overwrite | |
2568 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2569 | else if (section_is_mapped (bl->section)) |
2570 | val = target_remove_breakpoint (bl->gdbarch, | |
2571 | &bl->target_info); | |
aa67235e UW |
2572 | else |
2573 | val = 0; | |
c906108c | 2574 | } |
c02f5703 MS |
2575 | else |
2576 | { | |
2577 | /* No -- not inserted, so no need to remove. No error. */ | |
2578 | val = 0; | |
2579 | } | |
c906108c | 2580 | } |
879d1e6b UW |
2581 | |
2582 | /* In some cases, we might not be able to remove a breakpoint | |
2583 | in a shared library that has already been removed, but we | |
2584 | have not yet processed the shlib unload event. */ | |
35df4500 | 2585 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2586 | val = 0; |
2587 | ||
c906108c SS |
2588 | if (val) |
2589 | return val; | |
35df4500 | 2590 | bl->inserted = (is == mark_inserted); |
c906108c | 2591 | } |
35df4500 | 2592 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2593 | { |
77b06cd7 TJB |
2594 | gdb_assert (bl->owner->ops != NULL |
2595 | && bl->owner->ops->remove_location != NULL); | |
2596 | ||
35df4500 | 2597 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2598 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2599 | |
c906108c | 2600 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2601 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2602 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2603 | bl->owner->number); |
c906108c | 2604 | } |
35df4500 TJB |
2605 | else if (bl->owner->type == bp_catchpoint |
2606 | && breakpoint_enabled (bl->owner) | |
2607 | && !bl->duplicate) | |
ce78b96d | 2608 | { |
77b06cd7 TJB |
2609 | gdb_assert (bl->owner->ops != NULL |
2610 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2611 | |
77b06cd7 | 2612 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2613 | if (val) |
2614 | return val; | |
77b06cd7 | 2615 | |
35df4500 | 2616 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2617 | } |
c906108c SS |
2618 | |
2619 | return 0; | |
2620 | } | |
2621 | ||
6c95b8df | 2622 | static int |
35df4500 | 2623 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2624 | { |
2625 | int ret; | |
2626 | struct cleanup *old_chain; | |
2627 | ||
35df4500 TJB |
2628 | /* BL is never in moribund_locations by our callers. */ |
2629 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2630 | |
35df4500 | 2631 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2632 | /* Permanent breakpoints cannot be inserted or removed. */ |
2633 | return 0; | |
2634 | ||
2635 | /* The type of none suggests that owner is actually deleted. | |
2636 | This should not ever happen. */ | |
35df4500 | 2637 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2638 | |
2639 | old_chain = save_current_space_and_thread (); | |
2640 | ||
35df4500 | 2641 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2642 | |
35df4500 | 2643 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2644 | |
2645 | do_cleanups (old_chain); | |
2646 | return ret; | |
2647 | } | |
2648 | ||
c906108c SS |
2649 | /* Clear the "inserted" flag in all breakpoints. */ |
2650 | ||
25b22b0a | 2651 | void |
fba45db2 | 2652 | mark_breakpoints_out (void) |
c906108c | 2653 | { |
35df4500 | 2654 | struct bp_location *bl, **blp_tmp; |
c906108c | 2655 | |
35df4500 TJB |
2656 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2657 | if (bl->pspace == current_program_space) | |
2658 | bl->inserted = 0; | |
c906108c SS |
2659 | } |
2660 | ||
53a5351d JM |
2661 | /* Clear the "inserted" flag in all breakpoints and delete any |
2662 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2663 | |
2664 | Plus other such housekeeping that has to be done for breakpoints | |
2665 | between runs. | |
2666 | ||
53a5351d JM |
2667 | Note: this function gets called at the end of a run (by |
2668 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2669 | init_wait_for_inferior). */ |
c906108c SS |
2670 | |
2671 | ||
2672 | ||
2673 | void | |
fba45db2 | 2674 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2675 | { |
35df4500 TJB |
2676 | struct breakpoint *b, *b_tmp; |
2677 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2678 | int ix; |
6c95b8df | 2679 | struct program_space *pspace = current_program_space; |
c906108c | 2680 | |
50c71eaf PA |
2681 | /* If breakpoint locations are shared across processes, then there's |
2682 | nothing to do. */ | |
2567c7d9 | 2683 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2684 | return; |
2685 | ||
35df4500 | 2686 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2687 | { |
35df4500 TJB |
2688 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2689 | if (bl->pspace == pspace | |
2690 | && bl->owner->enable_state != bp_permanent) | |
2691 | bl->inserted = 0; | |
6c95b8df | 2692 | } |
075f6582 | 2693 | |
35df4500 | 2694 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2695 | { |
6c95b8df PA |
2696 | if (b->loc && b->loc->pspace != pspace) |
2697 | continue; | |
2698 | ||
c5aa993b JM |
2699 | switch (b->type) |
2700 | { | |
2701 | case bp_call_dummy: | |
c906108c | 2702 | |
c5aa993b | 2703 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2704 | cause problems when the inferior is rerun, so we better get |
2705 | rid of it. */ | |
2706 | ||
2707 | case bp_watchpoint_scope: | |
2708 | ||
2709 | /* Also get rid of scope breakpoints. */ | |
2710 | ||
2711 | case bp_shlib_event: | |
2712 | ||
2713 | /* Also remove solib event breakpoints. Their addresses may | |
2714 | have changed since the last time we ran the program. | |
2715 | Actually we may now be debugging against different target; | |
2716 | and so the solib backend that installed this breakpoint may | |
2717 | not be used in by the target. E.g., | |
2718 | ||
2719 | (gdb) file prog-linux | |
2720 | (gdb) run # native linux target | |
2721 | ... | |
2722 | (gdb) kill | |
2723 | (gdb) file prog-win.exe | |
2724 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2725 | */ | |
c906108c | 2726 | |
c5aa993b JM |
2727 | delete_breakpoint (b); |
2728 | break; | |
c906108c | 2729 | |
c5aa993b JM |
2730 | case bp_watchpoint: |
2731 | case bp_hardware_watchpoint: | |
2732 | case bp_read_watchpoint: | |
2733 | case bp_access_watchpoint: | |
c906108c | 2734 | |
c5aa993b JM |
2735 | /* Likewise for watchpoints on local expressions. */ |
2736 | if (b->exp_valid_block != NULL) | |
2737 | delete_breakpoint (b); | |
967af18d | 2738 | else if (context == inf_starting) |
c860120c | 2739 | { |
4a64f543 MS |
2740 | /* Reset val field to force reread of starting value in |
2741 | insert_breakpoints. */ | |
c860120c PM |
2742 | if (b->val) |
2743 | value_free (b->val); | |
2744 | b->val = NULL; | |
fa4727a6 | 2745 | b->val_valid = 0; |
c860120c | 2746 | } |
c5aa993b JM |
2747 | break; |
2748 | default: | |
c5aa993b JM |
2749 | break; |
2750 | } | |
2751 | } | |
1c5cfe86 PA |
2752 | |
2753 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2754 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2755 | decref_bp_location (&bl); | |
1c5cfe86 | 2756 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2757 | } |
2758 | ||
6c95b8df PA |
2759 | /* These functions concern about actual breakpoints inserted in the |
2760 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2761 | we need to hop over the bkpt --- so we check for address space | |
2762 | match, not program space. */ | |
2763 | ||
c2c6d25f JM |
2764 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2765 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2766 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2767 | permanent breakpoint. | |
2768 | - When continuing from a location with an ordinary breakpoint, we | |
2769 | actually single step once before calling insert_breakpoints. | |
2770 | - When continuing from a localion with a permanent breakpoint, we | |
2771 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2772 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2773 | |
c2c6d25f | 2774 | enum breakpoint_here |
6c95b8df | 2775 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2776 | { |
35df4500 | 2777 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2778 | int any_breakpoint_here = 0; |
c906108c | 2779 | |
35df4500 | 2780 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2781 | { |
35df4500 TJB |
2782 | if (bl->loc_type != bp_loc_software_breakpoint |
2783 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2784 | continue; |
2785 | ||
35df4500 TJB |
2786 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2787 | if ((breakpoint_enabled (bl->owner) | |
2788 | || bl->owner->enable_state == bp_permanent) | |
2789 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2790 | aspace, pc)) |
075f6582 DJ |
2791 | { |
2792 | if (overlay_debugging | |
35df4500 TJB |
2793 | && section_is_overlay (bl->section) |
2794 | && !section_is_mapped (bl->section)) | |
075f6582 | 2795 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2796 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2797 | return permanent_breakpoint_here; |
2798 | else | |
2799 | any_breakpoint_here = 1; | |
2800 | } | |
2801 | } | |
c906108c | 2802 | |
c2c6d25f | 2803 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2804 | } |
2805 | ||
1c5cfe86 PA |
2806 | /* Return true if there's a moribund breakpoint at PC. */ |
2807 | ||
2808 | int | |
6c95b8df | 2809 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2810 | { |
2811 | struct bp_location *loc; | |
2812 | int ix; | |
2813 | ||
2814 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2815 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2816 | aspace, pc)) | |
1c5cfe86 PA |
2817 | return 1; |
2818 | ||
2819 | return 0; | |
2820 | } | |
c2c6d25f | 2821 | |
c36b740a | 2822 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2823 | inserted using regular breakpoint_chain / bp_location array |
2824 | mechanism. This does not check for single-step breakpoints, which | |
2825 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2826 | |
2827 | int | |
4a64f543 MS |
2828 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2829 | CORE_ADDR pc) | |
c906108c | 2830 | { |
35df4500 | 2831 | struct bp_location *bl, **blp_tmp; |
c906108c | 2832 | |
35df4500 | 2833 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2834 | { |
35df4500 TJB |
2835 | if (bl->loc_type != bp_loc_software_breakpoint |
2836 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2837 | continue; |
2838 | ||
35df4500 TJB |
2839 | if (bl->inserted |
2840 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2841 | aspace, pc)) |
075f6582 DJ |
2842 | { |
2843 | if (overlay_debugging | |
35df4500 TJB |
2844 | && section_is_overlay (bl->section) |
2845 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2846 | continue; /* unmapped overlay -- can't be a match */ |
2847 | else | |
2848 | return 1; | |
2849 | } | |
c5aa993b | 2850 | } |
c36b740a VP |
2851 | return 0; |
2852 | } | |
2853 | ||
2854 | /* Returns non-zero iff there's either regular breakpoint | |
2855 | or a single step breakpoint inserted at PC. */ | |
2856 | ||
2857 | int | |
6c95b8df | 2858 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2859 | { |
6c95b8df | 2860 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2861 | return 1; |
c906108c | 2862 | |
6c95b8df | 2863 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2864 | return 1; |
2865 | ||
c906108c SS |
2866 | return 0; |
2867 | } | |
2868 | ||
4fa8626c DJ |
2869 | /* This function returns non-zero iff there is a software breakpoint |
2870 | inserted at PC. */ | |
2871 | ||
2872 | int | |
3e43a32a MS |
2873 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2874 | CORE_ADDR pc) | |
4fa8626c | 2875 | { |
35df4500 | 2876 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2877 | |
35df4500 | 2878 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2879 | { |
35df4500 | 2880 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2881 | continue; |
2882 | ||
35df4500 TJB |
2883 | if (bl->inserted |
2884 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2885 | aspace, pc)) |
4fa8626c DJ |
2886 | { |
2887 | if (overlay_debugging | |
35df4500 TJB |
2888 | && section_is_overlay (bl->section) |
2889 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2890 | continue; /* unmapped overlay -- can't be a match */ |
2891 | else | |
2892 | return 1; | |
2893 | } | |
2894 | } | |
2895 | ||
1aafd4da | 2896 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2897 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2898 | return 1; |
2899 | ||
4fa8626c DJ |
2900 | return 0; |
2901 | } | |
2902 | ||
9093389c PA |
2903 | int |
2904 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2905 | CORE_ADDR addr, ULONGEST len) | |
2906 | { | |
2907 | struct breakpoint *bpt; | |
2908 | ||
2909 | ALL_BREAKPOINTS (bpt) | |
2910 | { | |
2911 | struct bp_location *loc; | |
2912 | ||
2913 | if (bpt->type != bp_hardware_watchpoint | |
2914 | && bpt->type != bp_access_watchpoint) | |
2915 | continue; | |
2916 | ||
2917 | if (!breakpoint_enabled (bpt)) | |
2918 | continue; | |
2919 | ||
2920 | for (loc = bpt->loc; loc; loc = loc->next) | |
2921 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2922 | { | |
2923 | CORE_ADDR l, h; | |
2924 | ||
2925 | /* Check for intersection. */ | |
2926 | l = max (loc->address, addr); | |
2927 | h = min (loc->address + loc->length, addr + len); | |
2928 | if (l < h) | |
2929 | return 1; | |
2930 | } | |
2931 | } | |
2932 | return 0; | |
2933 | } | |
2934 | ||
075f6582 DJ |
2935 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2936 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2937 | |
2938 | int | |
6c95b8df PA |
2939 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2940 | ptid_t ptid) | |
c906108c | 2941 | { |
35df4500 | 2942 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2943 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2944 | int thread = -1; |
4a306c9a | 2945 | int task = 0; |
a6f1cd96 | 2946 | |
35df4500 | 2947 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2948 | { |
35df4500 TJB |
2949 | if (bl->loc_type != bp_loc_software_breakpoint |
2950 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2951 | continue; |
2952 | ||
35df4500 TJB |
2953 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2954 | if (!breakpoint_enabled (bl->owner) | |
2955 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2956 | continue; |
2957 | ||
35df4500 | 2958 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
6c95b8df | 2959 | aspace, pc)) |
a6f1cd96 JB |
2960 | continue; |
2961 | ||
35df4500 | 2962 | if (bl->owner->thread != -1) |
075f6582 | 2963 | { |
a6f1cd96 JB |
2964 | /* This is a thread-specific breakpoint. Check that ptid |
2965 | matches that thread. If thread hasn't been computed yet, | |
2966 | it is now time to do so. */ | |
2967 | if (thread == -1) | |
2968 | thread = pid_to_thread_id (ptid); | |
35df4500 | 2969 | if (bl->owner->thread != thread) |
a6f1cd96 | 2970 | continue; |
075f6582 | 2971 | } |
a6f1cd96 | 2972 | |
35df4500 | 2973 | if (bl->owner->task != 0) |
4a306c9a JB |
2974 | { |
2975 | /* This is a task-specific breakpoint. Check that ptid | |
2976 | matches that task. If task hasn't been computed yet, | |
2977 | it is now time to do so. */ | |
2978 | if (task == 0) | |
2979 | task = ada_get_task_number (ptid); | |
35df4500 | 2980 | if (bl->owner->task != task) |
4a306c9a JB |
2981 | continue; |
2982 | } | |
2983 | ||
a6f1cd96 | 2984 | if (overlay_debugging |
35df4500 TJB |
2985 | && section_is_overlay (bl->section) |
2986 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
2987 | continue; /* unmapped overlay -- can't be a match */ |
2988 | ||
2989 | return 1; | |
c5aa993b | 2990 | } |
c906108c SS |
2991 | |
2992 | return 0; | |
2993 | } | |
c906108c | 2994 | \f |
c5aa993b | 2995 | |
c906108c SS |
2996 | /* bpstat stuff. External routines' interfaces are documented |
2997 | in breakpoint.h. */ | |
2998 | ||
2999 | int | |
fba45db2 | 3000 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3001 | { |
533be4dd | 3002 | return (ep->type == bp_catchpoint); |
c906108c SS |
3003 | } |
3004 | ||
f431efe5 PA |
3005 | /* Frees any storage that is part of a bpstat. Does not walk the |
3006 | 'next' chain. */ | |
3007 | ||
3008 | static void | |
198757a8 VP |
3009 | bpstat_free (bpstat bs) |
3010 | { | |
3011 | if (bs->old_val != NULL) | |
3012 | value_free (bs->old_val); | |
9add0f1b | 3013 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3014 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3015 | xfree (bs); |
3016 | } | |
3017 | ||
c906108c SS |
3018 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3019 | Also free any storage that is part of a bpstat. */ | |
3020 | ||
3021 | void | |
fba45db2 | 3022 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3023 | { |
3024 | bpstat p; | |
3025 | bpstat q; | |
3026 | ||
3027 | if (bsp == 0) | |
3028 | return; | |
3029 | p = *bsp; | |
3030 | while (p != NULL) | |
3031 | { | |
3032 | q = p->next; | |
198757a8 | 3033 | bpstat_free (p); |
c906108c SS |
3034 | p = q; |
3035 | } | |
3036 | *bsp = NULL; | |
3037 | } | |
3038 | ||
3039 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3040 | is part of the bpstat is copied as well. */ | |
3041 | ||
3042 | bpstat | |
fba45db2 | 3043 | bpstat_copy (bpstat bs) |
c906108c SS |
3044 | { |
3045 | bpstat p = NULL; | |
3046 | bpstat tmp; | |
3047 | bpstat retval = NULL; | |
3048 | ||
3049 | if (bs == NULL) | |
3050 | return bs; | |
3051 | ||
3052 | for (; bs != NULL; bs = bs->next) | |
3053 | { | |
3054 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3055 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3056 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3057 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3058 | if (bs->old_val != NULL) |
3c3185ac JK |
3059 | { |
3060 | tmp->old_val = value_copy (bs->old_val); | |
3061 | release_value (tmp->old_val); | |
3062 | } | |
31cc81e9 | 3063 | |
c906108c SS |
3064 | if (p == NULL) |
3065 | /* This is the first thing in the chain. */ | |
3066 | retval = tmp; | |
3067 | else | |
3068 | p->next = tmp; | |
3069 | p = tmp; | |
3070 | } | |
3071 | p->next = NULL; | |
3072 | return retval; | |
3073 | } | |
3074 | ||
4a64f543 | 3075 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3076 | |
3077 | bpstat | |
fba45db2 | 3078 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3079 | { |
c5aa993b JM |
3080 | if (bsp == NULL) |
3081 | return NULL; | |
c906108c | 3082 | |
c5aa993b JM |
3083 | for (; bsp != NULL; bsp = bsp->next) |
3084 | { | |
f431efe5 | 3085 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3086 | return bsp; |
3087 | } | |
c906108c SS |
3088 | return NULL; |
3089 | } | |
3090 | ||
4a64f543 MS |
3091 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3092 | stopped at. *BSP upon return is a bpstat which points to the | |
3093 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3094 | good for anything but further calls to bpstat_num). | |
3095 | ||
8671a17b PA |
3096 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3097 | Return -1 if stopped at a breakpoint that has been deleted since | |
3098 | we set it. | |
3099 | Return 1 otherwise. */ | |
c906108c SS |
3100 | |
3101 | int | |
8671a17b | 3102 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3103 | { |
3104 | struct breakpoint *b; | |
3105 | ||
3106 | if ((*bsp) == NULL) | |
3107 | return 0; /* No more breakpoint values */ | |
8671a17b | 3108 | |
4a64f543 MS |
3109 | /* We assume we'll never have several bpstats that correspond to a |
3110 | single breakpoint -- otherwise, this function might return the | |
3111 | same number more than once and this will look ugly. */ | |
f431efe5 | 3112 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3113 | *bsp = (*bsp)->next; |
3114 | if (b == NULL) | |
3115 | return -1; /* breakpoint that's been deleted since */ | |
3116 | ||
3117 | *num = b->number; /* We have its number */ | |
3118 | return 1; | |
c906108c SS |
3119 | } |
3120 | ||
3121 | /* Modify BS so that the actions will not be performed. */ | |
3122 | ||
3123 | void | |
fba45db2 | 3124 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3125 | { |
3126 | for (; bs != NULL; bs = bs->next) | |
3127 | { | |
9add0f1b | 3128 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3129 | bs->commands_left = NULL; |
c906108c SS |
3130 | if (bs->old_val != NULL) |
3131 | { | |
3132 | value_free (bs->old_val); | |
3133 | bs->old_val = NULL; | |
3134 | } | |
3135 | } | |
3136 | } | |
3137 | ||
f3b1572e PA |
3138 | /* Called when a command is about to proceed the inferior. */ |
3139 | ||
3140 | static void | |
3141 | breakpoint_about_to_proceed (void) | |
3142 | { | |
3143 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3144 | { | |
3145 | struct thread_info *tp = inferior_thread (); | |
3146 | ||
3147 | /* Allow inferior function calls in breakpoint commands to not | |
3148 | interrupt the command list. When the call finishes | |
3149 | successfully, the inferior will be standing at the same | |
3150 | breakpoint as if nothing happened. */ | |
16c381f0 | 3151 | if (tp->control.in_infcall) |
f3b1572e PA |
3152 | return; |
3153 | } | |
3154 | ||
3155 | breakpoint_proceeded = 1; | |
3156 | } | |
3157 | ||
4a64f543 MS |
3158 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3159 | command. */ | |
c906108c | 3160 | static void |
4efb68b1 | 3161 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3162 | { |
3163 | executing_breakpoint_commands = 0; | |
3164 | } | |
3165 | ||
4a64f543 MS |
3166 | /* Execute all the commands associated with all the breakpoints at |
3167 | this location. Any of these commands could cause the process to | |
3168 | proceed beyond this point, etc. We look out for such changes by | |
3169 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3170 | |
347bddb7 PA |
3171 | Returns true if a breakpoint command resumed the inferior. In that |
3172 | case, it is the caller's responsibility to recall it again with the | |
3173 | bpstat of the current thread. */ | |
3174 | ||
3175 | static int | |
3176 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3177 | { |
3178 | bpstat bs; | |
3179 | struct cleanup *old_chain; | |
347bddb7 | 3180 | int again = 0; |
c906108c SS |
3181 | |
3182 | /* Avoid endless recursion if a `source' command is contained | |
3183 | in bs->commands. */ | |
3184 | if (executing_breakpoint_commands) | |
347bddb7 | 3185 | return 0; |
c906108c SS |
3186 | |
3187 | executing_breakpoint_commands = 1; | |
3188 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3189 | ||
4a64f543 | 3190 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3191 | bs = *bsp; |
3192 | ||
3193 | breakpoint_proceeded = 0; | |
3194 | for (; bs != NULL; bs = bs->next) | |
3195 | { | |
9add0f1b | 3196 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3197 | struct command_line *cmd; |
3198 | struct cleanup *this_cmd_tree_chain; | |
3199 | ||
3200 | /* Take ownership of the BSP's command tree, if it has one. | |
3201 | ||
3202 | The command tree could legitimately contain commands like | |
3203 | 'step' and 'next', which call clear_proceed_status, which | |
3204 | frees stop_bpstat's command tree. To make sure this doesn't | |
3205 | free the tree we're executing out from under us, we need to | |
3206 | take ownership of the tree ourselves. Since a given bpstat's | |
3207 | commands are only executed once, we don't need to copy it; we | |
3208 | can clear the pointer in the bpstat, and make sure we free | |
3209 | the tree when we're done. */ | |
9add0f1b TT |
3210 | ccmd = bs->commands; |
3211 | bs->commands = NULL; | |
3212 | this_cmd_tree_chain | |
3213 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3214 | cmd = bs->commands_left; | |
3215 | bs->commands_left = NULL; | |
6c50ab1c | 3216 | |
c906108c SS |
3217 | while (cmd != NULL) |
3218 | { | |
3219 | execute_control_command (cmd); | |
3220 | ||
3221 | if (breakpoint_proceeded) | |
3222 | break; | |
3223 | else | |
3224 | cmd = cmd->next; | |
3225 | } | |
6c50ab1c JB |
3226 | |
3227 | /* We can free this command tree now. */ | |
3228 | do_cleanups (this_cmd_tree_chain); | |
3229 | ||
c906108c | 3230 | if (breakpoint_proceeded) |
32c1e744 VP |
3231 | { |
3232 | if (target_can_async_p ()) | |
347bddb7 PA |
3233 | /* If we are in async mode, then the target might be still |
3234 | running, not stopped at any breakpoint, so nothing for | |
3235 | us to do here -- just return to the event loop. */ | |
3236 | ; | |
32c1e744 VP |
3237 | else |
3238 | /* In sync mode, when execute_control_command returns | |
3239 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3240 | Breakpoint commands for that stop were not run, since |
3241 | execute_command does not run breakpoint commands -- | |
3242 | only command_line_handler does, but that one is not | |
3243 | involved in execution of breakpoint commands. So, we | |
3244 | can now execute breakpoint commands. It should be | |
3245 | noted that making execute_command do bpstat actions is | |
3246 | not an option -- in this case we'll have recursive | |
3247 | invocation of bpstat for each breakpoint with a | |
3248 | command, and can easily blow up GDB stack. Instead, we | |
3249 | return true, which will trigger the caller to recall us | |
3250 | with the new stop_bpstat. */ | |
3251 | again = 1; | |
3252 | break; | |
32c1e744 | 3253 | } |
c906108c | 3254 | } |
c2b8ed2c | 3255 | do_cleanups (old_chain); |
347bddb7 PA |
3256 | return again; |
3257 | } | |
3258 | ||
3259 | void | |
3260 | bpstat_do_actions (void) | |
3261 | { | |
3262 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3263 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3264 | && target_has_execution | |
3265 | && !is_exited (inferior_ptid) | |
3266 | && !is_executing (inferior_ptid)) | |
3267 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3268 | and only return when it is stopped at the next breakpoint, we | |
3269 | keep doing breakpoint actions until it returns false to | |
3270 | indicate the inferior was not resumed. */ | |
16c381f0 | 3271 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3272 | break; |
c906108c SS |
3273 | } |
3274 | ||
fa4727a6 DJ |
3275 | /* Print out the (old or new) value associated with a watchpoint. */ |
3276 | ||
3277 | static void | |
3278 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3279 | { | |
3280 | if (val == NULL) | |
3281 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3282 | else | |
79a45b7d TT |
3283 | { |
3284 | struct value_print_options opts; | |
3285 | get_user_print_options (&opts); | |
3286 | value_print (val, stream, &opts); | |
3287 | } | |
fa4727a6 DJ |
3288 | } |
3289 | ||
e514a9d6 | 3290 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3291 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3292 | by having it set different print_it values. |
3293 | ||
3294 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3295 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3296 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3297 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3298 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3299 | |
3300 | Return values from this routine (ultimately used by bpstat_print() | |
3301 | and normal_stop() to decide what to do): | |
3302 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3303 | don't print anything else. | |
3304 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3305 | that something to be followed by a location. | |
3306 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3307 | that something to be followed by a location. | |
3308 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3309 | analysis. */ | |
c906108c | 3310 | |
917317f4 | 3311 | static enum print_stop_action |
fba45db2 | 3312 | print_it_typical (bpstat bs) |
c906108c | 3313 | { |
f7545552 | 3314 | struct cleanup *old_chain; |
4f8d1dc6 | 3315 | struct breakpoint *b; |
89f9893c | 3316 | const struct bp_location *bl; |
8b93c638 | 3317 | struct ui_stream *stb; |
f7545552 TT |
3318 | int bp_temp = 0; |
3319 | enum print_stop_action result; | |
3320 | ||
f431efe5 PA |
3321 | gdb_assert (bs->bp_location_at != NULL); |
3322 | ||
3323 | bl = bs->bp_location_at; | |
3324 | b = bs->breakpoint_at; | |
c906108c | 3325 | |
f7545552 TT |
3326 | stb = ui_out_stream_new (uiout); |
3327 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3328 | ||
4f8d1dc6 | 3329 | switch (b->type) |
c906108c | 3330 | { |
e514a9d6 JM |
3331 | case bp_breakpoint: |
3332 | case bp_hardware_breakpoint: | |
f431efe5 | 3333 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3334 | if (bl->address != bl->requested_address) |
3335 | breakpoint_adjustment_warning (bl->requested_address, | |
3336 | bl->address, | |
4f8d1dc6 VP |
3337 | b->number, 1); |
3338 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3339 | if (bp_temp) |
3340 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3341 | else | |
3342 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3343 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3344 | { |
3345 | ui_out_field_string (uiout, "reason", | |
3346 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3347 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3348 | } | |
4f8d1dc6 | 3349 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3350 | ui_out_text (uiout, ", "); |
f7545552 | 3351 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3352 | break; |
3353 | ||
3354 | case bp_shlib_event: | |
917317f4 JM |
3355 | /* Did we stop because the user set the stop_on_solib_events |
3356 | variable? (If so, we report this as a generic, "Stopped due | |
3357 | to shlib event" message.) */ | |
a3f17187 | 3358 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3359 | result = PRINT_NOTHING; |
e514a9d6 JM |
3360 | break; |
3361 | ||
c4093a6a | 3362 | case bp_thread_event: |
4a64f543 | 3363 | /* Not sure how we will get here. |
c4093a6a | 3364 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3365 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3366 | result = PRINT_NOTHING; |
c4093a6a JM |
3367 | break; |
3368 | ||
1900040c | 3369 | case bp_overlay_event: |
4a64f543 | 3370 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3371 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3372 | result = PRINT_NOTHING; |
1900040c MS |
3373 | break; |
3374 | ||
0fd8e87f UW |
3375 | case bp_longjmp_master: |
3376 | /* These should never be enabled. */ | |
3377 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3378 | result = PRINT_NOTHING; | |
3379 | break; | |
3380 | ||
aa7d318d TT |
3381 | case bp_std_terminate_master: |
3382 | /* These should never be enabled. */ | |
3e43a32a MS |
3383 | printf_filtered (_("std::terminate Master Breakpoint: " |
3384 | "gdb should not stop!\n")); | |
aa7d318d TT |
3385 | result = PRINT_NOTHING; |
3386 | break; | |
3387 | ||
186c406b TT |
3388 | case bp_exception_master: |
3389 | /* These should never be enabled. */ | |
3e43a32a MS |
3390 | printf_filtered (_("Exception Master Breakpoint: " |
3391 | "gdb should not stop!\n")); | |
186c406b TT |
3392 | result = PRINT_NOTHING; |
3393 | break; | |
3394 | ||
e514a9d6 JM |
3395 | case bp_watchpoint: |
3396 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3397 | annotate_watchpoint (b->number); |
3398 | if (ui_out_is_mi_like_p (uiout)) | |
3399 | ui_out_field_string | |
3400 | (uiout, "reason", | |
3401 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3402 | mention (b); | |
f7545552 | 3403 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3404 | ui_out_text (uiout, "\nOld value = "); |
3405 | watchpoint_value_print (bs->old_val, stb->stream); | |
3406 | ui_out_field_stream (uiout, "old", stb); | |
3407 | ui_out_text (uiout, "\nNew value = "); | |
3408 | watchpoint_value_print (b->val, stb->stream); | |
3409 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3410 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3411 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3412 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3413 | break; |
3414 | ||
3415 | case bp_read_watchpoint: | |
9dc5e2a9 | 3416 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3417 | ui_out_field_string |
3418 | (uiout, "reason", | |
3419 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3420 | mention (b); |
f7545552 | 3421 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3422 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3423 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3424 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3425 | ui_out_text (uiout, "\n"); |
f7545552 | 3426 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3427 | break; |
3428 | ||
3429 | case bp_access_watchpoint: | |
fa4727a6 | 3430 | if (bs->old_val != NULL) |
8b93c638 | 3431 | { |
4f8d1dc6 | 3432 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3433 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3434 | ui_out_field_string |
3435 | (uiout, "reason", | |
3436 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3437 | mention (b); |
f7545552 | 3438 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3439 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3440 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3441 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3442 | ui_out_text (uiout, "\nNew value = "); |
3443 | } | |
3444 | else | |
3445 | { | |
4f8d1dc6 | 3446 | mention (b); |
9dc5e2a9 | 3447 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3448 | ui_out_field_string |
3449 | (uiout, "reason", | |
3450 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3451 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3452 | ui_out_text (uiout, "\nValue = "); |
3453 | } | |
fa4727a6 | 3454 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3455 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3456 | ui_out_text (uiout, "\n"); |
f7545552 | 3457 | result = PRINT_UNKNOWN; |
e514a9d6 | 3458 | break; |
4ce44c66 | 3459 | |
e514a9d6 | 3460 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3461 | here. */ |
e514a9d6 | 3462 | |
11cf8741 | 3463 | case bp_finish: |
9dc5e2a9 | 3464 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3465 | ui_out_field_string |
3466 | (uiout, "reason", | |
3467 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3468 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3469 | break; |
3470 | ||
e514a9d6 | 3471 | case bp_until: |
9dc5e2a9 | 3472 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3473 | ui_out_field_string |
3474 | (uiout, "reason", | |
3475 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3476 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3477 | break; |
3478 | ||
c2d11a7d | 3479 | case bp_none: |
e514a9d6 JM |
3480 | case bp_longjmp: |
3481 | case bp_longjmp_resume: | |
186c406b TT |
3482 | case bp_exception: |
3483 | case bp_exception_resume: | |
e514a9d6 | 3484 | case bp_step_resume: |
e514a9d6 JM |
3485 | case bp_watchpoint_scope: |
3486 | case bp_call_dummy: | |
aa7d318d | 3487 | case bp_std_terminate: |
1042e4c0 | 3488 | case bp_tracepoint: |
7a697b8d | 3489 | case bp_fast_tracepoint: |
4efc6507 | 3490 | case bp_jit_event: |
e514a9d6 | 3491 | default: |
f7545552 TT |
3492 | result = PRINT_UNKNOWN; |
3493 | break; | |
e514a9d6 | 3494 | } |
f7545552 TT |
3495 | |
3496 | do_cleanups (old_chain); | |
3497 | return result; | |
e514a9d6 JM |
3498 | } |
3499 | ||
3500 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3501 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3502 | 'print_it' in the bpstat structure. Under some circumstances we |
3503 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3504 | normal_stop(). */ |
e514a9d6 JM |
3505 | |
3506 | static enum print_stop_action | |
3507 | print_bp_stop_message (bpstat bs) | |
3508 | { | |
3509 | switch (bs->print_it) | |
3510 | { | |
3511 | case print_it_noop: | |
4a64f543 | 3512 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3513 | return PRINT_UNKNOWN; |
3514 | break; | |
3515 | ||
3516 | case print_it_done: | |
3517 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3518 | relevant messages. */ |
e514a9d6 JM |
3519 | return PRINT_SRC_AND_LOC; |
3520 | break; | |
3521 | ||
3522 | case print_it_normal: | |
4f8d1dc6 | 3523 | { |
f431efe5 PA |
3524 | struct breakpoint *b = bs->breakpoint_at; |
3525 | ||
1a6a67de TJB |
3526 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3527 | which has since been deleted. */ | |
3528 | if (b == NULL) | |
3529 | return PRINT_UNKNOWN; | |
3530 | ||
4f8d1dc6 VP |
3531 | /* Normal case. Call the breakpoint's print_it method, or |
3532 | print_it_typical. */ | |
1a6a67de | 3533 | if (b->ops != NULL && b->ops->print_it != NULL) |
4f8d1dc6 VP |
3534 | return b->ops->print_it (b); |
3535 | else | |
3536 | return print_it_typical (bs); | |
3537 | } | |
3538 | break; | |
3086aeae | 3539 | |
e514a9d6 | 3540 | default: |
8e65ff28 | 3541 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3542 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3543 | break; |
c906108c | 3544 | } |
c906108c SS |
3545 | } |
3546 | ||
e514a9d6 JM |
3547 | /* Print a message indicating what happened. This is called from |
3548 | normal_stop(). The input to this routine is the head of the bpstat | |
3549 | list - a list of the eventpoints that caused this stop. This | |
3550 | routine calls the generic print routine for printing a message | |
3551 | about reasons for stopping. This will print (for example) the | |
3552 | "Breakpoint n," part of the output. The return value of this | |
3553 | routine is one of: | |
c906108c | 3554 | |
4a64f543 | 3555 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3556 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3557 | code to print the location. An example is |
c5aa993b JM |
3558 | "Breakpoint 1, " which should be followed by |
3559 | the location. | |
917317f4 | 3560 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3561 | to also print the location part of the message. |
3562 | An example is the catch/throw messages, which | |
4a64f543 | 3563 | don't require a location appended to the end. |
917317f4 | 3564 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3565 | further info to be printed. */ |
c906108c | 3566 | |
917317f4 | 3567 | enum print_stop_action |
fba45db2 | 3568 | bpstat_print (bpstat bs) |
c906108c SS |
3569 | { |
3570 | int val; | |
c5aa993b | 3571 | |
c906108c | 3572 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3573 | (Currently all watchpoints go on the bpstat whether hit or not. |
3574 | That probably could (should) be changed, provided care is taken | |
c906108c | 3575 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3576 | for (; bs; bs = bs->next) |
3577 | { | |
3578 | val = print_bp_stop_message (bs); | |
3579 | if (val == PRINT_SRC_ONLY | |
3580 | || val == PRINT_SRC_AND_LOC | |
3581 | || val == PRINT_NOTHING) | |
3582 | return val; | |
3583 | } | |
c906108c | 3584 | |
e514a9d6 | 3585 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3586 | with and nothing was printed. */ |
917317f4 | 3587 | return PRINT_UNKNOWN; |
c906108c SS |
3588 | } |
3589 | ||
4a64f543 MS |
3590 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3591 | used inside a catch_errors to evaluate the breakpoint condition. | |
3592 | The argument is a "struct expression *" that has been cast to a | |
3593 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3594 | |
3595 | static int | |
4efb68b1 | 3596 | breakpoint_cond_eval (void *exp) |
c906108c | 3597 | { |
278cd55f | 3598 | struct value *mark = value_mark (); |
c5aa993b | 3599 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3600 | |
c906108c SS |
3601 | value_free_to_mark (mark); |
3602 | return i; | |
3603 | } | |
3604 | ||
5760d0ab | 3605 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3606 | |
3607 | static bpstat | |
5760d0ab | 3608 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3609 | { |
3610 | bpstat bs; | |
3611 | ||
3612 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3613 | bs->next = NULL; |
3614 | **bs_link_pointer = bs; | |
3615 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3616 | bs->breakpoint_at = bl->owner; |
3617 | bs->bp_location_at = bl; | |
3618 | incref_bp_location (bl); | |
c906108c SS |
3619 | /* If the condition is false, etc., don't do the commands. */ |
3620 | bs->commands = NULL; | |
9add0f1b | 3621 | bs->commands_left = NULL; |
c906108c SS |
3622 | bs->old_val = NULL; |
3623 | bs->print_it = print_it_normal; | |
3624 | return bs; | |
3625 | } | |
3626 | \f | |
d983da9c DJ |
3627 | /* The target has stopped with waitstatus WS. Check if any hardware |
3628 | watchpoints have triggered, according to the target. */ | |
3629 | ||
3630 | int | |
3631 | watchpoints_triggered (struct target_waitstatus *ws) | |
3632 | { | |
d92524f1 | 3633 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3634 | CORE_ADDR addr; |
3635 | struct breakpoint *b; | |
3636 | ||
3637 | if (!stopped_by_watchpoint) | |
3638 | { | |
3639 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3640 | as not triggered. */ | |
3641 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3642 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3643 | b->watchpoint_triggered = watch_triggered_no; |
3644 | ||
3645 | return 0; | |
3646 | } | |
3647 | ||
3648 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3649 | { | |
3650 | /* We were stopped by a watchpoint, but we don't know where. | |
3651 | Mark all watchpoints as unknown. */ | |
3652 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3653 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3654 | b->watchpoint_triggered = watch_triggered_unknown; |
3655 | ||
3656 | return stopped_by_watchpoint; | |
3657 | } | |
3658 | ||
3659 | /* The target could report the data address. Mark watchpoints | |
3660 | affected by this data address as triggered, and all others as not | |
3661 | triggered. */ | |
3662 | ||
3663 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3664 | if (is_hardware_watchpoint (b)) |
d983da9c | 3665 | { |
a5606eee | 3666 | struct bp_location *loc; |
d983da9c DJ |
3667 | |
3668 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3669 | for (loc = b->loc; loc; loc = loc->next) |
3670 | /* Exact match not required. Within range is | |
3671 | sufficient. */ | |
5009afc5 AS |
3672 | if (target_watchpoint_addr_within_range (¤t_target, |
3673 | addr, loc->address, | |
3674 | loc->length)) | |
a5606eee VP |
3675 | { |
3676 | b->watchpoint_triggered = watch_triggered_yes; | |
3677 | break; | |
3678 | } | |
d983da9c DJ |
3679 | } |
3680 | ||
3681 | return 1; | |
3682 | } | |
3683 | ||
c906108c SS |
3684 | /* Possible return values for watchpoint_check (this can't be an enum |
3685 | because of check_errors). */ | |
3686 | /* The watchpoint has been deleted. */ | |
3687 | #define WP_DELETED 1 | |
3688 | /* The value has changed. */ | |
3689 | #define WP_VALUE_CHANGED 2 | |
3690 | /* The value has not changed. */ | |
3691 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3692 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3693 | #define WP_IGNORE 4 | |
c906108c SS |
3694 | |
3695 | #define BP_TEMPFLAG 1 | |
3696 | #define BP_HARDWAREFLAG 2 | |
3697 | ||
4a64f543 MS |
3698 | /* Evaluate watchpoint condition expression and check if its value |
3699 | changed. | |
553e4c11 JB |
3700 | |
3701 | P should be a pointer to struct bpstat, but is defined as a void * | |
3702 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3703 | |
3704 | static int | |
4efb68b1 | 3705 | watchpoint_check (void *p) |
c906108c SS |
3706 | { |
3707 | bpstat bs = (bpstat) p; | |
3708 | struct breakpoint *b; | |
3709 | struct frame_info *fr; | |
3710 | int within_current_scope; | |
3711 | ||
f431efe5 | 3712 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3713 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3714 | b = bs->breakpoint_at; |
c906108c | 3715 | |
f6bc2008 PA |
3716 | /* If this is a local watchpoint, we only want to check if the |
3717 | watchpoint frame is in scope if the current thread is the thread | |
3718 | that was used to create the watchpoint. */ | |
3719 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3720 | return WP_IGNORE; |
f6bc2008 | 3721 | |
c906108c SS |
3722 | if (b->exp_valid_block == NULL) |
3723 | within_current_scope = 1; | |
3724 | else | |
3725 | { | |
edb3359d DJ |
3726 | struct frame_info *frame = get_current_frame (); |
3727 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3728 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3729 | ||
4a64f543 MS |
3730 | /* in_function_epilogue_p() returns a non-zero value if we're |
3731 | still in the function but the stack frame has already been | |
3732 | invalidated. Since we can't rely on the values of local | |
3733 | variables after the stack has been destroyed, we are treating | |
3734 | the watchpoint in that state as `not changed' without further | |
3735 | checking. Don't mark watchpoints as changed if the current | |
3736 | frame is in an epilogue - even if they are in some other | |
3737 | frame, our view of the stack is likely to be wrong and | |
3738 | frame_find_by_id could error out. */ | |
a0f49112 | 3739 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3740 | return WP_IGNORE; |
a0f49112 | 3741 | |
101dcfbe | 3742 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3743 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3744 | |
3745 | /* If we've gotten confused in the unwinder, we might have | |
3746 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3747 | if (within_current_scope) |
3748 | { | |
3749 | struct symbol *function; | |
3750 | ||
3751 | function = get_frame_function (fr); | |
3752 | if (function == NULL | |
3753 | || !contained_in (b->exp_valid_block, | |
3754 | SYMBOL_BLOCK_VALUE (function))) | |
3755 | within_current_scope = 0; | |
3756 | } | |
69fbadd5 | 3757 | |
edb3359d | 3758 | if (within_current_scope) |
c906108c SS |
3759 | /* If we end up stopping, the current frame will get selected |
3760 | in normal_stop. So this call to select_frame won't affect | |
3761 | the user. */ | |
0f7d239c | 3762 | select_frame (fr); |
c906108c | 3763 | } |
c5aa993b | 3764 | |
c906108c SS |
3765 | if (within_current_scope) |
3766 | { | |
4a64f543 MS |
3767 | /* We use value_{,free_to_}mark because it could be a *long* |
3768 | time before we return to the command level and call | |
3769 | free_all_values. We can't call free_all_values because we | |
3770 | might be in the middle of evaluating a function call. */ | |
c906108c | 3771 | |
0cf6dd15 | 3772 | int pc = 0; |
278cd55f | 3773 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3774 | struct value *new_val; |
3775 | ||
0cf6dd15 | 3776 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3777 | |
4a64f543 MS |
3778 | /* We use value_equal_contents instead of value_equal because |
3779 | the latter coerces an array to a pointer, thus comparing just | |
3780 | the address of the array instead of its contents. This is | |
3781 | not what we want. */ | |
fa4727a6 | 3782 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3783 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3784 | { |
fa4727a6 DJ |
3785 | if (new_val != NULL) |
3786 | { | |
3787 | release_value (new_val); | |
3788 | value_free_to_mark (mark); | |
3789 | } | |
c906108c SS |
3790 | bs->old_val = b->val; |
3791 | b->val = new_val; | |
fa4727a6 | 3792 | b->val_valid = 1; |
c906108c SS |
3793 | return WP_VALUE_CHANGED; |
3794 | } | |
3795 | else | |
3796 | { | |
60e1c644 | 3797 | /* Nothing changed. */ |
c906108c | 3798 | value_free_to_mark (mark); |
c906108c SS |
3799 | return WP_VALUE_NOT_CHANGED; |
3800 | } | |
3801 | } | |
3802 | else | |
3803 | { | |
3804 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3805 | if we temporarily ignored the watchpoint, then when |
3806 | we reenter the block in which it is valid it contains | |
3807 | garbage (in the case of a function, it may have two | |
3808 | garbage values, one before and one after the prologue). | |
3809 | So we can't even detect the first assignment to it and | |
3810 | watch after that (since the garbage may or may not equal | |
3811 | the first value assigned). */ | |
4ce44c66 JM |
3812 | /* We print all the stop information in print_it_typical(), but |
3813 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3814 | will be deleted already. So we have no choice but print the |
3815 | information here. */ | |
9dc5e2a9 | 3816 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3817 | ui_out_field_string |
3818 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3819 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3820 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3821 | ui_out_text (uiout, |
3822 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3823 | which its expression is valid.\n"); |
4ce44c66 | 3824 | |
c906108c | 3825 | if (b->related_breakpoint) |
60e1c644 PA |
3826 | { |
3827 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3828 | b->related_breakpoint->related_breakpoint = NULL; | |
3829 | b->related_breakpoint = NULL; | |
3830 | } | |
b5de0fa7 | 3831 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3832 | |
3833 | return WP_DELETED; | |
3834 | } | |
3835 | } | |
3836 | ||
18a18393 VP |
3837 | /* Return true if it looks like target has stopped due to hitting |
3838 | breakpoint location BL. This function does not check if we | |
3839 | should stop, only if BL explains the stop. */ | |
3840 | static int | |
6c95b8df PA |
3841 | bpstat_check_location (const struct bp_location *bl, |
3842 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3843 | { |
3844 | struct breakpoint *b = bl->owner; | |
3845 | ||
2bdf28a0 JK |
3846 | /* BL is from existing struct breakpoint. */ |
3847 | gdb_assert (b != NULL); | |
3848 | ||
e8595ef6 SS |
3849 | /* By definition, the inferior does not report stops at |
3850 | tracepoints. */ | |
d77f58be | 3851 | if (is_tracepoint (b)) |
e8595ef6 SS |
3852 | return 0; |
3853 | ||
cc60f2e3 | 3854 | if (!is_watchpoint (b) |
18a18393 | 3855 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3856 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3857 | { |
6c95b8df PA |
3858 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3859 | aspace, bp_addr)) | |
18a18393 VP |
3860 | return 0; |
3861 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3862 | && section_is_overlay (bl->section) |
18a18393 VP |
3863 | && !section_is_mapped (bl->section)) |
3864 | return 0; | |
3865 | } | |
cc60f2e3 | 3866 | |
18a18393 VP |
3867 | /* Continuable hardware watchpoints are treated as non-existent if the |
3868 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3869 | some data address). Otherwise gdb won't stop on a break instruction | |
3870 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3871 | been defined. Also skip watchpoints which we know did not trigger | |
3872 | (did not match the data address). */ | |
cc60f2e3 PA |
3873 | |
3874 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3875 | && b->watchpoint_triggered == watch_triggered_no) |
3876 | return 0; | |
3877 | ||
3878 | if (b->type == bp_hardware_breakpoint) | |
3879 | { | |
3880 | if (bl->address != bp_addr) | |
3881 | return 0; | |
3882 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3883 | && section_is_overlay (bl->section) |
18a18393 VP |
3884 | && !section_is_mapped (bl->section)) |
3885 | return 0; | |
3886 | } | |
ce78b96d | 3887 | |
ce78b96d JB |
3888 | if (b->type == bp_catchpoint) |
3889 | { | |
3890 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3891 | if (!b->ops->breakpoint_hit (b)) | |
3892 | return 0; | |
3893 | } | |
3894 | ||
18a18393 VP |
3895 | return 1; |
3896 | } | |
3897 | ||
3898 | /* If BS refers to a watchpoint, determine if the watched values | |
3899 | has actually changed, and we should stop. If not, set BS->stop | |
3900 | to 0. */ | |
3901 | static void | |
3902 | bpstat_check_watchpoint (bpstat bs) | |
3903 | { | |
2bdf28a0 JK |
3904 | const struct bp_location *bl; |
3905 | struct breakpoint *b; | |
3906 | ||
3907 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3908 | bl = bs->bp_location_at; |
2bdf28a0 | 3909 | gdb_assert (bl != NULL); |
f431efe5 | 3910 | b = bs->breakpoint_at; |
2bdf28a0 | 3911 | gdb_assert (b != NULL); |
18a18393 | 3912 | |
cc60f2e3 | 3913 | if (is_watchpoint (b)) |
18a18393 | 3914 | { |
18a18393 VP |
3915 | int must_check_value = 0; |
3916 | ||
3917 | if (b->type == bp_watchpoint) | |
3918 | /* For a software watchpoint, we must always check the | |
3919 | watched value. */ | |
3920 | must_check_value = 1; | |
3921 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3922 | /* We have a hardware watchpoint (read, write, or access) | |
3923 | and the target earlier reported an address watched by | |
3924 | this watchpoint. */ | |
3925 | must_check_value = 1; | |
3926 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3927 | && b->type == bp_hardware_watchpoint) | |
3928 | /* We were stopped by a hardware watchpoint, but the target could | |
3929 | not report the data address. We must check the watchpoint's | |
3930 | value. Access and read watchpoints are out of luck; without | |
3931 | a data address, we can't figure it out. */ | |
3932 | must_check_value = 1; | |
3933 | ||
3934 | if (must_check_value) | |
3935 | { | |
3e43a32a MS |
3936 | char *message |
3937 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3938 | b->number); | |
18a18393 VP |
3939 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3940 | int e = catch_errors (watchpoint_check, bs, message, | |
3941 | RETURN_MASK_ALL); | |
3942 | do_cleanups (cleanups); | |
3943 | switch (e) | |
3944 | { | |
3945 | case WP_DELETED: | |
3946 | /* We've already printed what needs to be printed. */ | |
3947 | bs->print_it = print_it_done; | |
3948 | /* Stop. */ | |
3949 | break; | |
60e1c644 PA |
3950 | case WP_IGNORE: |
3951 | bs->print_it = print_it_noop; | |
3952 | bs->stop = 0; | |
3953 | break; | |
18a18393 VP |
3954 | case WP_VALUE_CHANGED: |
3955 | if (b->type == bp_read_watchpoint) | |
3956 | { | |
85d721b8 PA |
3957 | /* There are two cases to consider here: |
3958 | ||
4a64f543 | 3959 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3960 | In that case, trust the target, and always report |
3961 | the watchpoint hit to the user. Even though | |
3962 | reads don't cause value changes, the value may | |
3963 | have changed since the last time it was read, and | |
3964 | since we're not trapping writes, we will not see | |
3965 | those, and as such we should ignore our notion of | |
3966 | old value. | |
3967 | ||
4a64f543 | 3968 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3969 | reads and writes. There are two ways this may |
3970 | happen: | |
3971 | ||
4a64f543 | 3972 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3973 | reads only, but can break on accesses (reads or |
3974 | writes), such as e.g., x86. We detect this case | |
3975 | at the time we try to insert read watchpoints. | |
3976 | ||
4a64f543 | 3977 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3978 | watchpoints, but, the user set an access or write |
3979 | watchpoint watching the same memory as this read | |
3980 | watchpoint. | |
3981 | ||
3982 | If we're watching memory writes as well as reads, | |
3983 | ignore watchpoint hits when we find that the | |
3984 | value hasn't changed, as reads don't cause | |
3985 | changes. This still gives false positives when | |
3986 | the program writes the same value to memory as | |
3987 | what there was already in memory (we will confuse | |
3988 | it for a read), but it's much better than | |
3989 | nothing. */ | |
3990 | ||
3991 | int other_write_watchpoint = 0; | |
3992 | ||
3993 | if (bl->watchpoint_type == hw_read) | |
3994 | { | |
3995 | struct breakpoint *other_b; | |
3996 | ||
3997 | ALL_BREAKPOINTS (other_b) | |
3998 | if ((other_b->type == bp_hardware_watchpoint | |
3999 | || other_b->type == bp_access_watchpoint) | |
4000 | && (other_b->watchpoint_triggered | |
4001 | == watch_triggered_yes)) | |
4002 | { | |
4003 | other_write_watchpoint = 1; | |
4004 | break; | |
4005 | } | |
4006 | } | |
4007 | ||
4008 | if (other_write_watchpoint | |
4009 | || bl->watchpoint_type == hw_access) | |
4010 | { | |
4011 | /* We're watching the same memory for writes, | |
4012 | and the value changed since the last time we | |
4013 | updated it, so this trap must be for a write. | |
4014 | Ignore it. */ | |
4015 | bs->print_it = print_it_noop; | |
4016 | bs->stop = 0; | |
4017 | } | |
18a18393 VP |
4018 | } |
4019 | break; | |
4020 | case WP_VALUE_NOT_CHANGED: | |
4021 | if (b->type == bp_hardware_watchpoint | |
4022 | || b->type == bp_watchpoint) | |
4023 | { | |
4024 | /* Don't stop: write watchpoints shouldn't fire if | |
4025 | the value hasn't changed. */ | |
4026 | bs->print_it = print_it_noop; | |
4027 | bs->stop = 0; | |
4028 | } | |
4029 | /* Stop. */ | |
4030 | break; | |
4031 | default: | |
4032 | /* Can't happen. */ | |
4033 | case 0: | |
4034 | /* Error from catch_errors. */ | |
4035 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
4036 | if (b->related_breakpoint) | |
4037 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
4038 | b->disposition = disp_del_at_next_stop; | |
4039 | /* We've already printed what needs to be printed. */ | |
4040 | bs->print_it = print_it_done; | |
4041 | break; | |
4042 | } | |
4043 | } | |
4044 | else /* must_check_value == 0 */ | |
4045 | { | |
4046 | /* This is a case where some watchpoint(s) triggered, but | |
4047 | not at the address of this watchpoint, or else no | |
4048 | watchpoint triggered after all. So don't print | |
4049 | anything for this watchpoint. */ | |
4050 | bs->print_it = print_it_noop; | |
4051 | bs->stop = 0; | |
4052 | } | |
4053 | } | |
4054 | } | |
4055 | ||
4056 | ||
4057 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4058 | of breakpoint referred to by BS. If we should not stop for this | |
4059 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4060 | |
18a18393 VP |
4061 | static void |
4062 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4063 | { | |
4064 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4065 | const struct bp_location *bl; |
4066 | struct breakpoint *b; | |
4067 | ||
4068 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4069 | bl = bs->bp_location_at; |
2bdf28a0 | 4070 | gdb_assert (bl != NULL); |
f431efe5 | 4071 | b = bs->breakpoint_at; |
2bdf28a0 | 4072 | gdb_assert (b != NULL); |
18a18393 VP |
4073 | |
4074 | if (frame_id_p (b->frame_id) | |
edb3359d | 4075 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4076 | bs->stop = 0; |
4077 | else if (bs->stop) | |
4078 | { | |
4079 | int value_is_zero = 0; | |
60e1c644 PA |
4080 | struct expression *cond; |
4081 | ||
7371cf6d PM |
4082 | /* Evaluate Python breakpoints that have a "stop" |
4083 | method implemented. */ | |
4084 | if (b->py_bp_object) | |
4085 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4086 | ||
60e1c644 PA |
4087 | if (is_watchpoint (b)) |
4088 | cond = b->cond_exp; | |
4089 | else | |
4090 | cond = bl->cond; | |
4091 | ||
f431efe5 | 4092 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4093 | { |
60e1c644 PA |
4094 | int within_current_scope = 1; |
4095 | ||
c5bc3a77 DJ |
4096 | /* We use value_mark and value_free_to_mark because it could |
4097 | be a long time before we return to the command level and | |
4098 | call free_all_values. We can't call free_all_values | |
4099 | because we might be in the middle of evaluating a | |
4100 | function call. */ | |
4101 | struct value *mark = value_mark (); | |
4102 | ||
edb3359d DJ |
4103 | /* Need to select the frame, with all that implies so that |
4104 | the conditions will have the right context. Because we | |
4105 | use the frame, we will not see an inlined function's | |
4106 | variables when we arrive at a breakpoint at the start | |
4107 | of the inlined function; the current frame will be the | |
4108 | call site. */ | |
60e1c644 PA |
4109 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4110 | select_frame (get_current_frame ()); | |
4111 | else | |
4112 | { | |
4113 | struct frame_info *frame; | |
4114 | ||
4115 | /* For local watchpoint expressions, which particular | |
4116 | instance of a local is being watched matters, so we | |
4117 | keep track of the frame to evaluate the expression | |
4118 | in. To evaluate the condition however, it doesn't | |
4119 | really matter which instantiation of the function | |
4120 | where the condition makes sense triggers the | |
4121 | watchpoint. This allows an expression like "watch | |
4122 | global if q > 10" set in `func', catch writes to | |
4123 | global on all threads that call `func', or catch | |
4124 | writes on all recursive calls of `func' by a single | |
4125 | thread. We simply always evaluate the condition in | |
4126 | the innermost frame that's executing where it makes | |
4127 | sense to evaluate the condition. It seems | |
4128 | intuitive. */ | |
4129 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4130 | if (frame != NULL) | |
4131 | select_frame (frame); | |
4132 | else | |
4133 | within_current_scope = 0; | |
4134 | } | |
4135 | if (within_current_scope) | |
4136 | value_is_zero | |
4137 | = catch_errors (breakpoint_cond_eval, cond, | |
4138 | "Error in testing breakpoint condition:\n", | |
4139 | RETURN_MASK_ALL); | |
4140 | else | |
4141 | { | |
4142 | warning (_("Watchpoint condition cannot be tested " | |
4143 | "in the current scope")); | |
4144 | /* If we failed to set the right context for this | |
4145 | watchpoint, unconditionally report it. */ | |
4146 | value_is_zero = 0; | |
4147 | } | |
4a64f543 | 4148 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4149 | value_free_to_mark (mark); |
18a18393 | 4150 | } |
60e1c644 PA |
4151 | |
4152 | if (cond && value_is_zero) | |
18a18393 VP |
4153 | { |
4154 | bs->stop = 0; | |
4155 | } | |
4156 | else if (b->thread != -1 && b->thread != thread_id) | |
4157 | { | |
4158 | bs->stop = 0; | |
4159 | } | |
4160 | else if (b->ignore_count > 0) | |
4161 | { | |
4162 | b->ignore_count--; | |
4163 | annotate_ignore_count_change (); | |
4164 | bs->stop = 0; | |
4a64f543 | 4165 | /* Increase the hit count even though we don't stop. */ |
18a18393 VP |
4166 | ++(b->hit_count); |
4167 | } | |
4168 | } | |
4169 | } | |
4170 | ||
4171 | ||
9709f61c | 4172 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4173 | BP_ADDR in thread PTID. |
c906108c | 4174 | |
d983da9c | 4175 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4176 | don't understand this stop. Result is a chain of bpstat's such |
4177 | that: | |
c906108c | 4178 | |
c5aa993b | 4179 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4180 | |
c5aa993b | 4181 | if we understand why we stopped, the result is not null. |
c906108c | 4182 | |
c5aa993b JM |
4183 | Each element of the chain refers to a particular breakpoint or |
4184 | watchpoint at which we have stopped. (We may have stopped for | |
4185 | several reasons concurrently.) | |
c906108c | 4186 | |
c5aa993b JM |
4187 | Each element of the chain has valid next, breakpoint_at, |
4188 | commands, FIXME??? fields. */ | |
c906108c SS |
4189 | |
4190 | bpstat | |
6c95b8df PA |
4191 | bpstat_stop_status (struct address_space *aspace, |
4192 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4193 | { |
0d381245 | 4194 | struct breakpoint *b = NULL; |
afe38095 | 4195 | struct bp_location *bl; |
20874c92 | 4196 | struct bp_location *loc; |
5760d0ab JK |
4197 | /* First item of allocated bpstat's. */ |
4198 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4199 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4200 | bpstat bs; |
20874c92 | 4201 | int ix; |
429374b8 | 4202 | int need_remove_insert; |
f431efe5 | 4203 | int removed_any; |
c906108c | 4204 | |
f431efe5 PA |
4205 | /* First, build the bpstat chain with locations that explain a |
4206 | target stop, while being careful to not set the target running, | |
4207 | as that may invalidate locations (in particular watchpoint | |
4208 | locations are recreated). Resuming will happen here with | |
4209 | breakpoint conditions or watchpoint expressions that include | |
4210 | inferior function calls. */ | |
c5aa993b | 4211 | |
429374b8 JK |
4212 | ALL_BREAKPOINTS (b) |
4213 | { | |
4214 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4215 | continue; | |
a5606eee | 4216 | |
429374b8 JK |
4217 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4218 | { | |
4a64f543 MS |
4219 | /* For hardware watchpoints, we look only at the first |
4220 | location. The watchpoint_check function will work on the | |
4221 | entire expression, not the individual locations. For | |
4222 | read watchpoints, the watchpoints_triggered function has | |
4223 | checked all locations already. */ | |
429374b8 JK |
4224 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4225 | break; | |
18a18393 | 4226 | |
429374b8 JK |
4227 | if (bl->shlib_disabled) |
4228 | continue; | |
c5aa993b | 4229 | |
429374b8 JK |
4230 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4231 | continue; | |
c5aa993b | 4232 | |
4a64f543 MS |
4233 | /* Come here if it's a watchpoint, or if the break address |
4234 | matches. */ | |
c5aa993b | 4235 | |
4a64f543 MS |
4236 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4237 | explain stop. */ | |
c5aa993b | 4238 | |
f431efe5 PA |
4239 | /* Assume we stop. Should we find a watchpoint that is not |
4240 | actually triggered, or if the condition of the breakpoint | |
4241 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4242 | bs->stop = 1; |
4243 | bs->print = 1; | |
d983da9c | 4244 | |
f431efe5 PA |
4245 | /* If this is a scope breakpoint, mark the associated |
4246 | watchpoint as triggered so that we will handle the | |
4247 | out-of-scope event. We'll get to the watchpoint next | |
4248 | iteration. */ | |
4249 | if (b->type == bp_watchpoint_scope) | |
4250 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
4251 | } | |
4252 | } | |
4253 | ||
4254 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4255 | { | |
4256 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, | |
4257 | aspace, bp_addr)) | |
4258 | { | |
5760d0ab | 4259 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4260 | /* For hits of moribund locations, we should just proceed. */ |
4261 | bs->stop = 0; | |
4262 | bs->print = 0; | |
4263 | bs->print_it = print_it_noop; | |
4264 | } | |
4265 | } | |
4266 | ||
f431efe5 PA |
4267 | /* Now go through the locations that caused the target to stop, and |
4268 | check whether we're interested in reporting this stop to higher | |
4269 | layers, or whether we should resume the target transparently. */ | |
4270 | ||
4271 | removed_any = 0; | |
4272 | ||
5760d0ab | 4273 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4274 | { |
4275 | if (!bs->stop) | |
4276 | continue; | |
4277 | ||
4278 | bpstat_check_watchpoint (bs); | |
4279 | if (!bs->stop) | |
4280 | continue; | |
4281 | ||
4282 | b = bs->breakpoint_at; | |
18a18393 | 4283 | |
429374b8 | 4284 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4285 | || b->type == bp_longjmp_master |
186c406b TT |
4286 | || b->type == bp_std_terminate_master |
4287 | || b->type == bp_exception_master) | |
429374b8 JK |
4288 | /* We do not stop for these. */ |
4289 | bs->stop = 0; | |
4290 | else | |
4291 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4292 | |
429374b8 JK |
4293 | if (bs->stop) |
4294 | { | |
4295 | ++(b->hit_count); | |
c906108c | 4296 | |
4a64f543 | 4297 | /* We will stop here. */ |
429374b8 JK |
4298 | if (b->disposition == disp_disable) |
4299 | { | |
4300 | if (b->enable_state != bp_permanent) | |
4301 | b->enable_state = bp_disabled; | |
f431efe5 | 4302 | removed_any = 1; |
429374b8 JK |
4303 | } |
4304 | if (b->silent) | |
4305 | bs->print = 0; | |
4306 | bs->commands = b->commands; | |
9add0f1b TT |
4307 | incref_counted_command_line (bs->commands); |
4308 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4309 | if (bs->commands_left | |
4310 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4311 | || (xdb_commands | |
4312 | && strcmp ("Q", | |
4313 | bs->commands_left->line) == 0))) | |
429374b8 | 4314 | { |
9add0f1b | 4315 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4316 | bs->print = 0; |
4317 | } | |
429374b8 JK |
4318 | } |
4319 | ||
4320 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4321 | if (bs->stop == 0 || bs->print == 0) | |
4322 | bs->print_it = print_it_noop; | |
429374b8 | 4323 | } |
876fa593 | 4324 | |
d983da9c DJ |
4325 | /* If we aren't stopping, the value of some hardware watchpoint may |
4326 | not have changed, but the intermediate memory locations we are | |
4327 | watching may have. Don't bother if we're stopping; this will get | |
4328 | done later. */ | |
d832cb68 | 4329 | need_remove_insert = 0; |
5760d0ab JK |
4330 | if (! bpstat_causes_stop (bs_head)) |
4331 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4332 | if (!bs->stop |
f431efe5 PA |
4333 | && bs->breakpoint_at |
4334 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4335 | { |
4a64f543 | 4336 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4337 | need_remove_insert = 1; |
d983da9c DJ |
4338 | } |
4339 | ||
d832cb68 | 4340 | if (need_remove_insert) |
2d134ed3 | 4341 | update_global_location_list (1); |
f431efe5 PA |
4342 | else if (removed_any) |
4343 | update_global_location_list (0); | |
d832cb68 | 4344 | |
5760d0ab | 4345 | return bs_head; |
c906108c | 4346 | } |
628fe4e4 JK |
4347 | |
4348 | static void | |
4349 | handle_jit_event (void) | |
4350 | { | |
4351 | struct frame_info *frame; | |
4352 | struct gdbarch *gdbarch; | |
4353 | ||
4354 | /* Switch terminal for any messages produced by | |
4355 | breakpoint_re_set. */ | |
4356 | target_terminal_ours_for_output (); | |
4357 | ||
4358 | frame = get_current_frame (); | |
4359 | gdbarch = get_frame_arch (frame); | |
4360 | ||
4361 | jit_event_handler (gdbarch); | |
4362 | ||
4363 | target_terminal_inferior (); | |
4364 | } | |
4365 | ||
4366 | /* Prepare WHAT final decision for infrun. */ | |
4367 | ||
4368 | /* Decide what infrun needs to do with this bpstat. */ | |
4369 | ||
c906108c | 4370 | struct bpstat_what |
fba45db2 | 4371 | bpstat_what (bpstat bs) |
c906108c | 4372 | { |
c906108c | 4373 | struct bpstat_what retval; |
628fe4e4 JK |
4374 | /* We need to defer calling `solib_add', as adding new symbols |
4375 | resets breakpoints, which in turn deletes breakpoint locations, | |
4376 | and hence may clear unprocessed entries in the BS chain. */ | |
4377 | int shlib_event = 0; | |
4378 | int jit_event = 0; | |
c906108c | 4379 | |
628fe4e4 | 4380 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4381 | retval.call_dummy = STOP_NONE; |
186c406b | 4382 | retval.is_longjmp = 0; |
628fe4e4 | 4383 | |
c906108c SS |
4384 | for (; bs != NULL; bs = bs->next) |
4385 | { | |
628fe4e4 JK |
4386 | /* Extract this BS's action. After processing each BS, we check |
4387 | if its action overrides all we've seem so far. */ | |
4388 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4389 | enum bptype bptype; | |
4390 | ||
c906108c | 4391 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4392 | { |
4393 | /* I suspect this can happen if it was a momentary | |
4394 | breakpoint which has since been deleted. */ | |
4395 | bptype = bp_none; | |
4396 | } | |
f431efe5 | 4397 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4398 | bptype = bp_none; |
20874c92 | 4399 | else |
f431efe5 | 4400 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4401 | |
4402 | switch (bptype) | |
c906108c SS |
4403 | { |
4404 | case bp_none: | |
628fe4e4 | 4405 | break; |
c906108c SS |
4406 | case bp_breakpoint: |
4407 | case bp_hardware_breakpoint: | |
4408 | case bp_until: | |
4409 | case bp_finish: | |
4410 | if (bs->stop) | |
4411 | { | |
4412 | if (bs->print) | |
628fe4e4 | 4413 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4414 | else |
628fe4e4 | 4415 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4416 | } |
4417 | else | |
628fe4e4 | 4418 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4419 | break; |
4420 | case bp_watchpoint: | |
4421 | case bp_hardware_watchpoint: | |
4422 | case bp_read_watchpoint: | |
4423 | case bp_access_watchpoint: | |
4424 | if (bs->stop) | |
4425 | { | |
4426 | if (bs->print) | |
628fe4e4 | 4427 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4428 | else |
628fe4e4 | 4429 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4430 | } |
4431 | else | |
628fe4e4 JK |
4432 | { |
4433 | /* There was a watchpoint, but we're not stopping. | |
4434 | This requires no further action. */ | |
4435 | } | |
c906108c SS |
4436 | break; |
4437 | case bp_longjmp: | |
186c406b | 4438 | case bp_exception: |
628fe4e4 | 4439 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4440 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4441 | break; |
4442 | case bp_longjmp_resume: | |
186c406b | 4443 | case bp_exception_resume: |
628fe4e4 | 4444 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4445 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4446 | break; |
4447 | case bp_step_resume: | |
4448 | if (bs->stop) | |
628fe4e4 JK |
4449 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4450 | else | |
c906108c | 4451 | { |
628fe4e4 JK |
4452 | /* It is for the wrong frame. */ |
4453 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4454 | } |
c906108c | 4455 | break; |
c906108c | 4456 | case bp_watchpoint_scope: |
c4093a6a | 4457 | case bp_thread_event: |
1900040c | 4458 | case bp_overlay_event: |
0fd8e87f | 4459 | case bp_longjmp_master: |
aa7d318d | 4460 | case bp_std_terminate_master: |
186c406b | 4461 | case bp_exception_master: |
628fe4e4 | 4462 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4463 | break; |
ce78b96d | 4464 | case bp_catchpoint: |
c5aa993b JM |
4465 | if (bs->stop) |
4466 | { | |
4467 | if (bs->print) | |
628fe4e4 | 4468 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4469 | else |
628fe4e4 | 4470 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4471 | } |
4472 | else | |
628fe4e4 JK |
4473 | { |
4474 | /* There was a catchpoint, but we're not stopping. | |
4475 | This requires no further action. */ | |
4476 | } | |
4477 | break; | |
4478 | case bp_shlib_event: | |
4479 | shlib_event = 1; | |
4480 | ||
4481 | /* If requested, stop when the dynamic linker notifies GDB | |
4482 | of events. This allows the user to get control and place | |
4483 | breakpoints in initializer routines for dynamically | |
4484 | loaded objects (among other things). */ | |
4485 | if (stop_on_solib_events) | |
4486 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4487 | else | |
4488 | this_action = BPSTAT_WHAT_SINGLE; | |
4489 | break; | |
4490 | case bp_jit_event: | |
4491 | jit_event = 1; | |
4492 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4493 | break; |
c906108c | 4494 | case bp_call_dummy: |
53a5351d JM |
4495 | /* Make sure the action is stop (silent or noisy), |
4496 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4497 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4498 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4499 | break; |
4500 | case bp_std_terminate: | |
4501 | /* Make sure the action is stop (silent or noisy), | |
4502 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4503 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4504 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4505 | break; |
1042e4c0 | 4506 | case bp_tracepoint: |
7a697b8d | 4507 | case bp_fast_tracepoint: |
0fb4aa4b | 4508 | case bp_static_tracepoint: |
1042e4c0 SS |
4509 | /* Tracepoint hits should not be reported back to GDB, and |
4510 | if one got through somehow, it should have been filtered | |
4511 | out already. */ | |
4512 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4513 | _("bpstat_what: tracepoint encountered")); |
628fe4e4 JK |
4514 | default: |
4515 | internal_error (__FILE__, __LINE__, | |
4516 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4517 | } |
628fe4e4 JK |
4518 | |
4519 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4520 | } |
628fe4e4 JK |
4521 | |
4522 | if (shlib_event) | |
4523 | { | |
4524 | if (debug_infrun) | |
4525 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4526 | ||
4527 | /* Check for any newly added shared libraries if we're supposed | |
4528 | to be adding them automatically. */ | |
4529 | ||
4530 | /* Switch terminal for any messages produced by | |
4531 | breakpoint_re_set. */ | |
4532 | target_terminal_ours_for_output (); | |
4533 | ||
4534 | #ifdef SOLIB_ADD | |
4535 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4536 | #else | |
4537 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4538 | #endif | |
4539 | ||
4540 | target_terminal_inferior (); | |
4541 | } | |
4542 | ||
4543 | if (jit_event) | |
4544 | { | |
4545 | if (debug_infrun) | |
4546 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4547 | ||
4548 | handle_jit_event (); | |
4549 | } | |
4550 | ||
c906108c SS |
4551 | return retval; |
4552 | } | |
4553 | ||
4554 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4555 | without hardware support). This isn't related to a specific bpstat, | |
4556 | just to things like whether watchpoints are set. */ | |
4557 | ||
c5aa993b | 4558 | int |
fba45db2 | 4559 | bpstat_should_step (void) |
c906108c SS |
4560 | { |
4561 | struct breakpoint *b; | |
cc59ec59 | 4562 | |
c906108c | 4563 | ALL_BREAKPOINTS (b) |
717a8278 | 4564 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4565 | return 1; |
c906108c SS |
4566 | return 0; |
4567 | } | |
4568 | ||
67822962 PA |
4569 | int |
4570 | bpstat_causes_stop (bpstat bs) | |
4571 | { | |
4572 | for (; bs != NULL; bs = bs->next) | |
4573 | if (bs->stop) | |
4574 | return 1; | |
4575 | ||
4576 | return 0; | |
4577 | } | |
4578 | ||
c906108c | 4579 | \f |
c5aa993b | 4580 | |
170b53b2 UW |
4581 | /* Compute a string of spaces suitable to indent the next line |
4582 | so it starts at the position corresponding to the table column | |
4583 | named COL_NAME in the currently active table of UIOUT. */ | |
4584 | ||
4585 | static char * | |
4586 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4587 | { | |
4588 | static char wrap_indent[80]; | |
4589 | int i, total_width, width, align; | |
4590 | char *text; | |
4591 | ||
4592 | total_width = 0; | |
4593 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4594 | { | |
4595 | if (strcmp (text, col_name) == 0) | |
4596 | { | |
4597 | gdb_assert (total_width < sizeof wrap_indent); | |
4598 | memset (wrap_indent, ' ', total_width); | |
4599 | wrap_indent[total_width] = 0; | |
4600 | ||
4601 | return wrap_indent; | |
4602 | } | |
4603 | ||
4604 | total_width += width + 1; | |
4605 | } | |
4606 | ||
4607 | return NULL; | |
4608 | } | |
4609 | ||
859825b8 JK |
4610 | /* Print the LOC location out of the list of B->LOC locations. */ |
4611 | ||
170b53b2 UW |
4612 | static void |
4613 | print_breakpoint_location (struct breakpoint *b, | |
4614 | struct bp_location *loc) | |
0d381245 | 4615 | { |
6c95b8df PA |
4616 | struct cleanup *old_chain = save_current_program_space (); |
4617 | ||
859825b8 JK |
4618 | if (loc != NULL && loc->shlib_disabled) |
4619 | loc = NULL; | |
4620 | ||
6c95b8df PA |
4621 | if (loc != NULL) |
4622 | set_current_program_space (loc->pspace); | |
4623 | ||
859825b8 | 4624 | if (b->source_file && loc) |
0d381245 VP |
4625 | { |
4626 | struct symbol *sym | |
4627 | = find_pc_sect_function (loc->address, loc->section); | |
4628 | if (sym) | |
4629 | { | |
4630 | ui_out_text (uiout, "in "); | |
4631 | ui_out_field_string (uiout, "func", | |
4632 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4633 | ui_out_text (uiout, " "); |
4634 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4635 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4636 | } |
4637 | ui_out_field_string (uiout, "file", b->source_file); | |
4638 | ui_out_text (uiout, ":"); | |
4639 | ||
4640 | if (ui_out_is_mi_like_p (uiout)) | |
4641 | { | |
4642 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4643 | char *fullname = symtab_to_fullname (sal.symtab); | |
4644 | ||
4645 | if (fullname) | |
4646 | ui_out_field_string (uiout, "fullname", fullname); | |
4647 | } | |
4648 | ||
4649 | ui_out_field_int (uiout, "line", b->line_number); | |
4650 | } | |
859825b8 | 4651 | else if (loc) |
0d381245 | 4652 | { |
170b53b2 UW |
4653 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4654 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4655 | ||
22e722e1 DJ |
4656 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4657 | demangle, ""); | |
0d381245 | 4658 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4659 | |
4660 | do_cleanups (stb_chain); | |
0d381245 | 4661 | } |
859825b8 JK |
4662 | else |
4663 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4664 | |
4665 | do_cleanups (old_chain); | |
0d381245 VP |
4666 | } |
4667 | ||
269b11a2 PA |
4668 | static const char * |
4669 | bptype_string (enum bptype type) | |
c906108c | 4670 | { |
c4093a6a JM |
4671 | struct ep_type_description |
4672 | { | |
4673 | enum bptype type; | |
4674 | char *description; | |
4675 | }; | |
4676 | static struct ep_type_description bptypes[] = | |
c906108c | 4677 | { |
c5aa993b JM |
4678 | {bp_none, "?deleted?"}, |
4679 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4680 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4681 | {bp_until, "until"}, |
4682 | {bp_finish, "finish"}, | |
4683 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4684 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4685 | {bp_read_watchpoint, "read watchpoint"}, |
4686 | {bp_access_watchpoint, "acc watchpoint"}, | |
4687 | {bp_longjmp, "longjmp"}, | |
4688 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4689 | {bp_exception, "exception"}, |
4690 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4691 | {bp_step_resume, "step resume"}, |
c5aa993b JM |
4692 | {bp_watchpoint_scope, "watchpoint scope"}, |
4693 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4694 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4695 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4696 | {bp_thread_event, "thread events"}, |
1900040c | 4697 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4698 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4699 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4700 | {bp_exception_master, "exception master"}, |
ce78b96d | 4701 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4702 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4703 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4704 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4705 | {bp_jit_event, "jit events"}, |
c5aa993b | 4706 | }; |
269b11a2 PA |
4707 | |
4708 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4709 | || ((int) type != bptypes[(int) type].type)) | |
4710 | internal_error (__FILE__, __LINE__, | |
4711 | _("bptypes table does not describe type #%d."), | |
4712 | (int) type); | |
4713 | ||
4714 | return bptypes[(int) type].description; | |
4715 | } | |
4716 | ||
4717 | /* Print B to gdb_stdout. */ | |
4718 | ||
4719 | static void | |
4720 | print_one_breakpoint_location (struct breakpoint *b, | |
4721 | struct bp_location *loc, | |
4722 | int loc_number, | |
4723 | struct bp_location **last_loc, | |
269b11a2 PA |
4724 | int allflag) |
4725 | { | |
4726 | struct command_line *l; | |
c2c6d25f | 4727 | static char bpenables[] = "nynny"; |
3b31d625 | 4728 | struct cleanup *bkpt_chain; |
c906108c | 4729 | |
0d381245 VP |
4730 | int header_of_multiple = 0; |
4731 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4732 | struct value_print_options opts; |
4733 | ||
4734 | get_user_print_options (&opts); | |
0d381245 VP |
4735 | |
4736 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4737 | /* See comment in print_one_breakpoint concerning treatment of |
4738 | breakpoints with single disabled location. */ | |
0d381245 VP |
4739 | if (loc == NULL |
4740 | && (b->loc != NULL | |
4741 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4742 | header_of_multiple = 1; | |
4743 | if (loc == NULL) | |
4744 | loc = b->loc; | |
4745 | ||
c4093a6a | 4746 | annotate_record (); |
3b31d625 | 4747 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4748 | |
4749 | /* 1 */ | |
4750 | annotate_field (0); | |
0d381245 VP |
4751 | if (part_of_multiple) |
4752 | { | |
4753 | char *formatted; | |
0c6773c1 | 4754 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4755 | ui_out_field_string (uiout, "number", formatted); |
4756 | xfree (formatted); | |
4757 | } | |
4758 | else | |
4759 | { | |
4760 | ui_out_field_int (uiout, "number", b->number); | |
4761 | } | |
c4093a6a JM |
4762 | |
4763 | /* 2 */ | |
4764 | annotate_field (1); | |
0d381245 VP |
4765 | if (part_of_multiple) |
4766 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4767 | else |
4768 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4769 | |
4770 | /* 3 */ | |
4771 | annotate_field (2); | |
0d381245 VP |
4772 | if (part_of_multiple) |
4773 | ui_out_field_skip (uiout, "disp"); | |
4774 | else | |
2cec12e5 | 4775 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4776 | |
c4093a6a JM |
4777 | |
4778 | /* 4 */ | |
4779 | annotate_field (3); | |
0d381245 | 4780 | if (part_of_multiple) |
54e52265 | 4781 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4782 | else |
4a64f543 MS |
4783 | ui_out_field_fmt (uiout, "enabled", "%c", |
4784 | bpenables[(int) b->enable_state]); | |
54e52265 | 4785 | ui_out_spaces (uiout, 2); |
0d381245 | 4786 | |
c4093a6a JM |
4787 | |
4788 | /* 5 and 6 */ | |
3086aeae | 4789 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4790 | { |
4a64f543 MS |
4791 | /* Although the print_one can possibly print all locations, |
4792 | calling it here is not likely to get any nice result. So, | |
4793 | make sure there's just one location. */ | |
0d381245 | 4794 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4795 | b->ops->print_one (b, last_loc); |
0d381245 | 4796 | } |
3086aeae DJ |
4797 | else |
4798 | switch (b->type) | |
4799 | { | |
4800 | case bp_none: | |
4801 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4802 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4803 | break; |
c906108c | 4804 | |
3086aeae DJ |
4805 | case bp_watchpoint: |
4806 | case bp_hardware_watchpoint: | |
4807 | case bp_read_watchpoint: | |
4808 | case bp_access_watchpoint: | |
4809 | /* Field 4, the address, is omitted (which makes the columns | |
4810 | not line up too nicely with the headers, but the effect | |
4811 | is relatively readable). */ | |
79a45b7d | 4812 | if (opts.addressprint) |
3086aeae DJ |
4813 | ui_out_field_skip (uiout, "addr"); |
4814 | annotate_field (5); | |
fa8a61dc | 4815 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4816 | break; |
4817 | ||
3086aeae DJ |
4818 | case bp_breakpoint: |
4819 | case bp_hardware_breakpoint: | |
4820 | case bp_until: | |
4821 | case bp_finish: | |
4822 | case bp_longjmp: | |
4823 | case bp_longjmp_resume: | |
186c406b TT |
4824 | case bp_exception: |
4825 | case bp_exception_resume: | |
3086aeae | 4826 | case bp_step_resume: |
3086aeae DJ |
4827 | case bp_watchpoint_scope: |
4828 | case bp_call_dummy: | |
aa7d318d | 4829 | case bp_std_terminate: |
3086aeae DJ |
4830 | case bp_shlib_event: |
4831 | case bp_thread_event: | |
4832 | case bp_overlay_event: | |
0fd8e87f | 4833 | case bp_longjmp_master: |
aa7d318d | 4834 | case bp_std_terminate_master: |
186c406b | 4835 | case bp_exception_master: |
1042e4c0 | 4836 | case bp_tracepoint: |
7a697b8d | 4837 | case bp_fast_tracepoint: |
0fb4aa4b | 4838 | case bp_static_tracepoint: |
4efc6507 | 4839 | case bp_jit_event: |
79a45b7d | 4840 | if (opts.addressprint) |
3086aeae DJ |
4841 | { |
4842 | annotate_field (4); | |
54e52265 | 4843 | if (header_of_multiple) |
0d381245 | 4844 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4845 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4846 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4847 | else |
5af949e3 UW |
4848 | ui_out_field_core_addr (uiout, "addr", |
4849 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4850 | } |
4851 | annotate_field (5); | |
0d381245 | 4852 | if (!header_of_multiple) |
170b53b2 | 4853 | print_breakpoint_location (b, loc); |
0d381245 | 4854 | if (b->loc) |
a6d9a66e | 4855 | *last_loc = b->loc; |
3086aeae DJ |
4856 | break; |
4857 | } | |
c906108c | 4858 | |
6c95b8df PA |
4859 | |
4860 | /* For backward compatibility, don't display inferiors unless there | |
4861 | are several. */ | |
4862 | if (loc != NULL | |
4863 | && !header_of_multiple | |
4864 | && (allflag | |
4865 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4866 | && (number_of_program_spaces () > 1 | |
4867 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4868 | /* LOC is for existing B, it cannot be in |
4869 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4870 | && loc->owner->type != bp_catchpoint))) |
4871 | { | |
4872 | struct inferior *inf; | |
4873 | int first = 1; | |
4874 | ||
4875 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4876 | { | |
4877 | if (inf->pspace == loc->pspace) | |
4878 | { | |
4879 | if (first) | |
4880 | { | |
4881 | first = 0; | |
4882 | ui_out_text (uiout, " inf "); | |
4883 | } | |
4884 | else | |
4885 | ui_out_text (uiout, ", "); | |
4886 | ui_out_text (uiout, plongest (inf->num)); | |
4887 | } | |
4888 | } | |
4889 | } | |
4890 | ||
4a306c9a | 4891 | if (!part_of_multiple) |
c4093a6a | 4892 | { |
4a306c9a JB |
4893 | if (b->thread != -1) |
4894 | { | |
4895 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4896 | "stop only in" line a little further down. */ |
4a306c9a JB |
4897 | ui_out_text (uiout, " thread "); |
4898 | ui_out_field_int (uiout, "thread", b->thread); | |
4899 | } | |
4900 | else if (b->task != 0) | |
4901 | { | |
4902 | ui_out_text (uiout, " task "); | |
4903 | ui_out_field_int (uiout, "task", b->task); | |
4904 | } | |
c4093a6a JM |
4905 | } |
4906 | ||
8b93c638 | 4907 | ui_out_text (uiout, "\n"); |
c4093a6a | 4908 | |
0fb4aa4b PA |
4909 | if (!part_of_multiple && b->static_trace_marker_id) |
4910 | { | |
4911 | gdb_assert (b->type == bp_static_tracepoint); | |
4912 | ||
4913 | ui_out_text (uiout, "\tmarker id is "); | |
4914 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4915 | b->static_trace_marker_id); | |
4916 | ui_out_text (uiout, "\n"); | |
4917 | } | |
4918 | ||
0d381245 | 4919 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4920 | { |
4921 | annotate_field (6); | |
8b93c638 | 4922 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4923 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4924 | the frame ID. */ | |
5af949e3 UW |
4925 | ui_out_field_core_addr (uiout, "frame", |
4926 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4927 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4928 | } |
4929 | ||
0d381245 | 4930 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4931 | { |
f7f9143b JB |
4932 | /* We do not print the condition for Ada exception catchpoints |
4933 | because the condition is an internal implementation detail | |
4934 | that we do not want to expose to the user. */ | |
c4093a6a | 4935 | annotate_field (7); |
d77f58be | 4936 | if (is_tracepoint (b)) |
1042e4c0 SS |
4937 | ui_out_text (uiout, "\ttrace only if "); |
4938 | else | |
4939 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4940 | ui_out_field_string (uiout, "cond", b->cond_string); |
4941 | ui_out_text (uiout, "\n"); | |
4942 | } | |
4943 | ||
0d381245 | 4944 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4945 | { |
4a64f543 | 4946 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4947 | ui_out_text (uiout, "\tstop only in thread "); |
4948 | ui_out_field_int (uiout, "thread", b->thread); | |
4949 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4950 | } |
4951 | ||
63c715c6 | 4952 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4953 | { |
4a64f543 | 4954 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4955 | if (ep_is_catchpoint (b)) |
4956 | ui_out_text (uiout, "\tcatchpoint"); | |
4957 | else | |
4958 | ui_out_text (uiout, "\tbreakpoint"); | |
4959 | ui_out_text (uiout, " already hit "); | |
4960 | ui_out_field_int (uiout, "times", b->hit_count); | |
4961 | if (b->hit_count == 1) | |
4962 | ui_out_text (uiout, " time\n"); | |
4963 | else | |
4964 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4965 | } |
4966 | ||
4a64f543 MS |
4967 | /* Output the count also if it is zero, but only if this is mi. |
4968 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4969 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4970 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4971 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4972 | |
0d381245 | 4973 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4974 | { |
4975 | annotate_field (8); | |
8b93c638 JM |
4976 | ui_out_text (uiout, "\tignore next "); |
4977 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4978 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4979 | } |
059fb39f | 4980 | |
9add0f1b | 4981 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4982 | if (!part_of_multiple && l) |
c4093a6a | 4983 | { |
3b31d625 EZ |
4984 | struct cleanup *script_chain; |
4985 | ||
c4093a6a | 4986 | annotate_field (9); |
3b31d625 | 4987 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4988 | print_command_lines (uiout, l, 4); |
3b31d625 | 4989 | do_cleanups (script_chain); |
c4093a6a | 4990 | } |
d24317b4 | 4991 | |
1042e4c0 SS |
4992 | if (!part_of_multiple && b->pass_count) |
4993 | { | |
4994 | annotate_field (10); | |
4995 | ui_out_text (uiout, "\tpass count "); | |
4996 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4997 | ui_out_text (uiout, " \n"); | |
4998 | } | |
4999 | ||
d24317b4 VP |
5000 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5001 | { | |
5002 | if (b->addr_string) | |
5003 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
5004 | else if (b->exp_string) | |
5005 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
5006 | } | |
5007 | ||
3b31d625 | 5008 | do_cleanups (bkpt_chain); |
c4093a6a | 5009 | } |
c5aa993b | 5010 | |
0d381245 VP |
5011 | static void |
5012 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5013 | struct bp_location **last_loc, |
6c95b8df | 5014 | int allflag) |
0d381245 | 5015 | { |
12c5a436 | 5016 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
0d381245 VP |
5017 | |
5018 | /* If this breakpoint has custom print function, | |
5019 | it's already printed. Otherwise, print individual | |
5020 | locations, if any. */ | |
5021 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5022 | { | |
4a64f543 MS |
5023 | /* If breakpoint has a single location that is disabled, we |
5024 | print it as if it had several locations, since otherwise it's | |
5025 | hard to represent "breakpoint enabled, location disabled" | |
5026 | situation. | |
5027 | ||
5028 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5029 | internally, that's not a property exposed to user. */ |
0d381245 | 5030 | if (b->loc |
a5606eee | 5031 | && !is_hardware_watchpoint (b) |
0d381245 | 5032 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 5033 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
5034 | { |
5035 | struct bp_location *loc; | |
5036 | int n = 1; | |
5037 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
12c5a436 | 5038 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
0d381245 VP |
5039 | } |
5040 | } | |
5041 | } | |
5042 | ||
a6d9a66e UW |
5043 | static int |
5044 | breakpoint_address_bits (struct breakpoint *b) | |
5045 | { | |
5046 | int print_address_bits = 0; | |
5047 | struct bp_location *loc; | |
5048 | ||
5049 | for (loc = b->loc; loc; loc = loc->next) | |
5050 | { | |
c7437ca6 PA |
5051 | int addr_bit; |
5052 | ||
5053 | /* Software watchpoints that aren't watching memory don't have | |
5054 | an address to print. */ | |
5055 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5056 | continue; | |
5057 | ||
5058 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5059 | if (addr_bit > print_address_bits) |
5060 | print_address_bits = addr_bit; | |
5061 | } | |
5062 | ||
5063 | return print_address_bits; | |
5064 | } | |
0d381245 | 5065 | |
c4093a6a JM |
5066 | struct captured_breakpoint_query_args |
5067 | { | |
5068 | int bnum; | |
5069 | }; | |
c5aa993b | 5070 | |
c4093a6a | 5071 | static int |
2b65245e | 5072 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5073 | { |
5074 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5075 | struct breakpoint *b; |
a6d9a66e | 5076 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5077 | |
c4093a6a JM |
5078 | ALL_BREAKPOINTS (b) |
5079 | { | |
5080 | if (args->bnum == b->number) | |
c5aa993b | 5081 | { |
12c5a436 | 5082 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5083 | return GDB_RC_OK; |
c5aa993b | 5084 | } |
c4093a6a JM |
5085 | } |
5086 | return GDB_RC_NONE; | |
5087 | } | |
c5aa993b | 5088 | |
c4093a6a | 5089 | enum gdb_rc |
4a64f543 MS |
5090 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5091 | char **error_message) | |
c4093a6a JM |
5092 | { |
5093 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5094 | |
c4093a6a JM |
5095 | args.bnum = bnum; |
5096 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5097 | an error. */ |
b0b13bb4 DJ |
5098 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5099 | error_message, RETURN_MASK_ALL) < 0) | |
5100 | return GDB_RC_FAIL; | |
5101 | else | |
5102 | return GDB_RC_OK; | |
c4093a6a | 5103 | } |
c5aa993b | 5104 | |
7f3b0473 | 5105 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4a64f543 | 5106 | catchpoints, et.al.). */ |
7f3b0473 AC |
5107 | |
5108 | static int | |
5109 | user_settable_breakpoint (const struct breakpoint *b) | |
5110 | { | |
5111 | return (b->type == bp_breakpoint | |
ce78b96d | 5112 | || b->type == bp_catchpoint |
7f3b0473 | 5113 | || b->type == bp_hardware_breakpoint |
d77f58be | 5114 | || is_tracepoint (b) |
cc60f2e3 | 5115 | || is_watchpoint (b)); |
7f3b0473 | 5116 | } |
4a64f543 | 5117 | |
09d682a4 TT |
5118 | /* Return true if this breakpoint was set by the user, false if it is |
5119 | internal or momentary. */ | |
5120 | ||
5121 | int | |
5122 | user_breakpoint_p (struct breakpoint *b) | |
5123 | { | |
5124 | return user_settable_breakpoint (b) && b->number > 0; | |
5125 | } | |
5126 | ||
7f3b0473 | 5127 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5128 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5129 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5130 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5131 | ones for which it returns non-zero. Return the total number of | |
5132 | breakpoints listed. */ | |
c906108c | 5133 | |
d77f58be | 5134 | static int |
e5a67952 | 5135 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5136 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5137 | { |
52f0bd74 | 5138 | struct breakpoint *b; |
a6d9a66e | 5139 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5140 | int nr_printable_breakpoints; |
3b31d625 | 5141 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5142 | struct value_print_options opts; |
a6d9a66e | 5143 | int print_address_bits = 0; |
269b11a2 PA |
5144 | int print_type_col_width = 14; |
5145 | ||
79a45b7d TT |
5146 | get_user_print_options (&opts); |
5147 | ||
4a64f543 MS |
5148 | /* Compute the number of rows in the table, as well as the size |
5149 | required for address fields. */ | |
7f3b0473 AC |
5150 | nr_printable_breakpoints = 0; |
5151 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5152 | { |
5153 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5154 | if (filter && !filter (b)) | |
5155 | continue; | |
5156 | ||
5157 | /* If we have an "args" string, it is a list of breakpoints to | |
5158 | accept. Skip the others. */ | |
5159 | if (args != NULL && *args != '\0') | |
5160 | { | |
5161 | if (allflag && parse_and_eval_long (args) != b->number) | |
5162 | continue; | |
5163 | if (!allflag && !number_is_in_list (args, b->number)) | |
5164 | continue; | |
5165 | } | |
269b11a2 | 5166 | |
e5a67952 MS |
5167 | if (allflag || user_breakpoint_p (b)) |
5168 | { | |
5169 | int addr_bit, type_len; | |
a6d9a66e | 5170 | |
e5a67952 MS |
5171 | addr_bit = breakpoint_address_bits (b); |
5172 | if (addr_bit > print_address_bits) | |
5173 | print_address_bits = addr_bit; | |
269b11a2 | 5174 | |
e5a67952 MS |
5175 | type_len = strlen (bptype_string (b->type)); |
5176 | if (type_len > print_type_col_width) | |
5177 | print_type_col_width = type_len; | |
5178 | ||
5179 | nr_printable_breakpoints++; | |
5180 | } | |
5181 | } | |
7f3b0473 | 5182 | |
79a45b7d | 5183 | if (opts.addressprint) |
3b31d625 | 5184 | bkpttbl_chain |
3e43a32a MS |
5185 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5186 | nr_printable_breakpoints, | |
3b31d625 | 5187 | "BreakpointTable"); |
8b93c638 | 5188 | else |
3b31d625 | 5189 | bkpttbl_chain |
3e43a32a MS |
5190 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5191 | nr_printable_breakpoints, | |
3b31d625 | 5192 | "BreakpointTable"); |
8b93c638 | 5193 | |
7f3b0473 | 5194 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5195 | annotate_breakpoints_headers (); |
5196 | if (nr_printable_breakpoints > 0) | |
5197 | annotate_field (0); | |
4a64f543 | 5198 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5199 | if (nr_printable_breakpoints > 0) |
5200 | annotate_field (1); | |
269b11a2 | 5201 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5202 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5203 | if (nr_printable_breakpoints > 0) |
5204 | annotate_field (2); | |
4a64f543 | 5205 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5206 | if (nr_printable_breakpoints > 0) |
5207 | annotate_field (3); | |
54e52265 | 5208 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5209 | if (opts.addressprint) |
e5a67952 MS |
5210 | { |
5211 | if (nr_printable_breakpoints > 0) | |
5212 | annotate_field (4); | |
5213 | if (print_address_bits <= 32) | |
5214 | ui_out_table_header (uiout, 10, ui_left, | |
5215 | "addr", "Address"); /* 5 */ | |
5216 | else | |
5217 | ui_out_table_header (uiout, 18, ui_left, | |
5218 | "addr", "Address"); /* 5 */ | |
5219 | } | |
d7faa9e7 AC |
5220 | if (nr_printable_breakpoints > 0) |
5221 | annotate_field (5); | |
5222 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5223 | ui_out_table_body (uiout); | |
5224 | if (nr_printable_breakpoints > 0) | |
5225 | annotate_breakpoints_table (); | |
7f3b0473 | 5226 | |
c4093a6a | 5227 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5228 | { |
5229 | QUIT; | |
5230 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5231 | if (filter && !filter (b)) | |
5232 | continue; | |
5233 | ||
5234 | /* If we have an "args" string, it is a list of breakpoints to | |
5235 | accept. Skip the others. */ | |
5236 | ||
5237 | if (args != NULL && *args != '\0') | |
5238 | { | |
5239 | if (allflag) /* maintenance info breakpoint */ | |
5240 | { | |
5241 | if (parse_and_eval_long (args) != b->number) | |
5242 | continue; | |
5243 | } | |
5244 | else /* all others */ | |
5245 | { | |
5246 | if (!number_is_in_list (args, b->number)) | |
5247 | continue; | |
5248 | } | |
5249 | } | |
5250 | /* We only print out user settable breakpoints unless the | |
5251 | allflag is set. */ | |
5252 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5253 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5254 | } |
5255 | ||
3b31d625 | 5256 | do_cleanups (bkpttbl_chain); |
698384cd | 5257 | |
7f3b0473 | 5258 | if (nr_printable_breakpoints == 0) |
c906108c | 5259 | { |
4a64f543 MS |
5260 | /* If there's a filter, let the caller decide how to report |
5261 | empty list. */ | |
d77f58be SS |
5262 | if (!filter) |
5263 | { | |
e5a67952 | 5264 | if (args == NULL || *args == '\0') |
d77f58be SS |
5265 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5266 | else | |
4a64f543 | 5267 | ui_out_message (uiout, 0, |
e5a67952 MS |
5268 | "No breakpoint or watchpoint matching '%s'.\n", |
5269 | args); | |
d77f58be | 5270 | } |
c906108c SS |
5271 | } |
5272 | else | |
c4093a6a | 5273 | { |
a6d9a66e UW |
5274 | if (last_loc && !server_command) |
5275 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5276 | } |
c906108c | 5277 | |
4a64f543 | 5278 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5279 | there have been breakpoints? */ |
c906108c | 5280 | annotate_breakpoints_table_end (); |
d77f58be SS |
5281 | |
5282 | return nr_printable_breakpoints; | |
c906108c SS |
5283 | } |
5284 | ||
ad443146 SS |
5285 | /* Display the value of default-collect in a way that is generally |
5286 | compatible with the breakpoint list. */ | |
5287 | ||
5288 | static void | |
5289 | default_collect_info (void) | |
5290 | { | |
5291 | /* If it has no value (which is frequently the case), say nothing; a | |
5292 | message like "No default-collect." gets in user's face when it's | |
5293 | not wanted. */ | |
5294 | if (!*default_collect) | |
5295 | return; | |
5296 | ||
5297 | /* The following phrase lines up nicely with per-tracepoint collect | |
5298 | actions. */ | |
5299 | ui_out_text (uiout, "default collect "); | |
5300 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5301 | ui_out_text (uiout, " \n"); | |
5302 | } | |
5303 | ||
c906108c | 5304 | static void |
e5a67952 | 5305 | breakpoints_info (char *args, int from_tty) |
c906108c | 5306 | { |
e5a67952 | 5307 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5308 | |
5309 | default_collect_info (); | |
d77f58be SS |
5310 | } |
5311 | ||
5312 | static void | |
e5a67952 | 5313 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5314 | { |
e5a67952 | 5315 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
d77f58be SS |
5316 | |
5317 | if (num_printed == 0) | |
5318 | { | |
e5a67952 | 5319 | if (args == NULL || *args == '\0') |
d77f58be SS |
5320 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5321 | else | |
e5a67952 | 5322 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5323 | } |
c906108c SS |
5324 | } |
5325 | ||
7a292a7a | 5326 | static void |
e5a67952 | 5327 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5328 | { |
e5a67952 | 5329 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5330 | |
5331 | default_collect_info (); | |
c906108c SS |
5332 | } |
5333 | ||
0d381245 | 5334 | static int |
714835d5 | 5335 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5336 | struct program_space *pspace, |
714835d5 | 5337 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5338 | { |
5339 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5340 | |
0d381245 VP |
5341 | for (; bl; bl = bl->next) |
5342 | { | |
6c95b8df PA |
5343 | if (bl->pspace == pspace |
5344 | && bl->address == pc | |
0d381245 VP |
5345 | && (!overlay_debugging || bl->section == section)) |
5346 | return 1; | |
5347 | } | |
5348 | return 0; | |
5349 | } | |
5350 | ||
6c95b8df PA |
5351 | /* Print a message describing any breakpoints set at PC. This |
5352 | concerns with logical breakpoints, so we match program spaces, not | |
5353 | address spaces. */ | |
c906108c SS |
5354 | |
5355 | static void | |
6c95b8df PA |
5356 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5357 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5358 | struct obj_section *section, int thread) |
c906108c | 5359 | { |
52f0bd74 AC |
5360 | int others = 0; |
5361 | struct breakpoint *b; | |
c906108c SS |
5362 | |
5363 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5364 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5365 | if (others > 0) |
5366 | { | |
a3f17187 AC |
5367 | if (others == 1) |
5368 | printf_filtered (_("Note: breakpoint ")); | |
5369 | else /* if (others == ???) */ | |
5370 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5371 | ALL_BREAKPOINTS (b) |
6c95b8df | 5372 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5373 | { |
5374 | others--; | |
5375 | printf_filtered ("%d", b->number); | |
5376 | if (b->thread == -1 && thread != -1) | |
5377 | printf_filtered (" (all threads)"); | |
5378 | else if (b->thread != -1) | |
5379 | printf_filtered (" (thread %d)", b->thread); | |
5380 | printf_filtered ("%s%s ", | |
059fb39f | 5381 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5382 | || b->enable_state == bp_call_disabled |
5383 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5384 | ? " (disabled)" |
5385 | : b->enable_state == bp_permanent | |
5386 | ? " (permanent)" | |
5387 | : ""), | |
5388 | (others > 1) ? "," | |
5389 | : ((others == 1) ? " and" : "")); | |
5390 | } | |
a3f17187 | 5391 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5392 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5393 | printf_filtered (".\n"); |
5394 | } | |
5395 | } | |
5396 | \f | |
5397 | /* Set the default place to put a breakpoint | |
5398 | for the `break' command with no arguments. */ | |
5399 | ||
5400 | void | |
6c95b8df PA |
5401 | set_default_breakpoint (int valid, struct program_space *pspace, |
5402 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5403 | int line) |
c906108c SS |
5404 | { |
5405 | default_breakpoint_valid = valid; | |
6c95b8df | 5406 | default_breakpoint_pspace = pspace; |
c906108c SS |
5407 | default_breakpoint_address = addr; |
5408 | default_breakpoint_symtab = symtab; | |
5409 | default_breakpoint_line = line; | |
5410 | } | |
5411 | ||
e4f237da KB |
5412 | /* Return true iff it is meaningful to use the address member of |
5413 | BPT. For some breakpoint types, the address member is irrelevant | |
5414 | and it makes no sense to attempt to compare it to other addresses | |
5415 | (or use it for any other purpose either). | |
5416 | ||
4a64f543 MS |
5417 | More specifically, each of the following breakpoint types will |
5418 | always have a zero valued address and we don't want to mark | |
5419 | breakpoints of any of these types to be a duplicate of an actual | |
5420 | breakpoint at address zero: | |
e4f237da KB |
5421 | |
5422 | bp_watchpoint | |
2d134ed3 PA |
5423 | bp_catchpoint |
5424 | ||
5425 | */ | |
e4f237da KB |
5426 | |
5427 | static int | |
5428 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5429 | { | |
5430 | enum bptype type = bpt->type; | |
5431 | ||
2d134ed3 PA |
5432 | return (type != bp_watchpoint && type != bp_catchpoint); |
5433 | } | |
5434 | ||
5435 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5436 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5437 | ||
5438 | static int | |
4a64f543 MS |
5439 | watchpoint_locations_match (struct bp_location *loc1, |
5440 | struct bp_location *loc2) | |
2d134ed3 | 5441 | { |
2bdf28a0 JK |
5442 | /* Both of them must not be in moribund_locations. */ |
5443 | gdb_assert (loc1->owner != NULL); | |
5444 | gdb_assert (loc2->owner != NULL); | |
5445 | ||
4a64f543 MS |
5446 | /* If the target can evaluate the condition expression in hardware, |
5447 | then we we need to insert both watchpoints even if they are at | |
5448 | the same place. Otherwise the watchpoint will only trigger when | |
5449 | the condition of whichever watchpoint was inserted evaluates to | |
5450 | true, not giving a chance for GDB to check the condition of the | |
5451 | other watchpoint. */ | |
0cf6dd15 | 5452 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5453 | && target_can_accel_watchpoint_condition (loc1->address, |
5454 | loc1->length, | |
0cf6dd15 TJB |
5455 | loc1->watchpoint_type, |
5456 | loc1->owner->cond_exp)) | |
5457 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5458 | && target_can_accel_watchpoint_condition (loc2->address, |
5459 | loc2->length, | |
0cf6dd15 TJB |
5460 | loc2->watchpoint_type, |
5461 | loc2->owner->cond_exp))) | |
5462 | return 0; | |
5463 | ||
85d721b8 PA |
5464 | /* Note that this checks the owner's type, not the location's. In |
5465 | case the target does not support read watchpoints, but does | |
5466 | support access watchpoints, we'll have bp_read_watchpoint | |
5467 | watchpoints with hw_access locations. Those should be considered | |
5468 | duplicates of hw_read locations. The hw_read locations will | |
5469 | become hw_access locations later. */ | |
2d134ed3 PA |
5470 | return (loc1->owner->type == loc2->owner->type |
5471 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5472 | && loc1->address == loc2->address | |
5473 | && loc1->length == loc2->length); | |
e4f237da KB |
5474 | } |
5475 | ||
6c95b8df PA |
5476 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5477 | same breakpoint location. In most targets, this can only be true | |
5478 | if ASPACE1 matches ASPACE2. On targets that have global | |
5479 | breakpoints, the address space doesn't really matter. */ | |
5480 | ||
5481 | static int | |
5482 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5483 | struct address_space *aspace2, CORE_ADDR addr2) | |
5484 | { | |
5485 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5486 | || aspace1 == aspace2) | |
5487 | && addr1 == addr2); | |
5488 | } | |
5489 | ||
2d134ed3 PA |
5490 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5491 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5492 | represent the same location. */ | |
5493 | ||
5494 | static int | |
4a64f543 MS |
5495 | breakpoint_locations_match (struct bp_location *loc1, |
5496 | struct bp_location *loc2) | |
2d134ed3 | 5497 | { |
2bdf28a0 JK |
5498 | int hw_point1, hw_point2; |
5499 | ||
5500 | /* Both of them must not be in moribund_locations. */ | |
5501 | gdb_assert (loc1->owner != NULL); | |
5502 | gdb_assert (loc2->owner != NULL); | |
5503 | ||
5504 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5505 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5506 | |
5507 | if (hw_point1 != hw_point2) | |
5508 | return 0; | |
5509 | else if (hw_point1) | |
5510 | return watchpoint_locations_match (loc1, loc2); | |
5511 | else | |
5512 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5513 | loc2->pspace->aspace, loc2->address); | |
5514 | } | |
5515 | ||
76897487 KB |
5516 | static void |
5517 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5518 | int bnum, int have_bnum) | |
5519 | { | |
f63fbe86 MS |
5520 | /* The longest string possibly returned by hex_string_custom |
5521 | is 50 chars. These must be at least that big for safety. */ | |
5522 | char astr1[64]; | |
5523 | char astr2[64]; | |
76897487 | 5524 | |
bb599908 PH |
5525 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5526 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5527 | if (have_bnum) |
8a3fe4f8 | 5528 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5529 | bnum, astr1, astr2); |
5530 | else | |
8a3fe4f8 | 5531 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5532 | } |
5533 | ||
4a64f543 MS |
5534 | /* Adjust a breakpoint's address to account for architectural |
5535 | constraints on breakpoint placement. Return the adjusted address. | |
5536 | Note: Very few targets require this kind of adjustment. For most | |
5537 | targets, this function is simply the identity function. */ | |
76897487 KB |
5538 | |
5539 | static CORE_ADDR | |
a6d9a66e UW |
5540 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5541 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5542 | { |
a6d9a66e | 5543 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5544 | { |
5545 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5546 | return bpaddr; | |
5547 | } | |
88f7da05 KB |
5548 | else if (bptype == bp_watchpoint |
5549 | || bptype == bp_hardware_watchpoint | |
5550 | || bptype == bp_read_watchpoint | |
5551 | || bptype == bp_access_watchpoint | |
fe798b75 | 5552 | || bptype == bp_catchpoint) |
88f7da05 KB |
5553 | { |
5554 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5555 | have their addresses modified. */ | |
5556 | return bpaddr; | |
5557 | } | |
76897487 KB |
5558 | else |
5559 | { | |
5560 | CORE_ADDR adjusted_bpaddr; | |
5561 | ||
5562 | /* Some targets have architectural constraints on the placement | |
5563 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5564 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5565 | |
5566 | /* An adjusted breakpoint address can significantly alter | |
5567 | a user's expectations. Print a warning if an adjustment | |
5568 | is required. */ | |
5569 | if (adjusted_bpaddr != bpaddr) | |
5570 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5571 | ||
5572 | return adjusted_bpaddr; | |
5573 | } | |
5574 | } | |
5575 | ||
7cc221ef DJ |
5576 | /* Allocate a struct bp_location. */ |
5577 | ||
26bb91f3 | 5578 | static struct bp_location * |
39d61571 | 5579 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5580 | { |
afe38095 | 5581 | struct bp_location *loc; |
7cc221ef DJ |
5582 | |
5583 | loc = xmalloc (sizeof (struct bp_location)); | |
5584 | memset (loc, 0, sizeof (*loc)); | |
5585 | ||
e049a4b5 | 5586 | loc->owner = bpt; |
511a6cd4 | 5587 | loc->cond = NULL; |
0d381245 VP |
5588 | loc->shlib_disabled = 0; |
5589 | loc->enabled = 1; | |
e049a4b5 | 5590 | |
39d61571 | 5591 | switch (bpt->type) |
e049a4b5 DJ |
5592 | { |
5593 | case bp_breakpoint: | |
5594 | case bp_until: | |
5595 | case bp_finish: | |
5596 | case bp_longjmp: | |
5597 | case bp_longjmp_resume: | |
186c406b TT |
5598 | case bp_exception: |
5599 | case bp_exception_resume: | |
e049a4b5 | 5600 | case bp_step_resume: |
e049a4b5 DJ |
5601 | case bp_watchpoint_scope: |
5602 | case bp_call_dummy: | |
aa7d318d | 5603 | case bp_std_terminate: |
e049a4b5 DJ |
5604 | case bp_shlib_event: |
5605 | case bp_thread_event: | |
5606 | case bp_overlay_event: | |
4efc6507 | 5607 | case bp_jit_event: |
0fd8e87f | 5608 | case bp_longjmp_master: |
aa7d318d | 5609 | case bp_std_terminate_master: |
186c406b | 5610 | case bp_exception_master: |
e049a4b5 DJ |
5611 | loc->loc_type = bp_loc_software_breakpoint; |
5612 | break; | |
5613 | case bp_hardware_breakpoint: | |
5614 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5615 | break; | |
5616 | case bp_hardware_watchpoint: | |
5617 | case bp_read_watchpoint: | |
5618 | case bp_access_watchpoint: | |
5619 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5620 | break; | |
5621 | case bp_watchpoint: | |
ce78b96d | 5622 | case bp_catchpoint: |
15c3d785 PA |
5623 | case bp_tracepoint: |
5624 | case bp_fast_tracepoint: | |
0fb4aa4b | 5625 | case bp_static_tracepoint: |
e049a4b5 DJ |
5626 | loc->loc_type = bp_loc_other; |
5627 | break; | |
5628 | default: | |
e2e0b3e5 | 5629 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5630 | } |
5631 | ||
f431efe5 | 5632 | loc->refc = 1; |
7cc221ef DJ |
5633 | return loc; |
5634 | } | |
5635 | ||
f431efe5 PA |
5636 | static void |
5637 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5638 | { |
5639 | if (loc->cond) | |
5640 | xfree (loc->cond); | |
74960c60 VP |
5641 | |
5642 | if (loc->function_name) | |
5643 | xfree (loc->function_name); | |
f431efe5 | 5644 | |
fe3f5fa8 VP |
5645 | xfree (loc); |
5646 | } | |
5647 | ||
f431efe5 PA |
5648 | /* Increment reference count. */ |
5649 | ||
5650 | static void | |
5651 | incref_bp_location (struct bp_location *bl) | |
5652 | { | |
5653 | ++bl->refc; | |
5654 | } | |
5655 | ||
5656 | /* Decrement reference count. If the reference count reaches 0, | |
5657 | destroy the bp_location. Sets *BLP to NULL. */ | |
5658 | ||
5659 | static void | |
5660 | decref_bp_location (struct bp_location **blp) | |
5661 | { | |
0807b50c PA |
5662 | gdb_assert ((*blp)->refc > 0); |
5663 | ||
f431efe5 PA |
5664 | if (--(*blp)->refc == 0) |
5665 | free_bp_location (*blp); | |
5666 | *blp = NULL; | |
5667 | } | |
5668 | ||
4a64f543 MS |
5669 | /* Helper to set_raw_breakpoint below. Creates a breakpoint that has |
5670 | type BPTYPE and has no locations as yet. */ | |
5671 | /* This function is used in gdbtk sources and thus can not be made | |
5672 | static. */ | |
c906108c | 5673 | |
c40e75cd | 5674 | static struct breakpoint * |
a6d9a66e UW |
5675 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5676 | enum bptype bptype) | |
c906108c | 5677 | { |
52f0bd74 | 5678 | struct breakpoint *b, *b1; |
c906108c SS |
5679 | |
5680 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5681 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5682 | |
4d28f7a8 | 5683 | b->type = bptype; |
a6d9a66e | 5684 | b->gdbarch = gdbarch; |
c906108c SS |
5685 | b->language = current_language->la_language; |
5686 | b->input_radix = input_radix; | |
5687 | b->thread = -1; | |
b5de0fa7 | 5688 | b->enable_state = bp_enabled; |
c906108c SS |
5689 | b->next = 0; |
5690 | b->silent = 0; | |
5691 | b->ignore_count = 0; | |
5692 | b->commands = NULL; | |
818dd999 | 5693 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5694 | b->forked_inferior_pid = null_ptid; |
c906108c | 5695 | b->exec_pathname = NULL; |
a96d9b2e | 5696 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5697 | b->ops = NULL; |
0d381245 | 5698 | b->condition_not_parsed = 0; |
84f4c1fe | 5699 | b->py_bp_object = NULL; |
c906108c | 5700 | |
4a64f543 MS |
5701 | /* Add this breakpoint to the end of the chain so that a list of |
5702 | breakpoints will come out in order of increasing numbers. */ | |
c906108c SS |
5703 | |
5704 | b1 = breakpoint_chain; | |
5705 | if (b1 == 0) | |
5706 | breakpoint_chain = b; | |
5707 | else | |
5708 | { | |
5709 | while (b1->next) | |
5710 | b1 = b1->next; | |
5711 | b1->next = b; | |
5712 | } | |
0d381245 VP |
5713 | return b; |
5714 | } | |
5715 | ||
5716 | /* Initialize loc->function_name. */ | |
5717 | static void | |
5718 | set_breakpoint_location_function (struct bp_location *loc) | |
5719 | { | |
2bdf28a0 JK |
5720 | gdb_assert (loc->owner != NULL); |
5721 | ||
0d381245 | 5722 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5723 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5724 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5725 | { |
5726 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5727 | NULL, NULL); | |
5728 | if (loc->function_name) | |
5729 | loc->function_name = xstrdup (loc->function_name); | |
5730 | } | |
5731 | } | |
5732 | ||
a6d9a66e UW |
5733 | /* Attempt to determine architecture of location identified by SAL. */ |
5734 | static struct gdbarch * | |
5735 | get_sal_arch (struct symtab_and_line sal) | |
5736 | { | |
5737 | if (sal.section) | |
5738 | return get_objfile_arch (sal.section->objfile); | |
5739 | if (sal.symtab) | |
5740 | return get_objfile_arch (sal.symtab->objfile); | |
5741 | ||
5742 | return NULL; | |
5743 | } | |
5744 | ||
0d381245 VP |
5745 | /* set_raw_breakpoint is a low level routine for allocating and |
5746 | partially initializing a breakpoint of type BPTYPE. The newly | |
5747 | created breakpoint's address, section, source file name, and line | |
5748 | number are provided by SAL. The newly created and partially | |
5749 | initialized breakpoint is added to the breakpoint chain and | |
5750 | is also returned as the value of this function. | |
5751 | ||
5752 | It is expected that the caller will complete the initialization of | |
5753 | the newly created breakpoint struct as well as output any status | |
5754 | information regarding the creation of a new breakpoint. In | |
5755 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5756 | number! Care should be taken to not allow an error to occur | |
5757 | prior to completing the initialization of the breakpoint. If this | |
5758 | should happen, a bogus breakpoint will be left on the chain. */ | |
5759 | ||
63c252f8 | 5760 | struct breakpoint * |
a6d9a66e UW |
5761 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5762 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5763 | { |
4a64f543 MS |
5764 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, |
5765 | bptype); | |
0d381245 | 5766 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5767 | struct gdbarch *loc_gdbarch; |
5768 | ||
5769 | loc_gdbarch = get_sal_arch (sal); | |
5770 | if (!loc_gdbarch) | |
5771 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5772 | |
6c95b8df PA |
5773 | if (bptype != bp_catchpoint) |
5774 | gdb_assert (sal.pspace != NULL); | |
5775 | ||
0d381245 VP |
5776 | /* Adjust the breakpoint's address prior to allocating a location. |
5777 | Once we call allocate_bp_location(), that mostly uninitialized | |
5778 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5779 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5780 | not want its scan of the location chain to find a breakpoint and |
5781 | location that's only been partially initialized. */ | |
4a64f543 MS |
5782 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5783 | sal.pc, b->type); | |
0d381245 | 5784 | |
39d61571 | 5785 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5786 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5787 | b->loc->requested_address = sal.pc; |
5788 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5789 | b->loc->pspace = sal.pspace; |
5790 | ||
5791 | /* Store the program space that was used to set the breakpoint, for | |
5792 | breakpoint resetting. */ | |
5793 | b->pspace = sal.pspace; | |
0d381245 VP |
5794 | |
5795 | if (sal.symtab == NULL) | |
5796 | b->source_file = NULL; | |
5797 | else | |
1b36a34b | 5798 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5799 | b->loc->section = sal.section; |
5800 | b->line_number = sal.line; | |
5801 | ||
5802 | set_breakpoint_location_function (b->loc); | |
c906108c | 5803 | |
c906108c SS |
5804 | breakpoints_changed (); |
5805 | ||
5806 | return b; | |
5807 | } | |
5808 | ||
c2c6d25f JM |
5809 | |
5810 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5811 | instruction, hard-wired into the inferior's code. */ | |
5812 | void | |
5813 | make_breakpoint_permanent (struct breakpoint *b) | |
5814 | { | |
0d381245 | 5815 | struct bp_location *bl; |
cc59ec59 | 5816 | |
b5de0fa7 | 5817 | b->enable_state = bp_permanent; |
c2c6d25f | 5818 | |
4a64f543 MS |
5819 | /* By definition, permanent breakpoints are already present in the |
5820 | code. Mark all locations as inserted. For now, | |
5821 | make_breakpoint_permanent is called in just one place, so it's | |
5822 | hard to say if it's reasonable to have permanent breakpoint with | |
5823 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
5824 | for (bl = b->loc; bl; bl = bl->next) |
5825 | bl->inserted = 1; | |
c2c6d25f JM |
5826 | } |
5827 | ||
53a5351d | 5828 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5829 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5830 | initiated the operation. */ | |
c906108c SS |
5831 | |
5832 | void | |
186c406b | 5833 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5834 | { |
35df4500 | 5835 | struct breakpoint *b, *b_tmp; |
186c406b | 5836 | int thread = tp->num; |
0fd8e87f UW |
5837 | |
5838 | /* To avoid having to rescan all objfile symbols at every step, | |
5839 | we maintain a list of continually-inserted but always disabled | |
5840 | longjmp "master" breakpoints. Here, we simply create momentary | |
5841 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5842 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5843 | if (b->pspace == current_program_space |
186c406b TT |
5844 | && (b->type == bp_longjmp_master |
5845 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
5846 | { |
5847 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5848 | |
186c406b | 5849 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
5850 | clone->thread = thread; |
5851 | } | |
186c406b TT |
5852 | |
5853 | tp->initiating_frame = frame; | |
c906108c SS |
5854 | } |
5855 | ||
611c83ae | 5856 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5857 | void |
611c83ae | 5858 | delete_longjmp_breakpoint (int thread) |
c906108c | 5859 | { |
35df4500 | 5860 | struct breakpoint *b, *b_tmp; |
c906108c | 5861 | |
35df4500 | 5862 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5863 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5864 | { |
5865 | if (b->thread == thread) | |
5866 | delete_breakpoint (b); | |
5867 | } | |
c906108c SS |
5868 | } |
5869 | ||
1900040c MS |
5870 | void |
5871 | enable_overlay_breakpoints (void) | |
5872 | { | |
52f0bd74 | 5873 | struct breakpoint *b; |
1900040c MS |
5874 | |
5875 | ALL_BREAKPOINTS (b) | |
5876 | if (b->type == bp_overlay_event) | |
5877 | { | |
5878 | b->enable_state = bp_enabled; | |
b60e7edf | 5879 | update_global_location_list (1); |
c02f5703 | 5880 | overlay_events_enabled = 1; |
1900040c MS |
5881 | } |
5882 | } | |
5883 | ||
5884 | void | |
5885 | disable_overlay_breakpoints (void) | |
5886 | { | |
52f0bd74 | 5887 | struct breakpoint *b; |
1900040c MS |
5888 | |
5889 | ALL_BREAKPOINTS (b) | |
5890 | if (b->type == bp_overlay_event) | |
5891 | { | |
5892 | b->enable_state = bp_disabled; | |
b60e7edf | 5893 | update_global_location_list (0); |
c02f5703 | 5894 | overlay_events_enabled = 0; |
1900040c MS |
5895 | } |
5896 | } | |
5897 | ||
aa7d318d TT |
5898 | /* Set an active std::terminate breakpoint for each std::terminate |
5899 | master breakpoint. */ | |
5900 | void | |
5901 | set_std_terminate_breakpoint (void) | |
5902 | { | |
35df4500 | 5903 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5904 | |
35df4500 | 5905 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5906 | if (b->pspace == current_program_space |
5907 | && b->type == bp_std_terminate_master) | |
5908 | { | |
5909 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5910 | clone->type = bp_std_terminate; | |
5911 | } | |
5912 | } | |
5913 | ||
5914 | /* Delete all the std::terminate breakpoints. */ | |
5915 | void | |
5916 | delete_std_terminate_breakpoint (void) | |
5917 | { | |
35df4500 | 5918 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5919 | |
35df4500 | 5920 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5921 | if (b->type == bp_std_terminate) |
5922 | delete_breakpoint (b); | |
5923 | } | |
5924 | ||
c4093a6a | 5925 | struct breakpoint * |
a6d9a66e | 5926 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5927 | { |
5928 | struct breakpoint *b; | |
c4093a6a | 5929 | |
a6d9a66e | 5930 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5931 | |
b5de0fa7 | 5932 | b->enable_state = bp_enabled; |
c4093a6a | 5933 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5934 | b->addr_string |
5935 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5936 | |
b60e7edf | 5937 | update_global_location_list_nothrow (1); |
74960c60 | 5938 | |
c4093a6a JM |
5939 | return b; |
5940 | } | |
5941 | ||
5942 | void | |
5943 | remove_thread_event_breakpoints (void) | |
5944 | { | |
35df4500 | 5945 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5946 | |
35df4500 | 5947 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5948 | if (b->type == bp_thread_event |
5949 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5950 | delete_breakpoint (b); |
5951 | } | |
5952 | ||
0101ce28 JJ |
5953 | struct captured_parse_breakpoint_args |
5954 | { | |
5955 | char **arg_p; | |
5956 | struct symtabs_and_lines *sals_p; | |
5957 | char ***addr_string_p; | |
5958 | int *not_found_ptr; | |
5959 | }; | |
5960 | ||
5961 | struct lang_and_radix | |
5962 | { | |
5963 | enum language lang; | |
5964 | int radix; | |
5965 | }; | |
5966 | ||
4efc6507 DE |
5967 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5968 | ||
5969 | struct breakpoint * | |
5970 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5971 | { | |
5972 | struct breakpoint *b; | |
5973 | ||
5974 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5975 | update_global_location_list_nothrow (1); | |
5976 | return b; | |
5977 | } | |
0101ce28 | 5978 | |
03673fc7 PP |
5979 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
5980 | ||
5981 | void | |
5982 | remove_jit_event_breakpoints (void) | |
5983 | { | |
5984 | struct breakpoint *b, *b_tmp; | |
5985 | ||
5986 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5987 | if (b->type == bp_jit_event | |
5988 | && b->loc->pspace == current_program_space) | |
5989 | delete_breakpoint (b); | |
5990 | } | |
5991 | ||
cae688ec JJ |
5992 | void |
5993 | remove_solib_event_breakpoints (void) | |
5994 | { | |
35df4500 | 5995 | struct breakpoint *b, *b_tmp; |
cae688ec | 5996 | |
35df4500 | 5997 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5998 | if (b->type == bp_shlib_event |
5999 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6000 | delete_breakpoint (b); |
6001 | } | |
6002 | ||
6003 | struct breakpoint * | |
a6d9a66e | 6004 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6005 | { |
6006 | struct breakpoint *b; | |
6007 | ||
a6d9a66e | 6008 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 6009 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6010 | return b; |
6011 | } | |
6012 | ||
6013 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6014 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6015 | ||
6016 | void | |
cb851954 | 6017 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6018 | { |
876fa593 | 6019 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6020 | |
876fa593 | 6021 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6022 | { |
2bdf28a0 | 6023 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6024 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6025 | |
4a64f543 MS |
6026 | /* We apply the check to all breakpoints, including disabled for |
6027 | those with loc->duplicate set. This is so that when breakpoint | |
6028 | becomes enabled, or the duplicate is removed, gdb will try to | |
6029 | insert all breakpoints. If we don't set shlib_disabled here, | |
6030 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6031 | if (((b->type == bp_breakpoint) |
508ccb1f | 6032 | || (b->type == bp_jit_event) |
1042e4c0 | 6033 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6034 | || (is_tracepoint (b))) |
6c95b8df | 6035 | && loc->pspace == current_program_space |
0d381245 | 6036 | && !loc->shlib_disabled |
a77053c2 | 6037 | #ifdef PC_SOLIB |
0d381245 | 6038 | && PC_SOLIB (loc->address) |
a77053c2 | 6039 | #else |
6c95b8df | 6040 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6041 | #endif |
6042 | ) | |
0d381245 VP |
6043 | { |
6044 | loc->shlib_disabled = 1; | |
6045 | } | |
cae688ec JJ |
6046 | } |
6047 | } | |
6048 | ||
4a64f543 MS |
6049 | /* Disable any breakpoints that are in in an unloaded shared library. |
6050 | Only apply to enabled breakpoints, disabled ones can just stay | |
6051 | disabled. */ | |
84acb35a | 6052 | |
75149521 | 6053 | static void |
84acb35a JJ |
6054 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6055 | { | |
876fa593 | 6056 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6057 | int disabled_shlib_breaks = 0; |
6058 | ||
c86cf029 VP |
6059 | /* SunOS a.out shared libraries are always mapped, so do not |
6060 | disable breakpoints; they will only be reported as unloaded | |
6061 | through clear_solib when GDB discards its shared library | |
6062 | list. See clear_solib for more information. */ | |
6063 | if (exec_bfd != NULL | |
6064 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6065 | return; | |
6066 | ||
876fa593 | 6067 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6068 | { |
2bdf28a0 | 6069 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6070 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6071 | |
0d381245 VP |
6072 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6073 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6074 | && solib->pspace == loc->pspace |
e2dd7057 | 6075 | && !loc->shlib_disabled |
508ccb1f TT |
6076 | && (b->type == bp_breakpoint |
6077 | || b->type == bp_jit_event | |
6078 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6079 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6080 | { |
e2dd7057 PP |
6081 | loc->shlib_disabled = 1; |
6082 | /* At this point, we cannot rely on remove_breakpoint | |
6083 | succeeding so we must mark the breakpoint as not inserted | |
6084 | to prevent future errors occurring in remove_breakpoints. */ | |
6085 | loc->inserted = 0; | |
6086 | if (!disabled_shlib_breaks) | |
6087 | { | |
6088 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6089 | warning (_("Temporarily disabling breakpoints " |
6090 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6091 | solib->so_name); |
84acb35a | 6092 | } |
e2dd7057 | 6093 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6094 | } |
6095 | } | |
84acb35a JJ |
6096 | } |
6097 | ||
ce78b96d JB |
6098 | /* FORK & VFORK catchpoints. */ |
6099 | ||
4a64f543 MS |
6100 | /* Implement the "insert" breakpoint_ops method for fork |
6101 | catchpoints. */ | |
ce78b96d | 6102 | |
77b06cd7 TJB |
6103 | static int |
6104 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6105 | { |
77b06cd7 | 6106 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6107 | } |
6108 | ||
4a64f543 MS |
6109 | /* Implement the "remove" breakpoint_ops method for fork |
6110 | catchpoints. */ | |
ce78b96d JB |
6111 | |
6112 | static int | |
77b06cd7 | 6113 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6114 | { |
6115 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6116 | } | |
6117 | ||
6118 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6119 | catchpoints. */ | |
6120 | ||
6121 | static int | |
6122 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
6123 | { | |
6124 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
6125 | } | |
6126 | ||
4a64f543 MS |
6127 | /* Implement the "print_it" breakpoint_ops method for fork |
6128 | catchpoints. */ | |
ce78b96d JB |
6129 | |
6130 | static enum print_stop_action | |
6131 | print_it_catch_fork (struct breakpoint *b) | |
6132 | { | |
6133 | annotate_catchpoint (b->number); | |
6134 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
6135 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6136 | return PRINT_SRC_AND_LOC; | |
6137 | } | |
6138 | ||
4a64f543 MS |
6139 | /* Implement the "print_one" breakpoint_ops method for fork |
6140 | catchpoints. */ | |
ce78b96d JB |
6141 | |
6142 | static void | |
a6d9a66e | 6143 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6144 | { |
79a45b7d TT |
6145 | struct value_print_options opts; |
6146 | ||
6147 | get_user_print_options (&opts); | |
6148 | ||
4a64f543 MS |
6149 | /* Field 4, the address, is omitted (which makes the columns not |
6150 | line up too nicely with the headers, but the effect is relatively | |
6151 | readable). */ | |
79a45b7d | 6152 | if (opts.addressprint) |
ce78b96d JB |
6153 | ui_out_field_skip (uiout, "addr"); |
6154 | annotate_field (5); | |
6155 | ui_out_text (uiout, "fork"); | |
6156 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6157 | { | |
6158 | ui_out_text (uiout, ", process "); | |
6159 | ui_out_field_int (uiout, "what", | |
6160 | ptid_get_pid (b->forked_inferior_pid)); | |
6161 | ui_out_spaces (uiout, 1); | |
6162 | } | |
6163 | } | |
6164 | ||
6165 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6166 | catchpoints. */ | |
6167 | ||
6168 | static void | |
6169 | print_mention_catch_fork (struct breakpoint *b) | |
6170 | { | |
6171 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6172 | } | |
6173 | ||
6149aea9 PA |
6174 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6175 | catchpoints. */ | |
6176 | ||
6177 | static void | |
6178 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6179 | { | |
6180 | fprintf_unfiltered (fp, "catch fork"); | |
6181 | } | |
6182 | ||
ce78b96d JB |
6183 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6184 | ||
6185 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6186 | { | |
6187 | insert_catch_fork, | |
6188 | remove_catch_fork, | |
6189 | breakpoint_hit_catch_fork, | |
e09342b5 | 6190 | NULL, /* resources_needed */ |
ce78b96d JB |
6191 | print_it_catch_fork, |
6192 | print_one_catch_fork, | |
6149aea9 PA |
6193 | print_mention_catch_fork, |
6194 | print_recreate_catch_fork | |
ce78b96d JB |
6195 | }; |
6196 | ||
4a64f543 MS |
6197 | /* Implement the "insert" breakpoint_ops method for vfork |
6198 | catchpoints. */ | |
ce78b96d | 6199 | |
77b06cd7 TJB |
6200 | static int |
6201 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6202 | { |
77b06cd7 | 6203 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6204 | } |
6205 | ||
4a64f543 MS |
6206 | /* Implement the "remove" breakpoint_ops method for vfork |
6207 | catchpoints. */ | |
ce78b96d JB |
6208 | |
6209 | static int | |
77b06cd7 | 6210 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6211 | { |
6212 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6213 | } | |
6214 | ||
6215 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6216 | catchpoints. */ | |
6217 | ||
6218 | static int | |
6219 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
6220 | { | |
6221 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
6222 | } | |
6223 | ||
4a64f543 MS |
6224 | /* Implement the "print_it" breakpoint_ops method for vfork |
6225 | catchpoints. */ | |
ce78b96d JB |
6226 | |
6227 | static enum print_stop_action | |
6228 | print_it_catch_vfork (struct breakpoint *b) | |
6229 | { | |
6230 | annotate_catchpoint (b->number); | |
6231 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
6232 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6233 | return PRINT_SRC_AND_LOC; | |
6234 | } | |
6235 | ||
4a64f543 MS |
6236 | /* Implement the "print_one" breakpoint_ops method for vfork |
6237 | catchpoints. */ | |
ce78b96d JB |
6238 | |
6239 | static void | |
a6d9a66e | 6240 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6241 | { |
79a45b7d TT |
6242 | struct value_print_options opts; |
6243 | ||
6244 | get_user_print_options (&opts); | |
4a64f543 MS |
6245 | /* Field 4, the address, is omitted (which makes the columns not |
6246 | line up too nicely with the headers, but the effect is relatively | |
6247 | readable). */ | |
79a45b7d | 6248 | if (opts.addressprint) |
ce78b96d JB |
6249 | ui_out_field_skip (uiout, "addr"); |
6250 | annotate_field (5); | |
6251 | ui_out_text (uiout, "vfork"); | |
6252 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6253 | { | |
6254 | ui_out_text (uiout, ", process "); | |
6255 | ui_out_field_int (uiout, "what", | |
6256 | ptid_get_pid (b->forked_inferior_pid)); | |
6257 | ui_out_spaces (uiout, 1); | |
6258 | } | |
6259 | } | |
6260 | ||
6261 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6262 | catchpoints. */ | |
6263 | ||
6264 | static void | |
6265 | print_mention_catch_vfork (struct breakpoint *b) | |
6266 | { | |
6267 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6268 | } | |
6269 | ||
6149aea9 PA |
6270 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6271 | catchpoints. */ | |
6272 | ||
6273 | static void | |
6274 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6275 | { | |
6276 | fprintf_unfiltered (fp, "catch vfork"); | |
6277 | } | |
6278 | ||
ce78b96d JB |
6279 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6280 | ||
6281 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6282 | { | |
6283 | insert_catch_vfork, | |
6284 | remove_catch_vfork, | |
6285 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6286 | NULL, /* resources_needed */ |
ce78b96d JB |
6287 | print_it_catch_vfork, |
6288 | print_one_catch_vfork, | |
6149aea9 PA |
6289 | print_mention_catch_vfork, |
6290 | print_recreate_catch_vfork | |
ce78b96d JB |
6291 | }; |
6292 | ||
a96d9b2e SDJ |
6293 | /* Implement the "insert" breakpoint_ops method for syscall |
6294 | catchpoints. */ | |
6295 | ||
77b06cd7 TJB |
6296 | static int |
6297 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e SDJ |
6298 | { |
6299 | struct inferior *inf = current_inferior (); | |
6300 | ||
6301 | ++inf->total_syscalls_count; | |
77b06cd7 | 6302 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6303 | ++inf->any_syscall_count; |
6304 | else | |
6305 | { | |
6306 | int i, iter; | |
cc59ec59 | 6307 | |
a96d9b2e | 6308 | for (i = 0; |
77b06cd7 | 6309 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6310 | i++) |
6311 | { | |
6312 | int elem; | |
cc59ec59 | 6313 | |
a96d9b2e SDJ |
6314 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6315 | { | |
6316 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6317 | uintptr_t vec_addr_offset |
6318 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6319 | uintptr_t vec_addr; |
6320 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6321 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6322 | vec_addr_offset; | |
6323 | memset ((void *) vec_addr, 0, | |
6324 | (iter + 1 - old_size) * sizeof (int)); | |
6325 | } | |
6326 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6327 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6328 | } | |
6329 | } | |
6330 | ||
77b06cd7 TJB |
6331 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6332 | inf->total_syscalls_count != 0, | |
6333 | inf->any_syscall_count, | |
6334 | VEC_length (int, inf->syscalls_counts), | |
6335 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6336 | } |
6337 | ||
6338 | /* Implement the "remove" breakpoint_ops method for syscall | |
6339 | catchpoints. */ | |
6340 | ||
6341 | static int | |
77b06cd7 | 6342 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e SDJ |
6343 | { |
6344 | struct inferior *inf = current_inferior (); | |
6345 | ||
6346 | --inf->total_syscalls_count; | |
77b06cd7 | 6347 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6348 | --inf->any_syscall_count; |
6349 | else | |
6350 | { | |
6351 | int i, iter; | |
cc59ec59 | 6352 | |
a96d9b2e | 6353 | for (i = 0; |
77b06cd7 | 6354 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6355 | i++) |
6356 | { | |
6357 | int elem; | |
6358 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6359 | /* Shouldn't happen. */ | |
6360 | continue; | |
6361 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6362 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6363 | } | |
6364 | } | |
6365 | ||
6366 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6367 | inf->total_syscalls_count != 0, | |
6368 | inf->any_syscall_count, | |
6369 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6370 | VEC_address (int, |
6371 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6372 | } |
6373 | ||
6374 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6375 | catchpoints. */ | |
6376 | ||
6377 | static int | |
6378 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6379 | { | |
4a64f543 MS |
6380 | /* We must check if we are catching specific syscalls in this |
6381 | breakpoint. If we are, then we must guarantee that the called | |
6382 | syscall is the same syscall we are catching. */ | |
a96d9b2e SDJ |
6383 | int syscall_number = 0; |
6384 | ||
6385 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6386 | return 0; | |
6387 | ||
6388 | /* Now, checking if the syscall is the same. */ | |
6389 | if (b->syscalls_to_be_caught) | |
6390 | { | |
6391 | int i, iter; | |
cc59ec59 | 6392 | |
a96d9b2e SDJ |
6393 | for (i = 0; |
6394 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6395 | i++) | |
6396 | if (syscall_number == iter) | |
6397 | break; | |
6398 | /* Not the same. */ | |
6399 | if (!iter) | |
6400 | return 0; | |
6401 | } | |
6402 | ||
6403 | return 1; | |
6404 | } | |
6405 | ||
6406 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6407 | catchpoints. */ | |
6408 | ||
6409 | static enum print_stop_action | |
6410 | print_it_catch_syscall (struct breakpoint *b) | |
6411 | { | |
6412 | /* These are needed because we want to know in which state a | |
6413 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6414 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6415 | must print "called syscall" or "returned from syscall". */ | |
6416 | ptid_t ptid; | |
6417 | struct target_waitstatus last; | |
6418 | struct syscall s; | |
6419 | struct cleanup *old_chain; | |
6420 | char *syscall_id; | |
6421 | ||
6422 | get_last_target_status (&ptid, &last); | |
6423 | ||
6424 | get_syscall_by_number (last.value.syscall_number, &s); | |
6425 | ||
6426 | annotate_catchpoint (b->number); | |
6427 | ||
6428 | if (s.name == NULL) | |
6429 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6430 | else | |
6431 | syscall_id = xstrprintf ("'%s'", s.name); | |
6432 | ||
6433 | old_chain = make_cleanup (xfree, syscall_id); | |
6434 | ||
6435 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6436 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6437 | b->number, syscall_id); | |
6438 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6439 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6440 | b->number, syscall_id); | |
6441 | ||
6442 | do_cleanups (old_chain); | |
6443 | ||
6444 | return PRINT_SRC_AND_LOC; | |
6445 | } | |
6446 | ||
6447 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6448 | catchpoints. */ | |
6449 | ||
6450 | static void | |
6451 | print_one_catch_syscall (struct breakpoint *b, | |
6452 | struct bp_location **last_loc) | |
6453 | { | |
6454 | struct value_print_options opts; | |
6455 | ||
6456 | get_user_print_options (&opts); | |
4a64f543 MS |
6457 | /* Field 4, the address, is omitted (which makes the columns not |
6458 | line up too nicely with the headers, but the effect is relatively | |
6459 | readable). */ | |
a96d9b2e SDJ |
6460 | if (opts.addressprint) |
6461 | ui_out_field_skip (uiout, "addr"); | |
6462 | annotate_field (5); | |
6463 | ||
6464 | if (b->syscalls_to_be_caught | |
6465 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6466 | ui_out_text (uiout, "syscalls \""); | |
6467 | else | |
6468 | ui_out_text (uiout, "syscall \""); | |
6469 | ||
6470 | if (b->syscalls_to_be_caught) | |
6471 | { | |
6472 | int i, iter; | |
6473 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6474 | |
a96d9b2e SDJ |
6475 | for (i = 0; |
6476 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6477 | i++) | |
6478 | { | |
6479 | char *x = text; | |
6480 | struct syscall s; | |
6481 | get_syscall_by_number (iter, &s); | |
6482 | ||
6483 | if (s.name != NULL) | |
6484 | text = xstrprintf ("%s%s, ", text, s.name); | |
6485 | else | |
6486 | text = xstrprintf ("%s%d, ", text, iter); | |
6487 | ||
6488 | /* We have to xfree the last 'text' (now stored at 'x') | |
6489 | because xstrprintf dinamically allocates new space for it | |
6490 | on every call. */ | |
6491 | xfree (x); | |
6492 | } | |
6493 | /* Remove the last comma. */ | |
6494 | text[strlen (text) - 2] = '\0'; | |
6495 | ui_out_field_string (uiout, "what", text); | |
6496 | } | |
6497 | else | |
6498 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6499 | ui_out_text (uiout, "\" "); | |
6500 | } | |
6501 | ||
6502 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6503 | catchpoints. */ | |
6504 | ||
6505 | static void | |
6506 | print_mention_catch_syscall (struct breakpoint *b) | |
6507 | { | |
6508 | if (b->syscalls_to_be_caught) | |
6509 | { | |
6510 | int i, iter; | |
6511 | ||
6512 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6513 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6514 | else | |
6515 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6516 | ||
6517 | for (i = 0; | |
6518 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6519 | i++) | |
6520 | { | |
6521 | struct syscall s; | |
6522 | get_syscall_by_number (iter, &s); | |
6523 | ||
6524 | if (s.name) | |
6525 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6526 | else | |
6527 | printf_filtered (" %d", s.number); | |
6528 | } | |
6529 | printf_filtered (")"); | |
6530 | } | |
6531 | else | |
6532 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6533 | b->number); | |
6534 | } | |
6535 | ||
6149aea9 PA |
6536 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6537 | catchpoints. */ | |
6538 | ||
6539 | static void | |
6540 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6541 | { | |
6542 | fprintf_unfiltered (fp, "catch syscall"); | |
6543 | ||
6544 | if (b->syscalls_to_be_caught) | |
6545 | { | |
6546 | int i, iter; | |
6547 | ||
6548 | for (i = 0; | |
6549 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6550 | i++) | |
6551 | { | |
6552 | struct syscall s; | |
6553 | ||
6554 | get_syscall_by_number (iter, &s); | |
6555 | if (s.name) | |
6556 | fprintf_unfiltered (fp, " %s", s.name); | |
6557 | else | |
6558 | fprintf_unfiltered (fp, " %d", s.number); | |
6559 | } | |
6560 | } | |
6561 | } | |
6562 | ||
a96d9b2e SDJ |
6563 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6564 | ||
6565 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6566 | { | |
6567 | insert_catch_syscall, | |
6568 | remove_catch_syscall, | |
6569 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6570 | NULL, /* resources_needed */ |
a96d9b2e SDJ |
6571 | print_it_catch_syscall, |
6572 | print_one_catch_syscall, | |
6149aea9 PA |
6573 | print_mention_catch_syscall, |
6574 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6575 | }; |
6576 | ||
6577 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6578 | ||
6579 | static int | |
6580 | syscall_catchpoint_p (struct breakpoint *b) | |
6581 | { | |
6582 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6583 | } | |
6584 | ||
6585 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6586 | but does NOT mention it nor update the global location list. | |
6587 | This is useful if you need to fill more fields in the | |
6588 | struct breakpoint before calling mention. | |
ce78b96d JB |
6589 | |
6590 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6591 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6592 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6593 | to the catchpoint. */ | |
6594 | ||
6595 | static struct breakpoint * | |
a96d9b2e SDJ |
6596 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6597 | char *cond_string, | |
6598 | struct breakpoint_ops *ops) | |
c906108c | 6599 | { |
c5aa993b JM |
6600 | struct symtab_and_line sal; |
6601 | struct breakpoint *b; | |
c5aa993b | 6602 | |
fe39c653 | 6603 | init_sal (&sal); |
6c95b8df | 6604 | sal.pspace = current_program_space; |
c5aa993b | 6605 | |
a6d9a66e | 6606 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6607 | set_breakpoint_count (breakpoint_count + 1); |
6608 | b->number = breakpoint_count; | |
ce78b96d | 6609 | |
1b36a34b | 6610 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6611 | b->thread = -1; |
c906108c | 6612 | b->addr_string = NULL; |
b5de0fa7 EZ |
6613 | b->enable_state = bp_enabled; |
6614 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6615 | b->ops = ops; |
c5aa993b | 6616 | |
a96d9b2e SDJ |
6617 | return b; |
6618 | } | |
6619 | ||
6620 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6621 | ||
6622 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6623 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6624 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6625 | to the catchpoint. */ | |
6626 | ||
6627 | static struct breakpoint * | |
6628 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6629 | char *cond_string, struct breakpoint_ops *ops) | |
6630 | { | |
6631 | struct breakpoint *b = | |
6632 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6633 | ||
c906108c | 6634 | mention (b); |
ce78b96d | 6635 | update_global_location_list (1); |
c906108c | 6636 | |
ce78b96d | 6637 | return b; |
c906108c | 6638 | } |
c5aa993b | 6639 | |
9b70b993 | 6640 | static void |
a6d9a66e UW |
6641 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6642 | int tempflag, char *cond_string, | |
ce78b96d | 6643 | struct breakpoint_ops *ops) |
c906108c | 6644 | { |
a6d9a66e UW |
6645 | struct breakpoint *b |
6646 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6647 | |
6648 | /* FIXME: We should put this information in a breakpoint private data | |
6649 | area. */ | |
6650 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6651 | } |
6652 | ||
fe798b75 JB |
6653 | /* Exec catchpoints. */ |
6654 | ||
77b06cd7 TJB |
6655 | static int |
6656 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6657 | { |
77b06cd7 | 6658 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6659 | } |
c906108c | 6660 | |
fe798b75 | 6661 | static int |
77b06cd7 | 6662 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6663 | { |
6664 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6665 | } | |
c906108c | 6666 | |
fe798b75 JB |
6667 | static int |
6668 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6669 | { | |
6670 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6671 | } | |
c906108c | 6672 | |
fe798b75 JB |
6673 | static enum print_stop_action |
6674 | print_it_catch_exec (struct breakpoint *b) | |
6675 | { | |
6676 | annotate_catchpoint (b->number); | |
6677 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6678 | b->exec_pathname); | |
6679 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6680 | } |
6681 | ||
fe798b75 | 6682 | static void |
a6d9a66e | 6683 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6684 | { |
6685 | struct value_print_options opts; | |
6686 | ||
6687 | get_user_print_options (&opts); | |
6688 | ||
6689 | /* Field 4, the address, is omitted (which makes the columns | |
6690 | not line up too nicely with the headers, but the effect | |
6691 | is relatively readable). */ | |
6692 | if (opts.addressprint) | |
6693 | ui_out_field_skip (uiout, "addr"); | |
6694 | annotate_field (5); | |
6695 | ui_out_text (uiout, "exec"); | |
6696 | if (b->exec_pathname != NULL) | |
6697 | { | |
6698 | ui_out_text (uiout, ", program \""); | |
6699 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6700 | ui_out_text (uiout, "\" "); | |
6701 | } | |
6702 | } | |
6703 | ||
6704 | static void | |
6705 | print_mention_catch_exec (struct breakpoint *b) | |
6706 | { | |
6707 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6708 | } | |
6709 | ||
6149aea9 PA |
6710 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6711 | catchpoints. */ | |
6712 | ||
6713 | static void | |
6714 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6715 | { | |
6716 | fprintf_unfiltered (fp, "catch exec"); | |
6717 | } | |
6718 | ||
fe798b75 JB |
6719 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6720 | { | |
6721 | insert_catch_exec, | |
6722 | remove_catch_exec, | |
6723 | breakpoint_hit_catch_exec, | |
e09342b5 | 6724 | NULL, /* resources_needed */ |
fe798b75 JB |
6725 | print_it_catch_exec, |
6726 | print_one_catch_exec, | |
6149aea9 PA |
6727 | print_mention_catch_exec, |
6728 | print_recreate_catch_exec | |
fe798b75 JB |
6729 | }; |
6730 | ||
a96d9b2e SDJ |
6731 | static void |
6732 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6733 | struct breakpoint_ops *ops) | |
6734 | { | |
6735 | struct gdbarch *gdbarch = get_current_arch (); | |
6736 | struct breakpoint *b = | |
6737 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6738 | ||
6739 | b->syscalls_to_be_caught = filter; | |
6740 | ||
6741 | /* Now, we have to mention the breakpoint and update the global | |
6742 | location list. */ | |
6743 | mention (b); | |
6744 | update_global_location_list (1); | |
6745 | } | |
6746 | ||
c906108c | 6747 | static int |
fba45db2 | 6748 | hw_breakpoint_used_count (void) |
c906108c | 6749 | { |
52f0bd74 | 6750 | struct breakpoint *b; |
c906108c SS |
6751 | int i = 0; |
6752 | ||
6753 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6754 | { |
d6b74ac4 | 6755 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6756 | i++; |
6757 | } | |
c906108c SS |
6758 | |
6759 | return i; | |
6760 | } | |
6761 | ||
6762 | static int | |
fba45db2 | 6763 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6764 | { |
c906108c | 6765 | int i = 0; |
e09342b5 TJB |
6766 | struct breakpoint *b; |
6767 | struct bp_location *bl; | |
c906108c SS |
6768 | |
6769 | *other_type_used = 0; | |
6770 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6771 | { |
6772 | if (!breakpoint_enabled (b)) | |
6773 | continue; | |
6774 | ||
c5aa993b | 6775 | if (b->type == type) |
e09342b5 TJB |
6776 | for (bl = b->loc; bl; bl = bl->next) |
6777 | { | |
6778 | /* Special types of hardware watchpoints may use more than | |
6779 | one register. */ | |
6780 | if (b->ops && b->ops->resources_needed) | |
6781 | i += b->ops->resources_needed (bl); | |
6782 | else | |
6783 | i++; | |
6784 | } | |
cc60f2e3 | 6785 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6786 | *other_type_used = 1; |
e09342b5 TJB |
6787 | } |
6788 | ||
c906108c SS |
6789 | return i; |
6790 | } | |
6791 | ||
c906108c | 6792 | void |
fba45db2 | 6793 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6794 | { |
c5aa993b | 6795 | struct breakpoint *b; |
c906108c SS |
6796 | |
6797 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6798 | { |
cc60f2e3 | 6799 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6800 | { |
b5de0fa7 | 6801 | b->enable_state = bp_call_disabled; |
b60e7edf | 6802 | update_global_location_list (0); |
c5aa993b JM |
6803 | } |
6804 | } | |
c906108c SS |
6805 | } |
6806 | ||
6807 | void | |
fba45db2 | 6808 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6809 | { |
c5aa993b | 6810 | struct breakpoint *b; |
c906108c SS |
6811 | |
6812 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6813 | { |
cc60f2e3 | 6814 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6815 | { |
b5de0fa7 | 6816 | b->enable_state = bp_enabled; |
b60e7edf | 6817 | update_global_location_list (1); |
c5aa993b JM |
6818 | } |
6819 | } | |
c906108c SS |
6820 | } |
6821 | ||
8bea4e01 UW |
6822 | void |
6823 | disable_breakpoints_before_startup (void) | |
6824 | { | |
6825 | struct breakpoint *b; | |
6826 | int found = 0; | |
6827 | ||
6828 | ALL_BREAKPOINTS (b) | |
6829 | { | |
6c95b8df PA |
6830 | if (b->pspace != current_program_space) |
6831 | continue; | |
6832 | ||
8bea4e01 UW |
6833 | if ((b->type == bp_breakpoint |
6834 | || b->type == bp_hardware_breakpoint) | |
6835 | && breakpoint_enabled (b)) | |
6836 | { | |
6837 | b->enable_state = bp_startup_disabled; | |
6838 | found = 1; | |
6839 | } | |
6840 | } | |
6841 | ||
6842 | if (found) | |
6843 | update_global_location_list (0); | |
6844 | ||
6c95b8df | 6845 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6846 | } |
6847 | ||
6848 | void | |
6849 | enable_breakpoints_after_startup (void) | |
6850 | { | |
6851 | struct breakpoint *b; | |
6852 | int found = 0; | |
6853 | ||
6c95b8df | 6854 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6855 | |
6856 | ALL_BREAKPOINTS (b) | |
6857 | { | |
6c95b8df PA |
6858 | if (b->pspace != current_program_space) |
6859 | continue; | |
6860 | ||
8bea4e01 UW |
6861 | if ((b->type == bp_breakpoint |
6862 | || b->type == bp_hardware_breakpoint) | |
6863 | && b->enable_state == bp_startup_disabled) | |
6864 | { | |
6865 | b->enable_state = bp_enabled; | |
6866 | found = 1; | |
6867 | } | |
6868 | } | |
6869 | ||
6870 | if (found) | |
6871 | breakpoint_re_set (); | |
6872 | } | |
6873 | ||
c906108c SS |
6874 | |
6875 | /* Set a breakpoint that will evaporate an end of command | |
6876 | at address specified by SAL. | |
6877 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6878 | ||
6879 | struct breakpoint * | |
a6d9a66e UW |
6880 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6881 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6882 | { |
52f0bd74 | 6883 | struct breakpoint *b; |
edb3359d DJ |
6884 | |
6885 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6886 | one. */ | |
6887 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6888 | ||
a6d9a66e | 6889 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6890 | b->enable_state = bp_enabled; |
6891 | b->disposition = disp_donttouch; | |
818dd999 | 6892 | b->frame_id = frame_id; |
c906108c | 6893 | |
4a64f543 MS |
6894 | /* If we're debugging a multi-threaded program, then we want |
6895 | momentary breakpoints to be active in only a single thread of | |
6896 | control. */ | |
39f77062 KB |
6897 | if (in_thread_list (inferior_ptid)) |
6898 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6899 | |
b60e7edf | 6900 | update_global_location_list_nothrow (1); |
74960c60 | 6901 | |
c906108c SS |
6902 | return b; |
6903 | } | |
611c83ae | 6904 | |
e58b0e63 PA |
6905 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6906 | ORIG is NULL. */ | |
6907 | ||
6908 | struct breakpoint * | |
6909 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6910 | { | |
6911 | struct breakpoint *copy; | |
6912 | ||
6913 | /* If there's nothing to clone, then return nothing. */ | |
6914 | if (orig == NULL) | |
6915 | return NULL; | |
6916 | ||
a6d9a66e | 6917 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6918 | copy->loc = allocate_bp_location (copy); |
6919 | set_breakpoint_location_function (copy->loc); | |
6920 | ||
a6d9a66e | 6921 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6922 | copy->loc->requested_address = orig->loc->requested_address; |
6923 | copy->loc->address = orig->loc->address; | |
6924 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6925 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6926 | |
6927 | if (orig->source_file == NULL) | |
6928 | copy->source_file = NULL; | |
6929 | else | |
6930 | copy->source_file = xstrdup (orig->source_file); | |
6931 | ||
6932 | copy->line_number = orig->line_number; | |
6933 | copy->frame_id = orig->frame_id; | |
6934 | copy->thread = orig->thread; | |
6c95b8df | 6935 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6936 | |
6937 | copy->enable_state = bp_enabled; | |
6938 | copy->disposition = disp_donttouch; | |
6939 | copy->number = internal_breakpoint_number--; | |
6940 | ||
6941 | update_global_location_list_nothrow (0); | |
6942 | return copy; | |
6943 | } | |
6944 | ||
611c83ae | 6945 | struct breakpoint * |
a6d9a66e UW |
6946 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6947 | enum bptype type) | |
611c83ae PA |
6948 | { |
6949 | struct symtab_and_line sal; | |
6950 | ||
6951 | sal = find_pc_line (pc, 0); | |
6952 | sal.pc = pc; | |
6953 | sal.section = find_pc_overlay (pc); | |
6954 | sal.explicit_pc = 1; | |
6955 | ||
a6d9a66e | 6956 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6957 | } |
c906108c | 6958 | \f |
c5aa993b | 6959 | |
c906108c SS |
6960 | /* Tell the user we have just set a breakpoint B. */ |
6961 | ||
6962 | static void | |
fba45db2 | 6963 | mention (struct breakpoint *b) |
c906108c SS |
6964 | { |
6965 | int say_where = 0; | |
fa8a61dc | 6966 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6967 | struct value_print_options opts; |
6968 | ||
6969 | get_user_print_options (&opts); | |
8b93c638 | 6970 | |
9a4105ab AC |
6971 | /* FIXME: This is misplaced; mention() is called by things (like |
6972 | hitting a watchpoint) other than breakpoint creation. It should | |
6973 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6974 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6975 | observer_notify_breakpoint_created (b->number); |
c906108c | 6976 | |
3086aeae DJ |
6977 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6978 | b->ops->print_mention (b); | |
6979 | else | |
6980 | switch (b->type) | |
6981 | { | |
6982 | case bp_none: | |
3e43a32a MS |
6983 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
6984 | b->number); | |
3086aeae DJ |
6985 | break; |
6986 | case bp_watchpoint: | |
6987 | ui_out_text (uiout, "Watchpoint "); | |
6988 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6989 | ui_out_field_int (uiout, "number", b->number); | |
6990 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6991 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6992 | do_cleanups (ui_out_chain); |
6993 | break; | |
6994 | case bp_hardware_watchpoint: | |
6995 | ui_out_text (uiout, "Hardware watchpoint "); | |
6996 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6997 | ui_out_field_int (uiout, "number", b->number); | |
6998 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6999 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7000 | do_cleanups (ui_out_chain); |
7001 | break; | |
7002 | case bp_read_watchpoint: | |
7003 | ui_out_text (uiout, "Hardware read watchpoint "); | |
7004 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
7005 | ui_out_field_int (uiout, "number", b->number); | |
7006 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7007 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7008 | do_cleanups (ui_out_chain); |
7009 | break; | |
7010 | case bp_access_watchpoint: | |
7011 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
7012 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
7013 | ui_out_field_int (uiout, "number", b->number); | |
7014 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7015 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7016 | do_cleanups (ui_out_chain); |
7017 | break; | |
7018 | case bp_breakpoint: | |
7019 | if (ui_out_is_mi_like_p (uiout)) | |
7020 | { | |
7021 | say_where = 0; | |
7022 | break; | |
7023 | } | |
2cec12e5 AR |
7024 | if (b->disposition == disp_del) |
7025 | printf_filtered (_("Temporary breakpoint")); | |
7026 | else | |
7027 | printf_filtered (_("Breakpoint")); | |
7028 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
7029 | say_where = 1; |
7030 | break; | |
7031 | case bp_hardware_breakpoint: | |
7032 | if (ui_out_is_mi_like_p (uiout)) | |
7033 | { | |
7034 | say_where = 0; | |
7035 | break; | |
7036 | } | |
a3f17187 | 7037 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
7038 | say_where = 1; |
7039 | break; | |
1042e4c0 SS |
7040 | case bp_tracepoint: |
7041 | if (ui_out_is_mi_like_p (uiout)) | |
7042 | { | |
7043 | say_where = 0; | |
7044 | break; | |
7045 | } | |
7046 | printf_filtered (_("Tracepoint")); | |
7047 | printf_filtered (_(" %d"), b->number); | |
7048 | say_where = 1; | |
7049 | break; | |
7a697b8d SS |
7050 | case bp_fast_tracepoint: |
7051 | if (ui_out_is_mi_like_p (uiout)) | |
7052 | { | |
7053 | say_where = 0; | |
7054 | break; | |
7055 | } | |
7056 | printf_filtered (_("Fast tracepoint")); | |
7057 | printf_filtered (_(" %d"), b->number); | |
7058 | say_where = 1; | |
7059 | break; | |
0fb4aa4b PA |
7060 | case bp_static_tracepoint: |
7061 | if (ui_out_is_mi_like_p (uiout)) | |
7062 | { | |
7063 | say_where = 0; | |
7064 | break; | |
7065 | } | |
7066 | printf_filtered (_("Static tracepoint")); | |
7067 | printf_filtered (_(" %d"), b->number); | |
7068 | say_where = 1; | |
7069 | break; | |
3086aeae DJ |
7070 | |
7071 | case bp_until: | |
7072 | case bp_finish: | |
7073 | case bp_longjmp: | |
7074 | case bp_longjmp_resume: | |
186c406b TT |
7075 | case bp_exception: |
7076 | case bp_exception_resume: | |
3086aeae | 7077 | case bp_step_resume: |
3086aeae | 7078 | case bp_call_dummy: |
aa7d318d | 7079 | case bp_std_terminate: |
3086aeae DJ |
7080 | case bp_watchpoint_scope: |
7081 | case bp_shlib_event: | |
7082 | case bp_thread_event: | |
7083 | case bp_overlay_event: | |
4efc6507 | 7084 | case bp_jit_event: |
0fd8e87f | 7085 | case bp_longjmp_master: |
aa7d318d | 7086 | case bp_std_terminate_master: |
186c406b | 7087 | case bp_exception_master: |
3086aeae DJ |
7088 | break; |
7089 | } | |
c906108c | 7090 | |
c906108c SS |
7091 | if (say_where) |
7092 | { | |
a3f17187 AC |
7093 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7094 | single string. */ | |
0d381245 | 7095 | if (b->loc == NULL) |
c906108c | 7096 | { |
a3f17187 | 7097 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7098 | } |
7099 | else | |
7100 | { | |
79a45b7d | 7101 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7102 | { |
7103 | printf_filtered (" at "); | |
5af949e3 UW |
7104 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7105 | gdb_stdout); | |
0101ce28 JJ |
7106 | } |
7107 | if (b->source_file) | |
7108 | printf_filtered (": file %s, line %d.", | |
7109 | b->source_file, b->line_number); | |
0d381245 VP |
7110 | |
7111 | if (b->loc->next) | |
7112 | { | |
7113 | struct bp_location *loc = b->loc; | |
7114 | int n = 0; | |
7115 | for (; loc; loc = loc->next) | |
7116 | ++n; | |
7117 | printf_filtered (" (%d locations)", n); | |
7118 | } | |
7119 | ||
c906108c | 7120 | } |
c906108c | 7121 | } |
9dc5e2a9 | 7122 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7123 | return; |
c906108c SS |
7124 | printf_filtered ("\n"); |
7125 | } | |
c906108c | 7126 | \f |
c5aa993b | 7127 | |
0d381245 | 7128 | static struct bp_location * |
39d61571 | 7129 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7130 | const struct symtab_and_line *sal) |
7131 | { | |
7132 | struct bp_location *loc, **tmp; | |
7133 | ||
39d61571 | 7134 | loc = allocate_bp_location (b); |
0d381245 VP |
7135 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7136 | ; | |
7137 | *tmp = loc; | |
a6d9a66e UW |
7138 | loc->gdbarch = get_sal_arch (*sal); |
7139 | if (!loc->gdbarch) | |
7140 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7141 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7142 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7143 | loc->requested_address, b->type); | |
6c95b8df PA |
7144 | loc->pspace = sal->pspace; |
7145 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7146 | loc->section = sal->section; |
7147 | ||
7148 | set_breakpoint_location_function (loc); | |
7149 | return loc; | |
7150 | } | |
514f746b AR |
7151 | \f |
7152 | ||
7153 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7154 | return 0 otherwise. */ | |
7155 | ||
7156 | static int | |
7157 | bp_loc_is_permanent (struct bp_location *loc) | |
7158 | { | |
7159 | int len; | |
7160 | CORE_ADDR addr; | |
7161 | const gdb_byte *brk; | |
7162 | gdb_byte *target_mem; | |
939c61fa JK |
7163 | struct cleanup *cleanup; |
7164 | int retval = 0; | |
514f746b AR |
7165 | |
7166 | gdb_assert (loc != NULL); | |
7167 | ||
7168 | addr = loc->address; | |
a6d9a66e | 7169 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7170 | |
939c61fa JK |
7171 | /* Software breakpoints unsupported? */ |
7172 | if (brk == NULL) | |
7173 | return 0; | |
7174 | ||
514f746b AR |
7175 | target_mem = alloca (len); |
7176 | ||
939c61fa JK |
7177 | /* Enable the automatic memory restoration from breakpoints while |
7178 | we read the memory. Otherwise we could say about our temporary | |
7179 | breakpoints they are permanent. */ | |
6c95b8df PA |
7180 | cleanup = save_current_space_and_thread (); |
7181 | ||
7182 | switch_to_program_space_and_thread (loc->pspace); | |
7183 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7184 | |
514f746b AR |
7185 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7186 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7187 | retval = 1; |
514f746b | 7188 | |
939c61fa JK |
7189 | do_cleanups (cleanup); |
7190 | ||
7191 | return retval; | |
514f746b AR |
7192 | } |
7193 | ||
7194 | ||
c3f6f71d | 7195 | |
018d34a4 VP |
7196 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7197 | as textual description of the location, and COND_STRING | |
db107f19 | 7198 | as condition expression. */ |
018d34a4 VP |
7199 | |
7200 | static void | |
8cdf0e15 VP |
7201 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7202 | struct symtabs_and_lines sals, char *addr_string, | |
7203 | char *cond_string, | |
7204 | enum bptype type, enum bpdisp disposition, | |
7205 | int thread, int task, int ignore_count, | |
84f4c1fe PM |
7206 | struct breakpoint_ops *ops, int from_tty, |
7207 | int enabled, int internal) | |
018d34a4 | 7208 | { |
0d381245 VP |
7209 | struct breakpoint *b = NULL; |
7210 | int i; | |
018d34a4 VP |
7211 | |
7212 | if (type == bp_hardware_breakpoint) | |
7213 | { | |
7214 | int i = hw_breakpoint_used_count (); | |
7215 | int target_resources_ok = | |
d92524f1 | 7216 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7217 | i + 1, 0); |
7218 | if (target_resources_ok == 0) | |
7219 | error (_("No hardware breakpoint support in the target.")); | |
7220 | else if (target_resources_ok < 0) | |
7221 | error (_("Hardware breakpoints used exceeds limit.")); | |
7222 | } | |
7223 | ||
6c95b8df PA |
7224 | gdb_assert (sals.nelts > 0); |
7225 | ||
0d381245 VP |
7226 | for (i = 0; i < sals.nelts; ++i) |
7227 | { | |
7228 | struct symtab_and_line sal = sals.sals[i]; | |
7229 | struct bp_location *loc; | |
7230 | ||
7231 | if (from_tty) | |
5af949e3 UW |
7232 | { |
7233 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7234 | if (!loc_gdbarch) | |
7235 | loc_gdbarch = gdbarch; | |
7236 | ||
7237 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7238 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7239 | } |
0d381245 VP |
7240 | |
7241 | if (i == 0) | |
7242 | { | |
a6d9a66e | 7243 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7244 | set_breakpoint_number (internal, b); |
0d381245 | 7245 | b->thread = thread; |
4a306c9a | 7246 | b->task = task; |
018d34a4 | 7247 | |
0d381245 VP |
7248 | b->cond_string = cond_string; |
7249 | b->ignore_count = ignore_count; | |
41447f92 | 7250 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7251 | b->disposition = disposition; |
6c95b8df PA |
7252 | b->pspace = sals.sals[0].pspace; |
7253 | ||
0fb4aa4b PA |
7254 | if (type == bp_static_tracepoint) |
7255 | { | |
7256 | struct static_tracepoint_marker marker; | |
7257 | ||
7258 | if (is_marker_spec (addr_string)) | |
7259 | { | |
7260 | /* We already know the marker exists, otherwise, we | |
7261 | wouldn't see a sal for it. */ | |
7262 | char *p = &addr_string[3]; | |
7263 | char *endp; | |
7264 | char *marker_str; | |
7265 | int i; | |
7266 | ||
e9cafbcc | 7267 | p = skip_spaces (p); |
0fb4aa4b | 7268 | |
e9cafbcc | 7269 | endp = skip_to_space (p); |
0fb4aa4b PA |
7270 | |
7271 | marker_str = savestring (p, endp - p); | |
7272 | b->static_trace_marker_id = marker_str; | |
7273 | ||
3e43a32a MS |
7274 | printf_filtered (_("Probed static tracepoint " |
7275 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7276 | b->static_trace_marker_id); |
7277 | } | |
7278 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7279 | { | |
7280 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7281 | release_static_tracepoint_marker (&marker); | |
7282 | ||
3e43a32a MS |
7283 | printf_filtered (_("Probed static tracepoint " |
7284 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7285 | b->static_trace_marker_id); |
7286 | } | |
7287 | else | |
3e43a32a MS |
7288 | warning (_("Couldn't determine the static " |
7289 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7290 | } |
7291 | ||
6c95b8df | 7292 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7293 | && (b->type == bp_breakpoint |
7294 | || b->type == bp_hardware_breakpoint)) | |
7295 | b->enable_state = bp_startup_disabled; | |
7296 | ||
0d381245 VP |
7297 | loc = b->loc; |
7298 | } | |
7299 | else | |
018d34a4 | 7300 | { |
39d61571 | 7301 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7302 | } |
7303 | ||
514f746b AR |
7304 | if (bp_loc_is_permanent (loc)) |
7305 | make_breakpoint_permanent (b); | |
7306 | ||
0d381245 VP |
7307 | if (b->cond_string) |
7308 | { | |
7309 | char *arg = b->cond_string; | |
d32a6982 | 7310 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7311 | if (*arg) |
db107f19 | 7312 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7313 | } |
0d381245 | 7314 | } |
018d34a4 VP |
7315 | |
7316 | if (addr_string) | |
7317 | b->addr_string = addr_string; | |
7318 | else | |
7319 | /* addr_string has to be used or breakpoint_re_set will delete | |
7320 | me. */ | |
5af949e3 UW |
7321 | b->addr_string |
7322 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7323 | |
604133b5 | 7324 | b->ops = ops; |
84f4c1fe PM |
7325 | if (internal) |
7326 | /* Do not mention breakpoints with a negative number, but do | |
7327 | notify observers. */ | |
7328 | observer_notify_breakpoint_created (b->number); | |
7329 | else | |
7330 | mention (b); | |
018d34a4 VP |
7331 | } |
7332 | ||
ed0616c6 VP |
7333 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7334 | elements to fill the void space. */ | |
2c0b251b PA |
7335 | static void |
7336 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7337 | { |
7338 | int i = index_to_remove+1; | |
7339 | int last_index = sal->nelts-1; | |
7340 | ||
7341 | for (;i <= last_index; ++i) | |
7342 | sal->sals[i-1] = sal->sals[i]; | |
7343 | ||
7344 | --(sal->nelts); | |
7345 | } | |
7346 | ||
6c95b8df PA |
7347 | /* If appropriate, obtains all sals that correspond to the same file |
7348 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7349 | will want to set a breakpoint at foo.c:line, and not really care | |
7350 | about program spaces. This is done only if SAL does not have | |
7351 | explicit PC and has line and file information. If we got just a | |
7352 | single expanded sal, return the original. | |
ed0616c6 | 7353 | |
6c95b8df PA |
7354 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7355 | which the name of enclosing function is different from SAL. This | |
7356 | makes sure that if we have breakpoint originally set in template | |
7357 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7358 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7359 | |
2c0b251b | 7360 | static struct symtabs_and_lines |
ed0616c6 VP |
7361 | expand_line_sal_maybe (struct symtab_and_line sal) |
7362 | { | |
7363 | struct symtabs_and_lines expanded; | |
7364 | CORE_ADDR original_pc = sal.pc; | |
7365 | char *original_function = NULL; | |
7366 | int found; | |
7367 | int i; | |
6c95b8df | 7368 | struct cleanup *old_chain; |
ed0616c6 VP |
7369 | |
7370 | /* If we have explicit pc, don't expand. | |
7371 | If we have no line number, we can't expand. */ | |
7372 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7373 | { | |
7374 | expanded.nelts = 1; | |
7375 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7376 | expanded.sals[0] = sal; | |
7377 | return expanded; | |
7378 | } | |
7379 | ||
7380 | sal.pc = 0; | |
6c95b8df PA |
7381 | |
7382 | old_chain = save_current_space_and_thread (); | |
7383 | ||
7384 | switch_to_program_space_and_thread (sal.pspace); | |
7385 | ||
ed0616c6 | 7386 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7387 | |
7388 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7389 | expanded = expand_line_sal (sal); |
6c95b8df | 7390 | |
ed0616c6 VP |
7391 | if (expanded.nelts == 1) |
7392 | { | |
3dba1c98 JB |
7393 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7394 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7395 | xfree (expanded.sals); |
7396 | expanded.nelts = 1; | |
7397 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7398 | sal.pc = original_pc; | |
7399 | expanded.sals[0] = sal; | |
3dba1c98 | 7400 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7401 | do_cleanups (old_chain); |
ed0616c6 VP |
7402 | return expanded; |
7403 | } | |
7404 | ||
7405 | if (!sal.explicit_line) | |
7406 | { | |
7407 | CORE_ADDR func_addr, func_end; | |
7408 | for (i = 0; i < expanded.nelts; ++i) | |
7409 | { | |
7410 | CORE_ADDR pc = expanded.sals[i].pc; | |
7411 | char *this_function; | |
6c95b8df PA |
7412 | |
7413 | /* We need to switch threads as well since we're about to | |
7414 | read memory. */ | |
7415 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7416 | ||
ed0616c6 VP |
7417 | if (find_pc_partial_function (pc, &this_function, |
7418 | &func_addr, &func_end)) | |
7419 | { | |
059fb39f PM |
7420 | if (this_function |
7421 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7422 | { |
7423 | remove_sal (&expanded, i); | |
7424 | --i; | |
7425 | } | |
ed0616c6 VP |
7426 | } |
7427 | } | |
7428 | } | |
059acae7 UW |
7429 | |
7430 | /* Skip the function prologue if necessary. */ | |
7431 | for (i = 0; i < expanded.nelts; ++i) | |
7432 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7433 | |
6c95b8df PA |
7434 | do_cleanups (old_chain); |
7435 | ||
ed0616c6 VP |
7436 | if (expanded.nelts <= 1) |
7437 | { | |
4a64f543 MS |
7438 | /* This is un ugly workaround. If we get zero expanded sals |
7439 | then something is really wrong. Fix that by returning the | |
7440 | original sal. */ | |
7441 | ||
ed0616c6 VP |
7442 | xfree (expanded.sals); |
7443 | expanded.nelts = 1; | |
7444 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7445 | sal.pc = original_pc; | |
7446 | expanded.sals[0] = sal; | |
7447 | return expanded; | |
7448 | } | |
7449 | ||
7450 | if (original_pc) | |
7451 | { | |
7452 | found = 0; | |
7453 | for (i = 0; i < expanded.nelts; ++i) | |
7454 | if (expanded.sals[i].pc == original_pc) | |
7455 | { | |
7456 | found = 1; | |
7457 | break; | |
7458 | } | |
7459 | gdb_assert (found); | |
7460 | } | |
7461 | ||
7462 | return expanded; | |
7463 | } | |
7464 | ||
018d34a4 VP |
7465 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7466 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7467 | value. COND_STRING, if not NULL, specified the condition to be | |
7468 | used for all breakpoints. Essentially the only case where | |
7469 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7470 | function. In that case, it's still not possible to specify | |
7471 | separate conditions for different overloaded functions, so | |
7472 | we take just a single condition string. | |
7473 | ||
c3f6f71d | 7474 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7475 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7476 | array contents). If the function fails (error() is called), the |
7477 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7478 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7479 | |
7480 | static void | |
8cdf0e15 VP |
7481 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7482 | struct symtabs_and_lines sals, char **addr_string, | |
7483 | char *cond_string, | |
7484 | enum bptype type, enum bpdisp disposition, | |
7485 | int thread, int task, int ignore_count, | |
7486 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7487 | int enabled, int internal) |
c906108c | 7488 | { |
018d34a4 | 7489 | int i; |
cc59ec59 | 7490 | |
018d34a4 | 7491 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7492 | { |
ed0616c6 VP |
7493 | struct symtabs_and_lines expanded = |
7494 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7495 | |
8cdf0e15 VP |
7496 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7497 | cond_string, type, disposition, | |
84f4c1fe PM |
7498 | thread, task, ignore_count, ops, |
7499 | from_tty, enabled, internal); | |
c3f6f71d | 7500 | } |
c3f6f71d | 7501 | } |
c906108c | 7502 | |
9998af43 | 7503 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7504 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7505 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7506 | address strings. ADDRESS points to the end of the SAL. |
7507 | ||
7508 | The array and the line spec strings are allocated on the heap, it is | |
7509 | the caller's responsibility to free them. */ | |
c906108c | 7510 | |
b9362cc7 | 7511 | static void |
c3f6f71d JM |
7512 | parse_breakpoint_sals (char **address, |
7513 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7514 | char ***addr_string, |
7515 | int *not_found_ptr) | |
c3f6f71d JM |
7516 | { |
7517 | char *addr_start = *address; | |
cc59ec59 | 7518 | |
c3f6f71d JM |
7519 | *addr_string = NULL; |
7520 | /* If no arg given, or if first arg is 'if ', use the default | |
4a64f543 | 7521 | breakpoint. */ |
c3f6f71d JM |
7522 | if ((*address) == NULL |
7523 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7524 | { |
7525 | if (default_breakpoint_valid) | |
7526 | { | |
c3f6f71d | 7527 | struct symtab_and_line sal; |
cc59ec59 | 7528 | |
4a64f543 | 7529 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7530 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7531 | xmalloc (sizeof (struct symtab_and_line)); |
7532 | sal.pc = default_breakpoint_address; | |
7533 | sal.line = default_breakpoint_line; | |
7534 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7535 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7536 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7537 | |
4a64f543 MS |
7538 | /* "break" without arguments is equivalent to "break *PC" |
7539 | where PC is the default_breakpoint_address. So make sure | |
7540 | to set sal.explicit_pc to prevent GDB from trying to | |
7541 | expand the list of sals to include all other instances | |
7542 | with the same symtab and line. */ | |
00903456 JK |
7543 | sal.explicit_pc = 1; |
7544 | ||
c3f6f71d JM |
7545 | sals->sals[0] = sal; |
7546 | sals->nelts = 1; | |
c906108c SS |
7547 | } |
7548 | else | |
8a3fe4f8 | 7549 | error (_("No default breakpoint address now.")); |
c906108c SS |
7550 | } |
7551 | else | |
7552 | { | |
c906108c | 7553 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7554 | current_source_symtab (which is decode_line_1's default). |
7555 | This should produce the results we want almost all of the | |
7556 | time while leaving default_breakpoint_* alone. | |
7557 | ||
1aeae86e AF |
7558 | ObjC: However, don't match an Objective-C method name which |
7559 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7560 | |
c214a6fd | 7561 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7562 | |
c906108c | 7563 | if (default_breakpoint_valid |
0378c332 | 7564 | && (!cursal.symtab |
1aeae86e AF |
7565 | || ((strchr ("+-", (*address)[0]) != NULL) |
7566 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7567 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7568 | default_breakpoint_line, addr_string, |
7569 | not_found_ptr); | |
c906108c | 7570 | else |
0101ce28 JJ |
7571 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7572 | addr_string, not_found_ptr); | |
c906108c | 7573 | } |
4a64f543 | 7574 | /* For any SAL that didn't have a canonical string, fill one in. */ |
c3f6f71d JM |
7575 | if (sals->nelts > 0 && *addr_string == NULL) |
7576 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7577 | if (addr_start != (*address)) | |
c906108c | 7578 | { |
c3f6f71d | 7579 | int i; |
cc59ec59 | 7580 | |
c3f6f71d | 7581 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7582 | { |
4a64f543 | 7583 | /* Add the string if not present. */ |
c3f6f71d | 7584 | if ((*addr_string)[i] == NULL) |
cc59ec59 MS |
7585 | (*addr_string)[i] = savestring (addr_start, |
7586 | (*address) - addr_start); | |
c906108c SS |
7587 | } |
7588 | } | |
c3f6f71d | 7589 | } |
c906108c | 7590 | |
c906108c | 7591 | |
c3f6f71d | 7592 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7593 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7594 | |
b9362cc7 | 7595 | static void |
23e7acfb | 7596 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7597 | { |
7598 | int i; | |
cc59ec59 | 7599 | |
c3f6f71d | 7600 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7601 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7602 | } |
7603 | ||
7a697b8d SS |
7604 | /* Fast tracepoints may have restrictions on valid locations. For |
7605 | instance, a fast tracepoint using a jump instead of a trap will | |
7606 | likely have to overwrite more bytes than a trap would, and so can | |
7607 | only be placed where the instruction is longer than the jump, or a | |
7608 | multi-instruction sequence does not have a jump into the middle of | |
7609 | it, etc. */ | |
7610 | ||
7611 | static void | |
7612 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7613 | struct symtabs_and_lines *sals) | |
7614 | { | |
7615 | int i, rslt; | |
7616 | struct symtab_and_line *sal; | |
7617 | char *msg; | |
7618 | struct cleanup *old_chain; | |
7619 | ||
7620 | for (i = 0; i < sals->nelts; i++) | |
7621 | { | |
7622 | sal = &sals->sals[i]; | |
7623 | ||
7624 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7625 | NULL, &msg); | |
7626 | old_chain = make_cleanup (xfree, msg); | |
7627 | ||
7628 | if (!rslt) | |
7629 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7630 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7631 | ||
7632 | do_cleanups (old_chain); | |
7633 | } | |
7634 | } | |
7635 | ||
05ff989b | 7636 | static void |
0101ce28 JJ |
7637 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7638 | { | |
7639 | struct captured_parse_breakpoint_args *args = data; | |
7640 | ||
7641 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7642 | args->not_found_ptr); | |
0101ce28 JJ |
7643 | } |
7644 | ||
018d34a4 VP |
7645 | /* Given TOK, a string specification of condition and thread, as |
7646 | accepted by the 'break' command, extract the condition | |
7647 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7648 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7649 | If no condition is found, *COND_STRING is set to NULL. |
7650 | If no thread is found, *THREAD is set to -1. */ | |
7651 | static void | |
7652 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7653 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7654 | { |
7655 | *cond_string = NULL; | |
7656 | *thread = -1; | |
7657 | while (tok && *tok) | |
7658 | { | |
7659 | char *end_tok; | |
7660 | int toklen; | |
7661 | char *cond_start = NULL; | |
7662 | char *cond_end = NULL; | |
cc59ec59 | 7663 | |
e9cafbcc | 7664 | tok = skip_spaces (tok); |
018d34a4 | 7665 | |
e9cafbcc | 7666 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7667 | |
7668 | toklen = end_tok - tok; | |
7669 | ||
7670 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7671 | { | |
f7545552 TT |
7672 | struct expression *expr; |
7673 | ||
018d34a4 | 7674 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7675 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7676 | xfree (expr); | |
018d34a4 VP |
7677 | cond_end = tok; |
7678 | *cond_string = savestring (cond_start, | |
7679 | cond_end - cond_start); | |
7680 | } | |
7681 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7682 | { | |
7683 | char *tmptok; | |
7684 | ||
7685 | tok = end_tok + 1; | |
7686 | tmptok = tok; | |
7687 | *thread = strtol (tok, &tok, 0); | |
7688 | if (tok == tmptok) | |
7689 | error (_("Junk after thread keyword.")); | |
7690 | if (!valid_thread_id (*thread)) | |
7691 | error (_("Unknown thread %d."), *thread); | |
7692 | } | |
4a306c9a JB |
7693 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7694 | { | |
7695 | char *tmptok; | |
7696 | ||
7697 | tok = end_tok + 1; | |
7698 | tmptok = tok; | |
7699 | *task = strtol (tok, &tok, 0); | |
7700 | if (tok == tmptok) | |
7701 | error (_("Junk after task keyword.")); | |
7702 | if (!valid_task_id (*task)) | |
b6199126 | 7703 | error (_("Unknown task %d."), *task); |
4a306c9a | 7704 | } |
018d34a4 VP |
7705 | else |
7706 | error (_("Junk at end of arguments.")); | |
7707 | } | |
7708 | } | |
7709 | ||
0fb4aa4b PA |
7710 | /* Decode a static tracepoint marker spec. */ |
7711 | ||
7712 | static struct symtabs_and_lines | |
7713 | decode_static_tracepoint_spec (char **arg_p) | |
7714 | { | |
7715 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7716 | struct symtabs_and_lines sals; | |
7717 | struct symtab_and_line sal; | |
7718 | struct symbol *sym; | |
7719 | struct cleanup *old_chain; | |
7720 | char *p = &(*arg_p)[3]; | |
7721 | char *endp; | |
7722 | char *marker_str; | |
7723 | int i; | |
7724 | ||
e9cafbcc | 7725 | p = skip_spaces (p); |
0fb4aa4b | 7726 | |
e9cafbcc | 7727 | endp = skip_to_space (p); |
0fb4aa4b PA |
7728 | |
7729 | marker_str = savestring (p, endp - p); | |
7730 | old_chain = make_cleanup (xfree, marker_str); | |
7731 | ||
7732 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7733 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7734 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7735 | ||
7736 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7737 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7738 | ||
7739 | for (i = 0; i < sals.nelts; i++) | |
7740 | { | |
7741 | struct static_tracepoint_marker *marker; | |
7742 | ||
7743 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7744 | ||
7745 | init_sal (&sals.sals[i]); | |
7746 | ||
7747 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7748 | sals.sals[i].pc = marker->address; | |
7749 | ||
7750 | release_static_tracepoint_marker (marker); | |
7751 | } | |
7752 | ||
7753 | do_cleanups (old_chain); | |
7754 | ||
7755 | *arg_p = endp; | |
7756 | return sals; | |
7757 | } | |
7758 | ||
fd9b8c24 PA |
7759 | /* Set a breakpoint. This function is shared between CLI and MI |
7760 | functions for setting a breakpoint. This function has two major | |
7761 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7762 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7763 | breakpoint location, address and thread. Otherwise, ARG is just |
7764 | the location of breakpoint, with condition and thread specified by | |
7765 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7766 | the breakpoint number will be allocated from the internal | |
7767 | breakpoint count. Returns true if any breakpoint was created; | |
7768 | false otherwise. */ | |
0101ce28 | 7769 | |
8cdf0e15 VP |
7770 | int |
7771 | create_breakpoint (struct gdbarch *gdbarch, | |
7772 | char *arg, char *cond_string, int thread, | |
7773 | int parse_condition_and_thread, | |
0fb4aa4b | 7774 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7775 | int ignore_count, |
7776 | enum auto_boolean pending_break_support, | |
7777 | struct breakpoint_ops *ops, | |
84f4c1fe | 7778 | int from_tty, int enabled, int internal) |
c3f6f71d | 7779 | { |
71fff37b | 7780 | struct gdb_exception e; |
c3f6f71d | 7781 | struct symtabs_and_lines sals; |
0101ce28 | 7782 | struct symtab_and_line pending_sal; |
0101ce28 | 7783 | char *copy_arg; |
c3f6f71d JM |
7784 | char *addr_start = arg; |
7785 | char **addr_string; | |
7786 | struct cleanup *old_chain; | |
80c99de1 | 7787 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7788 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7789 | int i; |
0101ce28 | 7790 | int pending = 0; |
0101ce28 | 7791 | int not_found = 0; |
4a306c9a | 7792 | int task = 0; |
86b17b60 | 7793 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7794 | |
c3f6f71d JM |
7795 | sals.sals = NULL; |
7796 | sals.nelts = 0; | |
7797 | addr_string = NULL; | |
c3f6f71d | 7798 | |
0101ce28 JJ |
7799 | parse_args.arg_p = &arg; |
7800 | parse_args.sals_p = &sals; | |
7801 | parse_args.addr_string_p = &addr_string; | |
7802 | parse_args.not_found_ptr = ¬_found; | |
7803 | ||
0fb4aa4b PA |
7804 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7805 | { | |
7806 | int i; | |
7807 | ||
7808 | sals = decode_static_tracepoint_spec (&arg); | |
7809 | ||
7810 | copy_arg = savestring (addr_start, arg - addr_start); | |
7811 | addr_string = xcalloc (sals.nelts, sizeof (char **)); | |
7812 | for (i = 0; i < sals.nelts; i++) | |
7813 | addr_string[i] = xstrdup (copy_arg); | |
7814 | goto done; | |
7815 | } | |
7816 | ||
05ff989b AC |
7817 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7818 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7819 | |
7820 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7821 | switch (e.reason) |
0101ce28 | 7822 | { |
05ff989b | 7823 | case RETURN_QUIT: |
98deb0da | 7824 | throw_exception (e); |
05ff989b AC |
7825 | case RETURN_ERROR: |
7826 | switch (e.error) | |
0101ce28 | 7827 | { |
05ff989b | 7828 | case NOT_FOUND_ERROR: |
0101ce28 | 7829 | |
05ff989b AC |
7830 | /* If pending breakpoint support is turned off, throw |
7831 | error. */ | |
fa8d40ab JJ |
7832 | |
7833 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7834 | throw_exception (e); |
7835 | ||
7836 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7837 | |
05ff989b AC |
7838 | /* If pending breakpoint support is auto query and the user |
7839 | selects no, then simply return the error code. */ | |
059fb39f | 7840 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7841 | && !nquery (_("Make breakpoint pending on " |
7842 | "future shared library load? "))) | |
fd9b8c24 | 7843 | return 0; |
fa8d40ab | 7844 | |
05ff989b AC |
7845 | /* At this point, either the user was queried about setting |
7846 | a pending breakpoint and selected yes, or pending | |
7847 | breakpoint behavior is on and thus a pending breakpoint | |
7848 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7849 | copy_arg = xstrdup (addr_start); |
7850 | addr_string = ©_arg; | |
7851 | sals.nelts = 1; | |
7852 | sals.sals = &pending_sal; | |
7853 | pending_sal.pc = 0; | |
7854 | pending = 1; | |
05ff989b AC |
7855 | break; |
7856 | default: | |
98deb0da | 7857 | throw_exception (e); |
0101ce28 | 7858 | } |
2abae994 | 7859 | break; |
05ff989b AC |
7860 | default: |
7861 | if (!sals.nelts) | |
fd9b8c24 | 7862 | return 0; |
0101ce28 | 7863 | } |
c3f6f71d | 7864 | |
0fb4aa4b PA |
7865 | done: |
7866 | ||
4a64f543 | 7867 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7868 | old_chain = make_cleanup (null_cleanup, 0); |
7869 | ||
0101ce28 JJ |
7870 | if (!pending) |
7871 | { | |
7872 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7873 | make_cleanup (xfree, sals.sals); | |
7874 | ||
4a64f543 | 7875 | /* Cleanup the addr_string array but not its contents. */ |
0101ce28 JJ |
7876 | make_cleanup (xfree, addr_string); |
7877 | } | |
c3f6f71d | 7878 | |
c3f6f71d JM |
7879 | /* ----------------------------- SNIP ----------------------------- |
7880 | Anything added to the cleanup chain beyond this point is assumed | |
7881 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7882 | then the memory is not reclaimed. */ |
7883 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7884 | |
7885 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7886 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7887 | for (i = 0; i < sals.nelts; i++) |
7888 | { | |
7889 | if (addr_string[i] != NULL) | |
b8c9b27d | 7890 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7891 | } |
7892 | ||
7893 | /* Resolve all line numbers to PC's and verify that the addresses | |
7894 | are ok for the target. */ | |
0101ce28 | 7895 | if (!pending) |
23e7acfb | 7896 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7897 | |
7a697b8d SS |
7898 | /* Fast tracepoints may have additional restrictions on location. */ |
7899 | if (type_wanted == bp_fast_tracepoint) | |
7900 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7901 | ||
c3f6f71d JM |
7902 | /* Verify that condition can be parsed, before setting any |
7903 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7904 | breakpoint. */ |
0101ce28 | 7905 | if (!pending) |
c3f6f71d | 7906 | { |
2f069f6f | 7907 | if (parse_condition_and_thread) |
72b2ff0e VP |
7908 | { |
7909 | /* Here we only parse 'arg' to separate condition | |
7910 | from thread number, so parsing in context of first | |
7911 | sal is OK. When setting the breakpoint we'll | |
7912 | re-parse it in context of each sal. */ | |
7913 | cond_string = NULL; | |
7914 | thread = -1; | |
4a306c9a JB |
7915 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7916 | &thread, &task); | |
72b2ff0e VP |
7917 | if (cond_string) |
7918 | make_cleanup (xfree, cond_string); | |
7919 | } | |
2f069f6f | 7920 | else |
72b2ff0e VP |
7921 | { |
7922 | /* Create a private copy of condition string. */ | |
7923 | if (cond_string) | |
7924 | { | |
7925 | cond_string = xstrdup (cond_string); | |
7926 | make_cleanup (xfree, cond_string); | |
7927 | } | |
7928 | } | |
0fb4aa4b PA |
7929 | |
7930 | /* If the user is creating a static tracepoint by marker id | |
7931 | (strace -m MARKER_ID), then store the sals index, so that | |
7932 | breakpoint_re_set can try to match up which of the newly | |
7933 | found markers corresponds to this one, and, don't try to | |
7934 | expand multiple locations for each sal, given than SALS | |
7935 | already should contain all sals for MARKER_ID. */ | |
7936 | if (type_wanted == bp_static_tracepoint | |
7937 | && is_marker_spec (addr_string[0])) | |
7938 | { | |
7939 | int i; | |
7940 | ||
7941 | for (i = 0; i < sals.nelts; ++i) | |
7942 | { | |
7943 | struct symtabs_and_lines expanded; | |
7944 | struct breakpoint *tp; | |
7945 | struct cleanup *old_chain; | |
7946 | ||
7947 | expanded.nelts = 1; | |
7948 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7949 | expanded.sals[0] = sals.sals[i]; | |
7950 | old_chain = make_cleanup (xfree, expanded.sals); | |
7951 | ||
7952 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], | |
7953 | cond_string, type_wanted, | |
7954 | tempflag ? disp_del : disp_donttouch, | |
7955 | thread, task, ignore_count, ops, | |
84f4c1fe | 7956 | from_tty, enabled, internal); |
0fb4aa4b PA |
7957 | |
7958 | do_cleanups (old_chain); | |
7959 | ||
7960 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
7961 | if (internal) |
7962 | tp = get_breakpoint (internal_breakpoint_number); | |
7963 | else | |
7964 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
7965 | gdb_assert (tp != NULL); |
7966 | ||
7967 | /* Given that its possible to have multiple markers with | |
7968 | the same string id, if the user is creating a static | |
7969 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7970 | store the sals index, so that breakpoint_re_set can | |
7971 | try to match up which of the newly found markers | |
7972 | corresponds to this one */ | |
7973 | tp->static_trace_marker_id_idx = i; | |
7974 | } | |
7975 | } | |
7976 | else | |
7977 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, | |
3e43a32a MS |
7978 | type_wanted, |
7979 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7980 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7981 | enabled, internal); |
c906108c | 7982 | } |
0101ce28 JJ |
7983 | else |
7984 | { | |
0101ce28 JJ |
7985 | struct breakpoint *b; |
7986 | ||
0101ce28 JJ |
7987 | make_cleanup (xfree, copy_arg); |
7988 | ||
a6d9a66e | 7989 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 7990 | set_breakpoint_number (internal, b); |
72b2ff0e | 7991 | b->thread = -1; |
018d34a4 | 7992 | b->addr_string = addr_string[0]; |
72b2ff0e | 7993 | b->cond_string = NULL; |
0101ce28 | 7994 | b->ignore_count = ignore_count; |
0101ce28 | 7995 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7996 | b->condition_not_parsed = 1; |
604133b5 | 7997 | b->ops = ops; |
41447f92 | 7998 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7999 | b->pspace = current_program_space; |
84f4c1fe | 8000 | b->py_bp_object = NULL; |
74960c60 | 8001 | |
6c95b8df | 8002 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8003 | && (b->type == bp_breakpoint |
8004 | || b->type == bp_hardware_breakpoint)) | |
8005 | b->enable_state = bp_startup_disabled; | |
8006 | ||
84f4c1fe PM |
8007 | if (internal) |
8008 | /* Do not mention breakpoints with a negative number, | |
8009 | but do notify observers. */ | |
8010 | observer_notify_breakpoint_created (b->number); | |
8011 | else | |
8012 | mention (b); | |
0101ce28 JJ |
8013 | } |
8014 | ||
c3f6f71d | 8015 | if (sals.nelts > 1) |
95a42b64 | 8016 | { |
3e43a32a MS |
8017 | warning (_("Multiple breakpoints were set.\nUse the " |
8018 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8019 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8020 | } |
8021 | ||
80c99de1 PA |
8022 | /* That's it. Discard the cleanups for data inserted into the |
8023 | breakpoint. */ | |
8024 | discard_cleanups (bkpt_chain); | |
8025 | /* But cleanup everything else. */ | |
c3f6f71d | 8026 | do_cleanups (old_chain); |
217dc9e2 | 8027 | |
80c99de1 | 8028 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8029 | update_global_location_list (1); |
fd9b8c24 PA |
8030 | |
8031 | return 1; | |
c3f6f71d | 8032 | } |
c906108c | 8033 | |
72b2ff0e VP |
8034 | /* Set a breakpoint. |
8035 | ARG is a string describing breakpoint address, | |
8036 | condition, and thread. | |
8037 | FLAG specifies if a breakpoint is hardware on, | |
8038 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8039 | and BP_TEMPFLAG. */ | |
8040 | ||
98deb0da | 8041 | static void |
72b2ff0e | 8042 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8043 | { |
72b2ff0e | 8044 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8045 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8046 | ? bp_hardware_breakpoint | |
8047 | : bp_breakpoint); | |
c3f6f71d | 8048 | |
8cdf0e15 VP |
8049 | create_breakpoint (get_current_arch (), |
8050 | arg, | |
8051 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8052 | tempflag, type_wanted, |
8cdf0e15 VP |
8053 | 0 /* Ignore count */, |
8054 | pending_break_support, | |
8055 | NULL /* breakpoint_ops */, | |
8056 | from_tty, | |
84f4c1fe PM |
8057 | 1 /* enabled */, |
8058 | 0 /* internal */); | |
c906108c SS |
8059 | } |
8060 | ||
72b2ff0e | 8061 | |
c906108c SS |
8062 | /* Helper function for break_command_1 and disassemble_command. */ |
8063 | ||
8064 | void | |
fba45db2 | 8065 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8066 | { |
8067 | CORE_ADDR pc; | |
8068 | ||
8069 | if (sal->pc == 0 && sal->symtab != NULL) | |
8070 | { | |
8071 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8072 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8073 | sal->line, sal->symtab->filename); |
8074 | sal->pc = pc; | |
6a048695 | 8075 | |
4a64f543 MS |
8076 | /* If this SAL corresponds to a breakpoint inserted using a line |
8077 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8078 | if (sal->explicit_line) |
059acae7 | 8079 | skip_prologue_sal (sal); |
c906108c SS |
8080 | } |
8081 | ||
8082 | if (sal->section == 0 && sal->symtab != NULL) | |
8083 | { | |
8084 | struct blockvector *bv; | |
c5aa993b JM |
8085 | struct block *b; |
8086 | struct symbol *sym; | |
c906108c | 8087 | |
801e3a5b | 8088 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8089 | if (bv != NULL) |
8090 | { | |
7f0df278 | 8091 | sym = block_linkage_function (b); |
c906108c SS |
8092 | if (sym != NULL) |
8093 | { | |
8094 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8095 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8096 | } |
8097 | else | |
8098 | { | |
4a64f543 MS |
8099 | /* It really is worthwhile to have the section, so we'll |
8100 | just have to look harder. This case can be executed | |
8101 | if we have line numbers but no functions (as can | |
8102 | happen in assembly source). */ | |
c906108c | 8103 | |
c5aa993b | 8104 | struct minimal_symbol *msym; |
6c95b8df PA |
8105 | struct cleanup *old_chain = save_current_space_and_thread (); |
8106 | ||
8107 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8108 | |
8109 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8110 | if (msym) | |
714835d5 | 8111 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8112 | |
8113 | do_cleanups (old_chain); | |
c906108c SS |
8114 | } |
8115 | } | |
8116 | } | |
8117 | } | |
8118 | ||
8119 | void | |
fba45db2 | 8120 | break_command (char *arg, int from_tty) |
c906108c | 8121 | { |
db107f19 | 8122 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8123 | } |
8124 | ||
c906108c | 8125 | void |
fba45db2 | 8126 | tbreak_command (char *arg, int from_tty) |
c906108c | 8127 | { |
db107f19 | 8128 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8129 | } |
8130 | ||
c906108c | 8131 | static void |
fba45db2 | 8132 | hbreak_command (char *arg, int from_tty) |
c906108c | 8133 | { |
db107f19 | 8134 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8135 | } |
8136 | ||
8137 | static void | |
fba45db2 | 8138 | thbreak_command (char *arg, int from_tty) |
c906108c | 8139 | { |
db107f19 | 8140 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8141 | } |
8142 | ||
8143 | static void | |
fba45db2 | 8144 | stop_command (char *arg, int from_tty) |
c906108c | 8145 | { |
a3f17187 | 8146 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8147 | Usage: stop in <function | address>\n\ |
a3f17187 | 8148 | stop at <line>\n")); |
c906108c SS |
8149 | } |
8150 | ||
8151 | static void | |
fba45db2 | 8152 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8153 | { |
8154 | int badInput = 0; | |
8155 | ||
c5aa993b | 8156 | if (arg == (char *) NULL) |
c906108c SS |
8157 | badInput = 1; |
8158 | else if (*arg != '*') | |
8159 | { | |
8160 | char *argptr = arg; | |
8161 | int hasColon = 0; | |
8162 | ||
4a64f543 | 8163 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8164 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8165 | function/method name. */ |
c906108c | 8166 | while (*argptr && !hasColon) |
c5aa993b JM |
8167 | { |
8168 | hasColon = (*argptr == ':'); | |
8169 | argptr++; | |
8170 | } | |
c906108c SS |
8171 | |
8172 | if (hasColon) | |
c5aa993b | 8173 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8174 | else |
c5aa993b | 8175 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8176 | } |
8177 | ||
8178 | if (badInput) | |
a3f17187 | 8179 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8180 | else |
db107f19 | 8181 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8182 | } |
8183 | ||
8184 | static void | |
fba45db2 | 8185 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8186 | { |
8187 | int badInput = 0; | |
8188 | ||
c5aa993b | 8189 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8190 | badInput = 1; |
8191 | else | |
8192 | { | |
8193 | char *argptr = arg; | |
8194 | int hasColon = 0; | |
8195 | ||
4a64f543 MS |
8196 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8197 | it is probably a line number. */ | |
c906108c | 8198 | while (*argptr && !hasColon) |
c5aa993b JM |
8199 | { |
8200 | hasColon = (*argptr == ':'); | |
8201 | argptr++; | |
8202 | } | |
c906108c SS |
8203 | |
8204 | if (hasColon) | |
c5aa993b | 8205 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8206 | else |
c5aa993b | 8207 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8208 | } |
8209 | ||
8210 | if (badInput) | |
a3f17187 | 8211 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8212 | else |
db107f19 | 8213 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8214 | } |
8215 | ||
4a64f543 MS |
8216 | /* Return non-zero if EXP is verified as constant. Returned zero |
8217 | means EXP is variable. Also the constant detection may fail for | |
8218 | some constant expressions and in such case still falsely return | |
8219 | zero. */ | |
65d79d4b SDJ |
8220 | static int |
8221 | watchpoint_exp_is_const (const struct expression *exp) | |
8222 | { | |
8223 | int i = exp->nelts; | |
8224 | ||
8225 | while (i > 0) | |
8226 | { | |
8227 | int oplenp, argsp; | |
8228 | ||
8229 | /* We are only interested in the descriptor of each element. */ | |
8230 | operator_length (exp, i, &oplenp, &argsp); | |
8231 | i -= oplenp; | |
8232 | ||
8233 | switch (exp->elts[i].opcode) | |
8234 | { | |
8235 | case BINOP_ADD: | |
8236 | case BINOP_SUB: | |
8237 | case BINOP_MUL: | |
8238 | case BINOP_DIV: | |
8239 | case BINOP_REM: | |
8240 | case BINOP_MOD: | |
8241 | case BINOP_LSH: | |
8242 | case BINOP_RSH: | |
8243 | case BINOP_LOGICAL_AND: | |
8244 | case BINOP_LOGICAL_OR: | |
8245 | case BINOP_BITWISE_AND: | |
8246 | case BINOP_BITWISE_IOR: | |
8247 | case BINOP_BITWISE_XOR: | |
8248 | case BINOP_EQUAL: | |
8249 | case BINOP_NOTEQUAL: | |
8250 | case BINOP_LESS: | |
8251 | case BINOP_GTR: | |
8252 | case BINOP_LEQ: | |
8253 | case BINOP_GEQ: | |
8254 | case BINOP_REPEAT: | |
8255 | case BINOP_COMMA: | |
8256 | case BINOP_EXP: | |
8257 | case BINOP_MIN: | |
8258 | case BINOP_MAX: | |
8259 | case BINOP_INTDIV: | |
8260 | case BINOP_CONCAT: | |
8261 | case BINOP_IN: | |
8262 | case BINOP_RANGE: | |
8263 | case TERNOP_COND: | |
8264 | case TERNOP_SLICE: | |
8265 | case TERNOP_SLICE_COUNT: | |
8266 | ||
8267 | case OP_LONG: | |
8268 | case OP_DOUBLE: | |
8269 | case OP_DECFLOAT: | |
8270 | case OP_LAST: | |
8271 | case OP_COMPLEX: | |
8272 | case OP_STRING: | |
8273 | case OP_BITSTRING: | |
8274 | case OP_ARRAY: | |
8275 | case OP_TYPE: | |
8276 | case OP_NAME: | |
8277 | case OP_OBJC_NSSTRING: | |
8278 | ||
8279 | case UNOP_NEG: | |
8280 | case UNOP_LOGICAL_NOT: | |
8281 | case UNOP_COMPLEMENT: | |
8282 | case UNOP_ADDR: | |
8283 | case UNOP_HIGH: | |
4a64f543 MS |
8284 | /* Unary, binary and ternary operators: We have to check |
8285 | their operands. If they are constant, then so is the | |
8286 | result of that operation. For instance, if A and B are | |
8287 | determined to be constants, then so is "A + B". | |
8288 | ||
8289 | UNOP_IND is one exception to the rule above, because the | |
8290 | value of *ADDR is not necessarily a constant, even when | |
8291 | ADDR is. */ | |
65d79d4b SDJ |
8292 | break; |
8293 | ||
8294 | case OP_VAR_VALUE: | |
8295 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8296 | |
65d79d4b | 8297 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8298 | possible that a buggy compiler could mark a variable as |
8299 | constant even when it is not, and TYPE_CONST would return | |
8300 | true in this case, while SYMBOL_CLASS wouldn't. | |
8301 | ||
8302 | We also have to check for function symbols because they | |
8303 | are always constant. */ | |
65d79d4b SDJ |
8304 | { |
8305 | struct symbol *s = exp->elts[i + 2].symbol; | |
8306 | ||
8307 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8308 | && SYMBOL_CLASS (s) != LOC_CONST | |
8309 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8310 | return 0; | |
8311 | break; | |
8312 | } | |
8313 | ||
8314 | /* The default action is to return 0 because we are using | |
8315 | the optimistic approach here: If we don't know something, | |
8316 | then it is not a constant. */ | |
8317 | default: | |
8318 | return 0; | |
8319 | } | |
8320 | } | |
8321 | ||
8322 | return 1; | |
8323 | } | |
8324 | ||
77b06cd7 TJB |
8325 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8326 | ||
8327 | static int | |
8328 | insert_watchpoint (struct bp_location *bl) | |
8329 | { | |
e09342b5 TJB |
8330 | int length = bl->owner->exact? 1 : bl->length; |
8331 | ||
8332 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8333 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8334 | } |
8335 | ||
8336 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8337 | ||
8338 | static int | |
8339 | remove_watchpoint (struct bp_location *bl) | |
8340 | { | |
e09342b5 TJB |
8341 | int length = bl->owner->exact? 1 : bl->length; |
8342 | ||
8343 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8344 | bl->owner->cond_exp); | |
8345 | } | |
8346 | ||
8347 | /* Implement the "resources_needed" breakpoint_ops method for | |
8348 | hardware watchpoints. */ | |
8349 | ||
8350 | static int | |
8351 | resources_needed_watchpoint (const struct bp_location *bl) | |
8352 | { | |
90e4670f | 8353 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8354 | |
90e4670f | 8355 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8356 | } |
8357 | ||
8358 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8359 | ||
8360 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8361 | { | |
8362 | insert_watchpoint, | |
8363 | remove_watchpoint, | |
8364 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8365 | resources_needed_watchpoint, |
77b06cd7 TJB |
8366 | NULL, /* print_it */ |
8367 | NULL, /* print_one */ | |
8368 | NULL, /* print_mention */ | |
8369 | NULL /* print_recreate */ | |
8370 | }; | |
8371 | ||
53a5351d JM |
8372 | /* accessflag: hw_write: watch write, |
8373 | hw_read: watch read, | |
8374 | hw_access: watch access (read or write) */ | |
c906108c | 8375 | static void |
84f4c1fe PM |
8376 | watch_command_1 (char *arg, int accessflag, int from_tty, |
8377 | int just_location, int internal) | |
c906108c | 8378 | { |
d983da9c | 8379 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 8380 | struct expression *exp; |
60e1c644 | 8381 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 8382 | struct value *val, *mark, *result; |
c906108c | 8383 | struct frame_info *frame; |
c906108c SS |
8384 | char *exp_start = NULL; |
8385 | char *exp_end = NULL; | |
37e4754d | 8386 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
8387 | int toklen; |
8388 | char *cond_start = NULL; | |
8389 | char *cond_end = NULL; | |
c906108c SS |
8390 | int i, other_type_used, target_resources_ok = 0; |
8391 | enum bptype bp_type; | |
e09342b5 | 8392 | int reg_cnt = 0; |
37e4754d | 8393 | int thread = -1; |
0cf6dd15 | 8394 | int pc = 0; |
c906108c | 8395 | |
37e4754d LM |
8396 | /* Make sure that we actually have parameters to parse. */ |
8397 | if (arg != NULL && arg[0] != '\0') | |
8398 | { | |
8399 | toklen = strlen (arg); /* Size of argument list. */ | |
8400 | ||
8401 | /* Points tok to the end of the argument list. */ | |
8402 | tok = arg + toklen - 1; | |
8403 | ||
4a64f543 MS |
8404 | /* Go backwards in the parameters list. Skip the last |
8405 | parameter. If we're expecting a 'thread <thread_num>' | |
8406 | parameter, this should be the thread identifier. */ | |
37e4754d LM |
8407 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8408 | tok--; | |
8409 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8410 | tok--; | |
8411 | ||
8412 | /* Points end_tok to the beginning of the last token. */ | |
8413 | id_tok_start = tok + 1; | |
8414 | ||
4a64f543 MS |
8415 | /* Go backwards in the parameters list. Skip one more |
8416 | parameter. If we're expecting a 'thread <thread_num>' | |
8417 | parameter, we should reach a "thread" token. */ | |
37e4754d LM |
8418 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8419 | tok--; | |
8420 | ||
8421 | end_tok = tok; | |
8422 | ||
8423 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8424 | tok--; | |
8425 | ||
8426 | /* Move the pointer forward to skip the whitespace and | |
8427 | calculate the length of the token. */ | |
8428 | tok++; | |
8429 | toklen = end_tok - tok; | |
8430 | ||
8431 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8432 | { | |
8433 | /* At this point we've found a "thread" token, which means | |
8434 | the user is trying to set a watchpoint that triggers | |
8435 | only in a specific thread. */ | |
8436 | char *endp; | |
8437 | ||
8438 | /* Extract the thread ID from the next token. */ | |
8439 | thread = strtol (id_tok_start, &endp, 0); | |
8440 | ||
8441 | /* Check if the user provided a valid numeric value for the | |
8442 | thread ID. */ | |
8443 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
8444 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
8445 | ||
8446 | /* Check if the thread actually exists. */ | |
8447 | if (!valid_thread_id (thread)) | |
8448 | error (_("Unknown thread %d."), thread); | |
8449 | ||
8450 | /* Truncate the string and get rid of the thread <thread_num> | |
8451 | parameter before the parameter list is parsed by the | |
8452 | evaluate_expression() function. */ | |
8453 | *tok = '\0'; | |
8454 | } | |
8455 | } | |
8456 | ||
8457 | /* Parse the rest of the arguments. */ | |
c906108c SS |
8458 | innermost_block = NULL; |
8459 | exp_start = arg; | |
8460 | exp = parse_exp_1 (&arg, 0, 0); | |
8461 | exp_end = arg; | |
fa8a61dc TT |
8462 | /* Remove trailing whitespace from the expression before saving it. |
8463 | This makes the eventual display of the expression string a bit | |
8464 | prettier. */ | |
8465 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
8466 | --exp_end; | |
8467 | ||
65d79d4b SDJ |
8468 | /* Checking if the expression is not constant. */ |
8469 | if (watchpoint_exp_is_const (exp)) | |
8470 | { | |
8471 | int len; | |
8472 | ||
8473 | len = exp_end - exp_start; | |
8474 | while (len > 0 && isspace (exp_start[len - 1])) | |
8475 | len--; | |
8476 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
8477 | } | |
8478 | ||
c906108c SS |
8479 | exp_valid_block = innermost_block; |
8480 | mark = value_mark (); | |
a1442452 | 8481 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
8482 | |
8483 | if (just_location) | |
8484 | { | |
8485 | exp_valid_block = NULL; | |
a1442452 | 8486 | val = value_addr (result); |
06a64a0b TT |
8487 | release_value (val); |
8488 | value_free_to_mark (mark); | |
8489 | } | |
8490 | else if (val != NULL) | |
fa4727a6 | 8491 | release_value (val); |
c906108c | 8492 | |
e9cafbcc TT |
8493 | tok = skip_spaces (arg); |
8494 | end_tok = skip_to_space (tok); | |
c906108c SS |
8495 | |
8496 | toklen = end_tok - tok; | |
8497 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8498 | { | |
2d134ed3 PA |
8499 | struct expression *cond; |
8500 | ||
60e1c644 | 8501 | innermost_block = NULL; |
c906108c SS |
8502 | tok = cond_start = end_tok + 1; |
8503 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
8504 | |
8505 | /* The watchpoint expression may not be local, but the condition | |
8506 | may still be. E.g.: `watch global if local > 0'. */ | |
8507 | cond_exp_valid_block = innermost_block; | |
8508 | ||
2d134ed3 | 8509 | xfree (cond); |
c906108c SS |
8510 | cond_end = tok; |
8511 | } | |
8512 | if (*tok) | |
8a3fe4f8 | 8513 | error (_("Junk at end of command.")); |
c906108c | 8514 | |
53a5351d | 8515 | if (accessflag == hw_read) |
c5aa993b | 8516 | bp_type = bp_read_watchpoint; |
53a5351d | 8517 | else if (accessflag == hw_access) |
c5aa993b JM |
8518 | bp_type = bp_access_watchpoint; |
8519 | else | |
8520 | bp_type = bp_hardware_watchpoint; | |
c906108c | 8521 | |
e09342b5 TJB |
8522 | reg_cnt = can_use_hardware_watchpoint (val, target_exact_watchpoints); |
8523 | if (reg_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 8524 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
e09342b5 | 8525 | if (reg_cnt != 0) |
c5aa993b JM |
8526 | { |
8527 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 8528 | target_resources_ok = |
e09342b5 | 8529 | target_can_use_hardware_watchpoint (bp_type, i + reg_cnt, |
53a5351d | 8530 | other_type_used); |
c5aa993b | 8531 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8532 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 8533 | |
c5aa993b | 8534 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
3e43a32a MS |
8535 | error (_("Target can only support one kind " |
8536 | "of HW watchpoint at a time.")); | |
c5aa993b | 8537 | } |
c906108c | 8538 | |
4a64f543 MS |
8539 | /* Change the type of breakpoint to an ordinary watchpoint if a |
8540 | hardware watchpoint could not be set. */ | |
e09342b5 | 8541 | if (!reg_cnt || target_resources_ok <= 0) |
4d28f7a8 KB |
8542 | bp_type = bp_watchpoint; |
8543 | ||
d983da9c | 8544 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
8545 | |
8546 | /* If the expression is "local", then set up a "watchpoint scope" | |
8547 | breakpoint at the point where we've left the scope of the watchpoint | |
8548 | expression. Create the scope breakpoint before the watchpoint, so | |
8549 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 8550 | if (exp_valid_block && frame) |
d983da9c | 8551 | { |
edb3359d DJ |
8552 | if (frame_id_p (frame_unwind_caller_id (frame))) |
8553 | { | |
8554 | scope_breakpoint | |
a6d9a66e UW |
8555 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
8556 | frame_unwind_caller_pc (frame), | |
edb3359d | 8557 | bp_watchpoint_scope); |
d983da9c | 8558 | |
edb3359d | 8559 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 8560 | |
edb3359d DJ |
8561 | /* Automatically delete the breakpoint when it hits. */ |
8562 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 8563 | |
edb3359d DJ |
8564 | /* Only break in the proper frame (help with recursion). */ |
8565 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 8566 | |
edb3359d | 8567 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
8568 | scope_breakpoint->loc->gdbarch |
8569 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
8570 | scope_breakpoint->loc->requested_address |
8571 | = frame_unwind_caller_pc (frame); | |
8572 | scope_breakpoint->loc->address | |
a6d9a66e UW |
8573 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
8574 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
8575 | scope_breakpoint->type); |
8576 | } | |
d983da9c DJ |
8577 | } |
8578 | ||
c906108c | 8579 | /* Now set up the breakpoint. */ |
2d134ed3 | 8580 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
84f4c1fe | 8581 | set_breakpoint_number (internal, b); |
37e4754d | 8582 | b->thread = thread; |
b5de0fa7 | 8583 | b->disposition = disp_donttouch; |
c906108c SS |
8584 | b->exp = exp; |
8585 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 8586 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
8587 | if (just_location) |
8588 | { | |
8589 | struct type *t = value_type (val); | |
8590 | CORE_ADDR addr = value_as_address (val); | |
8591 | char *name; | |
8592 | ||
8593 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
8594 | name = type_to_string (t); | |
8595 | ||
d63d0675 JK |
8596 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
8597 | core_addr_to_string (addr)); | |
06a64a0b TT |
8598 | xfree (name); |
8599 | ||
d63d0675 JK |
8600 | b->exp_string = xstrprintf ("-location: %.*s", |
8601 | (int) (exp_end - exp_start), exp_start); | |
8602 | ||
06a64a0b TT |
8603 | /* The above expression is in C. */ |
8604 | b->language = language_c; | |
8605 | } | |
8606 | else | |
8607 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
c906108c | 8608 | b->val = val; |
fa4727a6 | 8609 | b->val_valid = 1; |
77b06cd7 TJB |
8610 | b->ops = &watchpoint_breakpoint_ops; |
8611 | ||
e09342b5 TJB |
8612 | /* Use an exact watchpoint when there's only one memory region to be |
8613 | watched, and only one debug register is needed to watch it. */ | |
8614 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
8615 | ||
c906108c SS |
8616 | if (cond_start) |
8617 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
8618 | else | |
8619 | b->cond_string = 0; | |
c5aa993b | 8620 | |
c906108c | 8621 | if (frame) |
f6bc2008 PA |
8622 | { |
8623 | b->watchpoint_frame = get_frame_id (frame); | |
8624 | b->watchpoint_thread = inferior_ptid; | |
8625 | } | |
c906108c | 8626 | else |
f6bc2008 PA |
8627 | { |
8628 | b->watchpoint_frame = null_frame_id; | |
8629 | b->watchpoint_thread = null_ptid; | |
8630 | } | |
c906108c | 8631 | |
d983da9c | 8632 | if (scope_breakpoint != NULL) |
c906108c | 8633 | { |
d983da9c DJ |
8634 | /* The scope breakpoint is related to the watchpoint. We will |
8635 | need to act on them together. */ | |
8636 | b->related_breakpoint = scope_breakpoint; | |
8637 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 8638 | } |
d983da9c | 8639 | |
06a64a0b TT |
8640 | if (!just_location) |
8641 | value_free_to_mark (mark); | |
2d134ed3 PA |
8642 | |
8643 | /* Finally update the new watchpoint. This creates the locations | |
8644 | that should be inserted. */ | |
8645 | update_watchpoint (b, 1); | |
84f4c1fe PM |
8646 | if (internal) |
8647 | /* Do not mention breakpoints with a negative number, but do | |
8648 | notify observers. */ | |
8649 | observer_notify_breakpoint_created (b->number); | |
8650 | else | |
8651 | mention (b); | |
b60e7edf | 8652 | update_global_location_list (1); |
c906108c SS |
8653 | } |
8654 | ||
e09342b5 TJB |
8655 | /* Return count of debug registers needed to watch the given expression. |
8656 | If EXACT_WATCHPOINTS is 1, then consider that only the address of | |
8657 | the start of the watched region will be monitored (i.e., all accesses | |
8658 | will be aligned). This uses less debug registers on some targets. | |
8659 | ||
8660 | If the watchpoint cannot be handled in hardware return zero. */ | |
c906108c | 8661 | |
c906108c | 8662 | static int |
e09342b5 | 8663 | can_use_hardware_watchpoint (struct value *v, int exact_watchpoints) |
c906108c SS |
8664 | { |
8665 | int found_memory_cnt = 0; | |
2e70b7b9 | 8666 | struct value *head = v; |
c906108c SS |
8667 | |
8668 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 8669 | if (!can_use_hw_watchpoints) |
c906108c | 8670 | return 0; |
c5aa993b | 8671 | |
5c44784c JM |
8672 | /* Make sure that the value of the expression depends only upon |
8673 | memory contents, and values computed from them within GDB. If we | |
8674 | find any register references or function calls, we can't use a | |
8675 | hardware watchpoint. | |
8676 | ||
8677 | The idea here is that evaluating an expression generates a series | |
8678 | of values, one holding the value of every subexpression. (The | |
8679 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
8680 | a*b+c.) GDB's values hold almost enough information to establish | |
8681 | the criteria given above --- they identify memory lvalues, | |
8682 | register lvalues, computed values, etcetera. So we can evaluate | |
8683 | the expression, and then scan the chain of values that leaves | |
8684 | behind to decide whether we can detect any possible change to the | |
8685 | expression's final value using only hardware watchpoints. | |
8686 | ||
8687 | However, I don't think that the values returned by inferior | |
8688 | function calls are special in any way. So this function may not | |
8689 | notice that an expression involving an inferior function call | |
8690 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 8691 | for (; v; v = value_next (v)) |
c906108c | 8692 | { |
5c44784c | 8693 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 8694 | { |
8464be76 DJ |
8695 | if (v != head && value_lazy (v)) |
8696 | /* A lazy memory lvalue in the chain is one that GDB never | |
8697 | needed to fetch; we either just used its address (e.g., | |
8698 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
8699 | in `a,b'). This doesn't apply to HEAD; if that is | |
8700 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 8701 | ; |
53a5351d | 8702 | else |
5c44784c JM |
8703 | { |
8704 | /* Ahh, memory we actually used! Check if we can cover | |
8705 | it with hardware watchpoints. */ | |
df407dfe | 8706 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
8707 | |
8708 | /* We only watch structs and arrays if user asked for it | |
8709 | explicitly, never if they just happen to appear in a | |
8710 | middle of some value chain. */ | |
8711 | if (v == head | |
8712 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
8713 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
8714 | { | |
42ae5230 | 8715 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
8716 | int len; |
8717 | int num_regs; | |
8718 | ||
8719 | len = (exact_watchpoints | |
8720 | && is_scalar_type_recursive (vtype))? | |
8721 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 8722 | |
e09342b5 TJB |
8723 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
8724 | if (!num_regs) | |
2e70b7b9 MS |
8725 | return 0; |
8726 | else | |
e09342b5 | 8727 | found_memory_cnt += num_regs; |
2e70b7b9 | 8728 | } |
5c44784c | 8729 | } |
c5aa993b | 8730 | } |
5086187c AC |
8731 | else if (VALUE_LVAL (v) != not_lval |
8732 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 8733 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 8734 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 8735 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
8736 | } |
8737 | ||
8738 | /* The expression itself looks suitable for using a hardware | |
8739 | watchpoint, but give the target machine a chance to reject it. */ | |
8740 | return found_memory_cnt; | |
8741 | } | |
8742 | ||
8b93c638 | 8743 | void |
84f4c1fe | 8744 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8745 | { |
84f4c1fe | 8746 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
8747 | } |
8748 | ||
8749 | /* A helper function that looks for an argument at the start of a | |
8750 | string. The argument must also either be at the end of the string, | |
8751 | or be followed by whitespace. Returns 1 if it finds the argument, | |
8752 | 0 otherwise. If the argument is found, it updates *STR. */ | |
8753 | ||
8754 | static int | |
8755 | check_for_argument (char **str, char *arg, int arg_len) | |
8756 | { | |
8757 | if (strncmp (*str, arg, arg_len) == 0 | |
8758 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
8759 | { | |
8760 | *str += arg_len; | |
8761 | return 1; | |
8762 | } | |
8763 | return 0; | |
8764 | } | |
8765 | ||
8766 | /* A helper function that looks for the "-location" argument and then | |
8767 | calls watch_command_1. */ | |
8768 | ||
8769 | static void | |
8770 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
8771 | { | |
8772 | int just_location = 0; | |
8773 | ||
8774 | if (arg | |
8775 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
8776 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
8777 | { | |
e9cafbcc | 8778 | arg = skip_spaces (arg); |
06a64a0b TT |
8779 | just_location = 1; |
8780 | } | |
8781 | ||
84f4c1fe | 8782 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 8783 | } |
8926118c | 8784 | |
c5aa993b | 8785 | static void |
fba45db2 | 8786 | watch_command (char *arg, int from_tty) |
c906108c | 8787 | { |
06a64a0b | 8788 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
8789 | } |
8790 | ||
8b93c638 | 8791 | void |
84f4c1fe | 8792 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8793 | { |
84f4c1fe | 8794 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 8795 | } |
8926118c | 8796 | |
c5aa993b | 8797 | static void |
fba45db2 | 8798 | rwatch_command (char *arg, int from_tty) |
c906108c | 8799 | { |
06a64a0b | 8800 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
8801 | } |
8802 | ||
8b93c638 | 8803 | void |
84f4c1fe | 8804 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8805 | { |
84f4c1fe | 8806 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 8807 | } |
8926118c | 8808 | |
c5aa993b | 8809 | static void |
fba45db2 | 8810 | awatch_command (char *arg, int from_tty) |
c906108c | 8811 | { |
06a64a0b | 8812 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 8813 | } |
c906108c | 8814 | \f |
c5aa993b | 8815 | |
43ff13b4 | 8816 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8817 | because it uses the mechanisms of breakpoints. */ |
8818 | ||
bfec99b2 PA |
8819 | struct until_break_command_continuation_args |
8820 | { | |
8821 | struct breakpoint *breakpoint; | |
8822 | struct breakpoint *breakpoint2; | |
186c406b | 8823 | int thread_num; |
bfec99b2 PA |
8824 | }; |
8825 | ||
43ff13b4 | 8826 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 8827 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 8828 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 8829 | command. */ |
c2c6d25f | 8830 | static void |
604ead4a | 8831 | until_break_command_continuation (void *arg) |
43ff13b4 | 8832 | { |
bfec99b2 PA |
8833 | struct until_break_command_continuation_args *a = arg; |
8834 | ||
8835 | delete_breakpoint (a->breakpoint); | |
8836 | if (a->breakpoint2) | |
8837 | delete_breakpoint (a->breakpoint2); | |
186c406b | 8838 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
8839 | } |
8840 | ||
c906108c | 8841 | void |
ae66c1fc | 8842 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8843 | { |
8844 | struct symtabs_and_lines sals; | |
8845 | struct symtab_and_line sal; | |
206415a3 | 8846 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8847 | struct breakpoint *breakpoint; |
f107f563 | 8848 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 8849 | struct cleanup *old_chain; |
186c406b TT |
8850 | int thread; |
8851 | struct thread_info *tp; | |
c906108c SS |
8852 | |
8853 | clear_proceed_status (); | |
8854 | ||
8855 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 8856 | this function. */ |
c5aa993b | 8857 | |
c906108c SS |
8858 | if (default_breakpoint_valid) |
8859 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8860 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8861 | else |
53a5351d | 8862 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8863 | 0, (char ***) NULL, NULL); |
c5aa993b | 8864 | |
c906108c | 8865 | if (sals.nelts != 1) |
8a3fe4f8 | 8866 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8867 | |
c906108c | 8868 | sal = sals.sals[0]; |
4a64f543 | 8869 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 8870 | |
c906108c | 8871 | if (*arg) |
8a3fe4f8 | 8872 | error (_("Junk at end of arguments.")); |
c5aa993b | 8873 | |
c906108c | 8874 | resolve_sal_pc (&sal); |
c5aa993b | 8875 | |
ae66c1fc EZ |
8876 | if (anywhere) |
8877 | /* If the user told us to continue until a specified location, | |
8878 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8879 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8880 | null_frame_id, bp_until); | |
ae66c1fc | 8881 | else |
4a64f543 MS |
8882 | /* Otherwise, specify the selected frame, because we want to stop |
8883 | only at the very same frame. */ | |
a6d9a66e UW |
8884 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8885 | get_stack_frame_id (frame), | |
ae66c1fc | 8886 | bp_until); |
c5aa993b | 8887 | |
f107f563 | 8888 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8889 | |
186c406b TT |
8890 | tp = inferior_thread (); |
8891 | thread = tp->num; | |
8892 | ||
ae66c1fc EZ |
8893 | /* Keep within the current frame, or in frames called by the current |
8894 | one. */ | |
edb3359d DJ |
8895 | |
8896 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8897 | { |
edb3359d DJ |
8898 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8899 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8900 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8901 | sal, | |
edb3359d | 8902 | frame_unwind_caller_id (frame), |
f107f563 VP |
8903 | bp_until); |
8904 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
8905 | |
8906 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
8907 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 8908 | } |
c5aa993b | 8909 | |
c906108c | 8910 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 8911 | |
4a64f543 MS |
8912 | /* If we are running asynchronously, and proceed call above has |
8913 | actually managed to start the target, arrange for breakpoints to | |
8914 | be deleted when the target stops. Otherwise, we're already | |
8915 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 8916 | |
8ea051c5 | 8917 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8918 | { |
bfec99b2 PA |
8919 | struct until_break_command_continuation_args *args; |
8920 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8921 | |
bfec99b2 PA |
8922 | args->breakpoint = breakpoint; |
8923 | args->breakpoint2 = breakpoint2; | |
186c406b | 8924 | args->thread_num = thread; |
f107f563 VP |
8925 | |
8926 | discard_cleanups (old_chain); | |
95e54da7 PA |
8927 | add_continuation (inferior_thread (), |
8928 | until_break_command_continuation, args, | |
604ead4a | 8929 | xfree); |
f107f563 VP |
8930 | } |
8931 | else | |
c5aa993b | 8932 | do_cleanups (old_chain); |
c906108c | 8933 | } |
ae66c1fc | 8934 | |
c906108c SS |
8935 | /* This function attempts to parse an optional "if <cond>" clause |
8936 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8937 | |
c906108c SS |
8938 | Else, it returns a pointer to the condition string. (It does not |
8939 | attempt to evaluate the string against a particular block.) And, | |
8940 | it updates arg to point to the first character following the parsed | |
4a64f543 | 8941 | if clause in the arg string. */ |
53a5351d | 8942 | |
c906108c | 8943 | static char * |
fba45db2 | 8944 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8945 | { |
c5aa993b JM |
8946 | char *cond_string; |
8947 | ||
8948 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8949 | return NULL; |
c5aa993b | 8950 | |
4a64f543 | 8951 | /* Skip the "if" keyword. */ |
c906108c | 8952 | (*arg) += 2; |
c5aa993b | 8953 | |
c906108c | 8954 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 8955 | condition string. */ |
e9cafbcc | 8956 | *arg = skip_spaces (*arg); |
c906108c | 8957 | cond_string = *arg; |
c5aa993b | 8958 | |
4a64f543 MS |
8959 | /* Assume that the condition occupies the remainder of the arg |
8960 | string. */ | |
c906108c | 8961 | (*arg) += strlen (cond_string); |
c5aa993b | 8962 | |
c906108c SS |
8963 | return cond_string; |
8964 | } | |
c5aa993b | 8965 | |
c906108c SS |
8966 | /* Commands to deal with catching events, such as signals, exceptions, |
8967 | process start/exit, etc. */ | |
c5aa993b JM |
8968 | |
8969 | typedef enum | |
8970 | { | |
44feb3ce TT |
8971 | catch_fork_temporary, catch_vfork_temporary, |
8972 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8973 | } |
8974 | catch_fork_kind; | |
8975 | ||
c906108c | 8976 | static void |
cc59ec59 MS |
8977 | catch_fork_command_1 (char *arg, int from_tty, |
8978 | struct cmd_list_element *command) | |
c906108c | 8979 | { |
a6d9a66e | 8980 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8981 | char *cond_string = NULL; |
44feb3ce TT |
8982 | catch_fork_kind fork_kind; |
8983 | int tempflag; | |
8984 | ||
8985 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8986 | tempflag = (fork_kind == catch_fork_temporary | |
8987 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8988 | |
44feb3ce TT |
8989 | if (!arg) |
8990 | arg = ""; | |
e9cafbcc | 8991 | arg = skip_spaces (arg); |
c5aa993b | 8992 | |
c906108c | 8993 | /* The allowed syntax is: |
c5aa993b JM |
8994 | catch [v]fork |
8995 | catch [v]fork if <cond> | |
8996 | ||
4a64f543 | 8997 | First, check if there's an if clause. */ |
c906108c | 8998 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 8999 | |
c906108c | 9000 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9001 | error (_("Junk at end of arguments.")); |
c5aa993b | 9002 | |
c906108c | 9003 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9004 | and enable reporting of such events. */ |
c5aa993b JM |
9005 | switch (fork_kind) |
9006 | { | |
44feb3ce TT |
9007 | case catch_fork_temporary: |
9008 | case catch_fork_permanent: | |
a6d9a66e | 9009 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9010 | &catch_fork_breakpoint_ops); |
c906108c | 9011 | break; |
44feb3ce TT |
9012 | case catch_vfork_temporary: |
9013 | case catch_vfork_permanent: | |
a6d9a66e | 9014 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9015 | &catch_vfork_breakpoint_ops); |
c906108c | 9016 | break; |
c5aa993b | 9017 | default: |
8a3fe4f8 | 9018 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9019 | break; |
c5aa993b | 9020 | } |
c906108c SS |
9021 | } |
9022 | ||
9023 | static void | |
cc59ec59 MS |
9024 | catch_exec_command_1 (char *arg, int from_tty, |
9025 | struct cmd_list_element *command) | |
c906108c | 9026 | { |
a6d9a66e | 9027 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9028 | int tempflag; |
c5aa993b | 9029 | char *cond_string = NULL; |
c906108c | 9030 | |
44feb3ce TT |
9031 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9032 | ||
9033 | if (!arg) | |
9034 | arg = ""; | |
e9cafbcc | 9035 | arg = skip_spaces (arg); |
c906108c SS |
9036 | |
9037 | /* The allowed syntax is: | |
c5aa993b JM |
9038 | catch exec |
9039 | catch exec if <cond> | |
c906108c | 9040 | |
4a64f543 | 9041 | First, check if there's an if clause. */ |
c906108c SS |
9042 | cond_string = ep_parse_optional_if_clause (&arg); |
9043 | ||
9044 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9045 | error (_("Junk at end of arguments.")); |
c906108c SS |
9046 | |
9047 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 9048 | and enable reporting of such events. */ |
a6d9a66e UW |
9049 | create_catchpoint (gdbarch, tempflag, cond_string, |
9050 | &catch_exec_breakpoint_ops); | |
c906108c | 9051 | } |
c5aa993b | 9052 | |
3086aeae DJ |
9053 | static enum print_stop_action |
9054 | print_exception_catchpoint (struct breakpoint *b) | |
9055 | { | |
ade92717 | 9056 | int bp_temp, bp_throw; |
3086aeae | 9057 | |
ade92717 | 9058 | annotate_catchpoint (b->number); |
3086aeae | 9059 | |
ade92717 AR |
9060 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9061 | if (b->loc->address != b->loc->requested_address) | |
9062 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9063 | b->loc->address, | |
9064 | b->number, 1); | |
df2b6d2d | 9065 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9066 | ui_out_text (uiout, |
9067 | bp_temp ? "Temporary catchpoint " | |
9068 | : "Catchpoint "); | |
9069 | if (!ui_out_is_mi_like_p (uiout)) | |
9070 | ui_out_field_int (uiout, "bkptno", b->number); | |
9071 | ui_out_text (uiout, | |
c0b37c48 AR |
9072 | bp_throw ? " (exception thrown), " |
9073 | : " (exception caught), "); | |
ade92717 AR |
9074 | if (ui_out_is_mi_like_p (uiout)) |
9075 | { | |
9076 | ui_out_field_string (uiout, "reason", | |
9077 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9078 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9079 | ui_out_field_int (uiout, "bkptno", b->number); | |
9080 | } | |
3086aeae DJ |
9081 | return PRINT_SRC_AND_LOC; |
9082 | } | |
9083 | ||
9084 | static void | |
cc59ec59 MS |
9085 | print_one_exception_catchpoint (struct breakpoint *b, |
9086 | struct bp_location **last_loc) | |
3086aeae | 9087 | { |
79a45b7d | 9088 | struct value_print_options opts; |
cc59ec59 | 9089 | |
79a45b7d TT |
9090 | get_user_print_options (&opts); |
9091 | if (opts.addressprint) | |
3086aeae DJ |
9092 | { |
9093 | annotate_field (4); | |
604133b5 AR |
9094 | if (b->loc == NULL || b->loc->shlib_disabled) |
9095 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9096 | else | |
5af949e3 UW |
9097 | ui_out_field_core_addr (uiout, "addr", |
9098 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9099 | } |
9100 | annotate_field (5); | |
604133b5 | 9101 | if (b->loc) |
a6d9a66e | 9102 | *last_loc = b->loc; |
3086aeae DJ |
9103 | if (strstr (b->addr_string, "throw") != NULL) |
9104 | ui_out_field_string (uiout, "what", "exception throw"); | |
9105 | else | |
9106 | ui_out_field_string (uiout, "what", "exception catch"); | |
9107 | } | |
9108 | ||
9109 | static void | |
9110 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9111 | { | |
ade92717 AR |
9112 | int bp_temp; |
9113 | int bp_throw; | |
9114 | ||
df2b6d2d | 9115 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9116 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9117 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9118 | : _("Catchpoint ")); | |
9119 | ui_out_field_int (uiout, "bkptno", b->number); | |
9120 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9121 | : _(" (catch)")); | |
3086aeae DJ |
9122 | } |
9123 | ||
6149aea9 PA |
9124 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9125 | catch catchpoints. */ | |
9126 | ||
9127 | static void | |
4a64f543 MS |
9128 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9129 | struct ui_file *fp) | |
6149aea9 PA |
9130 | { |
9131 | int bp_temp; | |
9132 | int bp_throw; | |
9133 | ||
9134 | bp_temp = b->disposition == disp_del; | |
9135 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9136 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9137 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9138 | } | |
9139 | ||
3086aeae | 9140 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
9141 | NULL, /* insert */ |
9142 | NULL, /* remove */ | |
9143 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9144 | NULL, /* resources_needed */ |
3086aeae DJ |
9145 | print_exception_catchpoint, |
9146 | print_one_exception_catchpoint, | |
6149aea9 PA |
9147 | print_mention_exception_catchpoint, |
9148 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9149 | }; |
9150 | ||
9151 | static int | |
9152 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9153 | enum exception_event_kind ex_event, int from_tty) | |
9154 | { | |
604133b5 AR |
9155 | char *trigger_func_name; |
9156 | ||
3086aeae | 9157 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9158 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9159 | else |
604133b5 | 9160 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9161 | |
8cdf0e15 VP |
9162 | create_breakpoint (get_current_arch (), |
9163 | trigger_func_name, cond_string, -1, | |
9164 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9165 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9166 | 0, |
9167 | AUTO_BOOLEAN_TRUE /* pending */, | |
9168 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9169 | 1 /* enabled */, |
9170 | 0 /* internal */); | |
3086aeae | 9171 | |
3086aeae DJ |
9172 | return 1; |
9173 | } | |
9174 | ||
4a64f543 | 9175 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9176 | |
9177 | static void | |
fba45db2 KB |
9178 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9179 | int tempflag, int from_tty) | |
c906108c | 9180 | { |
c5aa993b | 9181 | char *cond_string = NULL; |
c5aa993b | 9182 | |
44feb3ce TT |
9183 | if (!arg) |
9184 | arg = ""; | |
e9cafbcc | 9185 | arg = skip_spaces (arg); |
c5aa993b | 9186 | |
c906108c SS |
9187 | cond_string = ep_parse_optional_if_clause (&arg); |
9188 | ||
9189 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9190 | error (_("Junk at end of arguments.")); |
c906108c | 9191 | |
059fb39f PM |
9192 | if (ex_event != EX_EVENT_THROW |
9193 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9194 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9195 | |
3086aeae DJ |
9196 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9197 | return; | |
9198 | ||
8a3fe4f8 | 9199 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9200 | } |
9201 | ||
44feb3ce TT |
9202 | /* Implementation of "catch catch" command. */ |
9203 | ||
9204 | static void | |
9205 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9206 | { | |
9207 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9208 | |
44feb3ce TT |
9209 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9210 | } | |
9211 | ||
9212 | /* Implementation of "catch throw" command. */ | |
9213 | ||
9214 | static void | |
9215 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9216 | { | |
9217 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9218 | |
44feb3ce TT |
9219 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9220 | } | |
9221 | ||
f7f9143b JB |
9222 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
9223 | ||
9224 | static void | |
a6d9a66e UW |
9225 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
9226 | struct symtab_and_line sal, | |
f7f9143b JB |
9227 | char *addr_string, |
9228 | char *exp_string, | |
9229 | char *cond_string, | |
9230 | struct expression *cond, | |
9231 | struct breakpoint_ops *ops, | |
9232 | int tempflag, | |
9233 | int from_tty) | |
9234 | { | |
9235 | struct breakpoint *b; | |
9236 | ||
9237 | if (from_tty) | |
9238 | { | |
5af949e3 UW |
9239 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9240 | if (!loc_gdbarch) | |
9241 | loc_gdbarch = gdbarch; | |
9242 | ||
6c95b8df PA |
9243 | describe_other_breakpoints (loc_gdbarch, |
9244 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9245 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9246 | version for exception catchpoints, because two catchpoints | |
9247 | used for different exception names will use the same address. | |
9248 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9249 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
9250 | inapropriate, we should use the word catchpoint, and tell |
9251 | the user what type of catchpoint it is. The above is good | |
9252 | enough for now, though. */ | |
9253 | } | |
9254 | ||
a6d9a66e | 9255 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
9256 | set_breakpoint_count (breakpoint_count + 1); |
9257 | ||
9258 | b->enable_state = bp_enabled; | |
9259 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
9260 | b->number = breakpoint_count; | |
9261 | b->ignore_count = 0; | |
511a6cd4 | 9262 | b->loc->cond = cond; |
f7f9143b JB |
9263 | b->addr_string = addr_string; |
9264 | b->language = language_ada; | |
9265 | b->cond_string = cond_string; | |
9266 | b->exp_string = exp_string; | |
9267 | b->thread = -1; | |
9268 | b->ops = ops; | |
f7f9143b JB |
9269 | |
9270 | mention (b); | |
b60e7edf | 9271 | update_global_location_list (1); |
f7f9143b JB |
9272 | } |
9273 | ||
9274 | /* Implement the "catch exception" command. */ | |
9275 | ||
9276 | static void | |
44feb3ce TT |
9277 | catch_ada_exception_command (char *arg, int from_tty, |
9278 | struct cmd_list_element *command) | |
f7f9143b | 9279 | { |
a6d9a66e | 9280 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9281 | int tempflag; |
f7f9143b | 9282 | struct symtab_and_line sal; |
f7f9143b JB |
9283 | char *addr_string = NULL; |
9284 | char *exp_string = NULL; | |
9285 | char *cond_string = NULL; | |
9286 | struct expression *cond = NULL; | |
9287 | struct breakpoint_ops *ops = NULL; | |
9288 | ||
44feb3ce TT |
9289 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9290 | ||
9291 | if (!arg) | |
9292 | arg = ""; | |
f7f9143b JB |
9293 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
9294 | &cond_string, &cond, &ops); | |
a6d9a66e | 9295 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
9296 | cond_string, cond, ops, tempflag, |
9297 | from_tty); | |
9298 | } | |
9299 | ||
a96d9b2e SDJ |
9300 | /* Cleanup function for a syscall filter list. */ |
9301 | static void | |
9302 | clean_up_filters (void *arg) | |
9303 | { | |
9304 | VEC(int) *iter = *(VEC(int) **) arg; | |
9305 | VEC_free (int, iter); | |
9306 | } | |
9307 | ||
9308 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9309 | filter list, or NULL if no filtering is required. */ | |
9310 | static VEC(int) * | |
9311 | catch_syscall_split_args (char *arg) | |
9312 | { | |
9313 | VEC(int) *result = NULL; | |
9314 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9315 | ||
9316 | while (*arg != '\0') | |
9317 | { | |
9318 | int i, syscall_number; | |
9319 | char *endptr; | |
9320 | char cur_name[128]; | |
9321 | struct syscall s; | |
9322 | ||
9323 | /* Skip whitespace. */ | |
9324 | while (isspace (*arg)) | |
9325 | arg++; | |
9326 | ||
9327 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9328 | cur_name[i] = arg[i]; | |
9329 | cur_name[i] = '\0'; | |
9330 | arg += i; | |
9331 | ||
9332 | /* Check if the user provided a syscall name or a number. */ | |
9333 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9334 | if (*endptr == '\0') | |
bccd0dd2 | 9335 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9336 | else |
9337 | { | |
9338 | /* We have a name. Let's check if it's valid and convert it | |
9339 | to a number. */ | |
9340 | get_syscall_by_name (cur_name, &s); | |
9341 | ||
9342 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9343 | /* Here we have to issue an error instead of a warning, |
9344 | because GDB cannot do anything useful if there's no | |
9345 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9346 | error (_("Unknown syscall name '%s'."), cur_name); |
9347 | } | |
9348 | ||
9349 | /* Ok, it's valid. */ | |
9350 | VEC_safe_push (int, result, s.number); | |
9351 | } | |
9352 | ||
9353 | discard_cleanups (cleanup); | |
9354 | return result; | |
9355 | } | |
9356 | ||
9357 | /* Implement the "catch syscall" command. */ | |
9358 | ||
9359 | static void | |
cc59ec59 MS |
9360 | catch_syscall_command_1 (char *arg, int from_tty, |
9361 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9362 | { |
9363 | int tempflag; | |
9364 | VEC(int) *filter; | |
9365 | struct syscall s; | |
9366 | struct gdbarch *gdbarch = get_current_arch (); | |
9367 | ||
9368 | /* Checking if the feature if supported. */ | |
9369 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
9370 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 9371 | this architecture yet.")); |
a96d9b2e SDJ |
9372 | |
9373 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
9374 | ||
e9cafbcc | 9375 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
9376 | |
9377 | /* We need to do this first "dummy" translation in order | |
9378 | to get the syscall XML file loaded or, most important, | |
9379 | to display a warning to the user if there's no XML file | |
9380 | for his/her architecture. */ | |
9381 | get_syscall_by_number (0, &s); | |
9382 | ||
9383 | /* The allowed syntax is: | |
9384 | catch syscall | |
9385 | catch syscall <name | number> [<name | number> ... <name | number>] | |
9386 | ||
9387 | Let's check if there's a syscall name. */ | |
9388 | ||
9389 | if (arg != NULL) | |
9390 | filter = catch_syscall_split_args (arg); | |
9391 | else | |
9392 | filter = NULL; | |
9393 | ||
9394 | create_syscall_event_catchpoint (tempflag, filter, | |
9395 | &catch_syscall_breakpoint_ops); | |
9396 | } | |
9397 | ||
f7f9143b JB |
9398 | /* Implement the "catch assert" command. */ |
9399 | ||
9400 | static void | |
3e43a32a MS |
9401 | catch_assert_command (char *arg, int from_tty, |
9402 | struct cmd_list_element *command) | |
f7f9143b | 9403 | { |
a6d9a66e | 9404 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9405 | int tempflag; |
f7f9143b JB |
9406 | struct symtab_and_line sal; |
9407 | char *addr_string = NULL; | |
9408 | struct breakpoint_ops *ops = NULL; | |
9409 | ||
44feb3ce TT |
9410 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9411 | ||
9412 | if (!arg) | |
9413 | arg = ""; | |
f7f9143b | 9414 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
9415 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
9416 | ops, tempflag, from_tty); | |
f7f9143b JB |
9417 | } |
9418 | ||
c906108c | 9419 | static void |
fba45db2 | 9420 | catch_command (char *arg, int from_tty) |
c906108c | 9421 | { |
44feb3ce | 9422 | error (_("Catch requires an event name.")); |
c906108c SS |
9423 | } |
9424 | \f | |
9425 | ||
9426 | static void | |
fba45db2 | 9427 | tcatch_command (char *arg, int from_tty) |
c906108c | 9428 | { |
44feb3ce | 9429 | error (_("Catch requires an event name.")); |
c906108c SS |
9430 | } |
9431 | ||
80f8a6eb | 9432 | /* Delete breakpoints by address or line. */ |
c906108c SS |
9433 | |
9434 | static void | |
fba45db2 | 9435 | clear_command (char *arg, int from_tty) |
c906108c | 9436 | { |
d6e956e5 VP |
9437 | struct breakpoint *b; |
9438 | VEC(breakpoint_p) *found = 0; | |
9439 | int ix; | |
c906108c SS |
9440 | int default_match; |
9441 | struct symtabs_and_lines sals; | |
9442 | struct symtab_and_line sal; | |
c906108c SS |
9443 | int i; |
9444 | ||
9445 | if (arg) | |
9446 | { | |
9447 | sals = decode_line_spec (arg, 1); | |
9448 | default_match = 0; | |
9449 | } | |
9450 | else | |
9451 | { | |
c5aa993b | 9452 | sals.sals = (struct symtab_and_line *) |
c906108c | 9453 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 9454 | make_cleanup (xfree, sals.sals); |
4a64f543 | 9455 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
9456 | sal.line = default_breakpoint_line; |
9457 | sal.symtab = default_breakpoint_symtab; | |
9458 | sal.pc = default_breakpoint_address; | |
6c95b8df | 9459 | sal.pspace = default_breakpoint_pspace; |
c906108c | 9460 | if (sal.symtab == 0) |
8a3fe4f8 | 9461 | error (_("No source file specified.")); |
c906108c SS |
9462 | |
9463 | sals.sals[0] = sal; | |
9464 | sals.nelts = 1; | |
9465 | ||
9466 | default_match = 1; | |
9467 | } | |
9468 | ||
4a64f543 MS |
9469 | /* We don't call resolve_sal_pc here. That's not as bad as it |
9470 | seems, because all existing breakpoints typically have both | |
9471 | file/line and pc set. So, if clear is given file/line, we can | |
9472 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
9473 | |
9474 | We only support clearing given the address explicitly | |
9475 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 9476 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 9477 | due to optimization, all in one block. |
4a64f543 MS |
9478 | |
9479 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
9480 | PC corresponding to the same file:line, the breakpoint won't |
9481 | be cleared. We probably can still clear the breakpoint, but | |
9482 | since the other PC value is never presented to user, user | |
9483 | can only find it by guessing, and it does not seem important | |
9484 | to support that. */ | |
9485 | ||
4a64f543 MS |
9486 | /* For each line spec given, delete bps which correspond to it. Do |
9487 | it in two passes, solely to preserve the current behavior that | |
9488 | from_tty is forced true if we delete more than one | |
9489 | breakpoint. */ | |
c906108c | 9490 | |
80f8a6eb | 9491 | found = NULL; |
c906108c SS |
9492 | for (i = 0; i < sals.nelts; i++) |
9493 | { | |
9494 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
9495 | If line given (pc == 0), clear all bpts on specified line. |
9496 | If defaulting, clear all bpts on default line | |
c906108c | 9497 | or at default pc. |
c5aa993b JM |
9498 | |
9499 | defaulting sal.pc != 0 tests to do | |
9500 | ||
9501 | 0 1 pc | |
9502 | 1 1 pc _and_ line | |
9503 | 0 0 line | |
9504 | 1 0 <can't happen> */ | |
c906108c SS |
9505 | |
9506 | sal = sals.sals[i]; | |
c906108c | 9507 | |
4a64f543 | 9508 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 9509 | ALL_BREAKPOINTS (b) |
c5aa993b | 9510 | { |
0d381245 | 9511 | int match = 0; |
4a64f543 | 9512 | /* Are we going to delete b? */ |
cc60f2e3 | 9513 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
9514 | { |
9515 | struct bp_location *loc = b->loc; | |
9516 | for (; loc; loc = loc->next) | |
9517 | { | |
6c95b8df PA |
9518 | int pc_match = sal.pc |
9519 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
9520 | && (loc->address == sal.pc) |
9521 | && (!section_is_overlay (loc->section) | |
9522 | || loc->section == sal.section); | |
9523 | int line_match = ((default_match || (0 == sal.pc)) | |
9524 | && b->source_file != NULL | |
9525 | && sal.symtab != NULL | |
6c95b8df | 9526 | && sal.pspace == loc->pspace |
3e43a32a MS |
9527 | && strcmp (b->source_file, |
9528 | sal.symtab->filename) == 0 | |
0d381245 VP |
9529 | && b->line_number == sal.line); |
9530 | if (pc_match || line_match) | |
9531 | { | |
9532 | match = 1; | |
9533 | break; | |
9534 | } | |
9535 | } | |
9536 | } | |
9537 | ||
9538 | if (match) | |
d6e956e5 | 9539 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 9540 | } |
80f8a6eb MS |
9541 | } |
9542 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 9543 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
9544 | { |
9545 | if (arg) | |
8a3fe4f8 | 9546 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 9547 | else |
8a3fe4f8 | 9548 | error (_("No breakpoint at this line.")); |
80f8a6eb | 9549 | } |
c906108c | 9550 | |
d6e956e5 | 9551 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 9552 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 9553 | if (from_tty) |
a3f17187 | 9554 | { |
d6e956e5 | 9555 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
9556 | printf_unfiltered (_("Deleted breakpoint ")); |
9557 | else | |
9558 | printf_unfiltered (_("Deleted breakpoints ")); | |
9559 | } | |
80f8a6eb | 9560 | breakpoints_changed (); |
d6e956e5 VP |
9561 | |
9562 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 9563 | { |
c5aa993b | 9564 | if (from_tty) |
d6e956e5 VP |
9565 | printf_unfiltered ("%d ", b->number); |
9566 | delete_breakpoint (b); | |
c906108c | 9567 | } |
80f8a6eb MS |
9568 | if (from_tty) |
9569 | putchar_unfiltered ('\n'); | |
c906108c SS |
9570 | } |
9571 | \f | |
9572 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
9573 | all breakpoints that are marked for deletion, whether hit or not. | |
9574 | This is called after any breakpoint is hit, or after errors. */ | |
9575 | ||
9576 | void | |
fba45db2 | 9577 | breakpoint_auto_delete (bpstat bs) |
c906108c | 9578 | { |
35df4500 | 9579 | struct breakpoint *b, *b_tmp; |
c906108c SS |
9580 | |
9581 | for (; bs; bs = bs->next) | |
f431efe5 PA |
9582 | if (bs->breakpoint_at |
9583 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 9584 | && bs->stop) |
f431efe5 | 9585 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 9586 | |
35df4500 | 9587 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 9588 | { |
b5de0fa7 | 9589 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
9590 | delete_breakpoint (b); |
9591 | } | |
c906108c SS |
9592 | } |
9593 | ||
4a64f543 MS |
9594 | /* A comparison function for bp_location AP and BP being interfaced to |
9595 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
9596 | does breakpoint_address_is_meaningful say for its OWNER), | |
9597 | secondarily by ordering first bp_permanent OWNERed elements and | |
9598 | terciarily just ensuring the array is sorted stable way despite | |
9599 | qsort being an instable algorithm. */ | |
876fa593 JK |
9600 | |
9601 | static int | |
494cfb0f | 9602 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 9603 | { |
494cfb0f JK |
9604 | struct bp_location *a = *(void **) ap; |
9605 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 9606 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
9607 | int a_perm = a->owner->enable_state == bp_permanent; |
9608 | int b_perm = b->owner->enable_state == bp_permanent; | |
9609 | ||
9610 | if (a->address != b->address) | |
9611 | return (a->address > b->address) - (a->address < b->address); | |
9612 | ||
9613 | /* Sort permanent breakpoints first. */ | |
9614 | if (a_perm != b_perm) | |
9615 | return (a_perm < b_perm) - (a_perm > b_perm); | |
9616 | ||
4a64f543 MS |
9617 | /* Make the user-visible order stable across GDB runs. Locations of |
9618 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
9619 | |
9620 | if (a->owner->number != b->owner->number) | |
9621 | return (a->owner->number > b->owner->number) | |
9622 | - (a->owner->number < b->owner->number); | |
9623 | ||
9624 | return (a > b) - (a < b); | |
9625 | } | |
9626 | ||
876fa593 | 9627 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
9628 | bp_location_shadow_len_after_address_max according to the current |
9629 | content of the bp_location array. */ | |
f7545552 TT |
9630 | |
9631 | static void | |
876fa593 | 9632 | bp_location_target_extensions_update (void) |
f7545552 | 9633 | { |
876fa593 JK |
9634 | struct bp_location *bl, **blp_tmp; |
9635 | ||
9636 | bp_location_placed_address_before_address_max = 0; | |
9637 | bp_location_shadow_len_after_address_max = 0; | |
9638 | ||
9639 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
9640 | { | |
9641 | CORE_ADDR start, end, addr; | |
9642 | ||
9643 | if (!bp_location_has_shadow (bl)) | |
9644 | continue; | |
9645 | ||
9646 | start = bl->target_info.placed_address; | |
9647 | end = start + bl->target_info.shadow_len; | |
9648 | ||
9649 | gdb_assert (bl->address >= start); | |
9650 | addr = bl->address - start; | |
9651 | if (addr > bp_location_placed_address_before_address_max) | |
9652 | bp_location_placed_address_before_address_max = addr; | |
9653 | ||
9654 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
9655 | ||
9656 | gdb_assert (bl->address < end); | |
9657 | addr = end - bl->address; | |
9658 | if (addr > bp_location_shadow_len_after_address_max) | |
9659 | bp_location_shadow_len_after_address_max = addr; | |
9660 | } | |
f7545552 TT |
9661 | } |
9662 | ||
4cd9bd08 | 9663 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
9664 | into the inferior, only remove already-inserted locations that no |
9665 | longer should be inserted. Functions that delete a breakpoint or | |
9666 | breakpoints should pass false, so that deleting a breakpoint | |
9667 | doesn't have the side effect of inserting the locations of other | |
9668 | breakpoints that are marked not-inserted, but should_be_inserted | |
9669 | returns true on them. | |
9670 | ||
9671 | This behaviour is useful is situations close to tear-down -- e.g., | |
9672 | after an exec, while the target still has execution, but breakpoint | |
9673 | shadows of the previous executable image should *NOT* be restored | |
9674 | to the new image; or before detaching, where the target still has | |
9675 | execution and wants to delete breakpoints from GDB's lists, and all | |
9676 | breakpoints had already been removed from the inferior. */ | |
9677 | ||
0d381245 | 9678 | static void |
b60e7edf | 9679 | update_global_location_list (int should_insert) |
0d381245 | 9680 | { |
74960c60 | 9681 | struct breakpoint *b; |
876fa593 | 9682 | struct bp_location **locp, *loc; |
f7545552 TT |
9683 | struct cleanup *cleanups; |
9684 | ||
2d134ed3 PA |
9685 | /* Used in the duplicates detection below. When iterating over all |
9686 | bp_locations, points to the first bp_location of a given address. | |
9687 | Breakpoints and watchpoints of different types are never | |
9688 | duplicates of each other. Keep one pointer for each type of | |
9689 | breakpoint/watchpoint, so we only need to loop over all locations | |
9690 | once. */ | |
9691 | struct bp_location *bp_loc_first; /* breakpoint */ | |
9692 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
9693 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
9694 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 9695 | |
4a64f543 MS |
9696 | /* Saved former bp_location array which we compare against the newly |
9697 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
9698 | struct bp_location **old_location, **old_locp; |
9699 | unsigned old_location_count; | |
9700 | ||
9701 | old_location = bp_location; | |
9702 | old_location_count = bp_location_count; | |
9703 | bp_location = NULL; | |
9704 | bp_location_count = 0; | |
9705 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 9706 | |
74960c60 | 9707 | ALL_BREAKPOINTS (b) |
876fa593 JK |
9708 | for (loc = b->loc; loc; loc = loc->next) |
9709 | bp_location_count++; | |
9710 | ||
9711 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
9712 | locp = bp_location; | |
9713 | ALL_BREAKPOINTS (b) | |
9714 | for (loc = b->loc; loc; loc = loc->next) | |
9715 | *locp++ = loc; | |
9716 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 9717 | bp_location_compare); |
876fa593 JK |
9718 | |
9719 | bp_location_target_extensions_update (); | |
74960c60 | 9720 | |
4a64f543 MS |
9721 | /* Identify bp_location instances that are no longer present in the |
9722 | new list, and therefore should be freed. Note that it's not | |
9723 | necessary that those locations should be removed from inferior -- | |
9724 | if there's another location at the same address (previously | |
9725 | marked as duplicate), we don't need to remove/insert the | |
9726 | location. | |
876fa593 | 9727 | |
4a64f543 MS |
9728 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
9729 | and former bp_location array state respectively. */ | |
876fa593 JK |
9730 | |
9731 | locp = bp_location; | |
9732 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
9733 | old_locp++) | |
74960c60 | 9734 | { |
876fa593 | 9735 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 9736 | struct bp_location **loc2p; |
876fa593 | 9737 | |
4a64f543 MS |
9738 | /* Tells if 'old_loc' is found amoung the new locations. If |
9739 | not, we have to free it. */ | |
c7d46a38 | 9740 | int found_object = 0; |
20874c92 VP |
9741 | /* Tells if the location should remain inserted in the target. */ |
9742 | int keep_in_target = 0; | |
9743 | int removed = 0; | |
876fa593 | 9744 | |
4a64f543 MS |
9745 | /* Skip LOCP entries which will definitely never be needed. |
9746 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 9747 | while (locp < bp_location + bp_location_count |
c7d46a38 | 9748 | && (*locp)->address < old_loc->address) |
876fa593 | 9749 | locp++; |
c7d46a38 PA |
9750 | |
9751 | for (loc2p = locp; | |
9752 | (loc2p < bp_location + bp_location_count | |
9753 | && (*loc2p)->address == old_loc->address); | |
9754 | loc2p++) | |
9755 | { | |
9756 | if (*loc2p == old_loc) | |
9757 | { | |
9758 | found_object = 1; | |
9759 | break; | |
9760 | } | |
9761 | } | |
74960c60 | 9762 | |
4a64f543 MS |
9763 | /* If this location is no longer present, and inserted, look if |
9764 | there's maybe a new location at the same address. If so, | |
9765 | mark that one inserted, and don't remove this one. This is | |
9766 | needed so that we don't have a time window where a breakpoint | |
9767 | at certain location is not inserted. */ | |
74960c60 | 9768 | |
876fa593 | 9769 | if (old_loc->inserted) |
0d381245 | 9770 | { |
4a64f543 MS |
9771 | /* If the location is inserted now, we might have to remove |
9772 | it. */ | |
74960c60 | 9773 | |
876fa593 | 9774 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 9775 | { |
4a64f543 MS |
9776 | /* The location is still present in the location list, |
9777 | and still should be inserted. Don't do anything. */ | |
20874c92 | 9778 | keep_in_target = 1; |
74960c60 VP |
9779 | } |
9780 | else | |
9781 | { | |
4a64f543 MS |
9782 | /* The location is either no longer present, or got |
9783 | disabled. See if there's another location at the | |
9784 | same address, in which case we don't need to remove | |
9785 | this one from the target. */ | |
876fa593 | 9786 | |
2bdf28a0 | 9787 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
9788 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
9789 | { | |
876fa593 | 9790 | for (loc2p = locp; |
c7d46a38 PA |
9791 | (loc2p < bp_location + bp_location_count |
9792 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
9793 | loc2p++) |
9794 | { | |
9795 | struct bp_location *loc2 = *loc2p; | |
9796 | ||
2d134ed3 | 9797 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
9798 | { |
9799 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
9800 | Duplicates check below will fix up this |
9801 | later. */ | |
c7d46a38 | 9802 | loc2->duplicate = 0; |
85d721b8 PA |
9803 | |
9804 | /* Read watchpoint locations are switched to | |
9805 | access watchpoints, if the former are not | |
9806 | supported, but the latter are. */ | |
9807 | if (is_hardware_watchpoint (old_loc->owner)) | |
9808 | { | |
9809 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
9810 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
9811 | } | |
9812 | ||
c7d46a38 PA |
9813 | if (loc2 != old_loc && should_be_inserted (loc2)) |
9814 | { | |
9815 | loc2->inserted = 1; | |
9816 | loc2->target_info = old_loc->target_info; | |
9817 | keep_in_target = 1; | |
9818 | break; | |
9819 | } | |
876fa593 JK |
9820 | } |
9821 | } | |
9822 | } | |
74960c60 VP |
9823 | } |
9824 | ||
20874c92 VP |
9825 | if (!keep_in_target) |
9826 | { | |
876fa593 | 9827 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 9828 | { |
4a64f543 MS |
9829 | /* This is just about all we can do. We could keep |
9830 | this location on the global list, and try to | |
9831 | remove it next time, but there's no particular | |
9832 | reason why we will succeed next time. | |
20874c92 | 9833 | |
4a64f543 MS |
9834 | Note that at this point, old_loc->owner is still |
9835 | valid, as delete_breakpoint frees the breakpoint | |
9836 | only after calling us. */ | |
3e43a32a MS |
9837 | printf_filtered (_("warning: Error removing " |
9838 | "breakpoint %d\n"), | |
876fa593 | 9839 | old_loc->owner->number); |
20874c92 VP |
9840 | } |
9841 | removed = 1; | |
9842 | } | |
0d381245 | 9843 | } |
74960c60 VP |
9844 | |
9845 | if (!found_object) | |
1c5cfe86 | 9846 | { |
db82e815 PA |
9847 | if (removed && non_stop |
9848 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9849 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9850 | { |
db82e815 PA |
9851 | /* This location was removed from the target. In |
9852 | non-stop mode, a race condition is possible where | |
9853 | we've removed a breakpoint, but stop events for that | |
9854 | breakpoint are already queued and will arrive later. | |
9855 | We apply an heuristic to be able to distinguish such | |
9856 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9857 | breakpoint location for a bit, and will retire it | |
9858 | after we see some number of events. The theory here | |
9859 | is that reporting of events should, "on the average", | |
9860 | be fair, so after a while we'll see events from all | |
9861 | threads that have anything of interest, and no longer | |
9862 | need to keep this breakpoint location around. We | |
9863 | don't hold locations forever so to reduce chances of | |
9864 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9865 | SIGTRAP. | |
9866 | ||
9867 | The heuristic failing can be disastrous on | |
9868 | decr_pc_after_break targets. | |
9869 | ||
9870 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9871 | if we fail to recognize a late breakpoint SIGTRAP, | |
9872 | because events_till_retirement has reached 0 too | |
9873 | soon, we'll fail to do the PC adjustment, and report | |
9874 | a random SIGTRAP to the user. When the user resumes | |
9875 | the inferior, it will most likely immediately crash | |
2dec564e | 9876 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
9877 | corrupted, because of being resumed e.g., in the |
9878 | middle of a multi-byte instruction, or skipped a | |
9879 | one-byte instruction. This was actually seen happen | |
9880 | on native x86-linux, and should be less rare on | |
9881 | targets that do not support new thread events, like | |
9882 | remote, due to the heuristic depending on | |
9883 | thread_count. | |
9884 | ||
9885 | Mistaking a random SIGTRAP for a breakpoint trap | |
9886 | causes similar symptoms (PC adjustment applied when | |
9887 | it shouldn't), but then again, playing with SIGTRAPs | |
9888 | behind the debugger's back is asking for trouble. | |
9889 | ||
9890 | Since hardware watchpoint traps are always | |
9891 | distinguishable from other traps, so we don't need to | |
9892 | apply keep hardware watchpoint moribund locations | |
9893 | around. We simply always ignore hardware watchpoint | |
9894 | traps we can no longer explain. */ | |
9895 | ||
876fa593 JK |
9896 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9897 | old_loc->owner = NULL; | |
20874c92 | 9898 | |
876fa593 | 9899 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9900 | } |
9901 | else | |
f431efe5 PA |
9902 | { |
9903 | old_loc->owner = NULL; | |
9904 | decref_bp_location (&old_loc); | |
9905 | } | |
20874c92 | 9906 | } |
74960c60 | 9907 | } |
1c5cfe86 | 9908 | |
2d134ed3 PA |
9909 | /* Rescan breakpoints at the same address and section, marking the |
9910 | first one as "first" and any others as "duplicates". This is so | |
9911 | that the bpt instruction is only inserted once. If we have a | |
9912 | permanent breakpoint at the same place as BPT, make that one the | |
9913 | official one, and the rest as duplicates. Permanent breakpoints | |
9914 | are sorted first for the same address. | |
9915 | ||
9916 | Do the same for hardware watchpoints, but also considering the | |
9917 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9918 | |
2d134ed3 PA |
9919 | bp_loc_first = NULL; |
9920 | wp_loc_first = NULL; | |
9921 | awp_loc_first = NULL; | |
9922 | rwp_loc_first = NULL; | |
876fa593 | 9923 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9924 | { |
4a64f543 MS |
9925 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
9926 | non-NULL. */ | |
876fa593 | 9927 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9928 | struct bp_location **loc_first_p; |
876fa593 JK |
9929 | |
9930 | if (b->enable_state == bp_disabled | |
9931 | || b->enable_state == bp_call_disabled | |
9932 | || b->enable_state == bp_startup_disabled | |
9933 | || !loc->enabled | |
9934 | || loc->shlib_disabled | |
15c3d785 | 9935 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9936 | || is_tracepoint (b)) |
876fa593 JK |
9937 | continue; |
9938 | ||
9939 | /* Permanent breakpoint should always be inserted. */ | |
9940 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9941 | internal_error (__FILE__, __LINE__, | |
9942 | _("allegedly permanent breakpoint is not " | |
9943 | "actually inserted")); | |
9944 | ||
2d134ed3 PA |
9945 | if (b->type == bp_hardware_watchpoint) |
9946 | loc_first_p = &wp_loc_first; | |
9947 | else if (b->type == bp_read_watchpoint) | |
9948 | loc_first_p = &rwp_loc_first; | |
9949 | else if (b->type == bp_access_watchpoint) | |
9950 | loc_first_p = &awp_loc_first; | |
9951 | else | |
9952 | loc_first_p = &bp_loc_first; | |
9953 | ||
9954 | if (*loc_first_p == NULL | |
9955 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9956 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9957 | { |
2d134ed3 | 9958 | *loc_first_p = loc; |
876fa593 JK |
9959 | loc->duplicate = 0; |
9960 | continue; | |
9961 | } | |
9962 | ||
9963 | loc->duplicate = 1; | |
9964 | ||
2d134ed3 PA |
9965 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9966 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9967 | internal_error (__FILE__, __LINE__, |
9968 | _("another breakpoint was inserted on top of " | |
9969 | "a permanent breakpoint")); | |
0d381245 | 9970 | } |
74960c60 | 9971 | |
50c71eaf | 9972 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9973 | && (have_live_inferiors () |
2567c7d9 | 9974 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9975 | insert_breakpoint_locations (); |
f7545552 TT |
9976 | |
9977 | do_cleanups (cleanups); | |
74960c60 VP |
9978 | } |
9979 | ||
20874c92 VP |
9980 | void |
9981 | breakpoint_retire_moribund (void) | |
9982 | { | |
9983 | struct bp_location *loc; | |
9984 | int ix; | |
9985 | ||
9986 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9987 | if (--(loc->events_till_retirement) == 0) | |
9988 | { | |
f431efe5 | 9989 | decref_bp_location (&loc); |
20874c92 VP |
9990 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
9991 | --ix; | |
9992 | } | |
9993 | } | |
9994 | ||
74960c60 | 9995 | static void |
b60e7edf | 9996 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9997 | { |
9998 | struct gdb_exception e; | |
cc59ec59 | 9999 | |
74960c60 | 10000 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 10001 | update_global_location_list (inserting); |
0d381245 VP |
10002 | } |
10003 | ||
f431efe5 PA |
10004 | /* Clear BKP from a BPS. */ |
10005 | ||
a474d7c2 | 10006 | static void |
f431efe5 | 10007 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
10008 | { |
10009 | bpstat bs; | |
cc59ec59 | 10010 | |
a474d7c2 | 10011 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 10012 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
10013 | { |
10014 | bs->breakpoint_at = NULL; | |
10015 | bs->old_val = NULL; | |
10016 | /* bs->commands will be freed later. */ | |
10017 | } | |
10018 | } | |
10019 | ||
10020 | /* Callback for iterate_over_threads. */ | |
10021 | static int | |
f431efe5 | 10022 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 10023 | { |
f431efe5 | 10024 | struct breakpoint *bpt = data; |
cc59ec59 | 10025 | |
16c381f0 | 10026 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
10027 | return 0; |
10028 | } | |
10029 | ||
53a5351d | 10030 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 10031 | structures. */ |
c906108c SS |
10032 | |
10033 | void | |
fba45db2 | 10034 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 10035 | { |
52f0bd74 | 10036 | struct breakpoint *b; |
c906108c | 10037 | |
8a3fe4f8 | 10038 | gdb_assert (bpt != NULL); |
c906108c | 10039 | |
4a64f543 MS |
10040 | /* Has this bp already been deleted? This can happen because |
10041 | multiple lists can hold pointers to bp's. bpstat lists are | |
10042 | especial culprits. | |
10043 | ||
10044 | One example of this happening is a watchpoint's scope bp. When | |
10045 | the scope bp triggers, we notice that the watchpoint is out of | |
10046 | scope, and delete it. We also delete its scope bp. But the | |
10047 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
10048 | That bpstat is then checked for auto-deleting bp's, which are | |
10049 | deleted. | |
10050 | ||
10051 | A real solution to this problem might involve reference counts in | |
10052 | bp's, and/or giving them pointers back to their referencing | |
10053 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
10054 | storage when no more references were extent. A cheaper bandaid | |
10055 | was chosen. */ | |
c906108c SS |
10056 | if (bpt->type == bp_none) |
10057 | return; | |
10058 | ||
4a64f543 MS |
10059 | /* At least avoid this stale reference until the reference counting |
10060 | of breakpoints gets resolved. */ | |
e5a0a904 JK |
10061 | if (bpt->related_breakpoint != NULL) |
10062 | { | |
10063 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
10064 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
10065 | bpt->related_breakpoint->related_breakpoint = NULL; | |
10066 | bpt->related_breakpoint = NULL; | |
10067 | } | |
10068 | ||
383f836e | 10069 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 10070 | |
c906108c SS |
10071 | if (breakpoint_chain == bpt) |
10072 | breakpoint_chain = bpt->next; | |
10073 | ||
c906108c SS |
10074 | ALL_BREAKPOINTS (b) |
10075 | if (b->next == bpt) | |
c5aa993b JM |
10076 | { |
10077 | b->next = bpt->next; | |
10078 | break; | |
10079 | } | |
c906108c | 10080 | |
9add0f1b | 10081 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10082 | xfree (bpt->cond_string); |
10083 | xfree (bpt->cond_exp); | |
10084 | xfree (bpt->addr_string); | |
10085 | xfree (bpt->exp); | |
10086 | xfree (bpt->exp_string); | |
d63d0675 | 10087 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10088 | value_free (bpt->val); |
10089 | xfree (bpt->source_file); | |
10090 | xfree (bpt->exec_pathname); | |
a96d9b2e | 10091 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 10092 | |
f431efe5 PA |
10093 | |
10094 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10095 | been freed. */ | |
10096 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10097 | in all threeds for now. Note that we cannot just remove bpstats | |
10098 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10099 | commands are associated with the bpstat; if we remove it here, | |
10100 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10101 | event-top.c won't do anything, and temporary breakpoints with | |
10102 | commands won't work. */ | |
10103 | ||
10104 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10105 | ||
4a64f543 MS |
10106 | /* Now that breakpoint is removed from breakpoint list, update the |
10107 | global location list. This will remove locations that used to | |
10108 | belong to this breakpoint. Do this before freeing the breakpoint | |
10109 | itself, since remove_breakpoint looks at location's owner. It | |
10110 | might be better design to have location completely | |
10111 | self-contained, but it's not the case now. */ | |
b60e7edf | 10112 | update_global_location_list (0); |
74960c60 VP |
10113 | |
10114 | ||
4a64f543 MS |
10115 | /* On the chance that someone will soon try again to delete this |
10116 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10117 | bpt->type = bp_none; |
10118 | ||
b8c9b27d | 10119 | xfree (bpt); |
c906108c SS |
10120 | } |
10121 | ||
4d6140d9 AC |
10122 | static void |
10123 | do_delete_breakpoint_cleanup (void *b) | |
10124 | { | |
10125 | delete_breakpoint (b); | |
10126 | } | |
10127 | ||
10128 | struct cleanup * | |
10129 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10130 | { | |
10131 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10132 | } | |
10133 | ||
95a42b64 TT |
10134 | /* A callback for map_breakpoint_numbers that calls |
10135 | delete_breakpoint. */ | |
10136 | ||
10137 | static void | |
10138 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10139 | { | |
10140 | delete_breakpoint (b); | |
10141 | } | |
10142 | ||
c906108c | 10143 | void |
fba45db2 | 10144 | delete_command (char *arg, int from_tty) |
c906108c | 10145 | { |
35df4500 | 10146 | struct breakpoint *b, *b_tmp; |
c906108c | 10147 | |
ea9365bb TT |
10148 | dont_repeat (); |
10149 | ||
c906108c SS |
10150 | if (arg == 0) |
10151 | { | |
10152 | int breaks_to_delete = 0; | |
10153 | ||
10154 | /* Delete all breakpoints if no argument. | |
4a64f543 MS |
10155 | Do not delete internal or call-dummy breakpoints, these have |
10156 | to be deleted with an explicit breakpoint number argument. */ | |
c5aa993b JM |
10157 | ALL_BREAKPOINTS (b) |
10158 | { | |
059fb39f | 10159 | if (b->type != bp_call_dummy |
aa7d318d | 10160 | && b->type != bp_std_terminate |
059fb39f | 10161 | && b->type != bp_shlib_event |
4efc6507 | 10162 | && b->type != bp_jit_event |
059fb39f PM |
10163 | && b->type != bp_thread_event |
10164 | && b->type != bp_overlay_event | |
0fd8e87f | 10165 | && b->type != bp_longjmp_master |
aa7d318d | 10166 | && b->type != bp_std_terminate_master |
186c406b | 10167 | && b->type != bp_exception_master |
059fb39f | 10168 | && b->number >= 0) |
973d738b DJ |
10169 | { |
10170 | breaks_to_delete = 1; | |
10171 | break; | |
10172 | } | |
c5aa993b | 10173 | } |
c906108c SS |
10174 | |
10175 | /* Ask user only if there are some breakpoints to delete. */ | |
10176 | if (!from_tty | |
e2e0b3e5 | 10177 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 10178 | { |
35df4500 | 10179 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10180 | { |
059fb39f | 10181 | if (b->type != bp_call_dummy |
aa7d318d | 10182 | && b->type != bp_std_terminate |
059fb39f PM |
10183 | && b->type != bp_shlib_event |
10184 | && b->type != bp_thread_event | |
4efc6507 | 10185 | && b->type != bp_jit_event |
059fb39f | 10186 | && b->type != bp_overlay_event |
0fd8e87f | 10187 | && b->type != bp_longjmp_master |
aa7d318d | 10188 | && b->type != bp_std_terminate_master |
186c406b | 10189 | && b->type != bp_exception_master |
059fb39f | 10190 | && b->number >= 0) |
c5aa993b JM |
10191 | delete_breakpoint (b); |
10192 | } | |
c906108c SS |
10193 | } |
10194 | } | |
10195 | else | |
95a42b64 | 10196 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
10197 | } |
10198 | ||
0d381245 VP |
10199 | static int |
10200 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 10201 | { |
0d381245 VP |
10202 | for (; loc; loc = loc->next) |
10203 | if (!loc->shlib_disabled) | |
10204 | return 0; | |
10205 | return 1; | |
fe3f5fa8 VP |
10206 | } |
10207 | ||
776592bf DE |
10208 | /* Subroutine of update_breakpoint_locations to simplify it. |
10209 | Return non-zero if multiple fns in list LOC have the same name. | |
10210 | Null names are ignored. */ | |
10211 | ||
10212 | static int | |
10213 | ambiguous_names_p (struct bp_location *loc) | |
10214 | { | |
10215 | struct bp_location *l; | |
10216 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
10217 | (int (*) (const void *, |
10218 | const void *)) streq, | |
776592bf DE |
10219 | NULL, xcalloc, xfree); |
10220 | ||
10221 | for (l = loc; l != NULL; l = l->next) | |
10222 | { | |
10223 | const char **slot; | |
10224 | const char *name = l->function_name; | |
10225 | ||
10226 | /* Allow for some names to be NULL, ignore them. */ | |
10227 | if (name == NULL) | |
10228 | continue; | |
10229 | ||
10230 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
10231 | INSERT); | |
4a64f543 MS |
10232 | /* NOTE: We can assume slot != NULL here because xcalloc never |
10233 | returns NULL. */ | |
776592bf DE |
10234 | if (*slot != NULL) |
10235 | { | |
10236 | htab_delete (htab); | |
10237 | return 1; | |
10238 | } | |
10239 | *slot = name; | |
10240 | } | |
10241 | ||
10242 | htab_delete (htab); | |
10243 | return 0; | |
10244 | } | |
10245 | ||
0fb4aa4b PA |
10246 | /* When symbols change, it probably means the sources changed as well, |
10247 | and it might mean the static tracepoint markers are no longer at | |
10248 | the same address or line numbers they used to be at last we | |
10249 | checked. Losing your static tracepoints whenever you rebuild is | |
10250 | undesirable. This function tries to resync/rematch gdb static | |
10251 | tracepoints with the markers on the target, for static tracepoints | |
10252 | that have not been set by marker id. Static tracepoint that have | |
10253 | been set by marker id are reset by marker id in breakpoint_re_set. | |
10254 | The heuristic is: | |
10255 | ||
10256 | 1) For a tracepoint set at a specific address, look for a marker at | |
10257 | the old PC. If one is found there, assume to be the same marker. | |
10258 | If the name / string id of the marker found is different from the | |
10259 | previous known name, assume that means the user renamed the marker | |
10260 | in the sources, and output a warning. | |
10261 | ||
10262 | 2) For a tracepoint set at a given line number, look for a marker | |
10263 | at the new address of the old line number. If one is found there, | |
10264 | assume to be the same marker. If the name / string id of the | |
10265 | marker found is different from the previous known name, assume that | |
10266 | means the user renamed the marker in the sources, and output a | |
10267 | warning. | |
10268 | ||
10269 | 3) If a marker is no longer found at the same address or line, it | |
10270 | may mean the marker no longer exists. But it may also just mean | |
10271 | the code changed a bit. Maybe the user added a few lines of code | |
10272 | that made the marker move up or down (in line number terms). Ask | |
10273 | the target for info about the marker with the string id as we knew | |
10274 | it. If found, update line number and address in the matching | |
10275 | static tracepoint. This will get confused if there's more than one | |
10276 | marker with the same ID (possible in UST, although unadvised | |
10277 | precisely because it confuses tools). */ | |
10278 | ||
10279 | static struct symtab_and_line | |
10280 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
10281 | { | |
10282 | struct static_tracepoint_marker marker; | |
10283 | CORE_ADDR pc; | |
10284 | int i; | |
10285 | ||
10286 | pc = sal.pc; | |
10287 | if (sal.line) | |
10288 | find_line_pc (sal.symtab, sal.line, &pc); | |
10289 | ||
10290 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
10291 | { | |
10292 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
10293 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
10294 | b->number, | |
10295 | b->static_trace_marker_id, marker.str_id); | |
10296 | ||
10297 | xfree (b->static_trace_marker_id); | |
10298 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
10299 | release_static_tracepoint_marker (&marker); | |
10300 | ||
10301 | return sal; | |
10302 | } | |
10303 | ||
10304 | /* Old marker wasn't found on target at lineno. Try looking it up | |
10305 | by string ID. */ | |
10306 | if (!sal.explicit_pc | |
10307 | && sal.line != 0 | |
10308 | && sal.symtab != NULL | |
10309 | && b->static_trace_marker_id != NULL) | |
10310 | { | |
10311 | VEC(static_tracepoint_marker_p) *markers; | |
10312 | ||
10313 | markers | |
10314 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
10315 | ||
10316 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
10317 | { | |
10318 | struct symtab_and_line sal; | |
10319 | struct symbol *sym; | |
10320 | struct static_tracepoint_marker *marker; | |
10321 | ||
10322 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
10323 | ||
10324 | xfree (b->static_trace_marker_id); | |
10325 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
10326 | ||
10327 | warning (_("marker for static tracepoint %d (%s) not " | |
10328 | "found at previous line number"), | |
10329 | b->number, b->static_trace_marker_id); | |
10330 | ||
10331 | init_sal (&sal); | |
10332 | ||
10333 | sal.pc = marker->address; | |
10334 | ||
10335 | sal = find_pc_line (marker->address, 0); | |
10336 | sym = find_pc_sect_function (marker->address, NULL); | |
10337 | ui_out_text (uiout, "Now in "); | |
10338 | if (sym) | |
10339 | { | |
10340 | ui_out_field_string (uiout, "func", | |
10341 | SYMBOL_PRINT_NAME (sym)); | |
10342 | ui_out_text (uiout, " at "); | |
10343 | } | |
10344 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
10345 | ui_out_text (uiout, ":"); | |
10346 | ||
10347 | if (ui_out_is_mi_like_p (uiout)) | |
10348 | { | |
10349 | char *fullname = symtab_to_fullname (sal.symtab); | |
10350 | ||
10351 | if (fullname) | |
10352 | ui_out_field_string (uiout, "fullname", fullname); | |
10353 | } | |
10354 | ||
10355 | ui_out_field_int (uiout, "line", sal.line); | |
10356 | ui_out_text (uiout, "\n"); | |
10357 | ||
10358 | b->line_number = sal.line; | |
10359 | ||
10360 | xfree (b->source_file); | |
10361 | if (sym) | |
10362 | b->source_file = xstrdup (sal.symtab->filename); | |
10363 | else | |
10364 | b->source_file = NULL; | |
10365 | ||
10366 | xfree (b->addr_string); | |
10367 | b->addr_string = xstrprintf ("%s:%d", | |
10368 | sal.symtab->filename, b->line_number); | |
10369 | ||
10370 | /* Might be nice to check if function changed, and warn if | |
10371 | so. */ | |
10372 | ||
10373 | release_static_tracepoint_marker (marker); | |
10374 | } | |
10375 | } | |
10376 | return sal; | |
10377 | } | |
10378 | ||
fe3f5fa8 | 10379 | static void |
0d381245 VP |
10380 | update_breakpoint_locations (struct breakpoint *b, |
10381 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
10382 | { |
10383 | int i; | |
10384 | char *s; | |
0d381245 VP |
10385 | struct bp_location *existing_locations = b->loc; |
10386 | ||
4a64f543 MS |
10387 | /* If there's no new locations, and all existing locations are |
10388 | pending, don't do anything. This optimizes the common case where | |
10389 | all locations are in the same shared library, that was unloaded. | |
10390 | We'd like to retain the location, so that when the library is | |
10391 | loaded again, we don't loose the enabled/disabled status of the | |
10392 | individual locations. */ | |
0d381245 | 10393 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
10394 | return; |
10395 | ||
fe3f5fa8 VP |
10396 | b->loc = NULL; |
10397 | ||
0d381245 | 10398 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 10399 | { |
0d381245 | 10400 | struct bp_location *new_loc = |
39d61571 | 10401 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 10402 | |
0d381245 VP |
10403 | /* Reparse conditions, they might contain references to the |
10404 | old symtab. */ | |
10405 | if (b->cond_string != NULL) | |
10406 | { | |
10407 | struct gdb_exception e; | |
fe3f5fa8 | 10408 | |
0d381245 VP |
10409 | s = b->cond_string; |
10410 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10411 | { | |
10412 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
10413 | 0); | |
10414 | } | |
10415 | if (e.reason < 0) | |
10416 | { | |
3e43a32a MS |
10417 | warning (_("failed to reevaluate condition " |
10418 | "for breakpoint %d: %s"), | |
0d381245 VP |
10419 | b->number, e.message); |
10420 | new_loc->enabled = 0; | |
10421 | } | |
10422 | } | |
fe3f5fa8 | 10423 | |
0d381245 VP |
10424 | if (b->source_file != NULL) |
10425 | xfree (b->source_file); | |
10426 | if (sals.sals[i].symtab == NULL) | |
10427 | b->source_file = NULL; | |
10428 | else | |
1b36a34b | 10429 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 10430 | |
0d381245 VP |
10431 | if (b->line_number == 0) |
10432 | b->line_number = sals.sals[i].line; | |
10433 | } | |
fe3f5fa8 | 10434 | |
514f746b AR |
10435 | /* Update locations of permanent breakpoints. */ |
10436 | if (b->enable_state == bp_permanent) | |
10437 | make_breakpoint_permanent (b); | |
10438 | ||
4a64f543 MS |
10439 | /* If possible, carry over 'disable' status from existing |
10440 | breakpoints. */ | |
0d381245 VP |
10441 | { |
10442 | struct bp_location *e = existing_locations; | |
776592bf DE |
10443 | /* If there are multiple breakpoints with the same function name, |
10444 | e.g. for inline functions, comparing function names won't work. | |
10445 | Instead compare pc addresses; this is just a heuristic as things | |
10446 | may have moved, but in practice it gives the correct answer | |
10447 | often enough until a better solution is found. */ | |
10448 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
10449 | ||
0d381245 VP |
10450 | for (; e; e = e->next) |
10451 | { | |
10452 | if (!e->enabled && e->function_name) | |
10453 | { | |
10454 | struct bp_location *l = b->loc; | |
776592bf DE |
10455 | if (have_ambiguous_names) |
10456 | { | |
10457 | for (; l; l = l->next) | |
6c95b8df PA |
10458 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
10459 | l->pspace->aspace, l->address)) | |
776592bf DE |
10460 | { |
10461 | l->enabled = 0; | |
10462 | break; | |
10463 | } | |
10464 | } | |
10465 | else | |
10466 | { | |
10467 | for (; l; l = l->next) | |
10468 | if (l->function_name | |
10469 | && strcmp (e->function_name, l->function_name) == 0) | |
10470 | { | |
10471 | l->enabled = 0; | |
10472 | break; | |
10473 | } | |
10474 | } | |
0d381245 VP |
10475 | } |
10476 | } | |
10477 | } | |
fe3f5fa8 | 10478 | |
b60e7edf | 10479 | update_global_location_list (1); |
fe3f5fa8 VP |
10480 | } |
10481 | ||
c906108c SS |
10482 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
10483 | The value we return ends up being the return value from catch_errors. | |
10484 | Unused in this case. */ | |
10485 | ||
10486 | static int | |
4efb68b1 | 10487 | breakpoint_re_set_one (void *bint) |
c906108c | 10488 | { |
4a64f543 | 10489 | /* Get past catch_errs. */ |
53a5351d | 10490 | struct breakpoint *b = (struct breakpoint *) bint; |
fe3f5fa8 VP |
10491 | int not_found = 0; |
10492 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
10493 | struct symtabs_and_lines sals = {0}; |
10494 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 10495 | char *s; |
fe3f5fa8 | 10496 | struct gdb_exception e; |
6c95b8df | 10497 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
0fb4aa4b | 10498 | int marker_spec = 0; |
c906108c SS |
10499 | |
10500 | switch (b->type) | |
10501 | { | |
10502 | case bp_none: | |
8a3fe4f8 | 10503 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 10504 | b->number); |
c906108c SS |
10505 | return 0; |
10506 | case bp_breakpoint: | |
10507 | case bp_hardware_breakpoint: | |
1042e4c0 | 10508 | case bp_tracepoint: |
7a697b8d | 10509 | case bp_fast_tracepoint: |
0fb4aa4b | 10510 | case bp_static_tracepoint: |
8bea4e01 UW |
10511 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10512 | if (b->enable_state == bp_startup_disabled) | |
10513 | return 0; | |
10514 | ||
c906108c SS |
10515 | if (b->addr_string == NULL) |
10516 | { | |
4a64f543 | 10517 | /* Anything without a string can't be re-set. */ |
c906108c SS |
10518 | delete_breakpoint (b); |
10519 | return 0; | |
10520 | } | |
c906108c | 10521 | |
c906108c SS |
10522 | input_radix = b->input_radix; |
10523 | s = b->addr_string; | |
6c95b8df PA |
10524 | |
10525 | save_current_space_and_thread (); | |
10526 | switch_to_program_space_and_thread (b->pspace); | |
10527 | ||
0fb4aa4b PA |
10528 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); |
10529 | ||
385d04dc | 10530 | set_language (b->language); |
fe3f5fa8 | 10531 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 10532 | { |
0fb4aa4b PA |
10533 | if (marker_spec) |
10534 | { | |
10535 | sals = decode_static_tracepoint_spec (&s); | |
10536 | if (sals.nelts > b->static_trace_marker_id_idx) | |
10537 | { | |
10538 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
10539 | sals.nelts = 1; | |
10540 | } | |
10541 | else | |
10542 | error (_("marker %s not found"), b->static_trace_marker_id); | |
10543 | } | |
10544 | else | |
3e43a32a MS |
10545 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, |
10546 | (char ***) NULL, not_found_ptr); | |
fe3f5fa8 VP |
10547 | } |
10548 | if (e.reason < 0) | |
10549 | { | |
10550 | int not_found_and_ok = 0; | |
4a64f543 MS |
10551 | /* For pending breakpoints, it's expected that parsing will |
10552 | fail until the right shared library is loaded. User has | |
10553 | already told to create pending breakpoints and don't need | |
10554 | extra messages. If breakpoint is in bp_shlib_disabled | |
10555 | state, then user already saw the message about that | |
10556 | breakpoint being disabled, and don't want to see more | |
10557 | errors. */ | |
0d381245 VP |
10558 | if (not_found |
10559 | && (b->condition_not_parsed | |
10560 | || (b->loc && b->loc->shlib_disabled) | |
10561 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
10562 | not_found_and_ok = 1; |
10563 | ||
10564 | if (!not_found_and_ok) | |
c906108c | 10565 | { |
fe3f5fa8 VP |
10566 | /* We surely don't want to warn about the same breakpoint |
10567 | 10 times. One solution, implemented here, is disable | |
10568 | the breakpoint on error. Another solution would be to | |
10569 | have separate 'warning emitted' flag. Since this | |
10570 | happens only when a binary has changed, I don't know | |
10571 | which approach is better. */ | |
10572 | b->enable_state = bp_disabled; | |
10573 | throw_exception (e); | |
c906108c | 10574 | } |
fe3f5fa8 | 10575 | } |
c906108c | 10576 | |
6c95b8df | 10577 | if (!not_found) |
fe3f5fa8 | 10578 | { |
6c95b8df PA |
10579 | gdb_assert (sals.nelts == 1); |
10580 | ||
10581 | resolve_sal_pc (&sals.sals[0]); | |
10582 | if (b->condition_not_parsed && s && s[0]) | |
10583 | { | |
10584 | char *cond_string = 0; | |
10585 | int thread = -1; | |
10586 | int task = 0; | |
10587 | ||
10588 | find_condition_and_thread (s, sals.sals[0].pc, | |
10589 | &cond_string, &thread, &task); | |
10590 | if (cond_string) | |
10591 | b->cond_string = cond_string; | |
10592 | b->thread = thread; | |
10593 | b->task = task; | |
10594 | b->condition_not_parsed = 0; | |
10595 | } | |
10596 | ||
0fb4aa4b PA |
10597 | if (b->type == bp_static_tracepoint && !marker_spec) |
10598 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
10599 | ||
6c95b8df | 10600 | expanded = expand_line_sal_maybe (sals.sals[0]); |
fe3f5fa8 | 10601 | } |
6c95b8df PA |
10602 | |
10603 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 10604 | update_breakpoint_locations (b, expanded); |
c906108c SS |
10605 | break; |
10606 | ||
10607 | case bp_watchpoint: | |
10608 | case bp_hardware_watchpoint: | |
10609 | case bp_read_watchpoint: | |
10610 | case bp_access_watchpoint: | |
4a64f543 MS |
10611 | /* Watchpoint can be either on expression using entirely global |
10612 | variables, or it can be on local variables. | |
10613 | ||
10614 | Watchpoints of the first kind are never auto-deleted, and | |
10615 | even persist across program restarts. Since they can use | |
10616 | variables from shared libraries, we need to reparse | |
10617 | expression as libraries are loaded and unloaded. | |
10618 | ||
10619 | Watchpoints on local variables can also change meaning as | |
10620 | result of solib event. For example, if a watchpoint uses | |
10621 | both a local and a global variables in expression, it's a | |
10622 | local watchpoint, but unloading of a shared library will make | |
10623 | the expression invalid. This is not a very common use case, | |
10624 | but we still re-evaluate expression, to avoid surprises to | |
10625 | the user. | |
0b3de036 VP |
10626 | |
10627 | Note that for local watchpoints, we re-evaluate it only if | |
10628 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
10629 | the watchpoint is out of scope and will be deleted soon. In |
10630 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
10631 | |
10632 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 10633 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
10634 | |
10635 | Don't do anything about disabled watchpoints, since they will | |
10636 | be reevaluated again when enabled. */ | |
a5606eee | 10637 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 10638 | break; |
c5aa993b JM |
10639 | /* We needn't really do anything to reset these, since the mask |
10640 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 10641 | loaded. */ |
ce78b96d | 10642 | case bp_catchpoint: |
c906108c | 10643 | break; |
c5aa993b | 10644 | |
c906108c | 10645 | default: |
a3f17187 | 10646 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 10647 | /* fall through */ |
0fd8e87f UW |
10648 | /* Delete overlay event and longjmp master breakpoints; they will be |
10649 | reset later by breakpoint_re_set. */ | |
1900040c | 10650 | case bp_overlay_event: |
0fd8e87f | 10651 | case bp_longjmp_master: |
aa7d318d | 10652 | case bp_std_terminate_master: |
186c406b | 10653 | case bp_exception_master: |
c906108c SS |
10654 | delete_breakpoint (b); |
10655 | break; | |
10656 | ||
c5aa993b JM |
10657 | /* This breakpoint is special, it's set up when the inferior |
10658 | starts and we really don't want to touch it. */ | |
c906108c SS |
10659 | case bp_shlib_event: |
10660 | ||
c4093a6a JM |
10661 | /* Like bp_shlib_event, this breakpoint type is special. |
10662 | Once it is set up, we do not want to touch it. */ | |
10663 | case bp_thread_event: | |
10664 | ||
4a64f543 MS |
10665 | /* Keep temporary breakpoints, which can be encountered when we |
10666 | step over a dlopen call and SOLIB_ADD is resetting the | |
10667 | breakpoints. Otherwise these should have been blown away via | |
10668 | the cleanup chain or by breakpoint_init_inferior when we | |
10669 | rerun the executable. */ | |
c906108c SS |
10670 | case bp_until: |
10671 | case bp_finish: | |
10672 | case bp_watchpoint_scope: | |
10673 | case bp_call_dummy: | |
aa7d318d | 10674 | case bp_std_terminate: |
c906108c | 10675 | case bp_step_resume: |
611c83ae PA |
10676 | case bp_longjmp: |
10677 | case bp_longjmp_resume: | |
186c406b TT |
10678 | case bp_exception: |
10679 | case bp_exception_resume: | |
4efc6507 | 10680 | case bp_jit_event: |
c906108c SS |
10681 | break; |
10682 | } | |
10683 | ||
6c95b8df | 10684 | do_cleanups (cleanups); |
c906108c SS |
10685 | return 0; |
10686 | } | |
10687 | ||
69de3c6a | 10688 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 10689 | void |
69de3c6a | 10690 | breakpoint_re_set (void) |
c906108c | 10691 | { |
35df4500 | 10692 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10693 | enum language save_language; |
10694 | int save_input_radix; | |
6c95b8df | 10695 | struct cleanup *old_chain; |
c5aa993b | 10696 | |
c906108c SS |
10697 | save_language = current_language->la_language; |
10698 | save_input_radix = input_radix; | |
6c95b8df PA |
10699 | old_chain = save_current_program_space (); |
10700 | ||
35df4500 | 10701 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10702 | { |
4a64f543 | 10703 | /* Format possible error msg. */ |
fe3f5fa8 | 10704 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
10705 | b->number); |
10706 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 10707 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 10708 | do_cleanups (cleanups); |
c5aa993b | 10709 | } |
c906108c SS |
10710 | set_language (save_language); |
10711 | input_radix = save_input_radix; | |
e62c965a | 10712 | |
0756c555 | 10713 | jit_breakpoint_re_set (); |
4efc6507 | 10714 | |
6c95b8df PA |
10715 | do_cleanups (old_chain); |
10716 | ||
af02033e PP |
10717 | create_overlay_event_breakpoint (); |
10718 | create_longjmp_master_breakpoint (); | |
10719 | create_std_terminate_master_breakpoint (); | |
186c406b | 10720 | create_exception_master_breakpoint (); |
c906108c SS |
10721 | } |
10722 | \f | |
c906108c SS |
10723 | /* Reset the thread number of this breakpoint: |
10724 | ||
10725 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 10726 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 10727 | void |
fba45db2 | 10728 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
10729 | { |
10730 | if (b->thread != -1) | |
10731 | { | |
39f77062 KB |
10732 | if (in_thread_list (inferior_ptid)) |
10733 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
10734 | |
10735 | /* We're being called after following a fork. The new fork is | |
10736 | selected as current, and unless this was a vfork will have a | |
10737 | different program space from the original thread. Reset that | |
10738 | as well. */ | |
10739 | b->loc->pspace = current_program_space; | |
c906108c SS |
10740 | } |
10741 | } | |
10742 | ||
03ac34d5 MS |
10743 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10744 | If from_tty is nonzero, it prints a message to that effect, | |
10745 | which ends with a period (no newline). */ | |
10746 | ||
c906108c | 10747 | void |
fba45db2 | 10748 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 10749 | { |
52f0bd74 | 10750 | struct breakpoint *b; |
c906108c SS |
10751 | |
10752 | if (count < 0) | |
10753 | count = 0; | |
10754 | ||
10755 | ALL_BREAKPOINTS (b) | |
10756 | if (b->number == bptnum) | |
c5aa993b | 10757 | { |
d77f58be SS |
10758 | if (is_tracepoint (b)) |
10759 | { | |
10760 | if (from_tty && count != 0) | |
10761 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
10762 | bptnum); | |
10763 | return; | |
10764 | } | |
10765 | ||
c5aa993b | 10766 | b->ignore_count = count; |
221ea385 KS |
10767 | if (from_tty) |
10768 | { | |
10769 | if (count == 0) | |
3e43a32a MS |
10770 | printf_filtered (_("Will stop next time " |
10771 | "breakpoint %d is reached."), | |
221ea385 KS |
10772 | bptnum); |
10773 | else if (count == 1) | |
a3f17187 | 10774 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
10775 | bptnum); |
10776 | else | |
3e43a32a MS |
10777 | printf_filtered (_("Will ignore next %d " |
10778 | "crossings of breakpoint %d."), | |
221ea385 KS |
10779 | count, bptnum); |
10780 | } | |
c5aa993b | 10781 | breakpoints_changed (); |
383f836e | 10782 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
10783 | return; |
10784 | } | |
c906108c | 10785 | |
8a3fe4f8 | 10786 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
10787 | } |
10788 | ||
c906108c SS |
10789 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
10790 | ||
10791 | static void | |
fba45db2 | 10792 | ignore_command (char *args, int from_tty) |
c906108c SS |
10793 | { |
10794 | char *p = args; | |
52f0bd74 | 10795 | int num; |
c906108c SS |
10796 | |
10797 | if (p == 0) | |
e2e0b3e5 | 10798 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 10799 | |
c906108c | 10800 | num = get_number (&p); |
5c44784c | 10801 | if (num == 0) |
8a3fe4f8 | 10802 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 10803 | if (*p == 0) |
8a3fe4f8 | 10804 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
10805 | |
10806 | set_ignore_count (num, | |
10807 | longest_to_int (value_as_long (parse_and_eval (p))), | |
10808 | from_tty); | |
221ea385 KS |
10809 | if (from_tty) |
10810 | printf_filtered ("\n"); | |
c906108c SS |
10811 | } |
10812 | \f | |
10813 | /* Call FUNCTION on each of the breakpoints | |
10814 | whose numbers are given in ARGS. */ | |
10815 | ||
10816 | static void | |
95a42b64 TT |
10817 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
10818 | void *), | |
10819 | void *data) | |
c906108c | 10820 | { |
52f0bd74 AC |
10821 | int num; |
10822 | struct breakpoint *b, *tmp; | |
11cf8741 | 10823 | int match; |
197f0a60 | 10824 | struct get_number_or_range_state state; |
c906108c | 10825 | |
197f0a60 | 10826 | if (args == 0) |
e2e0b3e5 | 10827 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 10828 | |
197f0a60 TT |
10829 | init_number_or_range (&state, args); |
10830 | ||
10831 | while (!state.finished) | |
c906108c | 10832 | { |
197f0a60 TT |
10833 | char *p = state.string; |
10834 | ||
11cf8741 | 10835 | match = 0; |
c5aa993b | 10836 | |
197f0a60 | 10837 | num = get_number_or_range (&state); |
5c44784c | 10838 | if (num == 0) |
c5aa993b | 10839 | { |
8a3fe4f8 | 10840 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
10841 | } |
10842 | else | |
10843 | { | |
10844 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
10845 | if (b->number == num) | |
10846 | { | |
10847 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 10848 | match = 1; |
95a42b64 | 10849 | function (b, data); |
5c44784c | 10850 | if (related_breakpoint) |
95a42b64 | 10851 | function (related_breakpoint, data); |
11cf8741 | 10852 | break; |
5c44784c | 10853 | } |
11cf8741 | 10854 | if (match == 0) |
a3f17187 | 10855 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 10856 | } |
c906108c SS |
10857 | } |
10858 | } | |
10859 | ||
0d381245 VP |
10860 | static struct bp_location * |
10861 | find_location_by_number (char *number) | |
10862 | { | |
10863 | char *dot = strchr (number, '.'); | |
10864 | char *p1; | |
10865 | int bp_num; | |
10866 | int loc_num; | |
10867 | struct breakpoint *b; | |
10868 | struct bp_location *loc; | |
10869 | ||
10870 | *dot = '\0'; | |
10871 | ||
10872 | p1 = number; | |
197f0a60 | 10873 | bp_num = get_number (&p1); |
0d381245 VP |
10874 | if (bp_num == 0) |
10875 | error (_("Bad breakpoint number '%s'"), number); | |
10876 | ||
10877 | ALL_BREAKPOINTS (b) | |
10878 | if (b->number == bp_num) | |
10879 | { | |
10880 | break; | |
10881 | } | |
10882 | ||
10883 | if (!b || b->number != bp_num) | |
10884 | error (_("Bad breakpoint number '%s'"), number); | |
10885 | ||
10886 | p1 = dot+1; | |
197f0a60 | 10887 | loc_num = get_number (&p1); |
0d381245 VP |
10888 | if (loc_num == 0) |
10889 | error (_("Bad breakpoint location number '%s'"), number); | |
10890 | ||
10891 | --loc_num; | |
10892 | loc = b->loc; | |
10893 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
10894 | ; | |
10895 | if (!loc) | |
10896 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
10897 | ||
10898 | return loc; | |
10899 | } | |
10900 | ||
10901 | ||
1900040c MS |
10902 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10903 | If from_tty is nonzero, it prints a message to that effect, | |
10904 | which ends with a period (no newline). */ | |
10905 | ||
c906108c | 10906 | void |
fba45db2 | 10907 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10908 | { |
10909 | /* Never disable a watchpoint scope breakpoint; we want to | |
10910 | hit them when we leave scope so we can delete both the | |
10911 | watchpoint and its scope breakpoint at that time. */ | |
10912 | if (bpt->type == bp_watchpoint_scope) | |
10913 | return; | |
10914 | ||
c2c6d25f | 10915 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 10916 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
10917 | return; |
10918 | ||
b5de0fa7 | 10919 | bpt->enable_state = bp_disabled; |
c906108c | 10920 | |
b60e7edf | 10921 | update_global_location_list (0); |
c906108c | 10922 | |
383f836e | 10923 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10924 | } |
10925 | ||
95a42b64 TT |
10926 | /* A callback for map_breakpoint_numbers that calls |
10927 | disable_breakpoint. */ | |
10928 | ||
10929 | static void | |
10930 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
10931 | { | |
10932 | disable_breakpoint (b); | |
10933 | } | |
10934 | ||
c906108c | 10935 | static void |
fba45db2 | 10936 | disable_command (char *args, int from_tty) |
c906108c | 10937 | { |
52f0bd74 | 10938 | struct breakpoint *bpt; |
cc59ec59 | 10939 | |
c906108c SS |
10940 | if (args == 0) |
10941 | ALL_BREAKPOINTS (bpt) | |
10942 | switch (bpt->type) | |
c5aa993b JM |
10943 | { |
10944 | case bp_none: | |
8a3fe4f8 | 10945 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 10946 | bpt->number); |
488919c4 | 10947 | break; |
c5aa993b | 10948 | case bp_breakpoint: |
1042e4c0 | 10949 | case bp_tracepoint: |
7a697b8d | 10950 | case bp_fast_tracepoint: |
0fb4aa4b | 10951 | case bp_static_tracepoint: |
ce78b96d | 10952 | case bp_catchpoint: |
c5aa993b JM |
10953 | case bp_hardware_breakpoint: |
10954 | case bp_watchpoint: | |
10955 | case bp_hardware_watchpoint: | |
10956 | case bp_read_watchpoint: | |
10957 | case bp_access_watchpoint: | |
10958 | disable_breakpoint (bpt); | |
488919c4 | 10959 | break; |
c5aa993b | 10960 | default: |
488919c4 | 10961 | break; |
c5aa993b | 10962 | } |
0d381245 VP |
10963 | else if (strchr (args, '.')) |
10964 | { | |
10965 | struct bp_location *loc = find_location_by_number (args); | |
10966 | if (loc) | |
10967 | loc->enabled = 0; | |
b60e7edf | 10968 | update_global_location_list (0); |
0d381245 | 10969 | } |
c906108c | 10970 | else |
95a42b64 | 10971 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
10972 | } |
10973 | ||
10974 | static void | |
fba45db2 | 10975 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 10976 | { |
afe38095 | 10977 | int target_resources_ok; |
c906108c SS |
10978 | |
10979 | if (bpt->type == bp_hardware_breakpoint) | |
10980 | { | |
10981 | int i; | |
c5aa993b | 10982 | i = hw_breakpoint_used_count (); |
53a5351d | 10983 | target_resources_ok = |
d92524f1 | 10984 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 10985 | i + 1, 0); |
c906108c | 10986 | if (target_resources_ok == 0) |
8a3fe4f8 | 10987 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 10988 | else if (target_resources_ok < 0) |
8a3fe4f8 | 10989 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
10990 | } |
10991 | ||
cc60f2e3 | 10992 | if (is_watchpoint (bpt)) |
c906108c | 10993 | { |
dde02812 ES |
10994 | struct gdb_exception e; |
10995 | ||
10996 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 10997 | { |
dde02812 | 10998 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 10999 | } |
dde02812 | 11000 | if (e.reason < 0) |
c5aa993b | 11001 | { |
dde02812 ES |
11002 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
11003 | bpt->number); | |
11004 | return; | |
c5aa993b | 11005 | } |
c906108c | 11006 | } |
0101ce28 | 11007 | |
b4c291bb KH |
11008 | if (bpt->enable_state != bp_permanent) |
11009 | bpt->enable_state = bp_enabled; | |
11010 | bpt->disposition = disposition; | |
b60e7edf | 11011 | update_global_location_list (1); |
b4c291bb KH |
11012 | breakpoints_changed (); |
11013 | ||
383f836e | 11014 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
11015 | } |
11016 | ||
fe3f5fa8 | 11017 | |
c906108c | 11018 | void |
fba45db2 | 11019 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
11020 | { |
11021 | do_enable_breakpoint (bpt, bpt->disposition); | |
11022 | } | |
11023 | ||
95a42b64 TT |
11024 | /* A callback for map_breakpoint_numbers that calls |
11025 | enable_breakpoint. */ | |
11026 | ||
11027 | static void | |
11028 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
11029 | { | |
11030 | enable_breakpoint (b); | |
11031 | } | |
11032 | ||
c906108c SS |
11033 | /* The enable command enables the specified breakpoints (or all defined |
11034 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 11035 | in stopping the inferior. */ |
c906108c | 11036 | |
c906108c | 11037 | static void |
fba45db2 | 11038 | enable_command (char *args, int from_tty) |
c906108c | 11039 | { |
52f0bd74 | 11040 | struct breakpoint *bpt; |
cc59ec59 | 11041 | |
c906108c SS |
11042 | if (args == 0) |
11043 | ALL_BREAKPOINTS (bpt) | |
11044 | switch (bpt->type) | |
c5aa993b JM |
11045 | { |
11046 | case bp_none: | |
8a3fe4f8 | 11047 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 11048 | bpt->number); |
488919c4 | 11049 | break; |
c5aa993b | 11050 | case bp_breakpoint: |
1042e4c0 | 11051 | case bp_tracepoint: |
7a697b8d | 11052 | case bp_fast_tracepoint: |
0fb4aa4b | 11053 | case bp_static_tracepoint: |
ce78b96d | 11054 | case bp_catchpoint: |
c5aa993b JM |
11055 | case bp_hardware_breakpoint: |
11056 | case bp_watchpoint: | |
11057 | case bp_hardware_watchpoint: | |
11058 | case bp_read_watchpoint: | |
11059 | case bp_access_watchpoint: | |
11060 | enable_breakpoint (bpt); | |
488919c4 | 11061 | break; |
c5aa993b | 11062 | default: |
488919c4 | 11063 | break; |
c5aa993b | 11064 | } |
0d381245 VP |
11065 | else if (strchr (args, '.')) |
11066 | { | |
11067 | struct bp_location *loc = find_location_by_number (args); | |
11068 | if (loc) | |
11069 | loc->enabled = 1; | |
b60e7edf | 11070 | update_global_location_list (1); |
0d381245 | 11071 | } |
c906108c | 11072 | else |
95a42b64 | 11073 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
11074 | } |
11075 | ||
11076 | static void | |
95a42b64 | 11077 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11078 | { |
b5de0fa7 | 11079 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
11080 | } |
11081 | ||
c906108c | 11082 | static void |
fba45db2 | 11083 | enable_once_command (char *args, int from_tty) |
c906108c | 11084 | { |
95a42b64 | 11085 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
11086 | } |
11087 | ||
11088 | static void | |
95a42b64 | 11089 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11090 | { |
b5de0fa7 | 11091 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
11092 | } |
11093 | ||
c906108c | 11094 | static void |
fba45db2 | 11095 | enable_delete_command (char *args, int from_tty) |
c906108c | 11096 | { |
95a42b64 | 11097 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
11098 | } |
11099 | \f | |
fa8d40ab JJ |
11100 | static void |
11101 | set_breakpoint_cmd (char *args, int from_tty) | |
11102 | { | |
11103 | } | |
11104 | ||
11105 | static void | |
11106 | show_breakpoint_cmd (char *args, int from_tty) | |
11107 | { | |
11108 | } | |
11109 | ||
1f3b5d1b PP |
11110 | /* Invalidate last known value of any hardware watchpoint if |
11111 | the memory which that value represents has been written to by | |
11112 | GDB itself. */ | |
11113 | ||
11114 | static void | |
11115 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
11116 | const bfd_byte *data) | |
11117 | { | |
11118 | struct breakpoint *bp; | |
11119 | ||
11120 | ALL_BREAKPOINTS (bp) | |
11121 | if (bp->enable_state == bp_enabled | |
11122 | && bp->type == bp_hardware_watchpoint | |
11123 | && bp->val_valid && bp->val) | |
11124 | { | |
11125 | struct bp_location *loc; | |
11126 | ||
11127 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
11128 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
11129 | && loc->address + loc->length > addr | |
11130 | && addr + len > loc->address) | |
11131 | { | |
11132 | value_free (bp->val); | |
11133 | bp->val = NULL; | |
11134 | bp->val_valid = 0; | |
11135 | } | |
11136 | } | |
11137 | } | |
11138 | ||
c906108c SS |
11139 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
11140 | ||
11141 | struct symtabs_and_lines | |
fba45db2 | 11142 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
11143 | { |
11144 | struct symtabs_and_lines sals; | |
cc59ec59 | 11145 | |
c906108c | 11146 | if (string == 0) |
8a3fe4f8 | 11147 | error (_("Empty line specification.")); |
c906108c SS |
11148 | if (default_breakpoint_valid) |
11149 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
11150 | default_breakpoint_symtab, |
11151 | default_breakpoint_line, | |
68219205 | 11152 | (char ***) NULL, NULL); |
c906108c SS |
11153 | else |
11154 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 11155 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 11156 | if (*string) |
8a3fe4f8 | 11157 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
11158 | return sals; |
11159 | } | |
8181d85f DJ |
11160 | |
11161 | /* Create and insert a raw software breakpoint at PC. Return an | |
11162 | identifier, which should be used to remove the breakpoint later. | |
11163 | In general, places which call this should be using something on the | |
11164 | breakpoint chain instead; this function should be eliminated | |
11165 | someday. */ | |
11166 | ||
11167 | void * | |
6c95b8df PA |
11168 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
11169 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
11170 | { |
11171 | struct bp_target_info *bp_tgt; | |
11172 | ||
6c95b8df | 11173 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 11174 | |
6c95b8df | 11175 | bp_tgt->placed_address_space = aspace; |
8181d85f | 11176 | bp_tgt->placed_address = pc; |
6c95b8df | 11177 | |
a6d9a66e | 11178 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
11179 | { |
11180 | /* Could not insert the breakpoint. */ | |
11181 | xfree (bp_tgt); | |
11182 | return NULL; | |
11183 | } | |
11184 | ||
11185 | return bp_tgt; | |
11186 | } | |
11187 | ||
4a64f543 MS |
11188 | /* Remove a breakpoint BP inserted by |
11189 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
11190 | |
11191 | int | |
a6d9a66e | 11192 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
11193 | { |
11194 | struct bp_target_info *bp_tgt = bp; | |
11195 | int ret; | |
11196 | ||
a6d9a66e | 11197 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
11198 | xfree (bp_tgt); |
11199 | ||
11200 | return ret; | |
11201 | } | |
11202 | ||
4a64f543 MS |
11203 | /* One (or perhaps two) breakpoints used for software single |
11204 | stepping. */ | |
8181d85f DJ |
11205 | |
11206 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 11207 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
11208 | |
11209 | /* Create and insert a breakpoint for software single step. */ | |
11210 | ||
11211 | void | |
6c95b8df | 11212 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
11213 | struct address_space *aspace, |
11214 | CORE_ADDR next_pc) | |
8181d85f DJ |
11215 | { |
11216 | void **bpt_p; | |
11217 | ||
11218 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
11219 | { |
11220 | bpt_p = &single_step_breakpoints[0]; | |
11221 | single_step_gdbarch[0] = gdbarch; | |
11222 | } | |
8181d85f DJ |
11223 | else |
11224 | { | |
11225 | gdb_assert (single_step_breakpoints[1] == NULL); | |
11226 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 11227 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
11228 | } |
11229 | ||
4a64f543 MS |
11230 | /* NOTE drow/2006-04-11: A future improvement to this function would |
11231 | be to only create the breakpoints once, and actually put them on | |
11232 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
11233 | We could adjust the addresses each time they were needed. Doing | |
11234 | this requires corresponding changes elsewhere where single step | |
11235 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 11236 | |
6c95b8df | 11237 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 11238 | if (*bpt_p == NULL) |
5af949e3 UW |
11239 | error (_("Could not insert single-step breakpoint at %s"), |
11240 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
11241 | } |
11242 | ||
f02253f1 HZ |
11243 | /* Check if the breakpoints used for software single stepping |
11244 | were inserted or not. */ | |
11245 | ||
11246 | int | |
11247 | single_step_breakpoints_inserted (void) | |
11248 | { | |
11249 | return (single_step_breakpoints[0] != NULL | |
11250 | || single_step_breakpoints[1] != NULL); | |
11251 | } | |
11252 | ||
8181d85f DJ |
11253 | /* Remove and delete any breakpoints used for software single step. */ |
11254 | ||
11255 | void | |
11256 | remove_single_step_breakpoints (void) | |
11257 | { | |
11258 | gdb_assert (single_step_breakpoints[0] != NULL); | |
11259 | ||
11260 | /* See insert_single_step_breakpoint for more about this deprecated | |
11261 | call. */ | |
a6d9a66e UW |
11262 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
11263 | single_step_breakpoints[0]); | |
11264 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
11265 | single_step_breakpoints[0] = NULL; |
11266 | ||
11267 | if (single_step_breakpoints[1] != NULL) | |
11268 | { | |
a6d9a66e UW |
11269 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
11270 | single_step_breakpoints[1]); | |
11271 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
11272 | single_step_breakpoints[1] = NULL; |
11273 | } | |
11274 | } | |
11275 | ||
d03285ec UW |
11276 | /* Delete software single step breakpoints without removing them from |
11277 | the inferior. This is intended to be used if the inferior's address | |
11278 | space where they were inserted is already gone, e.g. after exit or | |
11279 | exec. */ | |
11280 | ||
11281 | void | |
11282 | cancel_single_step_breakpoints (void) | |
11283 | { | |
11284 | int i; | |
11285 | ||
11286 | for (i = 0; i < 2; i++) | |
11287 | if (single_step_breakpoints[i]) | |
11288 | { | |
11289 | xfree (single_step_breakpoints[i]); | |
11290 | single_step_breakpoints[i] = NULL; | |
11291 | single_step_gdbarch[i] = NULL; | |
11292 | } | |
11293 | } | |
11294 | ||
11295 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
11296 | removing them. */ | |
11297 | ||
11298 | static void | |
11299 | detach_single_step_breakpoints (void) | |
11300 | { | |
11301 | int i; | |
11302 | ||
11303 | for (i = 0; i < 2; i++) | |
11304 | if (single_step_breakpoints[i]) | |
11305 | target_remove_breakpoint (single_step_gdbarch[i], | |
11306 | single_step_breakpoints[i]); | |
11307 | } | |
11308 | ||
4a64f543 MS |
11309 | /* Check whether a software single-step breakpoint is inserted at |
11310 | PC. */ | |
1aafd4da UW |
11311 | |
11312 | static int | |
cc59ec59 MS |
11313 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
11314 | CORE_ADDR pc) | |
1aafd4da UW |
11315 | { |
11316 | int i; | |
11317 | ||
11318 | for (i = 0; i < 2; i++) | |
11319 | { | |
11320 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
11321 | if (bp_tgt |
11322 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
11323 | bp_tgt->placed_address, | |
11324 | aspace, pc)) | |
1aafd4da UW |
11325 | return 1; |
11326 | } | |
11327 | ||
11328 | return 0; | |
11329 | } | |
11330 | ||
a96d9b2e SDJ |
11331 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
11332 | non-zero otherwise. */ | |
11333 | static int | |
11334 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
11335 | { | |
11336 | if (syscall_catchpoint_p (bp) | |
11337 | && bp->enable_state != bp_disabled | |
11338 | && bp->enable_state != bp_call_disabled) | |
11339 | return 1; | |
11340 | else | |
11341 | return 0; | |
11342 | } | |
11343 | ||
11344 | int | |
11345 | catch_syscall_enabled (void) | |
11346 | { | |
11347 | struct inferior *inf = current_inferior (); | |
11348 | ||
11349 | return inf->total_syscalls_count != 0; | |
11350 | } | |
11351 | ||
11352 | int | |
11353 | catching_syscall_number (int syscall_number) | |
11354 | { | |
11355 | struct breakpoint *bp; | |
11356 | ||
11357 | ALL_BREAKPOINTS (bp) | |
11358 | if (is_syscall_catchpoint_enabled (bp)) | |
11359 | { | |
11360 | if (bp->syscalls_to_be_caught) | |
11361 | { | |
11362 | int i, iter; | |
11363 | for (i = 0; | |
11364 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
11365 | i++) | |
11366 | if (syscall_number == iter) | |
11367 | return 1; | |
11368 | } | |
11369 | else | |
11370 | return 1; | |
11371 | } | |
11372 | ||
11373 | return 0; | |
11374 | } | |
11375 | ||
11376 | /* Complete syscall names. Used by "catch syscall". */ | |
11377 | static char ** | |
11378 | catch_syscall_completer (struct cmd_list_element *cmd, | |
11379 | char *text, char *word) | |
11380 | { | |
11381 | const char **list = get_syscall_names (); | |
c38eea1a MS |
11382 | char **retlist |
11383 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 11384 | |
c38eea1a MS |
11385 | xfree (list); |
11386 | return retlist; | |
a96d9b2e SDJ |
11387 | } |
11388 | ||
1042e4c0 SS |
11389 | /* Tracepoint-specific operations. */ |
11390 | ||
11391 | /* Set tracepoint count to NUM. */ | |
11392 | static void | |
11393 | set_tracepoint_count (int num) | |
11394 | { | |
11395 | tracepoint_count = num; | |
4fa62494 | 11396 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
11397 | } |
11398 | ||
11399 | void | |
11400 | trace_command (char *arg, int from_tty) | |
11401 | { | |
8cdf0e15 VP |
11402 | if (create_breakpoint (get_current_arch (), |
11403 | arg, | |
11404 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11405 | 0 /* tempflag */, |
11406 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11407 | 0 /* Ignore count */, |
11408 | pending_break_support, | |
11409 | NULL, | |
11410 | from_tty, | |
84f4c1fe PM |
11411 | 1 /* enabled */, |
11412 | 0 /* internal */)) | |
fd9b8c24 | 11413 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
11414 | } |
11415 | ||
7a697b8d SS |
11416 | void |
11417 | ftrace_command (char *arg, int from_tty) | |
11418 | { | |
8cdf0e15 VP |
11419 | if (create_breakpoint (get_current_arch (), |
11420 | arg, | |
11421 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11422 | 0 /* tempflag */, |
11423 | bp_fast_tracepoint /* type_wanted */, | |
11424 | 0 /* Ignore count */, | |
11425 | pending_break_support, | |
11426 | NULL, | |
11427 | from_tty, | |
84f4c1fe PM |
11428 | 1 /* enabled */, |
11429 | 0 /* internal */)) | |
0fb4aa4b PA |
11430 | set_tracepoint_count (breakpoint_count); |
11431 | } | |
11432 | ||
11433 | /* strace command implementation. Creates a static tracepoint. */ | |
11434 | ||
11435 | void | |
11436 | strace_command (char *arg, int from_tty) | |
11437 | { | |
11438 | if (create_breakpoint (get_current_arch (), | |
11439 | arg, | |
11440 | NULL, 0, 1 /* parse arg */, | |
11441 | 0 /* tempflag */, | |
11442 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11443 | 0 /* Ignore count */, |
11444 | pending_break_support, | |
11445 | NULL, | |
11446 | from_tty, | |
84f4c1fe PM |
11447 | 1 /* enabled */, |
11448 | 0 /* internal */)) | |
fd9b8c24 | 11449 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
11450 | } |
11451 | ||
409873ef SS |
11452 | /* Set up a fake reader function that gets command lines from a linked |
11453 | list that was acquired during tracepoint uploading. */ | |
11454 | ||
11455 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 11456 | static int next_cmd; |
409873ef SS |
11457 | |
11458 | static char * | |
11459 | read_uploaded_action (void) | |
11460 | { | |
11461 | char *rslt; | |
11462 | ||
3149d8c1 | 11463 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 11464 | |
3149d8c1 | 11465 | next_cmd++; |
409873ef SS |
11466 | |
11467 | return rslt; | |
11468 | } | |
11469 | ||
00bf0b85 SS |
11470 | /* Given information about a tracepoint as recorded on a target (which |
11471 | can be either a live system or a trace file), attempt to create an | |
11472 | equivalent GDB tracepoint. This is not a reliable process, since | |
11473 | the target does not necessarily have all the information used when | |
11474 | the tracepoint was originally defined. */ | |
11475 | ||
11476 | struct breakpoint * | |
11477 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 11478 | { |
409873ef | 11479 | char *addr_str, small_buf[100]; |
d5551862 | 11480 | struct breakpoint *tp; |
fd9b8c24 | 11481 | |
409873ef SS |
11482 | if (utp->at_string) |
11483 | addr_str = utp->at_string; | |
11484 | else | |
11485 | { | |
11486 | /* In the absence of a source location, fall back to raw | |
11487 | address. Since there is no way to confirm that the address | |
11488 | means the same thing as when the trace was started, warn the | |
11489 | user. */ | |
3e43a32a MS |
11490 | warning (_("Uploaded tracepoint %d has no " |
11491 | "source location, using raw address"), | |
409873ef SS |
11492 | utp->number); |
11493 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
11494 | addr_str = small_buf; | |
11495 | } | |
11496 | ||
11497 | /* There's not much we can do with a sequence of bytecodes. */ | |
11498 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
11499 | warning (_("Uploaded tracepoint %d condition " |
11500 | "has no source form, ignoring it"), | |
409873ef | 11501 | utp->number); |
d5551862 | 11502 | |
8cdf0e15 | 11503 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
11504 | addr_str, |
11505 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 11506 | 0 /* tempflag */, |
0fb4aa4b | 11507 | utp->type /* type_wanted */, |
8cdf0e15 VP |
11508 | 0 /* Ignore count */, |
11509 | pending_break_support, | |
11510 | NULL, | |
11511 | 0 /* from_tty */, | |
84f4c1fe PM |
11512 | utp->enabled /* enabled */, |
11513 | 0 /* internal */)) | |
fd9b8c24 PA |
11514 | return NULL; |
11515 | ||
00bf0b85 SS |
11516 | set_tracepoint_count (breakpoint_count); |
11517 | ||
409873ef | 11518 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
11519 | tp = get_tracepoint (tracepoint_count); |
11520 | gdb_assert (tp != NULL); | |
d5551862 | 11521 | |
00bf0b85 SS |
11522 | if (utp->pass > 0) |
11523 | { | |
409873ef | 11524 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 11525 | |
409873ef | 11526 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
11527 | } |
11528 | ||
409873ef SS |
11529 | /* If we have uploaded versions of the original commands, set up a |
11530 | special-purpose "reader" function and call the usual command line | |
11531 | reader, then pass the result to the breakpoint command-setting | |
11532 | function. */ | |
3149d8c1 | 11533 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 11534 | { |
409873ef | 11535 | struct command_line *cmd_list; |
00bf0b85 | 11536 | |
409873ef | 11537 | this_utp = utp; |
3149d8c1 | 11538 | next_cmd = 0; |
d5551862 | 11539 | |
409873ef SS |
11540 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
11541 | ||
11542 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 11543 | } |
3149d8c1 SS |
11544 | else if (!VEC_empty (char_ptr, utp->actions) |
11545 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
11546 | warning (_("Uploaded tracepoint %d actions " |
11547 | "have no source form, ignoring them"), | |
409873ef | 11548 | utp->number); |
00bf0b85 SS |
11549 | |
11550 | return tp; | |
11551 | } | |
11552 | ||
1042e4c0 SS |
11553 | /* Print information on tracepoint number TPNUM_EXP, or all if |
11554 | omitted. */ | |
11555 | ||
11556 | static void | |
e5a67952 | 11557 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 11558 | { |
e5a67952 | 11559 | int num_printed; |
1042e4c0 | 11560 | |
e5a67952 | 11561 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
11562 | |
11563 | if (num_printed == 0) | |
1042e4c0 | 11564 | { |
e5a67952 | 11565 | if (args == NULL || *args == '\0') |
d77f58be SS |
11566 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
11567 | else | |
e5a67952 | 11568 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 11569 | } |
ad443146 SS |
11570 | |
11571 | default_collect_info (); | |
1042e4c0 SS |
11572 | } |
11573 | ||
4a64f543 | 11574 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
11575 | Not supported by all targets. */ |
11576 | static void | |
11577 | enable_trace_command (char *args, int from_tty) | |
11578 | { | |
11579 | enable_command (args, from_tty); | |
11580 | } | |
11581 | ||
4a64f543 | 11582 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
11583 | Not supported by all targets. */ |
11584 | static void | |
11585 | disable_trace_command (char *args, int from_tty) | |
11586 | { | |
11587 | disable_command (args, from_tty); | |
11588 | } | |
11589 | ||
4a64f543 | 11590 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
11591 | static void |
11592 | delete_trace_command (char *arg, int from_tty) | |
11593 | { | |
35df4500 | 11594 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
11595 | |
11596 | dont_repeat (); | |
11597 | ||
11598 | if (arg == 0) | |
11599 | { | |
11600 | int breaks_to_delete = 0; | |
11601 | ||
11602 | /* Delete all breakpoints if no argument. | |
11603 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
11604 | have to be deleted with an explicit breakpoint number |
11605 | argument. */ | |
1042e4c0 SS |
11606 | ALL_TRACEPOINTS (b) |
11607 | { | |
11608 | if (b->number >= 0) | |
11609 | { | |
11610 | breaks_to_delete = 1; | |
11611 | break; | |
11612 | } | |
11613 | } | |
11614 | ||
11615 | /* Ask user only if there are some breakpoints to delete. */ | |
11616 | if (!from_tty | |
11617 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
11618 | { | |
35df4500 | 11619 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
1042e4c0 | 11620 | { |
d77f58be | 11621 | if (is_tracepoint (b) |
059fb39f | 11622 | && b->number >= 0) |
1042e4c0 SS |
11623 | delete_breakpoint (b); |
11624 | } | |
11625 | } | |
11626 | } | |
11627 | else | |
95a42b64 | 11628 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
11629 | } |
11630 | ||
197f0a60 TT |
11631 | /* Helper function for trace_pass_command. */ |
11632 | ||
11633 | static void | |
11634 | trace_pass_set_count (struct breakpoint *bp, int count, int from_tty) | |
11635 | { | |
11636 | bp->pass_count = count; | |
11637 | observer_notify_tracepoint_modified (bp->number); | |
11638 | if (from_tty) | |
11639 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
11640 | bp->number, count); | |
11641 | } | |
11642 | ||
1042e4c0 SS |
11643 | /* Set passcount for tracepoint. |
11644 | ||
11645 | First command argument is passcount, second is tracepoint number. | |
11646 | If tracepoint number omitted, apply to most recently defined. | |
11647 | Also accepts special argument "all". */ | |
11648 | ||
11649 | static void | |
11650 | trace_pass_command (char *args, int from_tty) | |
11651 | { | |
197f0a60 | 11652 | struct breakpoint *t1; |
1042e4c0 | 11653 | unsigned int count; |
1042e4c0 SS |
11654 | |
11655 | if (args == 0 || *args == 0) | |
3e43a32a MS |
11656 | error (_("passcount command requires an " |
11657 | "argument (count + optional TP num)")); | |
1042e4c0 | 11658 | |
4a64f543 | 11659 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
11660 | |
11661 | while (*args && isspace ((int) *args)) | |
11662 | args++; | |
11663 | ||
11664 | if (*args && strncasecmp (args, "all", 3) == 0) | |
11665 | { | |
11666 | args += 3; /* Skip special argument "all". */ | |
1042e4c0 SS |
11667 | if (*args) |
11668 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 11669 | |
197f0a60 TT |
11670 | ALL_TRACEPOINTS (t1) |
11671 | { | |
11672 | trace_pass_set_count (t1, count, from_tty); | |
11673 | } | |
11674 | } | |
11675 | else if (*args == '\0') | |
1042e4c0 | 11676 | { |
197f0a60 | 11677 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 11678 | if (t1) |
197f0a60 TT |
11679 | trace_pass_set_count (t1, count, from_tty); |
11680 | } | |
11681 | else | |
11682 | { | |
11683 | struct get_number_or_range_state state; | |
11684 | ||
11685 | init_number_or_range (&state, args); | |
11686 | while (!state.finished) | |
1042e4c0 | 11687 | { |
197f0a60 TT |
11688 | t1 = get_tracepoint_by_number (&args, &state, 1); |
11689 | if (t1) | |
11690 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
11691 | } |
11692 | } | |
1042e4c0 SS |
11693 | } |
11694 | ||
11695 | struct breakpoint * | |
11696 | get_tracepoint (int num) | |
11697 | { | |
11698 | struct breakpoint *t; | |
11699 | ||
11700 | ALL_TRACEPOINTS (t) | |
11701 | if (t->number == num) | |
11702 | return t; | |
11703 | ||
11704 | return NULL; | |
11705 | } | |
11706 | ||
d5551862 SS |
11707 | /* Find the tracepoint with the given target-side number (which may be |
11708 | different from the tracepoint number after disconnecting and | |
11709 | reconnecting). */ | |
11710 | ||
11711 | struct breakpoint * | |
11712 | get_tracepoint_by_number_on_target (int num) | |
11713 | { | |
11714 | struct breakpoint *t; | |
11715 | ||
11716 | ALL_TRACEPOINTS (t) | |
11717 | if (t->number_on_target == num) | |
11718 | return t; | |
11719 | ||
11720 | return NULL; | |
11721 | } | |
11722 | ||
1042e4c0 | 11723 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
11724 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
11725 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 SS |
11726 | recent tracepoint (tracepoint_count) is returned. */ |
11727 | struct breakpoint * | |
197f0a60 TT |
11728 | get_tracepoint_by_number (char **arg, |
11729 | struct get_number_or_range_state *state, | |
11730 | int optional_p) | |
1042e4c0 SS |
11731 | { |
11732 | extern int tracepoint_count; | |
11733 | struct breakpoint *t; | |
11734 | int tpnum; | |
11735 | char *instring = arg == NULL ? NULL : *arg; | |
11736 | ||
197f0a60 TT |
11737 | if (state) |
11738 | { | |
11739 | gdb_assert (!state->finished); | |
11740 | tpnum = get_number_or_range (state); | |
11741 | } | |
11742 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
11743 | { |
11744 | if (optional_p) | |
11745 | tpnum = tracepoint_count; | |
11746 | else | |
11747 | error_no_arg (_("tracepoint number")); | |
11748 | } | |
11749 | else | |
197f0a60 | 11750 | tpnum = get_number (arg); |
1042e4c0 SS |
11751 | |
11752 | if (tpnum <= 0) | |
11753 | { | |
11754 | if (instring && *instring) | |
11755 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
11756 | instring); | |
11757 | else | |
3e43a32a MS |
11758 | printf_filtered (_("Tracepoint argument missing " |
11759 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
11760 | return NULL; |
11761 | } | |
11762 | ||
11763 | ALL_TRACEPOINTS (t) | |
11764 | if (t->number == tpnum) | |
11765 | { | |
11766 | return t; | |
11767 | } | |
11768 | ||
1042e4c0 SS |
11769 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
11770 | return NULL; | |
11771 | } | |
11772 | ||
6149aea9 PA |
11773 | /* Save information on user settable breakpoints (watchpoints, etc) to |
11774 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
11775 | on each breakpoint and only include the ones for which it returns | |
11776 | non-zero. */ | |
11777 | ||
1042e4c0 | 11778 | static void |
6149aea9 PA |
11779 | save_breakpoints (char *filename, int from_tty, |
11780 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
11781 | { |
11782 | struct breakpoint *tp; | |
6149aea9 | 11783 | int any = 0; |
a7bdde9e | 11784 | char *pathname; |
1042e4c0 | 11785 | struct cleanup *cleanup; |
a7bdde9e | 11786 | struct ui_file *fp; |
6149aea9 | 11787 | int extra_trace_bits = 0; |
1042e4c0 | 11788 | |
6149aea9 PA |
11789 | if (filename == 0 || *filename == 0) |
11790 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
11791 | |
11792 | /* See if we have anything to save. */ | |
6149aea9 | 11793 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11794 | { |
6149aea9 | 11795 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11796 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
11797 | continue; |
11798 | ||
11799 | /* If we have a filter, only save the breakpoints it accepts. */ | |
11800 | if (filter && !filter (tp)) | |
11801 | continue; | |
11802 | ||
11803 | any = 1; | |
11804 | ||
11805 | if (is_tracepoint (tp)) | |
11806 | { | |
11807 | extra_trace_bits = 1; | |
11808 | ||
11809 | /* We can stop searching. */ | |
11810 | break; | |
11811 | } | |
1042e4c0 | 11812 | } |
6149aea9 PA |
11813 | |
11814 | if (!any) | |
1042e4c0 | 11815 | { |
6149aea9 | 11816 | warning (_("Nothing to save.")); |
1042e4c0 SS |
11817 | return; |
11818 | } | |
11819 | ||
6149aea9 | 11820 | pathname = tilde_expand (filename); |
1042e4c0 | 11821 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 11822 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 11823 | if (!fp) |
6149aea9 PA |
11824 | error (_("Unable to open file '%s' for saving (%s)"), |
11825 | filename, safe_strerror (errno)); | |
a7bdde9e | 11826 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 11827 | |
6149aea9 PA |
11828 | if (extra_trace_bits) |
11829 | save_trace_state_variables (fp); | |
8bf6485c | 11830 | |
6149aea9 | 11831 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11832 | { |
6149aea9 | 11833 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11834 | if (!user_breakpoint_p (tp)) |
6149aea9 | 11835 | continue; |
8bf6485c | 11836 | |
6149aea9 PA |
11837 | /* If we have a filter, only save the breakpoints it accepts. */ |
11838 | if (filter && !filter (tp)) | |
11839 | continue; | |
11840 | ||
11841 | if (tp->ops != NULL) | |
11842 | (tp->ops->print_recreate) (tp, fp); | |
1042e4c0 SS |
11843 | else |
11844 | { | |
6149aea9 PA |
11845 | if (tp->type == bp_fast_tracepoint) |
11846 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
11847 | if (tp->type == bp_static_tracepoint) |
11848 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
11849 | else if (tp->type == bp_tracepoint) |
11850 | fprintf_unfiltered (fp, "trace"); | |
11851 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11852 | fprintf_unfiltered (fp, "tbreak"); | |
11853 | else if (tp->type == bp_breakpoint) | |
11854 | fprintf_unfiltered (fp, "break"); | |
11855 | else if (tp->type == bp_hardware_breakpoint | |
11856 | && tp->disposition == disp_del) | |
11857 | fprintf_unfiltered (fp, "thbreak"); | |
11858 | else if (tp->type == bp_hardware_breakpoint) | |
11859 | fprintf_unfiltered (fp, "hbreak"); | |
11860 | else if (tp->type == bp_watchpoint) | |
11861 | fprintf_unfiltered (fp, "watch"); | |
11862 | else if (tp->type == bp_hardware_watchpoint) | |
11863 | fprintf_unfiltered (fp, "watch"); | |
11864 | else if (tp->type == bp_read_watchpoint) | |
11865 | fprintf_unfiltered (fp, "rwatch"); | |
11866 | else if (tp->type == bp_access_watchpoint) | |
11867 | fprintf_unfiltered (fp, "awatch"); | |
11868 | else | |
11869 | internal_error (__FILE__, __LINE__, | |
11870 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11871 | ||
11872 | if (tp->exp_string) | |
11873 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
11874 | else if (tp->addr_string) | |
11875 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
11876 | else | |
11877 | { | |
11878 | char tmp[40]; | |
11879 | ||
11880 | sprintf_vma (tmp, tp->loc->address); | |
11881 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
11882 | } | |
1042e4c0 SS |
11883 | } |
11884 | ||
6149aea9 PA |
11885 | if (tp->thread != -1) |
11886 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
11887 | ||
11888 | if (tp->task != 0) | |
11889 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
11890 | |
11891 | fprintf_unfiltered (fp, "\n"); | |
11892 | ||
6149aea9 PA |
11893 | /* Note, we can't rely on tp->number for anything, as we can't |
11894 | assume the recreated breakpoint numbers will match. Use $bpnum | |
11895 | instead. */ | |
11896 | ||
11897 | if (tp->cond_string) | |
11898 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
11899 | ||
11900 | if (tp->ignore_count) | |
11901 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
11902 | ||
1042e4c0 | 11903 | if (tp->pass_count) |
a7bdde9e | 11904 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 11905 | |
a7bdde9e | 11906 | if (tp->commands) |
1042e4c0 | 11907 | { |
a7bdde9e VP |
11908 | volatile struct gdb_exception ex; |
11909 | ||
6149aea9 | 11910 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
11911 | |
11912 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 11913 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 11914 | { |
9add0f1b | 11915 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
11916 | } |
11917 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 11918 | |
a7bdde9e VP |
11919 | if (ex.reason < 0) |
11920 | throw_exception (ex); | |
1042e4c0 | 11921 | |
a7bdde9e | 11922 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 11923 | } |
6149aea9 PA |
11924 | |
11925 | if (tp->enable_state == bp_disabled) | |
11926 | fprintf_unfiltered (fp, "disable\n"); | |
11927 | ||
11928 | /* If this is a multi-location breakpoint, check if the locations | |
11929 | should be individually disabled. Watchpoint locations are | |
11930 | special, and not user visible. */ | |
11931 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
11932 | { | |
11933 | struct bp_location *loc; | |
11934 | int n = 1; | |
11935 | ||
11936 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
11937 | if (!loc->enabled) | |
11938 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
11939 | } | |
1042e4c0 | 11940 | } |
8bf6485c | 11941 | |
6149aea9 | 11942 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
11943 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
11944 | ||
1042e4c0 SS |
11945 | do_cleanups (cleanup); |
11946 | if (from_tty) | |
6149aea9 PA |
11947 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
11948 | } | |
11949 | ||
11950 | /* The `save breakpoints' command. */ | |
11951 | ||
11952 | static void | |
11953 | save_breakpoints_command (char *args, int from_tty) | |
11954 | { | |
11955 | save_breakpoints (args, from_tty, NULL); | |
11956 | } | |
11957 | ||
11958 | /* The `save tracepoints' command. */ | |
11959 | ||
11960 | static void | |
11961 | save_tracepoints_command (char *args, int from_tty) | |
11962 | { | |
11963 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
11964 | } |
11965 | ||
11966 | /* Create a vector of all tracepoints. */ | |
11967 | ||
11968 | VEC(breakpoint_p) * | |
eeae04df | 11969 | all_tracepoints (void) |
1042e4c0 SS |
11970 | { |
11971 | VEC(breakpoint_p) *tp_vec = 0; | |
11972 | struct breakpoint *tp; | |
11973 | ||
11974 | ALL_TRACEPOINTS (tp) | |
11975 | { | |
11976 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
11977 | } | |
11978 | ||
11979 | return tp_vec; | |
11980 | } | |
11981 | ||
c906108c | 11982 | \f |
4a64f543 MS |
11983 | /* This help string is used for the break, hbreak, tbreak and thbreak |
11984 | commands. It is defined as a macro to prevent duplication. | |
11985 | COMMAND should be a string constant containing the name of the | |
11986 | command. */ | |
31e2b00f AS |
11987 | #define BREAK_ARGS_HELP(command) \ |
11988 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
11989 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
11990 | If a line number is specified, break at start of code for that line.\n\ | |
11991 | If a function is specified, break at start of code for that function.\n\ | |
11992 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
11993 | With no LOCATION, uses current execution address of the selected\n\ |
11994 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
11995 | \n\ |
11996 | THREADNUM is the number from \"info threads\".\n\ | |
11997 | CONDITION is a boolean expression.\n\ | |
11998 | \n\ | |
d41c0fc8 PA |
11999 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
12000 | conditions are different.\n\ | |
31e2b00f AS |
12001 | \n\ |
12002 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
12003 | ||
44feb3ce TT |
12004 | /* List of subcommands for "catch". */ |
12005 | static struct cmd_list_element *catch_cmdlist; | |
12006 | ||
12007 | /* List of subcommands for "tcatch". */ | |
12008 | static struct cmd_list_element *tcatch_cmdlist; | |
12009 | ||
12010 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
12011 | lists, and pass some additional user data to the command function. */ | |
12012 | static void | |
12013 | add_catch_command (char *name, char *docstring, | |
12014 | void (*sfunc) (char *args, int from_tty, | |
12015 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
12016 | char **(*completer) (struct cmd_list_element *cmd, |
12017 | char *text, char *word), | |
44feb3ce TT |
12018 | void *user_data_catch, |
12019 | void *user_data_tcatch) | |
12020 | { | |
12021 | struct cmd_list_element *command; | |
12022 | ||
12023 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12024 | &catch_cmdlist); | |
12025 | set_cmd_sfunc (command, sfunc); | |
12026 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 12027 | set_cmd_completer (command, completer); |
44feb3ce TT |
12028 | |
12029 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12030 | &tcatch_cmdlist); | |
12031 | set_cmd_sfunc (command, sfunc); | |
12032 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 12033 | set_cmd_completer (command, completer); |
44feb3ce TT |
12034 | } |
12035 | ||
6c95b8df | 12036 | static void |
a79b8f6e | 12037 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 12038 | { |
6c95b8df PA |
12039 | inf->total_syscalls_count = 0; |
12040 | inf->any_syscall_count = 0; | |
12041 | VEC_free (int, inf->syscalls_counts); | |
12042 | } | |
12043 | ||
6149aea9 PA |
12044 | static void |
12045 | save_command (char *arg, int from_tty) | |
12046 | { | |
3e43a32a MS |
12047 | printf_unfiltered (_("\"save\" must be followed by " |
12048 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
12049 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
12050 | } | |
12051 | ||
84f4c1fe PM |
12052 | struct breakpoint * |
12053 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
12054 | void *data) | |
12055 | { | |
35df4500 | 12056 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 12057 | |
35df4500 | 12058 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
12059 | { |
12060 | if ((*callback) (b, data)) | |
12061 | return b; | |
12062 | } | |
12063 | ||
12064 | return NULL; | |
12065 | } | |
12066 | ||
c906108c | 12067 | void |
fba45db2 | 12068 | _initialize_breakpoint (void) |
c906108c SS |
12069 | { |
12070 | struct cmd_list_element *c; | |
12071 | ||
84acb35a | 12072 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 12073 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 12074 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 12075 | |
17450429 PP |
12076 | breakpoint_objfile_key = register_objfile_data (); |
12077 | ||
c906108c SS |
12078 | breakpoint_chain = 0; |
12079 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
12080 | before a breakpoint is set. */ | |
12081 | breakpoint_count = 0; | |
12082 | ||
1042e4c0 SS |
12083 | tracepoint_count = 0; |
12084 | ||
1bedd215 AC |
12085 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
12086 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
12087 | Usage is `ignore N COUNT'.")); | |
c906108c | 12088 | if (xdb_commands) |
c5aa993b | 12089 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 12090 | |
1bedd215 AC |
12091 | add_com ("commands", class_breakpoint, commands_command, _("\ |
12092 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
12093 | Give breakpoint number as argument after \"commands\".\n\ |
12094 | With no argument, the targeted breakpoint is the last one set.\n\ | |
12095 | The commands themselves follow starting on the next line.\n\ | |
12096 | Type a line containing \"end\" to indicate the end of them.\n\ | |
12097 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 12098 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 12099 | |
1bedd215 AC |
12100 | add_com ("condition", class_breakpoint, condition_command, _("\ |
12101 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 12102 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 12103 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 12104 | |
1bedd215 | 12105 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 12106 | Set a temporary breakpoint.\n\ |
c906108c SS |
12107 | Like \"break\" except the breakpoint is only temporary,\n\ |
12108 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
12109 | by using \"enable delete\" on the breakpoint number.\n\ |
12110 | \n" | |
12111 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 12112 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12113 | |
1bedd215 | 12114 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 12115 | Set a hardware assisted breakpoint.\n\ |
c906108c | 12116 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
12117 | some target hardware may not have this support.\n\ |
12118 | \n" | |
12119 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 12120 | set_cmd_completer (c, location_completer); |
c906108c | 12121 | |
1bedd215 | 12122 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 12123 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 12124 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
12125 | so it will be deleted when hit.\n\ |
12126 | \n" | |
12127 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 12128 | set_cmd_completer (c, location_completer); |
c906108c | 12129 | |
1bedd215 AC |
12130 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
12131 | Enable some breakpoints.\n\ | |
c906108c SS |
12132 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12133 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12134 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12135 | With a subcommand you can enable temporarily."), |
c906108c SS |
12136 | &enablelist, "enable ", 1, &cmdlist); |
12137 | if (xdb_commands) | |
1bedd215 AC |
12138 | add_com ("ab", class_breakpoint, enable_command, _("\ |
12139 | Enable some breakpoints.\n\ | |
c906108c SS |
12140 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12141 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12142 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12143 | With a subcommand you can enable temporarily.")); |
c906108c SS |
12144 | |
12145 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
12146 | ||
84951ab5 | 12147 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 12148 | Enable some breakpoints.\n\ |
c906108c SS |
12149 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12150 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12151 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 12152 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 12153 | |
1a966eab AC |
12154 | add_cmd ("once", no_class, enable_once_command, _("\ |
12155 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12156 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12157 | &enablebreaklist); |
12158 | ||
1a966eab AC |
12159 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12160 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12161 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12162 | &enablebreaklist); |
12163 | ||
1a966eab AC |
12164 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12165 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12166 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12167 | &enablelist); |
12168 | ||
1a966eab AC |
12169 | add_cmd ("once", no_class, enable_once_command, _("\ |
12170 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12171 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12172 | &enablelist); |
12173 | ||
1bedd215 AC |
12174 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
12175 | Disable some breakpoints.\n\ | |
c906108c SS |
12176 | Arguments are breakpoint numbers with spaces in between.\n\ |
12177 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12178 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
12179 | &disablelist, "disable ", 1, &cmdlist); |
12180 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
12181 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
12182 | if (xdb_commands) | |
1bedd215 AC |
12183 | add_com ("sb", class_breakpoint, disable_command, _("\ |
12184 | Disable some breakpoints.\n\ | |
c906108c SS |
12185 | Arguments are breakpoint numbers with spaces in between.\n\ |
12186 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12187 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 12188 | |
1a966eab AC |
12189 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
12190 | Disable some breakpoints.\n\ | |
c906108c SS |
12191 | Arguments are breakpoint numbers with spaces in between.\n\ |
12192 | To disable all breakpoints, give no argument.\n\ | |
12193 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 12194 | This command may be abbreviated \"disable\"."), |
c906108c SS |
12195 | &disablelist); |
12196 | ||
1bedd215 AC |
12197 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
12198 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12199 | Arguments are breakpoint numbers with spaces in between.\n\ |
12200 | To delete all breakpoints, give no argument.\n\ | |
12201 | \n\ | |
12202 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 12203 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
12204 | &deletelist, "delete ", 1, &cmdlist); |
12205 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 12206 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 12207 | if (xdb_commands) |
1bedd215 AC |
12208 | add_com ("db", class_breakpoint, delete_command, _("\ |
12209 | Delete some breakpoints.\n\ | |
c906108c | 12210 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 12211 | To delete all breakpoints, give no argument.\n")); |
c906108c | 12212 | |
1a966eab AC |
12213 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
12214 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12215 | Arguments are breakpoint numbers with spaces in between.\n\ |
12216 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 12217 | This command may be abbreviated \"delete\"."), |
c906108c SS |
12218 | &deletelist); |
12219 | ||
1bedd215 AC |
12220 | add_com ("clear", class_breakpoint, clear_command, _("\ |
12221 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
12222 | Argument may be line number, function name, or \"*\" and an address.\n\ |
12223 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
12224 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
12225 | If an address is specified, breakpoints at that address are cleared.\n\ |
12226 | \n\ | |
12227 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
12228 | is executing in.\n\ |
12229 | \n\ | |
1bedd215 | 12230 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 12231 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 12232 | |
1bedd215 | 12233 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
12234 | Set breakpoint at specified line or function.\n" |
12235 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 12236 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12237 | |
c906108c SS |
12238 | add_com_alias ("b", "break", class_run, 1); |
12239 | add_com_alias ("br", "break", class_run, 1); | |
12240 | add_com_alias ("bre", "break", class_run, 1); | |
12241 | add_com_alias ("brea", "break", class_run, 1); | |
12242 | ||
7681d515 PM |
12243 | if (xdb_commands) |
12244 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
12245 | |
12246 | if (dbx_commands) | |
12247 | { | |
1bedd215 AC |
12248 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
12249 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
12250 | &stoplist, "stop ", 1, &cmdlist); |
12251 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 12252 | _("Break in function or address."), &stoplist); |
c5aa993b | 12253 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 12254 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
12255 | add_com ("status", class_info, breakpoints_info, _("\ |
12256 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12257 | The \"Type\" column indicates one of:\n\ |
12258 | \tbreakpoint - normal breakpoint\n\ | |
12259 | \twatchpoint - watchpoint\n\ | |
12260 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12261 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12262 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12263 | address and file/line number respectively.\n\ |
12264 | \n\ | |
12265 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12266 | are set to the address of the last breakpoint listed unless the command\n\ |
12267 | is prefixed with \"server \".\n\n\ | |
c906108c | 12268 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12269 | breakpoint set.")); |
c906108c SS |
12270 | } |
12271 | ||
1bedd215 | 12272 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 12273 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
12274 | The \"Type\" column indicates one of:\n\ |
12275 | \tbreakpoint - normal breakpoint\n\ | |
12276 | \twatchpoint - watchpoint\n\ | |
12277 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12278 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12279 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12280 | address and file/line number respectively.\n\ |
12281 | \n\ | |
12282 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12283 | are set to the address of the last breakpoint listed unless the command\n\ |
12284 | is prefixed with \"server \".\n\n\ | |
c906108c | 12285 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12286 | breakpoint set.")); |
c906108c | 12287 | |
6b04bdb7 MS |
12288 | add_info_alias ("b", "breakpoints", 1); |
12289 | ||
c906108c | 12290 | if (xdb_commands) |
1bedd215 AC |
12291 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
12292 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12293 | The \"Type\" column indicates one of:\n\ |
12294 | \tbreakpoint - normal breakpoint\n\ | |
12295 | \twatchpoint - watchpoint\n\ | |
12296 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12297 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12298 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12299 | address and file/line number respectively.\n\ |
12300 | \n\ | |
12301 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12302 | are set to the address of the last breakpoint listed unless the command\n\ |
12303 | is prefixed with \"server \".\n\n\ | |
c906108c | 12304 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12305 | breakpoint set.")); |
c906108c | 12306 | |
1a966eab AC |
12307 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
12308 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12309 | The \"Type\" column indicates one of:\n\ |
12310 | \tbreakpoint - normal breakpoint\n\ | |
12311 | \twatchpoint - watchpoint\n\ | |
12312 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
12313 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
12314 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
12315 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
12316 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
12317 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
12318 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
12319 | address and file/line number respectively.\n\ |
12320 | \n\ | |
12321 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12322 | are set to the address of the last breakpoint listed unless the command\n\ |
12323 | is prefixed with \"server \".\n\n\ | |
c906108c | 12324 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 12325 | breakpoint set."), |
c906108c SS |
12326 | &maintenanceinfolist); |
12327 | ||
44feb3ce TT |
12328 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
12329 | Set catchpoints to catch events."), | |
12330 | &catch_cmdlist, "catch ", | |
12331 | 0/*allow-unknown*/, &cmdlist); | |
12332 | ||
12333 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
12334 | Set temporary catchpoints to catch events."), | |
12335 | &tcatch_cmdlist, "tcatch ", | |
12336 | 0/*allow-unknown*/, &cmdlist); | |
12337 | ||
12338 | /* Add catch and tcatch sub-commands. */ | |
12339 | add_catch_command ("catch", _("\ | |
12340 | Catch an exception, when caught.\n\ | |
12341 | With an argument, catch only exceptions with the given name."), | |
12342 | catch_catch_command, | |
a96d9b2e | 12343 | NULL, |
44feb3ce TT |
12344 | CATCH_PERMANENT, |
12345 | CATCH_TEMPORARY); | |
12346 | add_catch_command ("throw", _("\ | |
12347 | Catch an exception, when thrown.\n\ | |
12348 | With an argument, catch only exceptions with the given name."), | |
12349 | catch_throw_command, | |
a96d9b2e | 12350 | NULL, |
44feb3ce TT |
12351 | CATCH_PERMANENT, |
12352 | CATCH_TEMPORARY); | |
12353 | add_catch_command ("fork", _("Catch calls to fork."), | |
12354 | catch_fork_command_1, | |
a96d9b2e | 12355 | NULL, |
44feb3ce TT |
12356 | (void *) (uintptr_t) catch_fork_permanent, |
12357 | (void *) (uintptr_t) catch_fork_temporary); | |
12358 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
12359 | catch_fork_command_1, | |
a96d9b2e | 12360 | NULL, |
44feb3ce TT |
12361 | (void *) (uintptr_t) catch_vfork_permanent, |
12362 | (void *) (uintptr_t) catch_vfork_temporary); | |
12363 | add_catch_command ("exec", _("Catch calls to exec."), | |
12364 | catch_exec_command_1, | |
a96d9b2e SDJ |
12365 | NULL, |
12366 | CATCH_PERMANENT, | |
12367 | CATCH_TEMPORARY); | |
12368 | add_catch_command ("syscall", _("\ | |
12369 | Catch system calls by their names and/or numbers.\n\ | |
12370 | Arguments say which system calls to catch. If no arguments\n\ | |
12371 | are given, every system call will be caught.\n\ | |
12372 | Arguments, if given, should be one or more system call names\n\ | |
12373 | (if your system supports that), or system call numbers."), | |
12374 | catch_syscall_command_1, | |
12375 | catch_syscall_completer, | |
44feb3ce TT |
12376 | CATCH_PERMANENT, |
12377 | CATCH_TEMPORARY); | |
44feb3ce TT |
12378 | add_catch_command ("exception", _("\ |
12379 | Catch Ada exceptions, when raised.\n\ | |
12380 | With an argument, catch only exceptions with the given name."), | |
12381 | catch_ada_exception_command, | |
a96d9b2e | 12382 | NULL, |
44feb3ce TT |
12383 | CATCH_PERMANENT, |
12384 | CATCH_TEMPORARY); | |
12385 | add_catch_command ("assert", _("\ | |
12386 | Catch failed Ada assertions, when raised.\n\ | |
12387 | With an argument, catch only exceptions with the given name."), | |
12388 | catch_assert_command, | |
a96d9b2e | 12389 | NULL, |
44feb3ce TT |
12390 | CATCH_PERMANENT, |
12391 | CATCH_TEMPORARY); | |
c5aa993b | 12392 | |
1bedd215 AC |
12393 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
12394 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12395 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 12396 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12397 | an expression changes.\n\ |
12398 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12399 | the memory to which it refers.")); | |
65d12d83 | 12400 | set_cmd_completer (c, expression_completer); |
c906108c | 12401 | |
1bedd215 AC |
12402 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
12403 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 12404 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 12405 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12406 | an expression is read.\n\ |
12407 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12408 | the memory to which it refers.")); | |
65d12d83 | 12409 | set_cmd_completer (c, expression_completer); |
c906108c | 12410 | |
1bedd215 AC |
12411 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
12412 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12413 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 12414 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12415 | an expression is either read or written.\n\ |
12416 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12417 | the memory to which it refers.")); | |
65d12d83 | 12418 | set_cmd_completer (c, expression_completer); |
c906108c | 12419 | |
d77f58be | 12420 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 12421 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 12422 | |
920d2a44 AC |
12423 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
12424 | respond to changes - contrary to the description. */ | |
85c07804 AC |
12425 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
12426 | &can_use_hw_watchpoints, _("\ | |
12427 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
12428 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
12429 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
12430 | such is available. (However, any hardware watchpoints that were\n\ | |
12431 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
12432 | hardware.)"), |
12433 | NULL, | |
920d2a44 | 12434 | show_can_use_hw_watchpoints, |
85c07804 | 12435 | &setlist, &showlist); |
c906108c SS |
12436 | |
12437 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 12438 | |
1042e4c0 SS |
12439 | /* Tracepoint manipulation commands. */ |
12440 | ||
12441 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
12442 | Set a tracepoint at specified line or function.\n\ | |
12443 | \n" | |
12444 | BREAK_ARGS_HELP ("trace") "\n\ | |
12445 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12446 | set_cmd_completer (c, location_completer); | |
12447 | ||
12448 | add_com_alias ("tp", "trace", class_alias, 0); | |
12449 | add_com_alias ("tr", "trace", class_alias, 1); | |
12450 | add_com_alias ("tra", "trace", class_alias, 1); | |
12451 | add_com_alias ("trac", "trace", class_alias, 1); | |
12452 | ||
7a697b8d SS |
12453 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
12454 | Set a fast tracepoint at specified line or function.\n\ | |
12455 | \n" | |
12456 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
12457 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12458 | set_cmd_completer (c, location_completer); | |
12459 | ||
0fb4aa4b PA |
12460 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
12461 | Set a static tracepoint at specified line, function or marker.\n\ | |
12462 | \n\ | |
12463 | strace [LOCATION] [if CONDITION]\n\ | |
12464 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
12465 | or -m MARKER_ID.\n\ | |
12466 | If a line number is specified, probe the marker at start of code\n\ | |
12467 | for that line. If a function is specified, probe the marker at start\n\ | |
12468 | of code for that function. If an address is specified, probe the marker\n\ | |
12469 | at that exact address. If a marker id is specified, probe the marker\n\ | |
12470 | with that name. With no LOCATION, uses current execution address of\n\ | |
12471 | the selected stack frame.\n\ | |
12472 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
12473 | This collects arbitrary user data passed in the probe point call to the\n\ | |
12474 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
12475 | by printing the $_sdata variable like any other convenience variable.\n\ | |
12476 | \n\ | |
12477 | CONDITION is a boolean expression.\n\ | |
12478 | \n\ | |
d41c0fc8 PA |
12479 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
12480 | conditions are different.\n\ | |
0fb4aa4b PA |
12481 | \n\ |
12482 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
12483 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12484 | set_cmd_completer (c, location_completer); | |
12485 | ||
1042e4c0 | 12486 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 12487 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
12488 | Convenience variable \"$tpnum\" contains the number of the\n\ |
12489 | last tracepoint set.")); | |
12490 | ||
12491 | add_info_alias ("tp", "tracepoints", 1); | |
12492 | ||
12493 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
12494 | Delete specified tracepoints.\n\ | |
12495 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12496 | No argument means delete all tracepoints."), | |
12497 | &deletelist); | |
12498 | ||
12499 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
12500 | Disable specified tracepoints.\n\ | |
12501 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12502 | No argument means disable all tracepoints."), | |
12503 | &disablelist); | |
12504 | deprecate_cmd (c, "disable"); | |
12505 | ||
12506 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
12507 | Enable specified tracepoints.\n\ | |
12508 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12509 | No argument means enable all tracepoints."), | |
12510 | &enablelist); | |
12511 | deprecate_cmd (c, "enable"); | |
12512 | ||
12513 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
12514 | Set the passcount for a tracepoint.\n\ | |
12515 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
12516 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
12517 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
12518 | ||
6149aea9 PA |
12519 | add_prefix_cmd ("save", class_breakpoint, save_command, |
12520 | _("Save breakpoint definitions as a script."), | |
12521 | &save_cmdlist, "save ", | |
12522 | 0/*allow-unknown*/, &cmdlist); | |
12523 | ||
12524 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
12525 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 12526 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
12527 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
12528 | session to restore them."), | |
12529 | &save_cmdlist); | |
12530 | set_cmd_completer (c, filename_completer); | |
12531 | ||
12532 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 12533 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
12534 | Use the 'source' command in another debug session to restore them."), |
12535 | &save_cmdlist); | |
1042e4c0 SS |
12536 | set_cmd_completer (c, filename_completer); |
12537 | ||
6149aea9 PA |
12538 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
12539 | deprecate_cmd (c, "save tracepoints"); | |
12540 | ||
1bedd215 | 12541 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12542 | Breakpoint specific settings\n\ |
12543 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12544 | pending breakpoint behavior"), |
fa8d40ab JJ |
12545 | &breakpoint_set_cmdlist, "set breakpoint ", |
12546 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 12547 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12548 | Breakpoint specific settings\n\ |
12549 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12550 | pending breakpoint behavior"), |
fa8d40ab JJ |
12551 | &breakpoint_show_cmdlist, "show breakpoint ", |
12552 | 0/*allow-unknown*/, &showlist); | |
12553 | ||
7915a72c AC |
12554 | add_setshow_auto_boolean_cmd ("pending", no_class, |
12555 | &pending_break_support, _("\ | |
12556 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
12557 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
12558 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
12559 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
12560 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 12561 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 12562 | NULL, |
920d2a44 | 12563 | show_pending_break_support, |
6e1d7d6c AC |
12564 | &breakpoint_set_cmdlist, |
12565 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
12566 | |
12567 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
12568 | |
12569 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
12570 | &automatic_hardware_breakpoints, _("\ | |
12571 | Set automatic usage of hardware breakpoints."), _("\ | |
12572 | Show automatic usage of hardware breakpoints."), _("\ | |
12573 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
12574 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
12575 | a warning will be emitted for such breakpoints."), | |
12576 | NULL, | |
12577 | show_automatic_hardware_breakpoints, | |
12578 | &breakpoint_set_cmdlist, | |
12579 | &breakpoint_show_cmdlist); | |
74960c60 | 12580 | |
33e5cbd6 PA |
12581 | add_setshow_enum_cmd ("always-inserted", class_support, |
12582 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
12583 | Set mode for inserting breakpoints."), _("\ |
12584 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
12585 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
12586 | resumed, and removed when execution stops. When this mode is on,\n\ | |
12587 | breakpoints are inserted immediately and removed only when the user\n\ | |
12588 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
12589 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
12590 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
12591 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
12592 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
12593 | NULL, |
12594 | &show_always_inserted_mode, | |
12595 | &breakpoint_set_cmdlist, | |
12596 | &breakpoint_show_cmdlist); | |
765dc015 VP |
12597 | |
12598 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
12599 | |
12600 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 12601 | } |