| 1 | /* Everything about breakpoints, for GDB. |
| 2 | |
| 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
| 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
| 5 | 2008, 2009, 2010 Free Software Foundation, Inc. |
| 6 | |
| 7 | This file is part of GDB. |
| 8 | |
| 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 |
| 11 | the Free Software Foundation; either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 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. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "arch-utils.h" |
| 24 | #include <ctype.h> |
| 25 | #include "hashtab.h" |
| 26 | #include "symtab.h" |
| 27 | #include "frame.h" |
| 28 | #include "breakpoint.h" |
| 29 | #include "tracepoint.h" |
| 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" |
| 45 | #include "source.h" |
| 46 | #include "linespec.h" |
| 47 | #include "completer.h" |
| 48 | #include "gdb.h" |
| 49 | #include "ui-out.h" |
| 50 | #include "cli/cli-script.h" |
| 51 | #include "gdb_assert.h" |
| 52 | #include "block.h" |
| 53 | #include "solib.h" |
| 54 | #include "solist.h" |
| 55 | #include "observer.h" |
| 56 | #include "exceptions.h" |
| 57 | #include "memattr.h" |
| 58 | #include "ada-lang.h" |
| 59 | #include "top.h" |
| 60 | #include "wrapper.h" |
| 61 | #include "valprint.h" |
| 62 | #include "jit.h" |
| 63 | #include "xml-syscall.h" |
| 64 | |
| 65 | /* readline include files */ |
| 66 | #include "readline/readline.h" |
| 67 | #include "readline/history.h" |
| 68 | |
| 69 | /* readline defines this. */ |
| 70 | #undef savestring |
| 71 | |
| 72 | #include "mi/mi-common.h" |
| 73 | |
| 74 | /* Arguments to pass as context to some catch command handlers. */ |
| 75 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) |
| 76 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) |
| 77 | |
| 78 | /* Prototypes for local functions. */ |
| 79 | |
| 80 | static void enable_delete_command (char *, int); |
| 81 | |
| 82 | static void enable_once_command (char *, int); |
| 83 | |
| 84 | static void disable_command (char *, int); |
| 85 | |
| 86 | static void enable_command (char *, int); |
| 87 | |
| 88 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
| 89 | void *), |
| 90 | void *); |
| 91 | |
| 92 | static void ignore_command (char *, int); |
| 93 | |
| 94 | static int breakpoint_re_set_one (void *); |
| 95 | |
| 96 | static void clear_command (char *, int); |
| 97 | |
| 98 | static void catch_command (char *, int); |
| 99 | |
| 100 | static void watch_command (char *, int); |
| 101 | |
| 102 | static int can_use_hardware_watchpoint (struct value *); |
| 103 | |
| 104 | static void break_command_1 (char *, int, int); |
| 105 | |
| 106 | static void mention (struct breakpoint *); |
| 107 | |
| 108 | /* This function is used in gdbtk sources and thus can not be made static. */ |
| 109 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
| 110 | struct symtab_and_line, |
| 111 | enum bptype); |
| 112 | |
| 113 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
| 114 | |
| 115 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 116 | CORE_ADDR bpaddr, |
| 117 | enum bptype bptype); |
| 118 | |
| 119 | static void describe_other_breakpoints (struct gdbarch *, |
| 120 | struct program_space *, CORE_ADDR, |
| 121 | struct obj_section *, int); |
| 122 | |
| 123 | static int breakpoint_address_match (struct address_space *aspace1, |
| 124 | CORE_ADDR addr1, |
| 125 | struct address_space *aspace2, |
| 126 | CORE_ADDR addr2); |
| 127 | |
| 128 | static int watchpoint_locations_match (struct bp_location *loc1, |
| 129 | struct bp_location *loc2); |
| 130 | |
| 131 | static void breakpoints_info (char *, int); |
| 132 | |
| 133 | static void watchpoints_info (char *, int); |
| 134 | |
| 135 | static int breakpoint_1 (int, int, int (*) (const struct breakpoint *)); |
| 136 | |
| 137 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
| 138 | |
| 139 | static int breakpoint_cond_eval (void *); |
| 140 | |
| 141 | static void cleanup_executing_breakpoints (void *); |
| 142 | |
| 143 | static void commands_command (char *, int); |
| 144 | |
| 145 | static void condition_command (char *, int); |
| 146 | |
| 147 | static int get_number_trailer (char **, int); |
| 148 | |
| 149 | typedef enum |
| 150 | { |
| 151 | mark_inserted, |
| 152 | mark_uninserted |
| 153 | } |
| 154 | insertion_state_t; |
| 155 | |
| 156 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
| 157 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
| 158 | |
| 159 | static enum print_stop_action print_it_typical (bpstat); |
| 160 | |
| 161 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
| 162 | |
| 163 | static int watchpoint_check (void *); |
| 164 | |
| 165 | static void maintenance_info_breakpoints (char *, int); |
| 166 | |
| 167 | static int hw_breakpoint_used_count (void); |
| 168 | |
| 169 | static int hw_watchpoint_used_count (enum bptype, int *); |
| 170 | |
| 171 | static void hbreak_command (char *, int); |
| 172 | |
| 173 | static void thbreak_command (char *, int); |
| 174 | |
| 175 | static void watch_command_1 (char *, int, int); |
| 176 | |
| 177 | static void rwatch_command (char *, int); |
| 178 | |
| 179 | static void awatch_command (char *, int); |
| 180 | |
| 181 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
| 182 | |
| 183 | static void stop_command (char *arg, int from_tty); |
| 184 | |
| 185 | static void stopin_command (char *arg, int from_tty); |
| 186 | |
| 187 | static void stopat_command (char *arg, int from_tty); |
| 188 | |
| 189 | static char *ep_parse_optional_if_clause (char **arg); |
| 190 | |
| 191 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
| 192 | char *arg, int tempflag, int from_tty); |
| 193 | |
| 194 | static void tcatch_command (char *arg, int from_tty); |
| 195 | |
| 196 | static void ep_skip_leading_whitespace (char **s); |
| 197 | |
| 198 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
| 199 | CORE_ADDR pc); |
| 200 | |
| 201 | static void free_bp_location (struct bp_location *loc); |
| 202 | |
| 203 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
| 204 | |
| 205 | static void update_global_location_list (int); |
| 206 | |
| 207 | static void update_global_location_list_nothrow (int); |
| 208 | |
| 209 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
| 210 | |
| 211 | static int is_watchpoint (const struct breakpoint *bpt); |
| 212 | |
| 213 | static void insert_breakpoint_locations (void); |
| 214 | |
| 215 | static int syscall_catchpoint_p (struct breakpoint *b); |
| 216 | |
| 217 | static void tracepoints_info (char *, int); |
| 218 | |
| 219 | static void delete_trace_command (char *, int); |
| 220 | |
| 221 | static void enable_trace_command (char *, int); |
| 222 | |
| 223 | static void disable_trace_command (char *, int); |
| 224 | |
| 225 | static void trace_pass_command (char *, int); |
| 226 | |
| 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 | } |
| 243 | |
| 244 | /* Flag indicating that a command has proceeded the inferior past the |
| 245 | current breakpoint. */ |
| 246 | |
| 247 | static int breakpoint_proceeded; |
| 248 | |
| 249 | static const char * |
| 250 | bpdisp_text (enum bpdisp disp) |
| 251 | { |
| 252 | /* NOTE: the following values are a part of MI protocol and represent |
| 253 | values of 'disp' field returned when inferior stops at a breakpoint. */ |
| 254 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; |
| 255 | return bpdisps[(int) disp]; |
| 256 | } |
| 257 | |
| 258 | /* Prototypes for exported functions. */ |
| 259 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
| 260 | if such is available. */ |
| 261 | static int can_use_hw_watchpoints; |
| 262 | |
| 263 | static void |
| 264 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, |
| 265 | struct cmd_list_element *c, |
| 266 | const char *value) |
| 267 | { |
| 268 | fprintf_filtered (file, _("\ |
| 269 | Debugger's willingness to use watchpoint hardware is %s.\n"), |
| 270 | value); |
| 271 | } |
| 272 | |
| 273 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
| 274 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints |
| 275 | for unrecognized breakpoint locations. |
| 276 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
| 277 | static enum auto_boolean pending_break_support; |
| 278 | static void |
| 279 | show_pending_break_support (struct ui_file *file, int from_tty, |
| 280 | struct cmd_list_element *c, |
| 281 | const char *value) |
| 282 | { |
| 283 | fprintf_filtered (file, _("\ |
| 284 | Debugger's behavior regarding pending breakpoints is %s.\n"), |
| 285 | value); |
| 286 | } |
| 287 | |
| 288 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
| 289 | set with "break" but falling in read-only memory. |
| 290 | If 0, gdb will warn about such breakpoints, but won't automatically |
| 291 | use hardware breakpoints. */ |
| 292 | static int automatic_hardware_breakpoints; |
| 293 | static void |
| 294 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, |
| 295 | struct cmd_list_element *c, |
| 296 | const char *value) |
| 297 | { |
| 298 | fprintf_filtered (file, _("\ |
| 299 | Automatic usage of hardware breakpoints is %s.\n"), |
| 300 | value); |
| 301 | } |
| 302 | |
| 303 | /* If on, gdb will keep breakpoints inserted even as inferior is |
| 304 | stopped, and immediately insert any new breakpoints. If off, gdb |
| 305 | will insert breakpoints into inferior only when resuming it, and |
| 306 | will remove breakpoints upon stop. If auto, GDB will behave as ON |
| 307 | if in non-stop mode, and as OFF if all-stop mode.*/ |
| 308 | |
| 309 | static const char always_inserted_auto[] = "auto"; |
| 310 | static const char always_inserted_on[] = "on"; |
| 311 | static const char always_inserted_off[] = "off"; |
| 312 | static const char *always_inserted_enums[] = { |
| 313 | always_inserted_auto, |
| 314 | always_inserted_off, |
| 315 | always_inserted_on, |
| 316 | NULL |
| 317 | }; |
| 318 | static const char *always_inserted_mode = always_inserted_auto; |
| 319 | static void |
| 320 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
| 321 | struct cmd_list_element *c, const char *value) |
| 322 | { |
| 323 | if (always_inserted_mode == always_inserted_auto) |
| 324 | fprintf_filtered (file, _("\ |
| 325 | Always inserted breakpoint mode is %s (currently %s).\n"), |
| 326 | value, |
| 327 | breakpoints_always_inserted_mode () ? "on" : "off"); |
| 328 | else |
| 329 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); |
| 330 | } |
| 331 | |
| 332 | int |
| 333 | breakpoints_always_inserted_mode (void) |
| 334 | { |
| 335 | return (always_inserted_mode == always_inserted_on |
| 336 | || (always_inserted_mode == always_inserted_auto && non_stop)); |
| 337 | } |
| 338 | |
| 339 | void _initialize_breakpoint (void); |
| 340 | |
| 341 | /* Are we executing breakpoint commands? */ |
| 342 | static int executing_breakpoint_commands; |
| 343 | |
| 344 | /* Are overlay event breakpoints enabled? */ |
| 345 | static int overlay_events_enabled; |
| 346 | |
| 347 | /* Walk the following statement or block through all breakpoints. |
| 348 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current |
| 349 | breakpoint. */ |
| 350 | |
| 351 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
| 352 | |
| 353 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
| 354 | for (B = breakpoint_chain; \ |
| 355 | B ? (TMP=B->next, 1): 0; \ |
| 356 | B = TMP) |
| 357 | |
| 358 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
| 359 | provided so update_global_location_list must not be called while executing |
| 360 | the block of ALL_BP_LOCATIONS. */ |
| 361 | |
| 362 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
| 363 | for (BP_TMP = bp_location; \ |
| 364 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ |
| 365 | BP_TMP++) |
| 366 | |
| 367 | /* Iterator for tracepoints only. */ |
| 368 | |
| 369 | #define ALL_TRACEPOINTS(B) \ |
| 370 | for (B = breakpoint_chain; B; B = B->next) \ |
| 371 | if (is_tracepoint (B)) |
| 372 | |
| 373 | /* Chains of all breakpoints defined. */ |
| 374 | |
| 375 | struct breakpoint *breakpoint_chain; |
| 376 | |
| 377 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
| 378 | |
| 379 | static struct bp_location **bp_location; |
| 380 | |
| 381 | /* Number of elements of BP_LOCATION. */ |
| 382 | |
| 383 | static unsigned bp_location_count; |
| 384 | |
| 385 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS |
| 386 | for the current elements of BP_LOCATION which get a valid result from |
| 387 | bp_location_has_shadow. You can use it for roughly limiting the subrange of |
| 388 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ |
| 389 | |
| 390 | static CORE_ADDR bp_location_placed_address_before_address_max; |
| 391 | |
| 392 | /* Maximum offset plus alignment between |
| 393 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for |
| 394 | the current elements of BP_LOCATION which get a valid result from |
| 395 | bp_location_has_shadow. You can use it for roughly limiting the subrange of |
| 396 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ |
| 397 | |
| 398 | static CORE_ADDR bp_location_shadow_len_after_address_max; |
| 399 | |
| 400 | /* The locations that no longer correspond to any breakpoint, |
| 401 | unlinked from bp_location array, but for which a hit |
| 402 | may still be reported by a target. */ |
| 403 | VEC(bp_location_p) *moribund_locations = NULL; |
| 404 | |
| 405 | /* Number of last breakpoint made. */ |
| 406 | |
| 407 | static int breakpoint_count; |
| 408 | |
| 409 | /* The value of `breakpoint_count' before the last command that |
| 410 | created breakpoints. If the last (break-like) command created more |
| 411 | than one breakpoint, then the difference between BREAKPOINT_COUNT |
| 412 | and PREV_BREAKPOINT_COUNT is more than one. */ |
| 413 | static int prev_breakpoint_count; |
| 414 | |
| 415 | /* Number of last tracepoint made. */ |
| 416 | |
| 417 | static int tracepoint_count; |
| 418 | |
| 419 | static struct cmd_list_element *breakpoint_set_cmdlist; |
| 420 | static struct cmd_list_element *breakpoint_show_cmdlist; |
| 421 | static struct cmd_list_element *save_cmdlist; |
| 422 | |
| 423 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
| 424 | static int |
| 425 | breakpoint_enabled (struct breakpoint *b) |
| 426 | { |
| 427 | return (b->enable_state == bp_enabled); |
| 428 | } |
| 429 | |
| 430 | /* Set breakpoint count to NUM. */ |
| 431 | |
| 432 | static void |
| 433 | set_breakpoint_count (int num) |
| 434 | { |
| 435 | prev_breakpoint_count = breakpoint_count; |
| 436 | breakpoint_count = num; |
| 437 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
| 438 | } |
| 439 | |
| 440 | /* Used by `start_rbreak_breakpoints' below, to record the current |
| 441 | breakpoint count before "rbreak" creates any breakpoint. */ |
| 442 | static int rbreak_start_breakpoint_count; |
| 443 | |
| 444 | /* Called at the start an "rbreak" command to record the first |
| 445 | breakpoint made. */ |
| 446 | |
| 447 | void |
| 448 | start_rbreak_breakpoints (void) |
| 449 | { |
| 450 | rbreak_start_breakpoint_count = breakpoint_count; |
| 451 | } |
| 452 | |
| 453 | /* Called at the end of an "rbreak" command to record the last |
| 454 | breakpoint made. */ |
| 455 | |
| 456 | void |
| 457 | end_rbreak_breakpoints (void) |
| 458 | { |
| 459 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
| 460 | } |
| 461 | |
| 462 | /* Used in run_command to zero the hit count when a new run starts. */ |
| 463 | |
| 464 | void |
| 465 | clear_breakpoint_hit_counts (void) |
| 466 | { |
| 467 | struct breakpoint *b; |
| 468 | |
| 469 | ALL_BREAKPOINTS (b) |
| 470 | b->hit_count = 0; |
| 471 | } |
| 472 | |
| 473 | /* Allocate a new counted_command_line with reference count of 1. |
| 474 | The new structure owns COMMANDS. */ |
| 475 | |
| 476 | static struct counted_command_line * |
| 477 | alloc_counted_command_line (struct command_line *commands) |
| 478 | { |
| 479 | struct counted_command_line *result |
| 480 | = xmalloc (sizeof (struct counted_command_line)); |
| 481 | result->refc = 1; |
| 482 | result->commands = commands; |
| 483 | return result; |
| 484 | } |
| 485 | |
| 486 | /* Increment reference count. This does nothing if CMD is NULL. */ |
| 487 | |
| 488 | static void |
| 489 | incref_counted_command_line (struct counted_command_line *cmd) |
| 490 | { |
| 491 | if (cmd) |
| 492 | ++cmd->refc; |
| 493 | } |
| 494 | |
| 495 | /* Decrement reference count. If the reference count reaches 0, |
| 496 | destroy the counted_command_line. Sets *CMDP to NULL. This does |
| 497 | nothing if *CMDP is NULL. */ |
| 498 | |
| 499 | static void |
| 500 | decref_counted_command_line (struct counted_command_line **cmdp) |
| 501 | { |
| 502 | if (*cmdp) |
| 503 | { |
| 504 | if (--(*cmdp)->refc == 0) |
| 505 | { |
| 506 | free_command_lines (&(*cmdp)->commands); |
| 507 | xfree (*cmdp); |
| 508 | } |
| 509 | *cmdp = NULL; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | /* A cleanup function that calls decref_counted_command_line. */ |
| 514 | |
| 515 | static void |
| 516 | do_cleanup_counted_command_line (void *arg) |
| 517 | { |
| 518 | decref_counted_command_line (arg); |
| 519 | } |
| 520 | |
| 521 | /* Create a cleanup that calls decref_counted_command_line on the |
| 522 | argument. */ |
| 523 | |
| 524 | static struct cleanup * |
| 525 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) |
| 526 | { |
| 527 | return make_cleanup (do_cleanup_counted_command_line, cmdp); |
| 528 | } |
| 529 | |
| 530 | /* Default address, symtab and line to put a breakpoint at |
| 531 | for "break" command with no arg. |
| 532 | if default_breakpoint_valid is zero, the other three are |
| 533 | not valid, and "break" with no arg is an error. |
| 534 | |
| 535 | This set by print_stack_frame, which calls set_default_breakpoint. */ |
| 536 | |
| 537 | int default_breakpoint_valid; |
| 538 | CORE_ADDR default_breakpoint_address; |
| 539 | struct symtab *default_breakpoint_symtab; |
| 540 | int default_breakpoint_line; |
| 541 | struct program_space *default_breakpoint_pspace; |
| 542 | |
| 543 | \f |
| 544 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. |
| 545 | Advance *PP after the string and any trailing whitespace. |
| 546 | |
| 547 | Currently the string can either be a number or "$" followed by the name |
| 548 | of a convenience variable. Making it an expression wouldn't work well |
| 549 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
| 550 | |
| 551 | If the string is a NULL pointer, that denotes the last breakpoint. |
| 552 | |
| 553 | TRAILER is a character which can be found after the number; most |
| 554 | commonly this is `-'. If you don't want a trailer, use \0. */ |
| 555 | static int |
| 556 | get_number_trailer (char **pp, int trailer) |
| 557 | { |
| 558 | int retval = 0; /* default */ |
| 559 | char *p = *pp; |
| 560 | |
| 561 | if (p == NULL) |
| 562 | /* Empty line means refer to the last breakpoint. */ |
| 563 | return breakpoint_count; |
| 564 | else if (*p == '$') |
| 565 | { |
| 566 | /* Make a copy of the name, so we can null-terminate it |
| 567 | to pass to lookup_internalvar(). */ |
| 568 | char *varname; |
| 569 | char *start = ++p; |
| 570 | LONGEST val; |
| 571 | |
| 572 | while (isalnum (*p) || *p == '_') |
| 573 | p++; |
| 574 | varname = (char *) alloca (p - start + 1); |
| 575 | strncpy (varname, start, p - start); |
| 576 | varname[p - start] = '\0'; |
| 577 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
| 578 | retval = (int) val; |
| 579 | else |
| 580 | { |
| 581 | printf_filtered (_("Convenience variable must have integer value.\n")); |
| 582 | retval = 0; |
| 583 | } |
| 584 | } |
| 585 | else |
| 586 | { |
| 587 | if (*p == '-') |
| 588 | ++p; |
| 589 | while (*p >= '0' && *p <= '9') |
| 590 | ++p; |
| 591 | if (p == *pp) |
| 592 | /* There is no number here. (e.g. "cond a == b"). */ |
| 593 | { |
| 594 | /* Skip non-numeric token */ |
| 595 | while (*p && !isspace((int) *p)) |
| 596 | ++p; |
| 597 | /* Return zero, which caller must interpret as error. */ |
| 598 | retval = 0; |
| 599 | } |
| 600 | else |
| 601 | retval = atoi (*pp); |
| 602 | } |
| 603 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) |
| 604 | { |
| 605 | /* Trailing junk: return 0 and let caller print error msg. */ |
| 606 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) |
| 607 | ++p; |
| 608 | retval = 0; |
| 609 | } |
| 610 | while (isspace (*p)) |
| 611 | p++; |
| 612 | *pp = p; |
| 613 | return retval; |
| 614 | } |
| 615 | |
| 616 | |
| 617 | /* Like get_number_trailer, but don't allow a trailer. */ |
| 618 | int |
| 619 | get_number (char **pp) |
| 620 | { |
| 621 | return get_number_trailer (pp, '\0'); |
| 622 | } |
| 623 | |
| 624 | /* Parse a number or a range. |
| 625 | * A number will be of the form handled by get_number. |
| 626 | * A range will be of the form <number1> - <number2>, and |
| 627 | * will represent all the integers between number1 and number2, |
| 628 | * inclusive. |
| 629 | * |
| 630 | * While processing a range, this fuction is called iteratively; |
| 631 | * At each call it will return the next value in the range. |
| 632 | * |
| 633 | * At the beginning of parsing a range, the char pointer PP will |
| 634 | * be advanced past <number1> and left pointing at the '-' token. |
| 635 | * Subsequent calls will not advance the pointer until the range |
| 636 | * is completed. The call that completes the range will advance |
| 637 | * pointer PP past <number2>. |
| 638 | */ |
| 639 | |
| 640 | int |
| 641 | get_number_or_range (char **pp) |
| 642 | { |
| 643 | static int last_retval, end_value; |
| 644 | static char *end_ptr; |
| 645 | static int in_range = 0; |
| 646 | |
| 647 | if (**pp != '-') |
| 648 | { |
| 649 | /* Default case: pp is pointing either to a solo number, |
| 650 | or to the first number of a range. */ |
| 651 | last_retval = get_number_trailer (pp, '-'); |
| 652 | if (**pp == '-') |
| 653 | { |
| 654 | char **temp; |
| 655 | |
| 656 | /* This is the start of a range (<number1> - <number2>). |
| 657 | Skip the '-', parse and remember the second number, |
| 658 | and also remember the end of the final token. */ |
| 659 | |
| 660 | temp = &end_ptr; |
| 661 | end_ptr = *pp + 1; |
| 662 | while (isspace ((int) *end_ptr)) |
| 663 | end_ptr++; /* skip white space */ |
| 664 | end_value = get_number (temp); |
| 665 | if (end_value < last_retval) |
| 666 | { |
| 667 | error (_("inverted range")); |
| 668 | } |
| 669 | else if (end_value == last_retval) |
| 670 | { |
| 671 | /* degenerate range (number1 == number2). Advance the |
| 672 | token pointer so that the range will be treated as a |
| 673 | single number. */ |
| 674 | *pp = end_ptr; |
| 675 | } |
| 676 | else |
| 677 | in_range = 1; |
| 678 | } |
| 679 | } |
| 680 | else if (! in_range) |
| 681 | error (_("negative value")); |
| 682 | else |
| 683 | { |
| 684 | /* pp points to the '-' that betokens a range. All |
| 685 | number-parsing has already been done. Return the next |
| 686 | integer value (one greater than the saved previous value). |
| 687 | Do not advance the token pointer 'pp' until the end of range |
| 688 | is reached. */ |
| 689 | |
| 690 | if (++last_retval == end_value) |
| 691 | { |
| 692 | /* End of range reached; advance token pointer. */ |
| 693 | *pp = end_ptr; |
| 694 | in_range = 0; |
| 695 | } |
| 696 | } |
| 697 | return last_retval; |
| 698 | } |
| 699 | |
| 700 | /* Return the breakpoint with the specified number, or NULL |
| 701 | if the number does not refer to an existing breakpoint. */ |
| 702 | |
| 703 | struct breakpoint * |
| 704 | get_breakpoint (int num) |
| 705 | { |
| 706 | struct breakpoint *b; |
| 707 | |
| 708 | ALL_BREAKPOINTS (b) |
| 709 | if (b->number == num) |
| 710 | return b; |
| 711 | |
| 712 | return NULL; |
| 713 | } |
| 714 | |
| 715 | \f |
| 716 | |
| 717 | void |
| 718 | set_breakpoint_condition (struct breakpoint *b, char *exp, |
| 719 | int from_tty) |
| 720 | { |
| 721 | struct bp_location *loc = b->loc; |
| 722 | |
| 723 | for (; loc; loc = loc->next) |
| 724 | { |
| 725 | xfree (loc->cond); |
| 726 | loc->cond = NULL; |
| 727 | } |
| 728 | xfree (b->cond_string); |
| 729 | b->cond_string = NULL; |
| 730 | xfree (b->cond_exp); |
| 731 | b->cond_exp = NULL; |
| 732 | |
| 733 | if (*exp == 0) |
| 734 | { |
| 735 | if (from_tty) |
| 736 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); |
| 737 | } |
| 738 | else |
| 739 | { |
| 740 | char *arg = exp; |
| 741 | /* I don't know if it matters whether this is the string the user |
| 742 | typed in or the decompiled expression. */ |
| 743 | b->cond_string = xstrdup (arg); |
| 744 | b->condition_not_parsed = 0; |
| 745 | |
| 746 | if (is_watchpoint (b)) |
| 747 | { |
| 748 | innermost_block = NULL; |
| 749 | arg = exp; |
| 750 | b->cond_exp = parse_exp_1 (&arg, 0, 0); |
| 751 | if (*arg) |
| 752 | error (_("Junk at end of expression")); |
| 753 | b->cond_exp_valid_block = innermost_block; |
| 754 | } |
| 755 | else |
| 756 | { |
| 757 | for (loc = b->loc; loc; loc = loc->next) |
| 758 | { |
| 759 | arg = exp; |
| 760 | loc->cond = |
| 761 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
| 762 | if (*arg) |
| 763 | error (_("Junk at end of expression")); |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | breakpoints_changed (); |
| 768 | observer_notify_breakpoint_modified (b->number); |
| 769 | } |
| 770 | |
| 771 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
| 772 | |
| 773 | static void |
| 774 | condition_command (char *arg, int from_tty) |
| 775 | { |
| 776 | struct breakpoint *b; |
| 777 | char *p; |
| 778 | int bnum; |
| 779 | |
| 780 | if (arg == 0) |
| 781 | error_no_arg (_("breakpoint number")); |
| 782 | |
| 783 | p = arg; |
| 784 | bnum = get_number (&p); |
| 785 | if (bnum == 0) |
| 786 | error (_("Bad breakpoint argument: '%s'"), arg); |
| 787 | |
| 788 | ALL_BREAKPOINTS (b) |
| 789 | if (b->number == bnum) |
| 790 | { |
| 791 | set_breakpoint_condition (b, p, from_tty); |
| 792 | return; |
| 793 | } |
| 794 | |
| 795 | error (_("No breakpoint number %d."), bnum); |
| 796 | } |
| 797 | |
| 798 | /* Check that COMMAND do not contain commands that are suitable |
| 799 | only for tracepoints and not suitable for ordinary breakpoints. |
| 800 | Throw if any such commands is found. |
| 801 | */ |
| 802 | static void |
| 803 | check_no_tracepoint_commands (struct command_line *commands) |
| 804 | { |
| 805 | struct command_line *c; |
| 806 | for (c = commands; c; c = c->next) |
| 807 | { |
| 808 | int i; |
| 809 | |
| 810 | if (c->control_type == while_stepping_control) |
| 811 | error (_("The 'while-stepping' command can only be used for tracepoints")); |
| 812 | |
| 813 | for (i = 0; i < c->body_count; ++i) |
| 814 | check_no_tracepoint_commands ((c->body_list)[i]); |
| 815 | |
| 816 | /* Not that command parsing removes leading whitespace and comment |
| 817 | lines and also empty lines. So, we only need to check for |
| 818 | command directly. */ |
| 819 | if (strstr (c->line, "collect ") == c->line) |
| 820 | error (_("The 'collect' command can only be used for tracepoints")); |
| 821 | |
| 822 | if (strstr (c->line, "teval ") == c->line) |
| 823 | error (_("The 'teval' command can only be used for tracepoints")); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | /* Encapsulate tests for different types of tracepoints. */ |
| 828 | |
| 829 | int |
| 830 | is_tracepoint (const struct breakpoint *b) |
| 831 | { |
| 832 | return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint); |
| 833 | } |
| 834 | |
| 835 | /* A helper function that validsates that COMMANDS are valid for a |
| 836 | breakpoint. This function will throw an exception if a problem is |
| 837 | found. */ |
| 838 | |
| 839 | static void |
| 840 | validate_commands_for_breakpoint (struct breakpoint *b, |
| 841 | struct command_line *commands) |
| 842 | { |
| 843 | if (is_tracepoint (b)) |
| 844 | { |
| 845 | /* We need to verify that each top-level element of commands |
| 846 | is valid for tracepoints, that there's at most one while-stepping |
| 847 | element, and that while-stepping's body has valid tracing commands |
| 848 | excluding nested while-stepping. */ |
| 849 | struct command_line *c; |
| 850 | struct command_line *while_stepping = 0; |
| 851 | for (c = commands; c; c = c->next) |
| 852 | { |
| 853 | char *l = c->line; |
| 854 | if (c->control_type == while_stepping_control) |
| 855 | { |
| 856 | if (b->type == bp_fast_tracepoint) |
| 857 | error (_("The 'while-stepping' command cannot be used for fast tracepoint")); |
| 858 | |
| 859 | if (while_stepping) |
| 860 | error (_("The 'while-stepping' command can be used only once")); |
| 861 | else |
| 862 | while_stepping = c; |
| 863 | } |
| 864 | } |
| 865 | if (while_stepping) |
| 866 | { |
| 867 | struct command_line *c2; |
| 868 | |
| 869 | gdb_assert (while_stepping->body_count == 1); |
| 870 | c2 = while_stepping->body_list[0]; |
| 871 | for (; c2; c2 = c2->next) |
| 872 | { |
| 873 | char *l = c2->line; |
| 874 | if (c2->control_type == while_stepping_control) |
| 875 | error (_("The 'while-stepping' command cannot be nested")); |
| 876 | } |
| 877 | } |
| 878 | } |
| 879 | else |
| 880 | { |
| 881 | check_no_tracepoint_commands (commands); |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
| 886 | validate that only allowed commands are included. |
| 887 | */ |
| 888 | |
| 889 | void |
| 890 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) |
| 891 | { |
| 892 | validate_commands_for_breakpoint (b, commands); |
| 893 | |
| 894 | decref_counted_command_line (&b->commands); |
| 895 | b->commands = alloc_counted_command_line (commands); |
| 896 | breakpoints_changed (); |
| 897 | observer_notify_breakpoint_modified (b->number); |
| 898 | } |
| 899 | |
| 900 | void |
| 901 | check_tracepoint_command (char *line, void *closure) |
| 902 | { |
| 903 | struct breakpoint *b = closure; |
| 904 | validate_actionline (&line, b); |
| 905 | } |
| 906 | |
| 907 | /* A structure used to pass information through |
| 908 | map_breakpoint_numbers. */ |
| 909 | |
| 910 | struct commands_info |
| 911 | { |
| 912 | /* True if the command was typed at a tty. */ |
| 913 | int from_tty; |
| 914 | |
| 915 | /* The breakpoint range spec. */ |
| 916 | char *arg; |
| 917 | |
| 918 | /* Non-NULL if the body of the commands are being read from this |
| 919 | already-parsed command. */ |
| 920 | struct command_line *control; |
| 921 | |
| 922 | /* The command lines read from the user, or NULL if they have not |
| 923 | yet been read. */ |
| 924 | struct counted_command_line *cmd; |
| 925 | }; |
| 926 | |
| 927 | /* A callback for map_breakpoint_numbers that sets the commands for |
| 928 | commands_command. */ |
| 929 | |
| 930 | static void |
| 931 | do_map_commands_command (struct breakpoint *b, void *data) |
| 932 | { |
| 933 | struct commands_info *info = data; |
| 934 | |
| 935 | if (info->cmd == NULL) |
| 936 | { |
| 937 | struct command_line *l; |
| 938 | |
| 939 | if (info->control != NULL) |
| 940 | l = copy_command_lines (info->control->body_list[0]); |
| 941 | else |
| 942 | { |
| 943 | struct cleanup *old_chain; |
| 944 | char *str; |
| 945 | |
| 946 | str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."), |
| 947 | info->arg); |
| 948 | |
| 949 | old_chain = make_cleanup (xfree, str); |
| 950 | |
| 951 | l = read_command_lines (str, |
| 952 | info->from_tty, 1, |
| 953 | (is_tracepoint (b) |
| 954 | ? check_tracepoint_command : 0), |
| 955 | b); |
| 956 | |
| 957 | do_cleanups (old_chain); |
| 958 | } |
| 959 | |
| 960 | info->cmd = alloc_counted_command_line (l); |
| 961 | } |
| 962 | |
| 963 | /* If a breakpoint was on the list more than once, we don't need to |
| 964 | do anything. */ |
| 965 | if (b->commands != info->cmd) |
| 966 | { |
| 967 | validate_commands_for_breakpoint (b, info->cmd->commands); |
| 968 | incref_counted_command_line (info->cmd); |
| 969 | decref_counted_command_line (&b->commands); |
| 970 | b->commands = info->cmd; |
| 971 | breakpoints_changed (); |
| 972 | observer_notify_breakpoint_modified (b->number); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | static void |
| 977 | commands_command_1 (char *arg, int from_tty, struct command_line *control) |
| 978 | { |
| 979 | struct cleanup *cleanups; |
| 980 | struct commands_info info; |
| 981 | |
| 982 | info.from_tty = from_tty; |
| 983 | info.control = control; |
| 984 | info.cmd = NULL; |
| 985 | /* If we read command lines from the user, then `info' will hold an |
| 986 | extra reference to the commands that we must clean up. */ |
| 987 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); |
| 988 | |
| 989 | if (arg == NULL || !*arg) |
| 990 | { |
| 991 | if (breakpoint_count - prev_breakpoint_count > 1) |
| 992 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count); |
| 993 | else if (breakpoint_count > 0) |
| 994 | arg = xstrprintf ("%d", breakpoint_count); |
| 995 | else |
| 996 | { |
| 997 | /* So that we don't try to free the incoming non-NULL |
| 998 | argument in the cleanup below. Mapping breakpoint |
| 999 | numbers will fail in this case. */ |
| 1000 | arg = NULL; |
| 1001 | } |
| 1002 | } |
| 1003 | else |
| 1004 | /* The command loop has some static state, so we need to preserve |
| 1005 | our argument. */ |
| 1006 | arg = xstrdup (arg); |
| 1007 | |
| 1008 | if (arg != NULL) |
| 1009 | make_cleanup (xfree, arg); |
| 1010 | |
| 1011 | info.arg = arg; |
| 1012 | |
| 1013 | map_breakpoint_numbers (arg, do_map_commands_command, &info); |
| 1014 | |
| 1015 | if (info.cmd == NULL) |
| 1016 | error (_("No breakpoints specified.")); |
| 1017 | |
| 1018 | do_cleanups (cleanups); |
| 1019 | } |
| 1020 | |
| 1021 | static void |
| 1022 | commands_command (char *arg, int from_tty) |
| 1023 | { |
| 1024 | commands_command_1 (arg, from_tty, NULL); |
| 1025 | } |
| 1026 | |
| 1027 | /* Like commands_command, but instead of reading the commands from |
| 1028 | input stream, takes them from an already parsed command structure. |
| 1029 | |
| 1030 | This is used by cli-script.c to DTRT with breakpoint commands |
| 1031 | that are part of if and while bodies. */ |
| 1032 | enum command_control_type |
| 1033 | commands_from_control_command (char *arg, struct command_line *cmd) |
| 1034 | { |
| 1035 | commands_command_1 (arg, 0, cmd); |
| 1036 | return simple_control; |
| 1037 | } |
| 1038 | |
| 1039 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ |
| 1040 | |
| 1041 | static int |
| 1042 | bp_location_has_shadow (struct bp_location *bl) |
| 1043 | { |
| 1044 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 1045 | return 0; |
| 1046 | if (!bl->inserted) |
| 1047 | return 0; |
| 1048 | if (bl->target_info.shadow_len == 0) |
| 1049 | /* bp isn't valid, or doesn't shadow memory. */ |
| 1050 | return 0; |
| 1051 | return 1; |
| 1052 | } |
| 1053 | |
| 1054 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
| 1055 | by replacing any memory breakpoints with their shadowed contents. |
| 1056 | |
| 1057 | The range of shadowed area by each bp_location is: |
| 1058 | b->address - bp_location_placed_address_before_address_max |
| 1059 | up to b->address + bp_location_shadow_len_after_address_max |
| 1060 | The range we were requested to resolve shadows for is: |
| 1061 | memaddr ... memaddr + len |
| 1062 | Thus the safe cutoff boundaries for performance optimization are |
| 1063 | memaddr + len <= b->address - bp_location_placed_address_before_address_max |
| 1064 | and: |
| 1065 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ |
| 1066 | |
| 1067 | void |
| 1068 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) |
| 1069 | { |
| 1070 | /* Left boundary, right boundary and median element of our binary search. */ |
| 1071 | unsigned bc_l, bc_r, bc; |
| 1072 | |
| 1073 | /* Find BC_L which is a leftmost element which may affect BUF content. It is |
| 1074 | safe to report lower value but a failure to report higher one. */ |
| 1075 | |
| 1076 | bc_l = 0; |
| 1077 | bc_r = bp_location_count; |
| 1078 | while (bc_l + 1 < bc_r) |
| 1079 | { |
| 1080 | struct bp_location *b; |
| 1081 | |
| 1082 | bc = (bc_l + bc_r) / 2; |
| 1083 | b = bp_location[bc]; |
| 1084 | |
| 1085 | /* Check first B->ADDRESS will not overflow due to the added constant. |
| 1086 | Then advance the left boundary only if we are sure the BC element can |
| 1087 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). |
| 1088 | |
| 1089 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that |
| 1090 | we cannot miss a breakpoint with its shadow range tail still reaching |
| 1091 | MEMADDR. */ |
| 1092 | |
| 1093 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
| 1094 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) |
| 1095 | bc_l = bc; |
| 1096 | else |
| 1097 | bc_r = bc; |
| 1098 | } |
| 1099 | |
| 1100 | /* Now do full processing of the found relevant range of elements. */ |
| 1101 | |
| 1102 | for (bc = bc_l; bc < bp_location_count; bc++) |
| 1103 | { |
| 1104 | struct bp_location *b = bp_location[bc]; |
| 1105 | CORE_ADDR bp_addr = 0; |
| 1106 | int bp_size = 0; |
| 1107 | int bptoffset = 0; |
| 1108 | |
| 1109 | if (b->owner->type == bp_none) |
| 1110 | warning (_("reading through apparently deleted breakpoint #%d?"), |
| 1111 | b->owner->number); |
| 1112 | |
| 1113 | /* Performance optimization: any futher element can no longer affect BUF |
| 1114 | content. */ |
| 1115 | |
| 1116 | if (b->address >= bp_location_placed_address_before_address_max |
| 1117 | && memaddr + len <= b->address |
| 1118 | - bp_location_placed_address_before_address_max) |
| 1119 | break; |
| 1120 | |
| 1121 | if (!bp_location_has_shadow (b)) |
| 1122 | continue; |
| 1123 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
| 1124 | current_program_space->aspace, 0)) |
| 1125 | continue; |
| 1126 | |
| 1127 | /* Addresses and length of the part of the breakpoint that |
| 1128 | we need to copy. */ |
| 1129 | bp_addr = b->target_info.placed_address; |
| 1130 | bp_size = b->target_info.shadow_len; |
| 1131 | |
| 1132 | if (bp_addr + bp_size <= memaddr) |
| 1133 | /* The breakpoint is entirely before the chunk of memory we |
| 1134 | are reading. */ |
| 1135 | continue; |
| 1136 | |
| 1137 | if (bp_addr >= memaddr + len) |
| 1138 | /* The breakpoint is entirely after the chunk of memory we are |
| 1139 | reading. */ |
| 1140 | continue; |
| 1141 | |
| 1142 | /* Offset within shadow_contents. */ |
| 1143 | if (bp_addr < memaddr) |
| 1144 | { |
| 1145 | /* Only copy the second part of the breakpoint. */ |
| 1146 | bp_size -= memaddr - bp_addr; |
| 1147 | bptoffset = memaddr - bp_addr; |
| 1148 | bp_addr = memaddr; |
| 1149 | } |
| 1150 | |
| 1151 | if (bp_addr + bp_size > memaddr + len) |
| 1152 | { |
| 1153 | /* Only copy the first part of the breakpoint. */ |
| 1154 | bp_size -= (bp_addr + bp_size) - (memaddr + len); |
| 1155 | } |
| 1156 | |
| 1157 | memcpy (buf + bp_addr - memaddr, |
| 1158 | b->target_info.shadow_contents + bptoffset, bp_size); |
| 1159 | } |
| 1160 | } |
| 1161 | \f |
| 1162 | |
| 1163 | /* A wrapper function for inserting catchpoints. */ |
| 1164 | static void |
| 1165 | insert_catchpoint (struct ui_out *uo, void *args) |
| 1166 | { |
| 1167 | struct breakpoint *b = (struct breakpoint *) args; |
| 1168 | int val = -1; |
| 1169 | |
| 1170 | gdb_assert (b->type == bp_catchpoint); |
| 1171 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); |
| 1172 | |
| 1173 | b->ops->insert (b); |
| 1174 | } |
| 1175 | |
| 1176 | /* Return true if BPT is of any hardware watchpoint kind. */ |
| 1177 | |
| 1178 | static int |
| 1179 | is_hardware_watchpoint (const struct breakpoint *bpt) |
| 1180 | { |
| 1181 | return (bpt->type == bp_hardware_watchpoint |
| 1182 | || bpt->type == bp_read_watchpoint |
| 1183 | || bpt->type == bp_access_watchpoint); |
| 1184 | } |
| 1185 | |
| 1186 | /* Return true if BPT is of any watchpoint kind, hardware or |
| 1187 | software. */ |
| 1188 | |
| 1189 | static int |
| 1190 | is_watchpoint (const struct breakpoint *bpt) |
| 1191 | { |
| 1192 | return (is_hardware_watchpoint (bpt) |
| 1193 | || bpt->type == bp_watchpoint); |
| 1194 | } |
| 1195 | |
| 1196 | /* Find the current value of a watchpoint on EXP. Return the value in |
| 1197 | *VALP and *RESULTP and the chain of intermediate and final values |
| 1198 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does |
| 1199 | not need them. |
| 1200 | |
| 1201 | If a memory error occurs while evaluating the expression, *RESULTP will |
| 1202 | be set to NULL. *RESULTP may be a lazy value, if the result could |
| 1203 | not be read from memory. It is used to determine whether a value |
| 1204 | is user-specified (we should watch the whole value) or intermediate |
| 1205 | (we should watch only the bit used to locate the final value). |
| 1206 | |
| 1207 | If the final value, or any intermediate value, could not be read |
| 1208 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be |
| 1209 | set to any referenced values. *VALP will never be a lazy value. |
| 1210 | This is the value which we store in struct breakpoint. |
| 1211 | |
| 1212 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the |
| 1213 | value chain. The caller must free the values individually. If |
| 1214 | VAL_CHAIN is NULL, all generated values will be left on the value |
| 1215 | chain. */ |
| 1216 | |
| 1217 | static void |
| 1218 | fetch_watchpoint_value (struct expression *exp, struct value **valp, |
| 1219 | struct value **resultp, struct value **val_chain) |
| 1220 | { |
| 1221 | struct value *mark, *new_mark, *result; |
| 1222 | volatile struct gdb_exception ex; |
| 1223 | |
| 1224 | *valp = NULL; |
| 1225 | if (resultp) |
| 1226 | *resultp = NULL; |
| 1227 | if (val_chain) |
| 1228 | *val_chain = NULL; |
| 1229 | |
| 1230 | /* Evaluate the expression. */ |
| 1231 | mark = value_mark (); |
| 1232 | result = NULL; |
| 1233 | |
| 1234 | TRY_CATCH (ex, RETURN_MASK_ALL) |
| 1235 | { |
| 1236 | result = evaluate_expression (exp); |
| 1237 | } |
| 1238 | if (ex.reason < 0) |
| 1239 | { |
| 1240 | /* Ignore memory errors, we want watchpoints pointing at |
| 1241 | inaccessible memory to still be created; otherwise, throw the |
| 1242 | error to some higher catcher. */ |
| 1243 | switch (ex.error) |
| 1244 | { |
| 1245 | case MEMORY_ERROR: |
| 1246 | break; |
| 1247 | default: |
| 1248 | throw_exception (ex); |
| 1249 | break; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | new_mark = value_mark (); |
| 1254 | if (mark == new_mark) |
| 1255 | return; |
| 1256 | if (resultp) |
| 1257 | *resultp = result; |
| 1258 | |
| 1259 | /* Make sure it's not lazy, so that after the target stops again we |
| 1260 | have a non-lazy previous value to compare with. */ |
| 1261 | if (result != NULL |
| 1262 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) |
| 1263 | *valp = result; |
| 1264 | |
| 1265 | if (val_chain) |
| 1266 | { |
| 1267 | /* Return the chain of intermediate values. We use this to |
| 1268 | decide which addresses to watch. */ |
| 1269 | *val_chain = new_mark; |
| 1270 | value_release_to_mark (mark); |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | /* Assuming that B is a watchpoint: returns true if the current thread |
| 1275 | and its running state are safe to evaluate or update watchpoint B. |
| 1276 | Watchpoints on local expressions need to be evaluated in the |
| 1277 | context of the thread that was current when the watchpoint was |
| 1278 | created, and, that thread needs to be stopped to be able to select |
| 1279 | the correct frame context. Watchpoints on global expressions can |
| 1280 | be evaluated on any thread, and in any state. It is presently left |
| 1281 | to the target allowing memory accesses when threads are |
| 1282 | running. */ |
| 1283 | |
| 1284 | static int |
| 1285 | watchpoint_in_thread_scope (struct breakpoint *b) |
| 1286 | { |
| 1287 | return (ptid_equal (b->watchpoint_thread, null_ptid) |
| 1288 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) |
| 1289 | && !is_executing (inferior_ptid))); |
| 1290 | } |
| 1291 | |
| 1292 | /* Assuming that B is a watchpoint: |
| 1293 | - Reparse watchpoint expression, if REPARSE is non-zero |
| 1294 | - Evaluate expression and store the result in B->val |
| 1295 | - Evaluate the condition if there is one, and store the result |
| 1296 | in b->loc->cond. |
| 1297 | - Update the list of values that must be watched in B->loc. |
| 1298 | |
| 1299 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
| 1300 | If this is local watchpoint that is out of scope, delete it. |
| 1301 | |
| 1302 | Even with `set breakpoint always-inserted on' the watchpoints are removed |
| 1303 | + inserted on each stop here. Normal breakpoints must never be removed |
| 1304 | because they might be missed by a running thread when debugging in non-stop |
| 1305 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; |
| 1306 | processed here) are specific to each LWP since they are stored in each LWP's |
| 1307 | hardware debug registers. Therefore, such LWP must be stopped first in |
| 1308 | order to be able to modify its hardware watchpoints. |
| 1309 | |
| 1310 | Hardware watchpoints must be reset exactly once after being presented to the |
| 1311 | user. It cannot be done sooner, because it would reset the data used to |
| 1312 | present the watchpoint hit to the user. And it must not be done later |
| 1313 | because it could display the same single watchpoint hit during multiple GDB |
| 1314 | stops. Note that the latter is relevant only to the hardware watchpoint |
| 1315 | types bp_read_watchpoint and bp_access_watchpoint. False hit by |
| 1316 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the |
| 1317 | memory content has not changed. |
| 1318 | |
| 1319 | The following constraints influence the location where we can reset hardware |
| 1320 | watchpoints: |
| 1321 | |
| 1322 | * target_stopped_by_watchpoint and target_stopped_data_address are called |
| 1323 | several times when GDB stops. |
| 1324 | |
| 1325 | [linux] |
| 1326 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to |
| 1327 | stop. GDB only presents one hardware watchpoint hit at a time as the |
| 1328 | reason for stopping, and all the other hits are presented later, one after |
| 1329 | the other, each time the user requests the execution to be resumed. |
| 1330 | Execution is not resumed for the threads still having pending hit event |
| 1331 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from |
| 1332 | the inferior on the first stop the thread hit event is kept being reported |
| 1333 | from its cached value by linux_nat_stopped_data_address until the real |
| 1334 | thread resume happens after the watchpoint gets presented and thus its |
| 1335 | LWP_INFO->STATUS gets reset. |
| 1336 | |
| 1337 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint |
| 1338 | removal from inferior. */ |
| 1339 | |
| 1340 | static void |
| 1341 | update_watchpoint (struct breakpoint *b, int reparse) |
| 1342 | { |
| 1343 | int within_current_scope; |
| 1344 | struct frame_id saved_frame_id; |
| 1345 | struct bp_location *loc; |
| 1346 | int frame_saved; |
| 1347 | bpstat bs; |
| 1348 | |
| 1349 | /* If this is a local watchpoint, we only want to check if the |
| 1350 | watchpoint frame is in scope if the current thread is the thread |
| 1351 | that was used to create the watchpoint. */ |
| 1352 | if (!watchpoint_in_thread_scope (b)) |
| 1353 | return; |
| 1354 | |
| 1355 | /* We don't free locations. They are stored in bp_location array and |
| 1356 | update_global_locations will eventually delete them and remove |
| 1357 | breakpoints if needed. */ |
| 1358 | b->loc = NULL; |
| 1359 | |
| 1360 | if (b->disposition == disp_del_at_next_stop) |
| 1361 | return; |
| 1362 | |
| 1363 | frame_saved = 0; |
| 1364 | |
| 1365 | /* Determine if the watchpoint is within scope. */ |
| 1366 | if (b->exp_valid_block == NULL) |
| 1367 | within_current_scope = 1; |
| 1368 | else |
| 1369 | { |
| 1370 | struct frame_info *fi; |
| 1371 | |
| 1372 | /* Save the current frame's ID so we can restore it after |
| 1373 | evaluating the watchpoint expression on its own frame. */ |
| 1374 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
| 1375 | took a frame parameter, so that we didn't have to change the |
| 1376 | selected frame. */ |
| 1377 | frame_saved = 1; |
| 1378 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); |
| 1379 | |
| 1380 | fi = frame_find_by_id (b->watchpoint_frame); |
| 1381 | within_current_scope = (fi != NULL); |
| 1382 | if (within_current_scope) |
| 1383 | select_frame (fi); |
| 1384 | } |
| 1385 | |
| 1386 | if (within_current_scope && reparse) |
| 1387 | { |
| 1388 | char *s; |
| 1389 | if (b->exp) |
| 1390 | { |
| 1391 | xfree (b->exp); |
| 1392 | b->exp = NULL; |
| 1393 | } |
| 1394 | s = b->exp_string; |
| 1395 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
| 1396 | /* If the meaning of expression itself changed, the old value is |
| 1397 | no longer relevant. We don't want to report a watchpoint hit |
| 1398 | to the user when the old value and the new value may actually |
| 1399 | be completely different objects. */ |
| 1400 | value_free (b->val); |
| 1401 | b->val = NULL; |
| 1402 | b->val_valid = 0; |
| 1403 | |
| 1404 | /* Note that unlike with breakpoints, the watchpoint's condition |
| 1405 | expression is stored in the breakpoint object, not in the |
| 1406 | locations (re)created below. */ |
| 1407 | if (b->cond_string != NULL) |
| 1408 | { |
| 1409 | if (b->cond_exp != NULL) |
| 1410 | { |
| 1411 | xfree (b->cond_exp); |
| 1412 | b->cond_exp = NULL; |
| 1413 | } |
| 1414 | |
| 1415 | s = b->cond_string; |
| 1416 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | /* If we failed to parse the expression, for example because |
| 1421 | it refers to a global variable in a not-yet-loaded shared library, |
| 1422 | don't try to insert watchpoint. We don't automatically delete |
| 1423 | such watchpoint, though, since failure to parse expression |
| 1424 | is different from out-of-scope watchpoint. */ |
| 1425 | if ( !target_has_execution) |
| 1426 | { |
| 1427 | /* Without execution, memory can't change. No use to try and |
| 1428 | set watchpoint locations. The watchpoint will be reset when |
| 1429 | the target gains execution, through breakpoint_re_set. */ |
| 1430 | } |
| 1431 | else if (within_current_scope && b->exp) |
| 1432 | { |
| 1433 | struct value *val_chain, *v, *result, *next; |
| 1434 | struct program_space *frame_pspace; |
| 1435 | |
| 1436 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
| 1437 | |
| 1438 | /* Avoid setting b->val if it's already set. The meaning of |
| 1439 | b->val is 'the last value' user saw, and we should update |
| 1440 | it only if we reported that last value to user. As it |
| 1441 | happens, the code that reports it updates b->val directly. */ |
| 1442 | if (!b->val_valid) |
| 1443 | { |
| 1444 | b->val = v; |
| 1445 | b->val_valid = 1; |
| 1446 | } |
| 1447 | |
| 1448 | /* Change the type of breakpoint between hardware assisted or an |
| 1449 | ordinary watchpoint depending on the hardware support and free |
| 1450 | hardware slots. REPARSE is set when the inferior is started. */ |
| 1451 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) |
| 1452 | && reparse) |
| 1453 | { |
| 1454 | int i, mem_cnt, other_type_used; |
| 1455 | |
| 1456 | /* We need to determine how many resources are already used |
| 1457 | for all other hardware watchpoints to see if we still have |
| 1458 | enough resources to also fit this watchpoint in as well. |
| 1459 | To avoid the hw_watchpoint_used_count call below from counting |
| 1460 | this watchpoint, make sure that it is marked as a software |
| 1461 | watchpoint. */ |
| 1462 | b->type = bp_watchpoint; |
| 1463 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
| 1464 | &other_type_used); |
| 1465 | mem_cnt = can_use_hardware_watchpoint (val_chain); |
| 1466 | |
| 1467 | if (!mem_cnt) |
| 1468 | b->type = bp_watchpoint; |
| 1469 | else |
| 1470 | { |
| 1471 | int target_resources_ok = target_can_use_hardware_watchpoint |
| 1472 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
| 1473 | if (target_resources_ok <= 0) |
| 1474 | b->type = bp_watchpoint; |
| 1475 | else |
| 1476 | b->type = bp_hardware_watchpoint; |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
| 1481 | |
| 1482 | /* Look at each value on the value chain. */ |
| 1483 | for (v = val_chain; v; v = next) |
| 1484 | { |
| 1485 | /* If it's a memory location, and GDB actually needed |
| 1486 | its contents to evaluate the expression, then we |
| 1487 | must watch it. If the first value returned is |
| 1488 | still lazy, that means an error occurred reading it; |
| 1489 | watch it anyway in case it becomes readable. */ |
| 1490 | if (VALUE_LVAL (v) == lval_memory |
| 1491 | && (v == val_chain || ! value_lazy (v))) |
| 1492 | { |
| 1493 | struct type *vtype = check_typedef (value_type (v)); |
| 1494 | |
| 1495 | /* We only watch structs and arrays if user asked |
| 1496 | for it explicitly, never if they just happen to |
| 1497 | appear in the middle of some value chain. */ |
| 1498 | if (v == result |
| 1499 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 1500 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 1501 | { |
| 1502 | CORE_ADDR addr; |
| 1503 | int len, type; |
| 1504 | struct bp_location *loc, **tmp; |
| 1505 | |
| 1506 | addr = value_address (v); |
| 1507 | len = TYPE_LENGTH (value_type (v)); |
| 1508 | type = hw_write; |
| 1509 | if (b->type == bp_read_watchpoint) |
| 1510 | type = hw_read; |
| 1511 | else if (b->type == bp_access_watchpoint) |
| 1512 | type = hw_access; |
| 1513 | |
| 1514 | loc = allocate_bp_location (b); |
| 1515 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
| 1516 | ; |
| 1517 | *tmp = loc; |
| 1518 | loc->gdbarch = get_type_arch (value_type (v)); |
| 1519 | |
| 1520 | loc->pspace = frame_pspace; |
| 1521 | loc->address = addr; |
| 1522 | loc->length = len; |
| 1523 | loc->watchpoint_type = type; |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | next = value_next (v); |
| 1528 | if (v != b->val) |
| 1529 | value_free (v); |
| 1530 | } |
| 1531 | |
| 1532 | /* If a software watchpoint is not watching any memory, then the |
| 1533 | above left it without any location set up. But, |
| 1534 | bpstat_stop_status requires a location to be able to report |
| 1535 | stops, so make sure there's at least a dummy one. */ |
| 1536 | if (b->type == bp_watchpoint && b->loc == NULL) |
| 1537 | { |
| 1538 | b->loc = allocate_bp_location (b); |
| 1539 | b->loc->pspace = frame_pspace; |
| 1540 | b->loc->address = -1; |
| 1541 | b->loc->length = -1; |
| 1542 | b->loc->watchpoint_type = -1; |
| 1543 | } |
| 1544 | } |
| 1545 | else if (!within_current_scope) |
| 1546 | { |
| 1547 | printf_filtered (_("\ |
| 1548 | Watchpoint %d deleted because the program has left the block \n\ |
| 1549 | in which its expression is valid.\n"), |
| 1550 | b->number); |
| 1551 | if (b->related_breakpoint) |
| 1552 | { |
| 1553 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
| 1554 | b->related_breakpoint->related_breakpoint = NULL; |
| 1555 | b->related_breakpoint= NULL; |
| 1556 | } |
| 1557 | b->disposition = disp_del_at_next_stop; |
| 1558 | } |
| 1559 | |
| 1560 | /* Restore the selected frame. */ |
| 1561 | if (frame_saved) |
| 1562 | select_frame (frame_find_by_id (saved_frame_id)); |
| 1563 | } |
| 1564 | |
| 1565 | |
| 1566 | /* Returns 1 iff breakpoint location should be |
| 1567 | inserted in the inferior. */ |
| 1568 | static int |
| 1569 | should_be_inserted (struct bp_location *bpt) |
| 1570 | { |
| 1571 | if (!breakpoint_enabled (bpt->owner)) |
| 1572 | return 0; |
| 1573 | |
| 1574 | if (bpt->owner->disposition == disp_del_at_next_stop) |
| 1575 | return 0; |
| 1576 | |
| 1577 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) |
| 1578 | return 0; |
| 1579 | |
| 1580 | /* This is set for example, when we're attached to the parent of a |
| 1581 | vfork, and have detached from the child. The child is running |
| 1582 | free, and we expect it to do an exec or exit, at which point the |
| 1583 | OS makes the parent schedulable again (and the target reports |
| 1584 | that the vfork is done). Until the child is done with the shared |
| 1585 | memory region, do not insert breakpoints in the parent, otherwise |
| 1586 | the child could still trip on the parent's breakpoints. Since |
| 1587 | the parent is blocked anyway, it won't miss any breakpoint. */ |
| 1588 | if (bpt->pspace->breakpoints_not_allowed) |
| 1589 | return 0; |
| 1590 | |
| 1591 | /* Tracepoints are inserted by the target at a time of its choosing, |
| 1592 | not by us. */ |
| 1593 | if (is_tracepoint (bpt->owner)) |
| 1594 | return 0; |
| 1595 | |
| 1596 | return 1; |
| 1597 | } |
| 1598 | |
| 1599 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
| 1600 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, |
| 1601 | and HW_BREAKPOINT_ERROR are used to report problems. |
| 1602 | |
| 1603 | NOTE drow/2003-09-09: This routine could be broken down to an object-style |
| 1604 | method for each breakpoint or catchpoint type. */ |
| 1605 | static int |
| 1606 | insert_bp_location (struct bp_location *bpt, |
| 1607 | struct ui_file *tmp_error_stream, |
| 1608 | int *disabled_breaks, |
| 1609 | int *hw_breakpoint_error) |
| 1610 | { |
| 1611 | int val = 0; |
| 1612 | |
| 1613 | if (!should_be_inserted (bpt) || bpt->inserted) |
| 1614 | return 0; |
| 1615 | |
| 1616 | /* Initialize the target-specific information. */ |
| 1617 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); |
| 1618 | bpt->target_info.placed_address = bpt->address; |
| 1619 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
| 1620 | |
| 1621 | if (bpt->loc_type == bp_loc_software_breakpoint |
| 1622 | || bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1623 | { |
| 1624 | if (bpt->owner->type != bp_hardware_breakpoint) |
| 1625 | { |
| 1626 | /* If the explicitly specified breakpoint type |
| 1627 | is not hardware breakpoint, check the memory map to see |
| 1628 | if the breakpoint address is in read only memory or not. |
| 1629 | Two important cases are: |
| 1630 | - location type is not hardware breakpoint, memory |
| 1631 | is readonly. We change the type of the location to |
| 1632 | hardware breakpoint. |
| 1633 | - location type is hardware breakpoint, memory is read-write. |
| 1634 | This means we've previously made the location hardware one, but |
| 1635 | then the memory map changed, so we undo. |
| 1636 | |
| 1637 | When breakpoints are removed, remove_breakpoints will |
| 1638 | use location types we've just set here, the only possible |
| 1639 | problem is that memory map has changed during running program, |
| 1640 | but it's not going to work anyway with current gdb. */ |
| 1641 | struct mem_region *mr |
| 1642 | = lookup_mem_region (bpt->target_info.placed_address); |
| 1643 | |
| 1644 | if (mr) |
| 1645 | { |
| 1646 | if (automatic_hardware_breakpoints) |
| 1647 | { |
| 1648 | int changed = 0; |
| 1649 | enum bp_loc_type new_type; |
| 1650 | |
| 1651 | if (mr->attrib.mode != MEM_RW) |
| 1652 | new_type = bp_loc_hardware_breakpoint; |
| 1653 | else |
| 1654 | new_type = bp_loc_software_breakpoint; |
| 1655 | |
| 1656 | if (new_type != bpt->loc_type) |
| 1657 | { |
| 1658 | static int said = 0; |
| 1659 | bpt->loc_type = new_type; |
| 1660 | if (!said) |
| 1661 | { |
| 1662 | fprintf_filtered (gdb_stdout, _("\ |
| 1663 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
| 1664 | said = 1; |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | else if (bpt->loc_type == bp_loc_software_breakpoint |
| 1669 | && mr->attrib.mode != MEM_RW) |
| 1670 | warning (_("cannot set software breakpoint at readonly address %s"), |
| 1671 | paddress (bpt->gdbarch, bpt->address)); |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | /* First check to see if we have to handle an overlay. */ |
| 1676 | if (overlay_debugging == ovly_off |
| 1677 | || bpt->section == NULL |
| 1678 | || !(section_is_overlay (bpt->section))) |
| 1679 | { |
| 1680 | /* No overlay handling: just set the breakpoint. */ |
| 1681 | |
| 1682 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1683 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
| 1684 | &bpt->target_info); |
| 1685 | else |
| 1686 | val = target_insert_breakpoint (bpt->gdbarch, |
| 1687 | &bpt->target_info); |
| 1688 | } |
| 1689 | else |
| 1690 | { |
| 1691 | /* This breakpoint is in an overlay section. |
| 1692 | Shall we set a breakpoint at the LMA? */ |
| 1693 | if (!overlay_events_enabled) |
| 1694 | { |
| 1695 | /* Yes -- overlay event support is not active, |
| 1696 | so we must try to set a breakpoint at the LMA. |
| 1697 | This will not work for a hardware breakpoint. */ |
| 1698 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1699 | warning (_("hardware breakpoint %d not supported in overlay!"), |
| 1700 | bpt->owner->number); |
| 1701 | else |
| 1702 | { |
| 1703 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, |
| 1704 | bpt->section); |
| 1705 | /* Set a software (trap) breakpoint at the LMA. */ |
| 1706 | bpt->overlay_target_info = bpt->target_info; |
| 1707 | bpt->overlay_target_info.placed_address = addr; |
| 1708 | val = target_insert_breakpoint (bpt->gdbarch, |
| 1709 | &bpt->overlay_target_info); |
| 1710 | if (val != 0) |
| 1711 | fprintf_unfiltered (tmp_error_stream, |
| 1712 | "Overlay breakpoint %d failed: in ROM?\n", |
| 1713 | bpt->owner->number); |
| 1714 | } |
| 1715 | } |
| 1716 | /* Shall we set a breakpoint at the VMA? */ |
| 1717 | if (section_is_mapped (bpt->section)) |
| 1718 | { |
| 1719 | /* Yes. This overlay section is mapped into memory. */ |
| 1720 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1721 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
| 1722 | &bpt->target_info); |
| 1723 | else |
| 1724 | val = target_insert_breakpoint (bpt->gdbarch, |
| 1725 | &bpt->target_info); |
| 1726 | } |
| 1727 | else |
| 1728 | { |
| 1729 | /* No. This breakpoint will not be inserted. |
| 1730 | No error, but do not mark the bp as 'inserted'. */ |
| 1731 | return 0; |
| 1732 | } |
| 1733 | } |
| 1734 | |
| 1735 | if (val) |
| 1736 | { |
| 1737 | /* Can't set the breakpoint. */ |
| 1738 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
| 1739 | { |
| 1740 | /* See also: disable_breakpoints_in_shlibs. */ |
| 1741 | val = 0; |
| 1742 | bpt->shlib_disabled = 1; |
| 1743 | if (!*disabled_breaks) |
| 1744 | { |
| 1745 | fprintf_unfiltered (tmp_error_stream, |
| 1746 | "Cannot insert breakpoint %d.\n", |
| 1747 | bpt->owner->number); |
| 1748 | fprintf_unfiltered (tmp_error_stream, |
| 1749 | "Temporarily disabling shared library breakpoints:\n"); |
| 1750 | } |
| 1751 | *disabled_breaks = 1; |
| 1752 | fprintf_unfiltered (tmp_error_stream, |
| 1753 | "breakpoint #%d\n", bpt->owner->number); |
| 1754 | } |
| 1755 | else |
| 1756 | { |
| 1757 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1758 | { |
| 1759 | *hw_breakpoint_error = 1; |
| 1760 | fprintf_unfiltered (tmp_error_stream, |
| 1761 | "Cannot insert hardware breakpoint %d.\n", |
| 1762 | bpt->owner->number); |
| 1763 | } |
| 1764 | else |
| 1765 | { |
| 1766 | fprintf_unfiltered (tmp_error_stream, |
| 1767 | "Cannot insert breakpoint %d.\n", |
| 1768 | bpt->owner->number); |
| 1769 | fprintf_filtered (tmp_error_stream, |
| 1770 | "Error accessing memory address "); |
| 1771 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
| 1772 | tmp_error_stream); |
| 1773 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
| 1774 | safe_strerror (val)); |
| 1775 | } |
| 1776 | |
| 1777 | } |
| 1778 | } |
| 1779 | else |
| 1780 | bpt->inserted = 1; |
| 1781 | |
| 1782 | return val; |
| 1783 | } |
| 1784 | |
| 1785 | else if (bpt->loc_type == bp_loc_hardware_watchpoint |
| 1786 | /* NOTE drow/2003-09-08: This state only exists for removing |
| 1787 | watchpoints. It's not clear that it's necessary... */ |
| 1788 | && bpt->owner->disposition != disp_del_at_next_stop) |
| 1789 | { |
| 1790 | val = target_insert_watchpoint (bpt->address, |
| 1791 | bpt->length, |
| 1792 | bpt->watchpoint_type); |
| 1793 | |
| 1794 | /* If trying to set a read-watchpoint, and it turns out it's not |
| 1795 | supported, try emulating one with an access watchpoint. */ |
| 1796 | if (val == 1 && bpt->watchpoint_type == hw_read) |
| 1797 | { |
| 1798 | struct bp_location *loc, **loc_temp; |
| 1799 | |
| 1800 | /* But don't try to insert it, if there's already another |
| 1801 | hw_access location that would be considered a duplicate |
| 1802 | of this one. */ |
| 1803 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 1804 | if (loc != bpt |
| 1805 | && loc->watchpoint_type == hw_access |
| 1806 | && watchpoint_locations_match (bpt, loc)) |
| 1807 | { |
| 1808 | bpt->duplicate = 1; |
| 1809 | bpt->inserted = 1; |
| 1810 | bpt->target_info = loc->target_info; |
| 1811 | bpt->watchpoint_type = hw_access; |
| 1812 | val = 0; |
| 1813 | break; |
| 1814 | } |
| 1815 | |
| 1816 | if (val == 1) |
| 1817 | { |
| 1818 | val = target_insert_watchpoint (bpt->address, |
| 1819 | bpt->length, |
| 1820 | hw_access); |
| 1821 | if (val == 0) |
| 1822 | bpt->watchpoint_type = hw_access; |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | bpt->inserted = (val == 0); |
| 1827 | } |
| 1828 | |
| 1829 | else if (bpt->owner->type == bp_catchpoint) |
| 1830 | { |
| 1831 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
| 1832 | bpt->owner, RETURN_MASK_ERROR); |
| 1833 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
| 1834 | bpt->owner->number); |
| 1835 | if (e.reason < 0) |
| 1836 | bpt->owner->enable_state = bp_disabled; |
| 1837 | else |
| 1838 | bpt->inserted = 1; |
| 1839 | |
| 1840 | /* We've already printed an error message if there was a problem |
| 1841 | inserting this catchpoint, and we've disabled the catchpoint, |
| 1842 | so just return success. */ |
| 1843 | return 0; |
| 1844 | } |
| 1845 | |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
| 1849 | /* This function is called when program space PSPACE is about to be |
| 1850 | deleted. It takes care of updating breakpoints to not reference |
| 1851 | PSPACE anymore. */ |
| 1852 | |
| 1853 | void |
| 1854 | breakpoint_program_space_exit (struct program_space *pspace) |
| 1855 | { |
| 1856 | struct breakpoint *b, *b_temp; |
| 1857 | struct bp_location *loc, **loc_temp; |
| 1858 | |
| 1859 | /* Remove any breakpoint that was set through this program space. */ |
| 1860 | ALL_BREAKPOINTS_SAFE (b, b_temp) |
| 1861 | { |
| 1862 | if (b->pspace == pspace) |
| 1863 | delete_breakpoint (b); |
| 1864 | } |
| 1865 | |
| 1866 | /* Breakpoints set through other program spaces could have locations |
| 1867 | bound to PSPACE as well. Remove those. */ |
| 1868 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 1869 | { |
| 1870 | struct bp_location *tmp; |
| 1871 | |
| 1872 | if (loc->pspace == pspace) |
| 1873 | { |
| 1874 | if (loc->owner->loc == loc) |
| 1875 | loc->owner->loc = loc->next; |
| 1876 | else |
| 1877 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) |
| 1878 | if (tmp->next == loc) |
| 1879 | { |
| 1880 | tmp->next = loc->next; |
| 1881 | break; |
| 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | /* Now update the global location list to permanently delete the |
| 1887 | removed locations above. */ |
| 1888 | update_global_location_list (0); |
| 1889 | } |
| 1890 | |
| 1891 | /* Make sure all breakpoints are inserted in inferior. |
| 1892 | Throws exception on any error. |
| 1893 | A breakpoint that is already inserted won't be inserted |
| 1894 | again, so calling this function twice is safe. */ |
| 1895 | void |
| 1896 | insert_breakpoints (void) |
| 1897 | { |
| 1898 | struct breakpoint *bpt; |
| 1899 | |
| 1900 | ALL_BREAKPOINTS (bpt) |
| 1901 | if (is_hardware_watchpoint (bpt)) |
| 1902 | update_watchpoint (bpt, 0 /* don't reparse. */); |
| 1903 | |
| 1904 | update_global_location_list (1); |
| 1905 | |
| 1906 | /* update_global_location_list does not insert breakpoints when |
| 1907 | always_inserted_mode is not enabled. Explicitly insert them |
| 1908 | now. */ |
| 1909 | if (!breakpoints_always_inserted_mode ()) |
| 1910 | insert_breakpoint_locations (); |
| 1911 | } |
| 1912 | |
| 1913 | /* insert_breakpoints is used when starting or continuing the program. |
| 1914 | remove_breakpoints is used when the program stops. |
| 1915 | Both return zero if successful, |
| 1916 | or an `errno' value if could not write the inferior. */ |
| 1917 | |
| 1918 | static void |
| 1919 | insert_breakpoint_locations (void) |
| 1920 | { |
| 1921 | struct breakpoint *bpt; |
| 1922 | struct bp_location *b, **bp_tmp; |
| 1923 | int error = 0; |
| 1924 | int val = 0; |
| 1925 | int disabled_breaks = 0; |
| 1926 | int hw_breakpoint_error = 0; |
| 1927 | |
| 1928 | struct ui_file *tmp_error_stream = mem_fileopen (); |
| 1929 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
| 1930 | |
| 1931 | /* Explicitly mark the warning -- this will only be printed if |
| 1932 | there was an error. */ |
| 1933 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); |
| 1934 | |
| 1935 | save_current_space_and_thread (); |
| 1936 | |
| 1937 | ALL_BP_LOCATIONS (b, bp_tmp) |
| 1938 | { |
| 1939 | struct thread_info *tp; |
| 1940 | CORE_ADDR last_addr; |
| 1941 | |
| 1942 | if (!should_be_inserted (b) || b->inserted) |
| 1943 | continue; |
| 1944 | |
| 1945 | /* There is no point inserting thread-specific breakpoints if the |
| 1946 | thread no longer exists. */ |
| 1947 | if (b->owner->thread != -1 |
| 1948 | && !valid_thread_id (b->owner->thread)) |
| 1949 | continue; |
| 1950 | |
| 1951 | switch_to_program_space_and_thread (b->pspace); |
| 1952 | |
| 1953 | /* For targets that support global breakpoints, there's no need |
| 1954 | to select an inferior to insert breakpoint to. In fact, even |
| 1955 | if we aren't attached to any process yet, we should still |
| 1956 | insert breakpoints. */ |
| 1957 | if (!gdbarch_has_global_breakpoints (target_gdbarch) |
| 1958 | && ptid_equal (inferior_ptid, null_ptid)) |
| 1959 | continue; |
| 1960 | |
| 1961 | val = insert_bp_location (b, tmp_error_stream, |
| 1962 | &disabled_breaks, |
| 1963 | &hw_breakpoint_error); |
| 1964 | if (val) |
| 1965 | error = val; |
| 1966 | } |
| 1967 | |
| 1968 | /* If we failed to insert all locations of a watchpoint, |
| 1969 | remove them, as half-inserted watchpoint is of limited use. */ |
| 1970 | ALL_BREAKPOINTS (bpt) |
| 1971 | { |
| 1972 | int some_failed = 0; |
| 1973 | struct bp_location *loc; |
| 1974 | |
| 1975 | if (!is_hardware_watchpoint (bpt)) |
| 1976 | continue; |
| 1977 | |
| 1978 | if (!breakpoint_enabled (bpt)) |
| 1979 | continue; |
| 1980 | |
| 1981 | if (bpt->disposition == disp_del_at_next_stop) |
| 1982 | continue; |
| 1983 | |
| 1984 | for (loc = bpt->loc; loc; loc = loc->next) |
| 1985 | if (!loc->inserted && should_be_inserted (loc)) |
| 1986 | { |
| 1987 | some_failed = 1; |
| 1988 | break; |
| 1989 | } |
| 1990 | if (some_failed) |
| 1991 | { |
| 1992 | for (loc = bpt->loc; loc; loc = loc->next) |
| 1993 | if (loc->inserted) |
| 1994 | remove_breakpoint (loc, mark_uninserted); |
| 1995 | |
| 1996 | hw_breakpoint_error = 1; |
| 1997 | fprintf_unfiltered (tmp_error_stream, |
| 1998 | "Could not insert hardware watchpoint %d.\n", |
| 1999 | bpt->number); |
| 2000 | error = -1; |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | if (error) |
| 2005 | { |
| 2006 | /* If a hardware breakpoint or watchpoint was inserted, add a |
| 2007 | message about possibly exhausted resources. */ |
| 2008 | if (hw_breakpoint_error) |
| 2009 | { |
| 2010 | fprintf_unfiltered (tmp_error_stream, |
| 2011 | "Could not insert hardware breakpoints:\n\ |
| 2012 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
| 2013 | } |
| 2014 | target_terminal_ours_for_output (); |
| 2015 | error_stream (tmp_error_stream); |
| 2016 | } |
| 2017 | |
| 2018 | do_cleanups (cleanups); |
| 2019 | } |
| 2020 | |
| 2021 | int |
| 2022 | remove_breakpoints (void) |
| 2023 | { |
| 2024 | struct bp_location *b, **bp_tmp; |
| 2025 | int val = 0; |
| 2026 | |
| 2027 | ALL_BP_LOCATIONS (b, bp_tmp) |
| 2028 | { |
| 2029 | if (b->inserted) |
| 2030 | val |= remove_breakpoint (b, mark_uninserted); |
| 2031 | } |
| 2032 | return val; |
| 2033 | } |
| 2034 | |
| 2035 | /* Remove breakpoints of process PID. */ |
| 2036 | |
| 2037 | int |
| 2038 | remove_breakpoints_pid (int pid) |
| 2039 | { |
| 2040 | struct bp_location *b, **b_tmp; |
| 2041 | int val; |
| 2042 | struct inferior *inf = find_inferior_pid (pid); |
| 2043 | |
| 2044 | ALL_BP_LOCATIONS (b, b_tmp) |
| 2045 | { |
| 2046 | if (b->pspace != inf->pspace) |
| 2047 | continue; |
| 2048 | |
| 2049 | if (b->inserted) |
| 2050 | { |
| 2051 | val = remove_breakpoint (b, mark_uninserted); |
| 2052 | if (val != 0) |
| 2053 | return val; |
| 2054 | } |
| 2055 | } |
| 2056 | return 0; |
| 2057 | } |
| 2058 | |
| 2059 | int |
| 2060 | remove_hw_watchpoints (void) |
| 2061 | { |
| 2062 | struct bp_location *b, **bp_tmp; |
| 2063 | int val = 0; |
| 2064 | |
| 2065 | ALL_BP_LOCATIONS (b, bp_tmp) |
| 2066 | { |
| 2067 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
| 2068 | val |= remove_breakpoint (b, mark_uninserted); |
| 2069 | } |
| 2070 | return val; |
| 2071 | } |
| 2072 | |
| 2073 | int |
| 2074 | reattach_breakpoints (int pid) |
| 2075 | { |
| 2076 | struct cleanup *old_chain; |
| 2077 | struct bp_location *b, **bp_tmp; |
| 2078 | int val; |
| 2079 | struct ui_file *tmp_error_stream = mem_fileopen (); |
| 2080 | int dummy1 = 0, dummy2 = 0; |
| 2081 | struct inferior *inf; |
| 2082 | struct thread_info *tp; |
| 2083 | |
| 2084 | tp = any_live_thread_of_process (pid); |
| 2085 | if (tp == NULL) |
| 2086 | return 1; |
| 2087 | |
| 2088 | inf = find_inferior_pid (pid); |
| 2089 | old_chain = save_inferior_ptid (); |
| 2090 | |
| 2091 | inferior_ptid = tp->ptid; |
| 2092 | |
| 2093 | make_cleanup_ui_file_delete (tmp_error_stream); |
| 2094 | |
| 2095 | ALL_BP_LOCATIONS (b, bp_tmp) |
| 2096 | { |
| 2097 | if (b->pspace != inf->pspace) |
| 2098 | continue; |
| 2099 | |
| 2100 | if (b->inserted) |
| 2101 | { |
| 2102 | b->inserted = 0; |
| 2103 | val = insert_bp_location (b, tmp_error_stream, |
| 2104 | &dummy1, &dummy2); |
| 2105 | if (val != 0) |
| 2106 | { |
| 2107 | do_cleanups (old_chain); |
| 2108 | return val; |
| 2109 | } |
| 2110 | } |
| 2111 | } |
| 2112 | do_cleanups (old_chain); |
| 2113 | return 0; |
| 2114 | } |
| 2115 | |
| 2116 | static int internal_breakpoint_number = -1; |
| 2117 | |
| 2118 | static struct breakpoint * |
| 2119 | create_internal_breakpoint (struct gdbarch *gdbarch, |
| 2120 | CORE_ADDR address, enum bptype type) |
| 2121 | { |
| 2122 | struct symtab_and_line sal; |
| 2123 | struct breakpoint *b; |
| 2124 | |
| 2125 | init_sal (&sal); /* initialize to zeroes */ |
| 2126 | |
| 2127 | sal.pc = address; |
| 2128 | sal.section = find_pc_overlay (sal.pc); |
| 2129 | sal.pspace = current_program_space; |
| 2130 | |
| 2131 | b = set_raw_breakpoint (gdbarch, sal, type); |
| 2132 | b->number = internal_breakpoint_number--; |
| 2133 | b->disposition = disp_donttouch; |
| 2134 | |
| 2135 | return b; |
| 2136 | } |
| 2137 | |
| 2138 | static void |
| 2139 | create_overlay_event_breakpoint (char *func_name) |
| 2140 | { |
| 2141 | struct objfile *objfile; |
| 2142 | |
| 2143 | ALL_OBJFILES (objfile) |
| 2144 | { |
| 2145 | struct breakpoint *b; |
| 2146 | struct minimal_symbol *m; |
| 2147 | |
| 2148 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 2149 | if (m == NULL) |
| 2150 | continue; |
| 2151 | |
| 2152 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
| 2153 | SYMBOL_VALUE_ADDRESS (m), |
| 2154 | bp_overlay_event); |
| 2155 | b->addr_string = xstrdup (func_name); |
| 2156 | |
| 2157 | if (overlay_debugging == ovly_auto) |
| 2158 | { |
| 2159 | b->enable_state = bp_enabled; |
| 2160 | overlay_events_enabled = 1; |
| 2161 | } |
| 2162 | else |
| 2163 | { |
| 2164 | b->enable_state = bp_disabled; |
| 2165 | overlay_events_enabled = 0; |
| 2166 | } |
| 2167 | } |
| 2168 | update_global_location_list (1); |
| 2169 | } |
| 2170 | |
| 2171 | static void |
| 2172 | create_longjmp_master_breakpoint (char *func_name) |
| 2173 | { |
| 2174 | struct program_space *pspace; |
| 2175 | struct objfile *objfile; |
| 2176 | struct cleanup *old_chain; |
| 2177 | |
| 2178 | old_chain = save_current_program_space (); |
| 2179 | |
| 2180 | ALL_PSPACES (pspace) |
| 2181 | ALL_OBJFILES (objfile) |
| 2182 | { |
| 2183 | struct breakpoint *b; |
| 2184 | struct minimal_symbol *m; |
| 2185 | |
| 2186 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) |
| 2187 | continue; |
| 2188 | |
| 2189 | set_current_program_space (pspace); |
| 2190 | |
| 2191 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 2192 | if (m == NULL) |
| 2193 | continue; |
| 2194 | |
| 2195 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
| 2196 | SYMBOL_VALUE_ADDRESS (m), |
| 2197 | bp_longjmp_master); |
| 2198 | b->addr_string = xstrdup (func_name); |
| 2199 | b->enable_state = bp_disabled; |
| 2200 | } |
| 2201 | update_global_location_list (1); |
| 2202 | |
| 2203 | do_cleanups (old_chain); |
| 2204 | } |
| 2205 | |
| 2206 | /* Create a master std::terminate breakpoint. The actual function |
| 2207 | looked for is named FUNC_NAME. */ |
| 2208 | static void |
| 2209 | create_std_terminate_master_breakpoint (const char *func_name) |
| 2210 | { |
| 2211 | struct program_space *pspace; |
| 2212 | struct objfile *objfile; |
| 2213 | struct cleanup *old_chain; |
| 2214 | |
| 2215 | old_chain = save_current_program_space (); |
| 2216 | |
| 2217 | ALL_PSPACES (pspace) |
| 2218 | ALL_OBJFILES (objfile) |
| 2219 | { |
| 2220 | struct breakpoint *b; |
| 2221 | struct minimal_symbol *m; |
| 2222 | |
| 2223 | set_current_program_space (pspace); |
| 2224 | |
| 2225 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
| 2226 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text |
| 2227 | && MSYMBOL_TYPE (m) != mst_file_text)) |
| 2228 | continue; |
| 2229 | |
| 2230 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
| 2231 | SYMBOL_VALUE_ADDRESS (m), |
| 2232 | bp_std_terminate_master); |
| 2233 | b->addr_string = xstrdup (func_name); |
| 2234 | b->enable_state = bp_disabled; |
| 2235 | } |
| 2236 | update_global_location_list (1); |
| 2237 | |
| 2238 | do_cleanups (old_chain); |
| 2239 | } |
| 2240 | |
| 2241 | void |
| 2242 | update_breakpoints_after_exec (void) |
| 2243 | { |
| 2244 | struct breakpoint *b; |
| 2245 | struct breakpoint *temp; |
| 2246 | struct bp_location *bploc, **bplocp_tmp; |
| 2247 | |
| 2248 | /* We're about to delete breakpoints from GDB's lists. If the |
| 2249 | INSERTED flag is true, GDB will try to lift the breakpoints by |
| 2250 | writing the breakpoints' "shadow contents" back into memory. The |
| 2251 | "shadow contents" are NOT valid after an exec, so GDB should not |
| 2252 | do that. Instead, the target is responsible from marking |
| 2253 | breakpoints out as soon as it detects an exec. We don't do that |
| 2254 | here instead, because there may be other attempts to delete |
| 2255 | breakpoints after detecting an exec and before reaching here. */ |
| 2256 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
| 2257 | if (bploc->pspace == current_program_space) |
| 2258 | gdb_assert (!bploc->inserted); |
| 2259 | |
| 2260 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 2261 | { |
| 2262 | if (b->pspace != current_program_space) |
| 2263 | continue; |
| 2264 | |
| 2265 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
| 2266 | if (b->type == bp_shlib_event) |
| 2267 | { |
| 2268 | delete_breakpoint (b); |
| 2269 | continue; |
| 2270 | } |
| 2271 | |
| 2272 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
| 2273 | if (b->type == bp_jit_event) |
| 2274 | { |
| 2275 | delete_breakpoint (b); |
| 2276 | continue; |
| 2277 | } |
| 2278 | |
| 2279 | /* Thread event breakpoints must be set anew after an exec(), |
| 2280 | as must overlay event and longjmp master breakpoints. */ |
| 2281 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
| 2282 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master) |
| 2283 | { |
| 2284 | delete_breakpoint (b); |
| 2285 | continue; |
| 2286 | } |
| 2287 | |
| 2288 | /* Step-resume breakpoints are meaningless after an exec(). */ |
| 2289 | if (b->type == bp_step_resume) |
| 2290 | { |
| 2291 | delete_breakpoint (b); |
| 2292 | continue; |
| 2293 | } |
| 2294 | |
| 2295 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
| 2296 | after an exec. */ |
| 2297 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) |
| 2298 | { |
| 2299 | delete_breakpoint (b); |
| 2300 | continue; |
| 2301 | } |
| 2302 | |
| 2303 | if (b->type == bp_catchpoint) |
| 2304 | { |
| 2305 | /* For now, none of the bp_catchpoint breakpoints need to |
| 2306 | do anything at this point. In the future, if some of |
| 2307 | the catchpoints need to something, we will need to add |
| 2308 | a new method, and call this method from here. */ |
| 2309 | continue; |
| 2310 | } |
| 2311 | |
| 2312 | /* bp_finish is a special case. The only way we ought to be able |
| 2313 | to see one of these when an exec() has happened, is if the user |
| 2314 | caught a vfork, and then said "finish". Ordinarily a finish just |
| 2315 | carries them to the call-site of the current callee, by setting |
| 2316 | a temporary bp there and resuming. But in this case, the finish |
| 2317 | will carry them entirely through the vfork & exec. |
| 2318 | |
| 2319 | We don't want to allow a bp_finish to remain inserted now. But |
| 2320 | we can't safely delete it, 'cause finish_command has a handle to |
| 2321 | the bp on a bpstat, and will later want to delete it. There's a |
| 2322 | chance (and I've seen it happen) that if we delete the bp_finish |
| 2323 | here, that its storage will get reused by the time finish_command |
| 2324 | gets 'round to deleting the "use to be a bp_finish" breakpoint. |
| 2325 | We really must allow finish_command to delete a bp_finish. |
| 2326 | |
| 2327 | In the absense of a general solution for the "how do we know |
| 2328 | it's safe to delete something others may have handles to?" |
| 2329 | problem, what we'll do here is just uninsert the bp_finish, and |
| 2330 | let finish_command delete it. |
| 2331 | |
| 2332 | (We know the bp_finish is "doomed" in the sense that it's |
| 2333 | momentary, and will be deleted as soon as finish_command sees |
| 2334 | the inferior stopped. So it doesn't matter that the bp's |
| 2335 | address is probably bogus in the new a.out, unlike e.g., the |
| 2336 | solib breakpoints.) */ |
| 2337 | |
| 2338 | if (b->type == bp_finish) |
| 2339 | { |
| 2340 | continue; |
| 2341 | } |
| 2342 | |
| 2343 | /* Without a symbolic address, we have little hope of the |
| 2344 | pre-exec() address meaning the same thing in the post-exec() |
| 2345 | a.out. */ |
| 2346 | if (b->addr_string == NULL) |
| 2347 | { |
| 2348 | delete_breakpoint (b); |
| 2349 | continue; |
| 2350 | } |
| 2351 | } |
| 2352 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
| 2353 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
| 2354 | create_longjmp_master_breakpoint ("longjmp"); |
| 2355 | create_longjmp_master_breakpoint ("_longjmp"); |
| 2356 | create_longjmp_master_breakpoint ("siglongjmp"); |
| 2357 | create_longjmp_master_breakpoint ("_siglongjmp"); |
| 2358 | create_std_terminate_master_breakpoint ("std::terminate()"); |
| 2359 | } |
| 2360 | |
| 2361 | int |
| 2362 | detach_breakpoints (int pid) |
| 2363 | { |
| 2364 | struct bp_location *b, **bp_tmp; |
| 2365 | int val = 0; |
| 2366 | struct cleanup *old_chain = save_inferior_ptid (); |
| 2367 | struct inferior *inf = current_inferior (); |
| 2368 | |
| 2369 | if (pid == PIDGET (inferior_ptid)) |
| 2370 | error (_("Cannot detach breakpoints of inferior_ptid")); |
| 2371 | |
| 2372 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
| 2373 | inferior_ptid = pid_to_ptid (pid); |
| 2374 | ALL_BP_LOCATIONS (b, bp_tmp) |
| 2375 | { |
| 2376 | if (b->pspace != inf->pspace) |
| 2377 | continue; |
| 2378 | |
| 2379 | if (b->inserted) |
| 2380 | val |= remove_breakpoint_1 (b, mark_inserted); |
| 2381 | } |
| 2382 | do_cleanups (old_chain); |
| 2383 | return val; |
| 2384 | } |
| 2385 | |
| 2386 | /* Remove the breakpoint location B from the current address space. |
| 2387 | Note that this is used to detach breakpoints from a child fork. |
| 2388 | When we get here, the child isn't in the inferior list, and neither |
| 2389 | do we have objects to represent its address space --- we should |
| 2390 | *not* look at b->pspace->aspace here. */ |
| 2391 | |
| 2392 | static int |
| 2393 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
| 2394 | { |
| 2395 | int val; |
| 2396 | struct cleanup *old_chain; |
| 2397 | |
| 2398 | if (b->owner->enable_state == bp_permanent) |
| 2399 | /* Permanent breakpoints cannot be inserted or removed. */ |
| 2400 | return 0; |
| 2401 | |
| 2402 | /* The type of none suggests that owner is actually deleted. |
| 2403 | This should not ever happen. */ |
| 2404 | gdb_assert (b->owner->type != bp_none); |
| 2405 | |
| 2406 | if (b->loc_type == bp_loc_software_breakpoint |
| 2407 | || b->loc_type == bp_loc_hardware_breakpoint) |
| 2408 | { |
| 2409 | /* "Normal" instruction breakpoint: either the standard |
| 2410 | trap-instruction bp (bp_breakpoint), or a |
| 2411 | bp_hardware_breakpoint. */ |
| 2412 | |
| 2413 | /* First check to see if we have to handle an overlay. */ |
| 2414 | if (overlay_debugging == ovly_off |
| 2415 | || b->section == NULL |
| 2416 | || !(section_is_overlay (b->section))) |
| 2417 | { |
| 2418 | /* No overlay handling: just remove the breakpoint. */ |
| 2419 | |
| 2420 | if (b->loc_type == bp_loc_hardware_breakpoint) |
| 2421 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
| 2422 | else |
| 2423 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
| 2424 | } |
| 2425 | else |
| 2426 | { |
| 2427 | /* This breakpoint is in an overlay section. |
| 2428 | Did we set a breakpoint at the LMA? */ |
| 2429 | if (!overlay_events_enabled) |
| 2430 | { |
| 2431 | /* Yes -- overlay event support is not active, so we |
| 2432 | should have set a breakpoint at the LMA. Remove it. |
| 2433 | */ |
| 2434 | /* Ignore any failures: if the LMA is in ROM, we will |
| 2435 | have already warned when we failed to insert it. */ |
| 2436 | if (b->loc_type == bp_loc_hardware_breakpoint) |
| 2437 | target_remove_hw_breakpoint (b->gdbarch, |
| 2438 | &b->overlay_target_info); |
| 2439 | else |
| 2440 | target_remove_breakpoint (b->gdbarch, |
| 2441 | &b->overlay_target_info); |
| 2442 | } |
| 2443 | /* Did we set a breakpoint at the VMA? |
| 2444 | If so, we will have marked the breakpoint 'inserted'. */ |
| 2445 | if (b->inserted) |
| 2446 | { |
| 2447 | /* Yes -- remove it. Previously we did not bother to |
| 2448 | remove the breakpoint if the section had been |
| 2449 | unmapped, but let's not rely on that being safe. We |
| 2450 | don't know what the overlay manager might do. */ |
| 2451 | if (b->loc_type == bp_loc_hardware_breakpoint) |
| 2452 | val = target_remove_hw_breakpoint (b->gdbarch, |
| 2453 | &b->target_info); |
| 2454 | |
| 2455 | /* However, we should remove *software* breakpoints only |
| 2456 | if the section is still mapped, or else we overwrite |
| 2457 | wrong code with the saved shadow contents. */ |
| 2458 | else if (section_is_mapped (b->section)) |
| 2459 | val = target_remove_breakpoint (b->gdbarch, |
| 2460 | &b->target_info); |
| 2461 | else |
| 2462 | val = 0; |
| 2463 | } |
| 2464 | else |
| 2465 | { |
| 2466 | /* No -- not inserted, so no need to remove. No error. */ |
| 2467 | val = 0; |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | /* In some cases, we might not be able to remove a breakpoint |
| 2472 | in a shared library that has already been removed, but we |
| 2473 | have not yet processed the shlib unload event. */ |
| 2474 | if (val && solib_name_from_address (b->pspace, b->address)) |
| 2475 | val = 0; |
| 2476 | |
| 2477 | if (val) |
| 2478 | return val; |
| 2479 | b->inserted = (is == mark_inserted); |
| 2480 | } |
| 2481 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
| 2482 | { |
| 2483 | struct value *v; |
| 2484 | struct value *n; |
| 2485 | |
| 2486 | b->inserted = (is == mark_inserted); |
| 2487 | val = target_remove_watchpoint (b->address, b->length, |
| 2488 | b->watchpoint_type); |
| 2489 | |
| 2490 | /* Failure to remove any of the hardware watchpoints comes here. */ |
| 2491 | if ((is == mark_uninserted) && (b->inserted)) |
| 2492 | warning (_("Could not remove hardware watchpoint %d."), |
| 2493 | b->owner->number); |
| 2494 | } |
| 2495 | else if (b->owner->type == bp_catchpoint |
| 2496 | && breakpoint_enabled (b->owner) |
| 2497 | && !b->duplicate) |
| 2498 | { |
| 2499 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); |
| 2500 | |
| 2501 | val = b->owner->ops->remove (b->owner); |
| 2502 | if (val) |
| 2503 | return val; |
| 2504 | b->inserted = (is == mark_inserted); |
| 2505 | } |
| 2506 | |
| 2507 | return 0; |
| 2508 | } |
| 2509 | |
| 2510 | static int |
| 2511 | remove_breakpoint (struct bp_location *b, insertion_state_t is) |
| 2512 | { |
| 2513 | int ret; |
| 2514 | struct cleanup *old_chain; |
| 2515 | |
| 2516 | if (b->owner->enable_state == bp_permanent) |
| 2517 | /* Permanent breakpoints cannot be inserted or removed. */ |
| 2518 | return 0; |
| 2519 | |
| 2520 | /* The type of none suggests that owner is actually deleted. |
| 2521 | This should not ever happen. */ |
| 2522 | gdb_assert (b->owner->type != bp_none); |
| 2523 | |
| 2524 | old_chain = save_current_space_and_thread (); |
| 2525 | |
| 2526 | switch_to_program_space_and_thread (b->pspace); |
| 2527 | |
| 2528 | ret = remove_breakpoint_1 (b, is); |
| 2529 | |
| 2530 | do_cleanups (old_chain); |
| 2531 | return ret; |
| 2532 | } |
| 2533 | |
| 2534 | /* Clear the "inserted" flag in all breakpoints. */ |
| 2535 | |
| 2536 | void |
| 2537 | mark_breakpoints_out (void) |
| 2538 | { |
| 2539 | struct bp_location *bpt, **bptp_tmp; |
| 2540 | |
| 2541 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
| 2542 | if (bpt->pspace == current_program_space) |
| 2543 | bpt->inserted = 0; |
| 2544 | } |
| 2545 | |
| 2546 | /* Clear the "inserted" flag in all breakpoints and delete any |
| 2547 | breakpoints which should go away between runs of the program. |
| 2548 | |
| 2549 | Plus other such housekeeping that has to be done for breakpoints |
| 2550 | between runs. |
| 2551 | |
| 2552 | Note: this function gets called at the end of a run (by |
| 2553 | generic_mourn_inferior) and when a run begins (by |
| 2554 | init_wait_for_inferior). */ |
| 2555 | |
| 2556 | |
| 2557 | |
| 2558 | void |
| 2559 | breakpoint_init_inferior (enum inf_context context) |
| 2560 | { |
| 2561 | struct breakpoint *b, *temp; |
| 2562 | struct bp_location *bpt, **bptp_tmp; |
| 2563 | int ix; |
| 2564 | struct program_space *pspace = current_program_space; |
| 2565 | |
| 2566 | /* If breakpoint locations are shared across processes, then there's |
| 2567 | nothing to do. */ |
| 2568 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
| 2569 | return; |
| 2570 | |
| 2571 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
| 2572 | { |
| 2573 | if (bpt->pspace == pspace |
| 2574 | && bpt->owner->enable_state != bp_permanent) |
| 2575 | bpt->inserted = 0; |
| 2576 | } |
| 2577 | |
| 2578 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 2579 | { |
| 2580 | if (b->loc && b->loc->pspace != pspace) |
| 2581 | continue; |
| 2582 | |
| 2583 | switch (b->type) |
| 2584 | { |
| 2585 | case bp_call_dummy: |
| 2586 | |
| 2587 | /* If the call dummy breakpoint is at the entry point it will |
| 2588 | cause problems when the inferior is rerun, so we better get |
| 2589 | rid of it. */ |
| 2590 | |
| 2591 | case bp_watchpoint_scope: |
| 2592 | |
| 2593 | /* Also get rid of scope breakpoints. */ |
| 2594 | |
| 2595 | case bp_shlib_event: |
| 2596 | |
| 2597 | /* Also remove solib event breakpoints. Their addresses may |
| 2598 | have changed since the last time we ran the program. |
| 2599 | Actually we may now be debugging against different target; |
| 2600 | and so the solib backend that installed this breakpoint may |
| 2601 | not be used in by the target. E.g., |
| 2602 | |
| 2603 | (gdb) file prog-linux |
| 2604 | (gdb) run # native linux target |
| 2605 | ... |
| 2606 | (gdb) kill |
| 2607 | (gdb) file prog-win.exe |
| 2608 | (gdb) tar rem :9999 # remote Windows gdbserver. |
| 2609 | */ |
| 2610 | |
| 2611 | delete_breakpoint (b); |
| 2612 | break; |
| 2613 | |
| 2614 | case bp_watchpoint: |
| 2615 | case bp_hardware_watchpoint: |
| 2616 | case bp_read_watchpoint: |
| 2617 | case bp_access_watchpoint: |
| 2618 | |
| 2619 | /* Likewise for watchpoints on local expressions. */ |
| 2620 | if (b->exp_valid_block != NULL) |
| 2621 | delete_breakpoint (b); |
| 2622 | else if (context == inf_starting) |
| 2623 | { |
| 2624 | /* Reset val field to force reread of starting value |
| 2625 | in insert_breakpoints. */ |
| 2626 | if (b->val) |
| 2627 | value_free (b->val); |
| 2628 | b->val = NULL; |
| 2629 | b->val_valid = 0; |
| 2630 | } |
| 2631 | break; |
| 2632 | default: |
| 2633 | break; |
| 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | /* Get rid of the moribund locations. */ |
| 2638 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) |
| 2639 | free_bp_location (bpt); |
| 2640 | VEC_free (bp_location_p, moribund_locations); |
| 2641 | } |
| 2642 | |
| 2643 | /* These functions concern about actual breakpoints inserted in the |
| 2644 | target --- to e.g. check if we need to do decr_pc adjustment or if |
| 2645 | we need to hop over the bkpt --- so we check for address space |
| 2646 | match, not program space. */ |
| 2647 | |
| 2648 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
| 2649 | exists at PC. It returns ordinary_breakpoint_here if it's an |
| 2650 | ordinary breakpoint, or permanent_breakpoint_here if it's a |
| 2651 | permanent breakpoint. |
| 2652 | - When continuing from a location with an ordinary breakpoint, we |
| 2653 | actually single step once before calling insert_breakpoints. |
| 2654 | - When continuing from a localion with a permanent breakpoint, we |
| 2655 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
| 2656 | the target, to advance the PC past the breakpoint. */ |
| 2657 | |
| 2658 | enum breakpoint_here |
| 2659 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 2660 | { |
| 2661 | struct bp_location *bpt, **bptp_tmp; |
| 2662 | int any_breakpoint_here = 0; |
| 2663 | |
| 2664 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
| 2665 | { |
| 2666 | if (bpt->loc_type != bp_loc_software_breakpoint |
| 2667 | && bpt->loc_type != bp_loc_hardware_breakpoint) |
| 2668 | continue; |
| 2669 | |
| 2670 | if ((breakpoint_enabled (bpt->owner) |
| 2671 | || bpt->owner->enable_state == bp_permanent) |
| 2672 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
| 2673 | aspace, pc)) |
| 2674 | { |
| 2675 | if (overlay_debugging |
| 2676 | && section_is_overlay (bpt->section) |
| 2677 | && !section_is_mapped (bpt->section)) |
| 2678 | continue; /* unmapped overlay -- can't be a match */ |
| 2679 | else if (bpt->owner->enable_state == bp_permanent) |
| 2680 | return permanent_breakpoint_here; |
| 2681 | else |
| 2682 | any_breakpoint_here = 1; |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
| 2687 | } |
| 2688 | |
| 2689 | /* Return true if there's a moribund breakpoint at PC. */ |
| 2690 | |
| 2691 | int |
| 2692 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 2693 | { |
| 2694 | struct bp_location *loc; |
| 2695 | int ix; |
| 2696 | |
| 2697 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 2698 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
| 2699 | aspace, pc)) |
| 2700 | return 1; |
| 2701 | |
| 2702 | return 0; |
| 2703 | } |
| 2704 | |
| 2705 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
| 2706 | inserted using regular breakpoint_chain / bp_location array mechanism. |
| 2707 | This does not check for single-step breakpoints, which are |
| 2708 | inserted and removed using direct target manipulation. */ |
| 2709 | |
| 2710 | int |
| 2711 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 2712 | { |
| 2713 | struct bp_location *bpt, **bptp_tmp; |
| 2714 | |
| 2715 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
| 2716 | { |
| 2717 | if (bpt->loc_type != bp_loc_software_breakpoint |
| 2718 | && bpt->loc_type != bp_loc_hardware_breakpoint) |
| 2719 | continue; |
| 2720 | |
| 2721 | if (bpt->inserted |
| 2722 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
| 2723 | aspace, pc)) |
| 2724 | { |
| 2725 | if (overlay_debugging |
| 2726 | && section_is_overlay (bpt->section) |
| 2727 | && !section_is_mapped (bpt->section)) |
| 2728 | continue; /* unmapped overlay -- can't be a match */ |
| 2729 | else |
| 2730 | return 1; |
| 2731 | } |
| 2732 | } |
| 2733 | return 0; |
| 2734 | } |
| 2735 | |
| 2736 | /* Returns non-zero iff there's either regular breakpoint |
| 2737 | or a single step breakpoint inserted at PC. */ |
| 2738 | |
| 2739 | int |
| 2740 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 2741 | { |
| 2742 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
| 2743 | return 1; |
| 2744 | |
| 2745 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
| 2746 | return 1; |
| 2747 | |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
| 2751 | /* This function returns non-zero iff there is a software breakpoint |
| 2752 | inserted at PC. */ |
| 2753 | |
| 2754 | int |
| 2755 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 2756 | { |
| 2757 | struct bp_location *bpt, **bptp_tmp; |
| 2758 | int any_breakpoint_here = 0; |
| 2759 | |
| 2760 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
| 2761 | { |
| 2762 | if (bpt->loc_type != bp_loc_software_breakpoint) |
| 2763 | continue; |
| 2764 | |
| 2765 | if (bpt->inserted |
| 2766 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
| 2767 | aspace, pc)) |
| 2768 | { |
| 2769 | if (overlay_debugging |
| 2770 | && section_is_overlay (bpt->section) |
| 2771 | && !section_is_mapped (bpt->section)) |
| 2772 | continue; /* unmapped overlay -- can't be a match */ |
| 2773 | else |
| 2774 | return 1; |
| 2775 | } |
| 2776 | } |
| 2777 | |
| 2778 | /* Also check for software single-step breakpoints. */ |
| 2779 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
| 2780 | return 1; |
| 2781 | |
| 2782 | return 0; |
| 2783 | } |
| 2784 | |
| 2785 | int |
| 2786 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, |
| 2787 | CORE_ADDR addr, ULONGEST len) |
| 2788 | { |
| 2789 | struct breakpoint *bpt; |
| 2790 | |
| 2791 | ALL_BREAKPOINTS (bpt) |
| 2792 | { |
| 2793 | struct bp_location *loc; |
| 2794 | |
| 2795 | if (bpt->type != bp_hardware_watchpoint |
| 2796 | && bpt->type != bp_access_watchpoint) |
| 2797 | continue; |
| 2798 | |
| 2799 | if (!breakpoint_enabled (bpt)) |
| 2800 | continue; |
| 2801 | |
| 2802 | for (loc = bpt->loc; loc; loc = loc->next) |
| 2803 | if (loc->pspace->aspace == aspace && loc->inserted) |
| 2804 | { |
| 2805 | CORE_ADDR l, h; |
| 2806 | |
| 2807 | /* Check for intersection. */ |
| 2808 | l = max (loc->address, addr); |
| 2809 | h = min (loc->address + loc->length, addr + len); |
| 2810 | if (l < h) |
| 2811 | return 1; |
| 2812 | } |
| 2813 | } |
| 2814 | return 0; |
| 2815 | } |
| 2816 | |
| 2817 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
| 2818 | PC is valid for process/thread PTID. */ |
| 2819 | |
| 2820 | int |
| 2821 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
| 2822 | ptid_t ptid) |
| 2823 | { |
| 2824 | struct bp_location *bpt, **bptp_tmp; |
| 2825 | /* The thread and task IDs associated to PTID, computed lazily. */ |
| 2826 | int thread = -1; |
| 2827 | int task = 0; |
| 2828 | |
| 2829 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
| 2830 | { |
| 2831 | if (bpt->loc_type != bp_loc_software_breakpoint |
| 2832 | && bpt->loc_type != bp_loc_hardware_breakpoint) |
| 2833 | continue; |
| 2834 | |
| 2835 | if (!breakpoint_enabled (bpt->owner) |
| 2836 | && bpt->owner->enable_state != bp_permanent) |
| 2837 | continue; |
| 2838 | |
| 2839 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
| 2840 | aspace, pc)) |
| 2841 | continue; |
| 2842 | |
| 2843 | if (bpt->owner->thread != -1) |
| 2844 | { |
| 2845 | /* This is a thread-specific breakpoint. Check that ptid |
| 2846 | matches that thread. If thread hasn't been computed yet, |
| 2847 | it is now time to do so. */ |
| 2848 | if (thread == -1) |
| 2849 | thread = pid_to_thread_id (ptid); |
| 2850 | if (bpt->owner->thread != thread) |
| 2851 | continue; |
| 2852 | } |
| 2853 | |
| 2854 | if (bpt->owner->task != 0) |
| 2855 | { |
| 2856 | /* This is a task-specific breakpoint. Check that ptid |
| 2857 | matches that task. If task hasn't been computed yet, |
| 2858 | it is now time to do so. */ |
| 2859 | if (task == 0) |
| 2860 | task = ada_get_task_number (ptid); |
| 2861 | if (bpt->owner->task != task) |
| 2862 | continue; |
| 2863 | } |
| 2864 | |
| 2865 | if (overlay_debugging |
| 2866 | && section_is_overlay (bpt->section) |
| 2867 | && !section_is_mapped (bpt->section)) |
| 2868 | continue; /* unmapped overlay -- can't be a match */ |
| 2869 | |
| 2870 | return 1; |
| 2871 | } |
| 2872 | |
| 2873 | return 0; |
| 2874 | } |
| 2875 | \f |
| 2876 | |
| 2877 | /* bpstat stuff. External routines' interfaces are documented |
| 2878 | in breakpoint.h. */ |
| 2879 | |
| 2880 | int |
| 2881 | ep_is_catchpoint (struct breakpoint *ep) |
| 2882 | { |
| 2883 | return (ep->type == bp_catchpoint); |
| 2884 | } |
| 2885 | |
| 2886 | void |
| 2887 | bpstat_free (bpstat bs) |
| 2888 | { |
| 2889 | if (bs->old_val != NULL) |
| 2890 | value_free (bs->old_val); |
| 2891 | decref_counted_command_line (&bs->commands); |
| 2892 | xfree (bs); |
| 2893 | } |
| 2894 | |
| 2895 | /* Clear a bpstat so that it says we are not at any breakpoint. |
| 2896 | Also free any storage that is part of a bpstat. */ |
| 2897 | |
| 2898 | void |
| 2899 | bpstat_clear (bpstat *bsp) |
| 2900 | { |
| 2901 | bpstat p; |
| 2902 | bpstat q; |
| 2903 | |
| 2904 | if (bsp == 0) |
| 2905 | return; |
| 2906 | p = *bsp; |
| 2907 | while (p != NULL) |
| 2908 | { |
| 2909 | q = p->next; |
| 2910 | bpstat_free (p); |
| 2911 | p = q; |
| 2912 | } |
| 2913 | *bsp = NULL; |
| 2914 | } |
| 2915 | |
| 2916 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
| 2917 | is part of the bpstat is copied as well. */ |
| 2918 | |
| 2919 | bpstat |
| 2920 | bpstat_copy (bpstat bs) |
| 2921 | { |
| 2922 | bpstat p = NULL; |
| 2923 | bpstat tmp; |
| 2924 | bpstat retval = NULL; |
| 2925 | |
| 2926 | if (bs == NULL) |
| 2927 | return bs; |
| 2928 | |
| 2929 | for (; bs != NULL; bs = bs->next) |
| 2930 | { |
| 2931 | tmp = (bpstat) xmalloc (sizeof (*tmp)); |
| 2932 | memcpy (tmp, bs, sizeof (*tmp)); |
| 2933 | incref_counted_command_line (tmp->commands); |
| 2934 | if (bs->old_val != NULL) |
| 2935 | { |
| 2936 | tmp->old_val = value_copy (bs->old_val); |
| 2937 | release_value (tmp->old_val); |
| 2938 | } |
| 2939 | |
| 2940 | if (p == NULL) |
| 2941 | /* This is the first thing in the chain. */ |
| 2942 | retval = tmp; |
| 2943 | else |
| 2944 | p->next = tmp; |
| 2945 | p = tmp; |
| 2946 | } |
| 2947 | p->next = NULL; |
| 2948 | return retval; |
| 2949 | } |
| 2950 | |
| 2951 | /* Find the bpstat associated with this breakpoint */ |
| 2952 | |
| 2953 | bpstat |
| 2954 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
| 2955 | { |
| 2956 | if (bsp == NULL) |
| 2957 | return NULL; |
| 2958 | |
| 2959 | for (; bsp != NULL; bsp = bsp->next) |
| 2960 | { |
| 2961 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
| 2962 | return bsp; |
| 2963 | } |
| 2964 | return NULL; |
| 2965 | } |
| 2966 | |
| 2967 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
| 2968 | at. *BSP upon return is a bpstat which points to the remaining |
| 2969 | breakpoints stopped at (but which is not guaranteed to be good for |
| 2970 | anything but further calls to bpstat_num). |
| 2971 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
| 2972 | Return -1 if stopped at a breakpoint that has been deleted since |
| 2973 | we set it. |
| 2974 | Return 1 otherwise. */ |
| 2975 | |
| 2976 | int |
| 2977 | bpstat_num (bpstat *bsp, int *num) |
| 2978 | { |
| 2979 | struct breakpoint *b; |
| 2980 | |
| 2981 | if ((*bsp) == NULL) |
| 2982 | return 0; /* No more breakpoint values */ |
| 2983 | |
| 2984 | /* We assume we'll never have several bpstats that |
| 2985 | correspond to a single breakpoint -- otherwise, |
| 2986 | this function might return the same number more |
| 2987 | than once and this will look ugly. */ |
| 2988 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; |
| 2989 | *bsp = (*bsp)->next; |
| 2990 | if (b == NULL) |
| 2991 | return -1; /* breakpoint that's been deleted since */ |
| 2992 | |
| 2993 | *num = b->number; /* We have its number */ |
| 2994 | return 1; |
| 2995 | } |
| 2996 | |
| 2997 | /* Modify BS so that the actions will not be performed. */ |
| 2998 | |
| 2999 | void |
| 3000 | bpstat_clear_actions (bpstat bs) |
| 3001 | { |
| 3002 | for (; bs != NULL; bs = bs->next) |
| 3003 | { |
| 3004 | decref_counted_command_line (&bs->commands); |
| 3005 | bs->commands_left = NULL; |
| 3006 | if (bs->old_val != NULL) |
| 3007 | { |
| 3008 | value_free (bs->old_val); |
| 3009 | bs->old_val = NULL; |
| 3010 | } |
| 3011 | } |
| 3012 | } |
| 3013 | |
| 3014 | /* Called when a command is about to proceed the inferior. */ |
| 3015 | |
| 3016 | static void |
| 3017 | breakpoint_about_to_proceed (void) |
| 3018 | { |
| 3019 | if (!ptid_equal (inferior_ptid, null_ptid)) |
| 3020 | { |
| 3021 | struct thread_info *tp = inferior_thread (); |
| 3022 | |
| 3023 | /* Allow inferior function calls in breakpoint commands to not |
| 3024 | interrupt the command list. When the call finishes |
| 3025 | successfully, the inferior will be standing at the same |
| 3026 | breakpoint as if nothing happened. */ |
| 3027 | if (tp->in_infcall) |
| 3028 | return; |
| 3029 | } |
| 3030 | |
| 3031 | breakpoint_proceeded = 1; |
| 3032 | } |
| 3033 | |
| 3034 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
| 3035 | static void |
| 3036 | cleanup_executing_breakpoints (void *ignore) |
| 3037 | { |
| 3038 | executing_breakpoint_commands = 0; |
| 3039 | } |
| 3040 | |
| 3041 | /* Execute all the commands associated with all the breakpoints at this |
| 3042 | location. Any of these commands could cause the process to proceed |
| 3043 | beyond this point, etc. We look out for such changes by checking |
| 3044 | the global "breakpoint_proceeded" after each command. |
| 3045 | |
| 3046 | Returns true if a breakpoint command resumed the inferior. In that |
| 3047 | case, it is the caller's responsibility to recall it again with the |
| 3048 | bpstat of the current thread. */ |
| 3049 | |
| 3050 | static int |
| 3051 | bpstat_do_actions_1 (bpstat *bsp) |
| 3052 | { |
| 3053 | bpstat bs; |
| 3054 | struct cleanup *old_chain; |
| 3055 | int again = 0; |
| 3056 | |
| 3057 | /* Avoid endless recursion if a `source' command is contained |
| 3058 | in bs->commands. */ |
| 3059 | if (executing_breakpoint_commands) |
| 3060 | return 0; |
| 3061 | |
| 3062 | executing_breakpoint_commands = 1; |
| 3063 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); |
| 3064 | |
| 3065 | /* This pointer will iterate over the list of bpstat's. */ |
| 3066 | bs = *bsp; |
| 3067 | |
| 3068 | breakpoint_proceeded = 0; |
| 3069 | for (; bs != NULL; bs = bs->next) |
| 3070 | { |
| 3071 | struct counted_command_line *ccmd; |
| 3072 | struct command_line *cmd; |
| 3073 | struct cleanup *this_cmd_tree_chain; |
| 3074 | |
| 3075 | /* Take ownership of the BSP's command tree, if it has one. |
| 3076 | |
| 3077 | The command tree could legitimately contain commands like |
| 3078 | 'step' and 'next', which call clear_proceed_status, which |
| 3079 | frees stop_bpstat's command tree. To make sure this doesn't |
| 3080 | free the tree we're executing out from under us, we need to |
| 3081 | take ownership of the tree ourselves. Since a given bpstat's |
| 3082 | commands are only executed once, we don't need to copy it; we |
| 3083 | can clear the pointer in the bpstat, and make sure we free |
| 3084 | the tree when we're done. */ |
| 3085 | ccmd = bs->commands; |
| 3086 | bs->commands = NULL; |
| 3087 | this_cmd_tree_chain |
| 3088 | = make_cleanup_decref_counted_command_line (&ccmd); |
| 3089 | cmd = bs->commands_left; |
| 3090 | bs->commands_left = NULL; |
| 3091 | |
| 3092 | while (cmd != NULL) |
| 3093 | { |
| 3094 | execute_control_command (cmd); |
| 3095 | |
| 3096 | if (breakpoint_proceeded) |
| 3097 | break; |
| 3098 | else |
| 3099 | cmd = cmd->next; |
| 3100 | } |
| 3101 | |
| 3102 | /* We can free this command tree now. */ |
| 3103 | do_cleanups (this_cmd_tree_chain); |
| 3104 | |
| 3105 | if (breakpoint_proceeded) |
| 3106 | { |
| 3107 | if (target_can_async_p ()) |
| 3108 | /* If we are in async mode, then the target might be still |
| 3109 | running, not stopped at any breakpoint, so nothing for |
| 3110 | us to do here -- just return to the event loop. */ |
| 3111 | ; |
| 3112 | else |
| 3113 | /* In sync mode, when execute_control_command returns |
| 3114 | we're already standing on the next breakpoint. |
| 3115 | Breakpoint commands for that stop were not run, since |
| 3116 | execute_command does not run breakpoint commands -- |
| 3117 | only command_line_handler does, but that one is not |
| 3118 | involved in execution of breakpoint commands. So, we |
| 3119 | can now execute breakpoint commands. It should be |
| 3120 | noted that making execute_command do bpstat actions is |
| 3121 | not an option -- in this case we'll have recursive |
| 3122 | invocation of bpstat for each breakpoint with a |
| 3123 | command, and can easily blow up GDB stack. Instead, we |
| 3124 | return true, which will trigger the caller to recall us |
| 3125 | with the new stop_bpstat. */ |
| 3126 | again = 1; |
| 3127 | break; |
| 3128 | } |
| 3129 | } |
| 3130 | do_cleanups (old_chain); |
| 3131 | return again; |
| 3132 | } |
| 3133 | |
| 3134 | void |
| 3135 | bpstat_do_actions (void) |
| 3136 | { |
| 3137 | /* Do any commands attached to breakpoint we are stopped at. */ |
| 3138 | while (!ptid_equal (inferior_ptid, null_ptid) |
| 3139 | && target_has_execution |
| 3140 | && !is_exited (inferior_ptid) |
| 3141 | && !is_executing (inferior_ptid)) |
| 3142 | /* Since in sync mode, bpstat_do_actions may resume the inferior, |
| 3143 | and only return when it is stopped at the next breakpoint, we |
| 3144 | keep doing breakpoint actions until it returns false to |
| 3145 | indicate the inferior was not resumed. */ |
| 3146 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) |
| 3147 | break; |
| 3148 | } |
| 3149 | |
| 3150 | /* Print out the (old or new) value associated with a watchpoint. */ |
| 3151 | |
| 3152 | static void |
| 3153 | watchpoint_value_print (struct value *val, struct ui_file *stream) |
| 3154 | { |
| 3155 | if (val == NULL) |
| 3156 | fprintf_unfiltered (stream, _("<unreadable>")); |
| 3157 | else |
| 3158 | { |
| 3159 | struct value_print_options opts; |
| 3160 | get_user_print_options (&opts); |
| 3161 | value_print (val, stream, &opts); |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | /* This is the normal print function for a bpstat. In the future, |
| 3166 | much of this logic could (should?) be moved to bpstat_stop_status, |
| 3167 | by having it set different print_it values. |
| 3168 | |
| 3169 | Current scheme: When we stop, bpstat_print() is called. It loops |
| 3170 | through the bpstat list of things causing this stop, calling the |
| 3171 | print_bp_stop_message function on each one. The behavior of the |
| 3172 | print_bp_stop_message function depends on the print_it field of |
| 3173 | bpstat. If such field so indicates, call this function here. |
| 3174 | |
| 3175 | Return values from this routine (ultimately used by bpstat_print() |
| 3176 | and normal_stop() to decide what to do): |
| 3177 | PRINT_NOTHING: Means we already printed all we needed to print, |
| 3178 | don't print anything else. |
| 3179 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire |
| 3180 | that something to be followed by a location. |
| 3181 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire |
| 3182 | that something to be followed by a location. |
| 3183 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more |
| 3184 | analysis. */ |
| 3185 | |
| 3186 | static enum print_stop_action |
| 3187 | print_it_typical (bpstat bs) |
| 3188 | { |
| 3189 | struct cleanup *old_chain; |
| 3190 | struct breakpoint *b; |
| 3191 | const struct bp_location *bl; |
| 3192 | struct ui_stream *stb; |
| 3193 | int bp_temp = 0; |
| 3194 | enum print_stop_action result; |
| 3195 | |
| 3196 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
| 3197 | which has since been deleted. */ |
| 3198 | if (bs->breakpoint_at == NULL) |
| 3199 | return PRINT_UNKNOWN; |
| 3200 | bl = bs->breakpoint_at; |
| 3201 | b = bl->owner; |
| 3202 | |
| 3203 | stb = ui_out_stream_new (uiout); |
| 3204 | old_chain = make_cleanup_ui_out_stream_delete (stb); |
| 3205 | |
| 3206 | switch (b->type) |
| 3207 | { |
| 3208 | case bp_breakpoint: |
| 3209 | case bp_hardware_breakpoint: |
| 3210 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
| 3211 | if (bl->address != bl->requested_address) |
| 3212 | breakpoint_adjustment_warning (bl->requested_address, |
| 3213 | bl->address, |
| 3214 | b->number, 1); |
| 3215 | annotate_breakpoint (b->number); |
| 3216 | if (bp_temp) |
| 3217 | ui_out_text (uiout, "\nTemporary breakpoint "); |
| 3218 | else |
| 3219 | ui_out_text (uiout, "\nBreakpoint "); |
| 3220 | if (ui_out_is_mi_like_p (uiout)) |
| 3221 | { |
| 3222 | ui_out_field_string (uiout, "reason", |
| 3223 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 3224 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 3225 | } |
| 3226 | ui_out_field_int (uiout, "bkptno", b->number); |
| 3227 | ui_out_text (uiout, ", "); |
| 3228 | result = PRINT_SRC_AND_LOC; |
| 3229 | break; |
| 3230 | |
| 3231 | case bp_shlib_event: |
| 3232 | /* Did we stop because the user set the stop_on_solib_events |
| 3233 | variable? (If so, we report this as a generic, "Stopped due |
| 3234 | to shlib event" message.) */ |
| 3235 | printf_filtered (_("Stopped due to shared library event\n")); |
| 3236 | result = PRINT_NOTHING; |
| 3237 | break; |
| 3238 | |
| 3239 | case bp_thread_event: |
| 3240 | /* Not sure how we will get here. |
| 3241 | GDB should not stop for these breakpoints. */ |
| 3242 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
| 3243 | result = PRINT_NOTHING; |
| 3244 | break; |
| 3245 | |
| 3246 | case bp_overlay_event: |
| 3247 | /* By analogy with the thread event, GDB should not stop for these. */ |
| 3248 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
| 3249 | result = PRINT_NOTHING; |
| 3250 | break; |
| 3251 | |
| 3252 | case bp_longjmp_master: |
| 3253 | /* These should never be enabled. */ |
| 3254 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); |
| 3255 | result = PRINT_NOTHING; |
| 3256 | break; |
| 3257 | |
| 3258 | case bp_std_terminate_master: |
| 3259 | /* These should never be enabled. */ |
| 3260 | printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n")); |
| 3261 | result = PRINT_NOTHING; |
| 3262 | break; |
| 3263 | |
| 3264 | case bp_watchpoint: |
| 3265 | case bp_hardware_watchpoint: |
| 3266 | annotate_watchpoint (b->number); |
| 3267 | if (ui_out_is_mi_like_p (uiout)) |
| 3268 | ui_out_field_string |
| 3269 | (uiout, "reason", |
| 3270 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 3271 | mention (b); |
| 3272 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 3273 | ui_out_text (uiout, "\nOld value = "); |
| 3274 | watchpoint_value_print (bs->old_val, stb->stream); |
| 3275 | ui_out_field_stream (uiout, "old", stb); |
| 3276 | ui_out_text (uiout, "\nNew value = "); |
| 3277 | watchpoint_value_print (b->val, stb->stream); |
| 3278 | ui_out_field_stream (uiout, "new", stb); |
| 3279 | ui_out_text (uiout, "\n"); |
| 3280 | /* More than one watchpoint may have been triggered. */ |
| 3281 | result = PRINT_UNKNOWN; |
| 3282 | break; |
| 3283 | |
| 3284 | case bp_read_watchpoint: |
| 3285 | if (ui_out_is_mi_like_p (uiout)) |
| 3286 | ui_out_field_string |
| 3287 | (uiout, "reason", |
| 3288 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 3289 | mention (b); |
| 3290 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 3291 | ui_out_text (uiout, "\nValue = "); |
| 3292 | watchpoint_value_print (b->val, stb->stream); |
| 3293 | ui_out_field_stream (uiout, "value", stb); |
| 3294 | ui_out_text (uiout, "\n"); |
| 3295 | result = PRINT_UNKNOWN; |
| 3296 | break; |
| 3297 | |
| 3298 | case bp_access_watchpoint: |
| 3299 | if (bs->old_val != NULL) |
| 3300 | { |
| 3301 | annotate_watchpoint (b->number); |
| 3302 | if (ui_out_is_mi_like_p (uiout)) |
| 3303 | ui_out_field_string |
| 3304 | (uiout, "reason", |
| 3305 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 3306 | mention (b); |
| 3307 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 3308 | ui_out_text (uiout, "\nOld value = "); |
| 3309 | watchpoint_value_print (bs->old_val, stb->stream); |
| 3310 | ui_out_field_stream (uiout, "old", stb); |
| 3311 | ui_out_text (uiout, "\nNew value = "); |
| 3312 | } |
| 3313 | else |
| 3314 | { |
| 3315 | mention (b); |
| 3316 | if (ui_out_is_mi_like_p (uiout)) |
| 3317 | ui_out_field_string |
| 3318 | (uiout, "reason", |
| 3319 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 3320 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 3321 | ui_out_text (uiout, "\nValue = "); |
| 3322 | } |
| 3323 | watchpoint_value_print (b->val, stb->stream); |
| 3324 | ui_out_field_stream (uiout, "new", stb); |
| 3325 | ui_out_text (uiout, "\n"); |
| 3326 | result = PRINT_UNKNOWN; |
| 3327 | break; |
| 3328 | |
| 3329 | /* Fall through, we don't deal with these types of breakpoints |
| 3330 | here. */ |
| 3331 | |
| 3332 | case bp_finish: |
| 3333 | if (ui_out_is_mi_like_p (uiout)) |
| 3334 | ui_out_field_string |
| 3335 | (uiout, "reason", |
| 3336 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); |
| 3337 | result = PRINT_UNKNOWN; |
| 3338 | break; |
| 3339 | |
| 3340 | case bp_until: |
| 3341 | if (ui_out_is_mi_like_p (uiout)) |
| 3342 | ui_out_field_string |
| 3343 | (uiout, "reason", |
| 3344 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); |
| 3345 | result = PRINT_UNKNOWN; |
| 3346 | break; |
| 3347 | |
| 3348 | case bp_none: |
| 3349 | case bp_longjmp: |
| 3350 | case bp_longjmp_resume: |
| 3351 | case bp_step_resume: |
| 3352 | case bp_watchpoint_scope: |
| 3353 | case bp_call_dummy: |
| 3354 | case bp_std_terminate: |
| 3355 | case bp_tracepoint: |
| 3356 | case bp_fast_tracepoint: |
| 3357 | case bp_jit_event: |
| 3358 | default: |
| 3359 | result = PRINT_UNKNOWN; |
| 3360 | break; |
| 3361 | } |
| 3362 | |
| 3363 | do_cleanups (old_chain); |
| 3364 | return result; |
| 3365 | } |
| 3366 | |
| 3367 | /* Generic routine for printing messages indicating why we |
| 3368 | stopped. The behavior of this function depends on the value |
| 3369 | 'print_it' in the bpstat structure. Under some circumstances we |
| 3370 | may decide not to print anything here and delegate the task to |
| 3371 | normal_stop(). */ |
| 3372 | |
| 3373 | static enum print_stop_action |
| 3374 | print_bp_stop_message (bpstat bs) |
| 3375 | { |
| 3376 | switch (bs->print_it) |
| 3377 | { |
| 3378 | case print_it_noop: |
| 3379 | /* Nothing should be printed for this bpstat entry. */ |
| 3380 | return PRINT_UNKNOWN; |
| 3381 | break; |
| 3382 | |
| 3383 | case print_it_done: |
| 3384 | /* We still want to print the frame, but we already printed the |
| 3385 | relevant messages. */ |
| 3386 | return PRINT_SRC_AND_LOC; |
| 3387 | break; |
| 3388 | |
| 3389 | case print_it_normal: |
| 3390 | { |
| 3391 | const struct bp_location *bl = bs->breakpoint_at; |
| 3392 | struct breakpoint *b = bl ? bl->owner : NULL; |
| 3393 | |
| 3394 | /* Normal case. Call the breakpoint's print_it method, or |
| 3395 | print_it_typical. */ |
| 3396 | /* FIXME: how breakpoint can ever be NULL here? */ |
| 3397 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) |
| 3398 | return b->ops->print_it (b); |
| 3399 | else |
| 3400 | return print_it_typical (bs); |
| 3401 | } |
| 3402 | break; |
| 3403 | |
| 3404 | default: |
| 3405 | internal_error (__FILE__, __LINE__, |
| 3406 | _("print_bp_stop_message: unrecognized enum value")); |
| 3407 | break; |
| 3408 | } |
| 3409 | } |
| 3410 | |
| 3411 | /* Print a message indicating what happened. This is called from |
| 3412 | normal_stop(). The input to this routine is the head of the bpstat |
| 3413 | list - a list of the eventpoints that caused this stop. This |
| 3414 | routine calls the generic print routine for printing a message |
| 3415 | about reasons for stopping. This will print (for example) the |
| 3416 | "Breakpoint n," part of the output. The return value of this |
| 3417 | routine is one of: |
| 3418 | |
| 3419 | PRINT_UNKNOWN: Means we printed nothing |
| 3420 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
| 3421 | code to print the location. An example is |
| 3422 | "Breakpoint 1, " which should be followed by |
| 3423 | the location. |
| 3424 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
| 3425 | to also print the location part of the message. |
| 3426 | An example is the catch/throw messages, which |
| 3427 | don't require a location appended to the end. |
| 3428 | PRINT_NOTHING: We have done some printing and we don't need any |
| 3429 | further info to be printed.*/ |
| 3430 | |
| 3431 | enum print_stop_action |
| 3432 | bpstat_print (bpstat bs) |
| 3433 | { |
| 3434 | int val; |
| 3435 | |
| 3436 | /* Maybe another breakpoint in the chain caused us to stop. |
| 3437 | (Currently all watchpoints go on the bpstat whether hit or not. |
| 3438 | That probably could (should) be changed, provided care is taken |
| 3439 | with respect to bpstat_explains_signal). */ |
| 3440 | for (; bs; bs = bs->next) |
| 3441 | { |
| 3442 | val = print_bp_stop_message (bs); |
| 3443 | if (val == PRINT_SRC_ONLY |
| 3444 | || val == PRINT_SRC_AND_LOC |
| 3445 | || val == PRINT_NOTHING) |
| 3446 | return val; |
| 3447 | } |
| 3448 | |
| 3449 | /* We reached the end of the chain, or we got a null BS to start |
| 3450 | with and nothing was printed. */ |
| 3451 | return PRINT_UNKNOWN; |
| 3452 | } |
| 3453 | |
| 3454 | /* Evaluate the expression EXP and return 1 if value is zero. |
| 3455 | This is used inside a catch_errors to evaluate the breakpoint condition. |
| 3456 | The argument is a "struct expression *" that has been cast to char * to |
| 3457 | make it pass through catch_errors. */ |
| 3458 | |
| 3459 | static int |
| 3460 | breakpoint_cond_eval (void *exp) |
| 3461 | { |
| 3462 | struct value *mark = value_mark (); |
| 3463 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
| 3464 | value_free_to_mark (mark); |
| 3465 | return i; |
| 3466 | } |
| 3467 | |
| 3468 | /* Allocate a new bpstat and chain it to the current one. */ |
| 3469 | |
| 3470 | static bpstat |
| 3471 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
| 3472 | { |
| 3473 | bpstat bs; |
| 3474 | |
| 3475 | bs = (bpstat) xmalloc (sizeof (*bs)); |
| 3476 | cbs->next = bs; |
| 3477 | bs->breakpoint_at = bl; |
| 3478 | /* If the condition is false, etc., don't do the commands. */ |
| 3479 | bs->commands = NULL; |
| 3480 | bs->commands_left = NULL; |
| 3481 | bs->old_val = NULL; |
| 3482 | bs->print_it = print_it_normal; |
| 3483 | return bs; |
| 3484 | } |
| 3485 | \f |
| 3486 | /* The target has stopped with waitstatus WS. Check if any hardware |
| 3487 | watchpoints have triggered, according to the target. */ |
| 3488 | |
| 3489 | int |
| 3490 | watchpoints_triggered (struct target_waitstatus *ws) |
| 3491 | { |
| 3492 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
| 3493 | CORE_ADDR addr; |
| 3494 | struct breakpoint *b; |
| 3495 | |
| 3496 | if (!stopped_by_watchpoint) |
| 3497 | { |
| 3498 | /* We were not stopped by a watchpoint. Mark all watchpoints |
| 3499 | as not triggered. */ |
| 3500 | ALL_BREAKPOINTS (b) |
| 3501 | if (is_hardware_watchpoint (b)) |
| 3502 | b->watchpoint_triggered = watch_triggered_no; |
| 3503 | |
| 3504 | return 0; |
| 3505 | } |
| 3506 | |
| 3507 | if (!target_stopped_data_address (¤t_target, &addr)) |
| 3508 | { |
| 3509 | /* We were stopped by a watchpoint, but we don't know where. |
| 3510 | Mark all watchpoints as unknown. */ |
| 3511 | ALL_BREAKPOINTS (b) |
| 3512 | if (is_hardware_watchpoint (b)) |
| 3513 | b->watchpoint_triggered = watch_triggered_unknown; |
| 3514 | |
| 3515 | return stopped_by_watchpoint; |
| 3516 | } |
| 3517 | |
| 3518 | /* The target could report the data address. Mark watchpoints |
| 3519 | affected by this data address as triggered, and all others as not |
| 3520 | triggered. */ |
| 3521 | |
| 3522 | ALL_BREAKPOINTS (b) |
| 3523 | if (is_hardware_watchpoint (b)) |
| 3524 | { |
| 3525 | struct bp_location *loc; |
| 3526 | struct value *v; |
| 3527 | |
| 3528 | b->watchpoint_triggered = watch_triggered_no; |
| 3529 | for (loc = b->loc; loc; loc = loc->next) |
| 3530 | /* Exact match not required. Within range is |
| 3531 | sufficient. */ |
| 3532 | if (target_watchpoint_addr_within_range (¤t_target, |
| 3533 | addr, loc->address, |
| 3534 | loc->length)) |
| 3535 | { |
| 3536 | b->watchpoint_triggered = watch_triggered_yes; |
| 3537 | break; |
| 3538 | } |
| 3539 | } |
| 3540 | |
| 3541 | return 1; |
| 3542 | } |
| 3543 | |
| 3544 | /* Possible return values for watchpoint_check (this can't be an enum |
| 3545 | because of check_errors). */ |
| 3546 | /* The watchpoint has been deleted. */ |
| 3547 | #define WP_DELETED 1 |
| 3548 | /* The value has changed. */ |
| 3549 | #define WP_VALUE_CHANGED 2 |
| 3550 | /* The value has not changed. */ |
| 3551 | #define WP_VALUE_NOT_CHANGED 3 |
| 3552 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
| 3553 | #define WP_IGNORE 4 |
| 3554 | |
| 3555 | #define BP_TEMPFLAG 1 |
| 3556 | #define BP_HARDWAREFLAG 2 |
| 3557 | |
| 3558 | /* Evaluate watchpoint condition expression and check if its value changed. |
| 3559 | |
| 3560 | P should be a pointer to struct bpstat, but is defined as a void * |
| 3561 | in order for this function to be usable with catch_errors. */ |
| 3562 | |
| 3563 | static int |
| 3564 | watchpoint_check (void *p) |
| 3565 | { |
| 3566 | bpstat bs = (bpstat) p; |
| 3567 | struct breakpoint *b; |
| 3568 | struct frame_info *fr; |
| 3569 | int within_current_scope; |
| 3570 | |
| 3571 | b = bs->breakpoint_at->owner; |
| 3572 | |
| 3573 | /* If this is a local watchpoint, we only want to check if the |
| 3574 | watchpoint frame is in scope if the current thread is the thread |
| 3575 | that was used to create the watchpoint. */ |
| 3576 | if (!watchpoint_in_thread_scope (b)) |
| 3577 | return WP_IGNORE; |
| 3578 | |
| 3579 | if (b->exp_valid_block == NULL) |
| 3580 | within_current_scope = 1; |
| 3581 | else |
| 3582 | { |
| 3583 | struct frame_info *frame = get_current_frame (); |
| 3584 | struct gdbarch *frame_arch = get_frame_arch (frame); |
| 3585 | CORE_ADDR frame_pc = get_frame_pc (frame); |
| 3586 | |
| 3587 | /* in_function_epilogue_p() returns a non-zero value if we're still |
| 3588 | in the function but the stack frame has already been invalidated. |
| 3589 | Since we can't rely on the values of local variables after the |
| 3590 | stack has been destroyed, we are treating the watchpoint in that |
| 3591 | state as `not changed' without further checking. Don't mark |
| 3592 | watchpoints as changed if the current frame is in an epilogue - |
| 3593 | even if they are in some other frame, our view of the stack |
| 3594 | is likely to be wrong and frame_find_by_id could error out. */ |
| 3595 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
| 3596 | return WP_IGNORE; |
| 3597 | |
| 3598 | fr = frame_find_by_id (b->watchpoint_frame); |
| 3599 | within_current_scope = (fr != NULL); |
| 3600 | |
| 3601 | /* If we've gotten confused in the unwinder, we might have |
| 3602 | returned a frame that can't describe this variable. */ |
| 3603 | if (within_current_scope) |
| 3604 | { |
| 3605 | struct symbol *function; |
| 3606 | |
| 3607 | function = get_frame_function (fr); |
| 3608 | if (function == NULL |
| 3609 | || !contained_in (b->exp_valid_block, |
| 3610 | SYMBOL_BLOCK_VALUE (function))) |
| 3611 | within_current_scope = 0; |
| 3612 | } |
| 3613 | |
| 3614 | if (within_current_scope) |
| 3615 | /* If we end up stopping, the current frame will get selected |
| 3616 | in normal_stop. So this call to select_frame won't affect |
| 3617 | the user. */ |
| 3618 | select_frame (fr); |
| 3619 | } |
| 3620 | |
| 3621 | if (within_current_scope) |
| 3622 | { |
| 3623 | /* We use value_{,free_to_}mark because it could be a |
| 3624 | *long* time before we return to the command level and |
| 3625 | call free_all_values. We can't call free_all_values because |
| 3626 | we might be in the middle of evaluating a function call. */ |
| 3627 | |
| 3628 | struct value *mark = value_mark (); |
| 3629 | struct value *new_val; |
| 3630 | |
| 3631 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); |
| 3632 | |
| 3633 | /* We use value_equal_contents instead of value_equal because the latter |
| 3634 | coerces an array to a pointer, thus comparing just the address of the |
| 3635 | array instead of its contents. This is not what we want. */ |
| 3636 | if ((b->val != NULL) != (new_val != NULL) |
| 3637 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
| 3638 | { |
| 3639 | if (new_val != NULL) |
| 3640 | { |
| 3641 | release_value (new_val); |
| 3642 | value_free_to_mark (mark); |
| 3643 | } |
| 3644 | bs->old_val = b->val; |
| 3645 | b->val = new_val; |
| 3646 | b->val_valid = 1; |
| 3647 | return WP_VALUE_CHANGED; |
| 3648 | } |
| 3649 | else |
| 3650 | { |
| 3651 | /* Nothing changed. */ |
| 3652 | value_free_to_mark (mark); |
| 3653 | return WP_VALUE_NOT_CHANGED; |
| 3654 | } |
| 3655 | } |
| 3656 | else |
| 3657 | { |
| 3658 | /* This seems like the only logical thing to do because |
| 3659 | if we temporarily ignored the watchpoint, then when |
| 3660 | we reenter the block in which it is valid it contains |
| 3661 | garbage (in the case of a function, it may have two |
| 3662 | garbage values, one before and one after the prologue). |
| 3663 | So we can't even detect the first assignment to it and |
| 3664 | watch after that (since the garbage may or may not equal |
| 3665 | the first value assigned). */ |
| 3666 | /* We print all the stop information in print_it_typical(), but |
| 3667 | in this case, by the time we call print_it_typical() this bp |
| 3668 | will be deleted already. So we have no choice but print the |
| 3669 | information here. */ |
| 3670 | if (ui_out_is_mi_like_p (uiout)) |
| 3671 | ui_out_field_string |
| 3672 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); |
| 3673 | ui_out_text (uiout, "\nWatchpoint "); |
| 3674 | ui_out_field_int (uiout, "wpnum", b->number); |
| 3675 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
| 3676 | which its expression is valid.\n"); |
| 3677 | |
| 3678 | if (b->related_breakpoint) |
| 3679 | { |
| 3680 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
| 3681 | b->related_breakpoint->related_breakpoint = NULL; |
| 3682 | b->related_breakpoint = NULL; |
| 3683 | } |
| 3684 | b->disposition = disp_del_at_next_stop; |
| 3685 | |
| 3686 | return WP_DELETED; |
| 3687 | } |
| 3688 | } |
| 3689 | |
| 3690 | /* Return true if it looks like target has stopped due to hitting |
| 3691 | breakpoint location BL. This function does not check if we |
| 3692 | should stop, only if BL explains the stop. */ |
| 3693 | static int |
| 3694 | bpstat_check_location (const struct bp_location *bl, |
| 3695 | struct address_space *aspace, CORE_ADDR bp_addr) |
| 3696 | { |
| 3697 | struct breakpoint *b = bl->owner; |
| 3698 | |
| 3699 | /* By definition, the inferior does not report stops at |
| 3700 | tracepoints. */ |
| 3701 | if (is_tracepoint (b)) |
| 3702 | return 0; |
| 3703 | |
| 3704 | if (!is_watchpoint (b) |
| 3705 | && b->type != bp_hardware_breakpoint |
| 3706 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
| 3707 | { |
| 3708 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 3709 | aspace, bp_addr)) |
| 3710 | return 0; |
| 3711 | if (overlay_debugging /* unmapped overlay section */ |
| 3712 | && section_is_overlay (bl->section) |
| 3713 | && !section_is_mapped (bl->section)) |
| 3714 | return 0; |
| 3715 | } |
| 3716 | |
| 3717 | /* Continuable hardware watchpoints are treated as non-existent if the |
| 3718 | reason we stopped wasn't a hardware watchpoint (we didn't stop on |
| 3719 | some data address). Otherwise gdb won't stop on a break instruction |
| 3720 | in the code (not from a breakpoint) when a hardware watchpoint has |
| 3721 | been defined. Also skip watchpoints which we know did not trigger |
| 3722 | (did not match the data address). */ |
| 3723 | |
| 3724 | if (is_hardware_watchpoint (b) |
| 3725 | && b->watchpoint_triggered == watch_triggered_no) |
| 3726 | return 0; |
| 3727 | |
| 3728 | if (b->type == bp_hardware_breakpoint) |
| 3729 | { |
| 3730 | if (bl->address != bp_addr) |
| 3731 | return 0; |
| 3732 | if (overlay_debugging /* unmapped overlay section */ |
| 3733 | && section_is_overlay (bl->section) |
| 3734 | && !section_is_mapped (bl->section)) |
| 3735 | return 0; |
| 3736 | } |
| 3737 | |
| 3738 | if (b->type == bp_catchpoint) |
| 3739 | { |
| 3740 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); |
| 3741 | if (!b->ops->breakpoint_hit (b)) |
| 3742 | return 0; |
| 3743 | } |
| 3744 | |
| 3745 | return 1; |
| 3746 | } |
| 3747 | |
| 3748 | /* If BS refers to a watchpoint, determine if the watched values |
| 3749 | has actually changed, and we should stop. If not, set BS->stop |
| 3750 | to 0. */ |
| 3751 | static void |
| 3752 | bpstat_check_watchpoint (bpstat bs) |
| 3753 | { |
| 3754 | const struct bp_location *bl = bs->breakpoint_at; |
| 3755 | struct breakpoint *b = bl->owner; |
| 3756 | |
| 3757 | if (is_watchpoint (b)) |
| 3758 | { |
| 3759 | CORE_ADDR addr; |
| 3760 | struct value *v; |
| 3761 | int must_check_value = 0; |
| 3762 | |
| 3763 | if (b->type == bp_watchpoint) |
| 3764 | /* For a software watchpoint, we must always check the |
| 3765 | watched value. */ |
| 3766 | must_check_value = 1; |
| 3767 | else if (b->watchpoint_triggered == watch_triggered_yes) |
| 3768 | /* We have a hardware watchpoint (read, write, or access) |
| 3769 | and the target earlier reported an address watched by |
| 3770 | this watchpoint. */ |
| 3771 | must_check_value = 1; |
| 3772 | else if (b->watchpoint_triggered == watch_triggered_unknown |
| 3773 | && b->type == bp_hardware_watchpoint) |
| 3774 | /* We were stopped by a hardware watchpoint, but the target could |
| 3775 | not report the data address. We must check the watchpoint's |
| 3776 | value. Access and read watchpoints are out of luck; without |
| 3777 | a data address, we can't figure it out. */ |
| 3778 | must_check_value = 1; |
| 3779 | |
| 3780 | if (must_check_value) |
| 3781 | { |
| 3782 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", |
| 3783 | b->number); |
| 3784 | struct cleanup *cleanups = make_cleanup (xfree, message); |
| 3785 | int e = catch_errors (watchpoint_check, bs, message, |
| 3786 | RETURN_MASK_ALL); |
| 3787 | do_cleanups (cleanups); |
| 3788 | switch (e) |
| 3789 | { |
| 3790 | case WP_DELETED: |
| 3791 | /* We've already printed what needs to be printed. */ |
| 3792 | bs->print_it = print_it_done; |
| 3793 | /* Stop. */ |
| 3794 | break; |
| 3795 | case WP_IGNORE: |
| 3796 | bs->print_it = print_it_noop; |
| 3797 | bs->stop = 0; |
| 3798 | break; |
| 3799 | case WP_VALUE_CHANGED: |
| 3800 | if (b->type == bp_read_watchpoint) |
| 3801 | { |
| 3802 | /* There are two cases to consider here: |
| 3803 | |
| 3804 | 1. we're watching the triggered memory for reads. |
| 3805 | In that case, trust the target, and always report |
| 3806 | the watchpoint hit to the user. Even though |
| 3807 | reads don't cause value changes, the value may |
| 3808 | have changed since the last time it was read, and |
| 3809 | since we're not trapping writes, we will not see |
| 3810 | those, and as such we should ignore our notion of |
| 3811 | old value. |
| 3812 | |
| 3813 | 2. we're watching the triggered memory for both |
| 3814 | reads and writes. There are two ways this may |
| 3815 | happen: |
| 3816 | |
| 3817 | 2.1. this is a target that can't break on data |
| 3818 | reads only, but can break on accesses (reads or |
| 3819 | writes), such as e.g., x86. We detect this case |
| 3820 | at the time we try to insert read watchpoints. |
| 3821 | |
| 3822 | 2.2. otherwise, the target supports read |
| 3823 | watchpoints, but, the user set an access or write |
| 3824 | watchpoint watching the same memory as this read |
| 3825 | watchpoint. |
| 3826 | |
| 3827 | If we're watching memory writes as well as reads, |
| 3828 | ignore watchpoint hits when we find that the |
| 3829 | value hasn't changed, as reads don't cause |
| 3830 | changes. This still gives false positives when |
| 3831 | the program writes the same value to memory as |
| 3832 | what there was already in memory (we will confuse |
| 3833 | it for a read), but it's much better than |
| 3834 | nothing. */ |
| 3835 | |
| 3836 | int other_write_watchpoint = 0; |
| 3837 | |
| 3838 | if (bl->watchpoint_type == hw_read) |
| 3839 | { |
| 3840 | struct breakpoint *other_b; |
| 3841 | |
| 3842 | ALL_BREAKPOINTS (other_b) |
| 3843 | if ((other_b->type == bp_hardware_watchpoint |
| 3844 | || other_b->type == bp_access_watchpoint) |
| 3845 | && (other_b->watchpoint_triggered |
| 3846 | == watch_triggered_yes)) |
| 3847 | { |
| 3848 | other_write_watchpoint = 1; |
| 3849 | break; |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | if (other_write_watchpoint |
| 3854 | || bl->watchpoint_type == hw_access) |
| 3855 | { |
| 3856 | /* We're watching the same memory for writes, |
| 3857 | and the value changed since the last time we |
| 3858 | updated it, so this trap must be for a write. |
| 3859 | Ignore it. */ |
| 3860 | bs->print_it = print_it_noop; |
| 3861 | bs->stop = 0; |
| 3862 | } |
| 3863 | } |
| 3864 | break; |
| 3865 | case WP_VALUE_NOT_CHANGED: |
| 3866 | if (b->type == bp_hardware_watchpoint |
| 3867 | || b->type == bp_watchpoint) |
| 3868 | { |
| 3869 | /* Don't stop: write watchpoints shouldn't fire if |
| 3870 | the value hasn't changed. */ |
| 3871 | bs->print_it = print_it_noop; |
| 3872 | bs->stop = 0; |
| 3873 | } |
| 3874 | /* Stop. */ |
| 3875 | break; |
| 3876 | default: |
| 3877 | /* Can't happen. */ |
| 3878 | case 0: |
| 3879 | /* Error from catch_errors. */ |
| 3880 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); |
| 3881 | if (b->related_breakpoint) |
| 3882 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
| 3883 | b->disposition = disp_del_at_next_stop; |
| 3884 | /* We've already printed what needs to be printed. */ |
| 3885 | bs->print_it = print_it_done; |
| 3886 | break; |
| 3887 | } |
| 3888 | } |
| 3889 | else /* must_check_value == 0 */ |
| 3890 | { |
| 3891 | /* This is a case where some watchpoint(s) triggered, but |
| 3892 | not at the address of this watchpoint, or else no |
| 3893 | watchpoint triggered after all. So don't print |
| 3894 | anything for this watchpoint. */ |
| 3895 | bs->print_it = print_it_noop; |
| 3896 | bs->stop = 0; |
| 3897 | } |
| 3898 | } |
| 3899 | } |
| 3900 | |
| 3901 | |
| 3902 | /* Check conditions (condition proper, frame, thread and ignore count) |
| 3903 | of breakpoint referred to by BS. If we should not stop for this |
| 3904 | breakpoint, set BS->stop to 0. */ |
| 3905 | static void |
| 3906 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) |
| 3907 | { |
| 3908 | int thread_id = pid_to_thread_id (ptid); |
| 3909 | const struct bp_location *bl = bs->breakpoint_at; |
| 3910 | struct breakpoint *b = bl->owner; |
| 3911 | |
| 3912 | if (frame_id_p (b->frame_id) |
| 3913 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
| 3914 | bs->stop = 0; |
| 3915 | else if (bs->stop) |
| 3916 | { |
| 3917 | int value_is_zero = 0; |
| 3918 | struct expression *cond; |
| 3919 | |
| 3920 | /* If this is a scope breakpoint, mark the associated |
| 3921 | watchpoint as triggered so that we will handle the |
| 3922 | out-of-scope event. We'll get to the watchpoint next |
| 3923 | iteration. */ |
| 3924 | if (b->type == bp_watchpoint_scope) |
| 3925 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; |
| 3926 | |
| 3927 | if (is_watchpoint (b)) |
| 3928 | cond = b->cond_exp; |
| 3929 | else |
| 3930 | cond = bl->cond; |
| 3931 | |
| 3932 | if (cond && bl->owner->disposition != disp_del_at_next_stop) |
| 3933 | { |
| 3934 | int within_current_scope = 1; |
| 3935 | |
| 3936 | /* We use value_mark and value_free_to_mark because it could |
| 3937 | be a long time before we return to the command level and |
| 3938 | call free_all_values. We can't call free_all_values |
| 3939 | because we might be in the middle of evaluating a |
| 3940 | function call. */ |
| 3941 | struct value *mark = value_mark (); |
| 3942 | |
| 3943 | /* Need to select the frame, with all that implies so that |
| 3944 | the conditions will have the right context. Because we |
| 3945 | use the frame, we will not see an inlined function's |
| 3946 | variables when we arrive at a breakpoint at the start |
| 3947 | of the inlined function; the current frame will be the |
| 3948 | call site. */ |
| 3949 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
| 3950 | select_frame (get_current_frame ()); |
| 3951 | else |
| 3952 | { |
| 3953 | struct frame_info *frame; |
| 3954 | |
| 3955 | /* For local watchpoint expressions, which particular |
| 3956 | instance of a local is being watched matters, so we |
| 3957 | keep track of the frame to evaluate the expression |
| 3958 | in. To evaluate the condition however, it doesn't |
| 3959 | really matter which instantiation of the function |
| 3960 | where the condition makes sense triggers the |
| 3961 | watchpoint. This allows an expression like "watch |
| 3962 | global if q > 10" set in `func', catch writes to |
| 3963 | global on all threads that call `func', or catch |
| 3964 | writes on all recursive calls of `func' by a single |
| 3965 | thread. We simply always evaluate the condition in |
| 3966 | the innermost frame that's executing where it makes |
| 3967 | sense to evaluate the condition. It seems |
| 3968 | intuitive. */ |
| 3969 | frame = block_innermost_frame (b->cond_exp_valid_block); |
| 3970 | if (frame != NULL) |
| 3971 | select_frame (frame); |
| 3972 | else |
| 3973 | within_current_scope = 0; |
| 3974 | } |
| 3975 | if (within_current_scope) |
| 3976 | value_is_zero |
| 3977 | = catch_errors (breakpoint_cond_eval, cond, |
| 3978 | "Error in testing breakpoint condition:\n", |
| 3979 | RETURN_MASK_ALL); |
| 3980 | else |
| 3981 | { |
| 3982 | warning (_("Watchpoint condition cannot be tested " |
| 3983 | "in the current scope")); |
| 3984 | /* If we failed to set the right context for this |
| 3985 | watchpoint, unconditionally report it. */ |
| 3986 | value_is_zero = 0; |
| 3987 | } |
| 3988 | /* FIXME-someday, should give breakpoint # */ |
| 3989 | value_free_to_mark (mark); |
| 3990 | } |
| 3991 | |
| 3992 | if (cond && value_is_zero) |
| 3993 | { |
| 3994 | bs->stop = 0; |
| 3995 | } |
| 3996 | else if (b->thread != -1 && b->thread != thread_id) |
| 3997 | { |
| 3998 | bs->stop = 0; |
| 3999 | } |
| 4000 | else if (b->ignore_count > 0) |
| 4001 | { |
| 4002 | b->ignore_count--; |
| 4003 | annotate_ignore_count_change (); |
| 4004 | bs->stop = 0; |
| 4005 | /* Increase the hit count even though we don't |
| 4006 | stop. */ |
| 4007 | ++(b->hit_count); |
| 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | |
| 4013 | /* Get a bpstat associated with having just stopped at address |
| 4014 | BP_ADDR in thread PTID. |
| 4015 | |
| 4016 | Determine whether we stopped at a breakpoint, etc, or whether we |
| 4017 | don't understand this stop. Result is a chain of bpstat's such that: |
| 4018 | |
| 4019 | if we don't understand the stop, the result is a null pointer. |
| 4020 | |
| 4021 | if we understand why we stopped, the result is not null. |
| 4022 | |
| 4023 | Each element of the chain refers to a particular breakpoint or |
| 4024 | watchpoint at which we have stopped. (We may have stopped for |
| 4025 | several reasons concurrently.) |
| 4026 | |
| 4027 | Each element of the chain has valid next, breakpoint_at, |
| 4028 | commands, FIXME??? fields. */ |
| 4029 | |
| 4030 | bpstat |
| 4031 | bpstat_stop_status (struct address_space *aspace, |
| 4032 | CORE_ADDR bp_addr, ptid_t ptid) |
| 4033 | { |
| 4034 | struct breakpoint *b = NULL; |
| 4035 | struct bp_location *bl, **blp_tmp; |
| 4036 | struct bp_location *loc; |
| 4037 | /* Root of the chain of bpstat's */ |
| 4038 | struct bpstats root_bs[1]; |
| 4039 | /* Pointer to the last thing in the chain currently. */ |
| 4040 | bpstat bs = root_bs; |
| 4041 | int ix; |
| 4042 | int need_remove_insert; |
| 4043 | |
| 4044 | /* ALL_BP_LOCATIONS iteration would break across |
| 4045 | update_global_location_list possibly executed by |
| 4046 | bpstat_check_breakpoint_conditions's inferior call. */ |
| 4047 | |
| 4048 | ALL_BREAKPOINTS (b) |
| 4049 | { |
| 4050 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
| 4051 | continue; |
| 4052 | |
| 4053 | for (bl = b->loc; bl != NULL; bl = bl->next) |
| 4054 | { |
| 4055 | /* For hardware watchpoints, we look only at the first location. |
| 4056 | The watchpoint_check function will work on the entire expression, |
| 4057 | not the individual locations. For read watchpoints, the |
| 4058 | watchpoints_triggered function has checked all locations |
| 4059 | already. */ |
| 4060 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
| 4061 | break; |
| 4062 | |
| 4063 | if (bl->shlib_disabled) |
| 4064 | continue; |
| 4065 | |
| 4066 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
| 4067 | continue; |
| 4068 | |
| 4069 | /* Come here if it's a watchpoint, or if the break address matches */ |
| 4070 | |
| 4071 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
| 4072 | |
| 4073 | /* Assume we stop. Should we find watchpoint that is not actually |
| 4074 | triggered, or if condition of breakpoint is false, we'll reset |
| 4075 | 'stop' to 0. */ |
| 4076 | bs->stop = 1; |
| 4077 | bs->print = 1; |
| 4078 | |
| 4079 | bpstat_check_watchpoint (bs); |
| 4080 | if (!bs->stop) |
| 4081 | continue; |
| 4082 | |
| 4083 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
| 4084 | || b->type == bp_longjmp_master |
| 4085 | || b->type == bp_std_terminate_master) |
| 4086 | /* We do not stop for these. */ |
| 4087 | bs->stop = 0; |
| 4088 | else |
| 4089 | bpstat_check_breakpoint_conditions (bs, ptid); |
| 4090 | |
| 4091 | if (bs->stop) |
| 4092 | { |
| 4093 | ++(b->hit_count); |
| 4094 | |
| 4095 | /* We will stop here */ |
| 4096 | if (b->disposition == disp_disable) |
| 4097 | { |
| 4098 | if (b->enable_state != bp_permanent) |
| 4099 | b->enable_state = bp_disabled; |
| 4100 | update_global_location_list (0); |
| 4101 | } |
| 4102 | if (b->silent) |
| 4103 | bs->print = 0; |
| 4104 | bs->commands = b->commands; |
| 4105 | incref_counted_command_line (bs->commands); |
| 4106 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; |
| 4107 | if (bs->commands_left |
| 4108 | && (strcmp ("silent", bs->commands_left->line) == 0 |
| 4109 | || (xdb_commands |
| 4110 | && strcmp ("Q", |
| 4111 | bs->commands_left->line) == 0))) |
| 4112 | { |
| 4113 | bs->commands_left = bs->commands_left->next; |
| 4114 | bs->print = 0; |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | /* Print nothing for this entry if we dont stop or dont print. */ |
| 4119 | if (bs->stop == 0 || bs->print == 0) |
| 4120 | bs->print_it = print_it_noop; |
| 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 4125 | { |
| 4126 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
| 4127 | aspace, bp_addr)) |
| 4128 | { |
| 4129 | bs = bpstat_alloc (loc, bs); |
| 4130 | /* For hits of moribund locations, we should just proceed. */ |
| 4131 | bs->stop = 0; |
| 4132 | bs->print = 0; |
| 4133 | bs->print_it = print_it_noop; |
| 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | bs->next = NULL; /* Terminate the chain */ |
| 4138 | |
| 4139 | /* If we aren't stopping, the value of some hardware watchpoint may |
| 4140 | not have changed, but the intermediate memory locations we are |
| 4141 | watching may have. Don't bother if we're stopping; this will get |
| 4142 | done later. */ |
| 4143 | need_remove_insert = 0; |
| 4144 | if (! bpstat_causes_stop (root_bs->next)) |
| 4145 | for (bs = root_bs->next; bs != NULL; bs = bs->next) |
| 4146 | if (!bs->stop |
| 4147 | && bs->breakpoint_at->owner |
| 4148 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
| 4149 | { |
| 4150 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
| 4151 | /* Updating watchpoints invalidates bs->breakpoint_at. |
| 4152 | Prevent further code from trying to use it. */ |
| 4153 | bs->breakpoint_at = NULL; |
| 4154 | need_remove_insert = 1; |
| 4155 | } |
| 4156 | |
| 4157 | if (need_remove_insert) |
| 4158 | update_global_location_list (1); |
| 4159 | |
| 4160 | return root_bs->next; |
| 4161 | } |
| 4162 | \f |
| 4163 | /* Tell what to do about this bpstat. */ |
| 4164 | struct bpstat_what |
| 4165 | bpstat_what (bpstat bs) |
| 4166 | { |
| 4167 | /* Classify each bpstat as one of the following. */ |
| 4168 | enum class |
| 4169 | { |
| 4170 | /* This bpstat element has no effect on the main_action. */ |
| 4171 | no_effect = 0, |
| 4172 | |
| 4173 | /* There was a watchpoint, stop but don't print. */ |
| 4174 | wp_silent, |
| 4175 | |
| 4176 | /* There was a watchpoint, stop and print. */ |
| 4177 | wp_noisy, |
| 4178 | |
| 4179 | /* There was a breakpoint but we're not stopping. */ |
| 4180 | bp_nostop, |
| 4181 | |
| 4182 | /* There was a breakpoint, stop but don't print. */ |
| 4183 | bp_silent, |
| 4184 | |
| 4185 | /* There was a breakpoint, stop and print. */ |
| 4186 | bp_noisy, |
| 4187 | |
| 4188 | /* We hit the longjmp breakpoint. */ |
| 4189 | long_jump, |
| 4190 | |
| 4191 | /* We hit the longjmp_resume breakpoint. */ |
| 4192 | long_resume, |
| 4193 | |
| 4194 | /* We hit the step_resume breakpoint. */ |
| 4195 | step_resume, |
| 4196 | |
| 4197 | /* We hit the shared library event breakpoint. */ |
| 4198 | shlib_event, |
| 4199 | |
| 4200 | /* We hit the jit event breakpoint. */ |
| 4201 | jit_event, |
| 4202 | |
| 4203 | /* This is just used to count how many enums there are. */ |
| 4204 | class_last |
| 4205 | }; |
| 4206 | |
| 4207 | /* Here is the table which drives this routine. So that we can |
| 4208 | format it pretty, we define some abbreviations for the |
| 4209 | enum bpstat_what codes. */ |
| 4210 | #define kc BPSTAT_WHAT_KEEP_CHECKING |
| 4211 | #define ss BPSTAT_WHAT_STOP_SILENT |
| 4212 | #define sn BPSTAT_WHAT_STOP_NOISY |
| 4213 | #define sgl BPSTAT_WHAT_SINGLE |
| 4214 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME |
| 4215 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME |
| 4216 | #define sr BPSTAT_WHAT_STEP_RESUME |
| 4217 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
| 4218 | #define jit BPSTAT_WHAT_CHECK_JIT |
| 4219 | |
| 4220 | /* "Can't happen." Might want to print an error message. |
| 4221 | abort() is not out of the question, but chances are GDB is just |
| 4222 | a bit confused, not unusable. */ |
| 4223 | #define err BPSTAT_WHAT_STOP_NOISY |
| 4224 | |
| 4225 | /* Given an old action and a class, come up with a new action. */ |
| 4226 | /* One interesting property of this table is that wp_silent is the same |
| 4227 | as bp_silent and wp_noisy is the same as bp_noisy. That is because |
| 4228 | after stopping, the check for whether to step over a breakpoint |
| 4229 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without |
| 4230 | reference to how we stopped. We retain separate wp_silent and |
| 4231 | bp_silent codes in case we want to change that someday. |
| 4232 | |
| 4233 | Another possibly interesting property of this table is that |
| 4234 | there's a partial ordering, priority-like, of the actions. Once |
| 4235 | you've decided that some action is appropriate, you'll never go |
| 4236 | back and decide something of a lower priority is better. The |
| 4237 | ordering is: |
| 4238 | |
| 4239 | kc < jit clr sgl shl slr sn sr ss |
| 4240 | sgl < jit shl slr sn sr ss |
| 4241 | slr < jit err shl sn sr ss |
| 4242 | clr < jit err shl sn sr ss |
| 4243 | ss < jit shl sn sr |
| 4244 | sn < jit shl sr |
| 4245 | jit < shl sr |
| 4246 | shl < sr |
| 4247 | sr < |
| 4248 | |
| 4249 | What I think this means is that we don't need a damned table |
| 4250 | here. If you just put the rows and columns in the right order, |
| 4251 | it'd look awfully regular. We could simply walk the bpstat list |
| 4252 | and choose the highest priority action we find, with a little |
| 4253 | logic to handle the 'err' cases. */ |
| 4254 | |
| 4255 | /* step_resume entries: a step resume breakpoint overrides another |
| 4256 | breakpoint of signal handling (see comment in wait_for_inferior |
| 4257 | at where we set the step_resume breakpoint). */ |
| 4258 | |
| 4259 | static const enum bpstat_what_main_action |
| 4260 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
| 4261 | { |
| 4262 | /* old action */ |
| 4263 | /* kc ss sn sgl slr clr sr shl jit */ |
| 4264 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, |
| 4265 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, |
| 4266 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, |
| 4267 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, |
| 4268 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, |
| 4269 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, |
| 4270 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, |
| 4271 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, |
| 4272 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, |
| 4273 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, |
| 4274 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} |
| 4275 | }; |
| 4276 | |
| 4277 | #undef kc |
| 4278 | #undef ss |
| 4279 | #undef sn |
| 4280 | #undef sgl |
| 4281 | #undef slr |
| 4282 | #undef clr |
| 4283 | #undef err |
| 4284 | #undef sr |
| 4285 | #undef ts |
| 4286 | #undef shl |
| 4287 | #undef jit |
| 4288 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 4289 | struct bpstat_what retval; |
| 4290 | |
| 4291 | retval.call_dummy = STOP_NONE; |
| 4292 | for (; bs != NULL; bs = bs->next) |
| 4293 | { |
| 4294 | enum class bs_class = no_effect; |
| 4295 | if (bs->breakpoint_at == NULL) |
| 4296 | /* I suspect this can happen if it was a momentary breakpoint |
| 4297 | which has since been deleted. */ |
| 4298 | continue; |
| 4299 | if (bs->breakpoint_at->owner == NULL) |
| 4300 | bs_class = bp_nostop; |
| 4301 | else |
| 4302 | switch (bs->breakpoint_at->owner->type) |
| 4303 | { |
| 4304 | case bp_none: |
| 4305 | continue; |
| 4306 | |
| 4307 | case bp_breakpoint: |
| 4308 | case bp_hardware_breakpoint: |
| 4309 | case bp_until: |
| 4310 | case bp_finish: |
| 4311 | if (bs->stop) |
| 4312 | { |
| 4313 | if (bs->print) |
| 4314 | bs_class = bp_noisy; |
| 4315 | else |
| 4316 | bs_class = bp_silent; |
| 4317 | } |
| 4318 | else |
| 4319 | bs_class = bp_nostop; |
| 4320 | break; |
| 4321 | case bp_watchpoint: |
| 4322 | case bp_hardware_watchpoint: |
| 4323 | case bp_read_watchpoint: |
| 4324 | case bp_access_watchpoint: |
| 4325 | if (bs->stop) |
| 4326 | { |
| 4327 | if (bs->print) |
| 4328 | bs_class = wp_noisy; |
| 4329 | else |
| 4330 | bs_class = wp_silent; |
| 4331 | } |
| 4332 | else |
| 4333 | /* There was a watchpoint, but we're not stopping. |
| 4334 | This requires no further action. */ |
| 4335 | bs_class = no_effect; |
| 4336 | break; |
| 4337 | case bp_longjmp: |
| 4338 | bs_class = long_jump; |
| 4339 | break; |
| 4340 | case bp_longjmp_resume: |
| 4341 | bs_class = long_resume; |
| 4342 | break; |
| 4343 | case bp_step_resume: |
| 4344 | if (bs->stop) |
| 4345 | { |
| 4346 | bs_class = step_resume; |
| 4347 | } |
| 4348 | else |
| 4349 | /* It is for the wrong frame. */ |
| 4350 | bs_class = bp_nostop; |
| 4351 | break; |
| 4352 | case bp_watchpoint_scope: |
| 4353 | bs_class = bp_nostop; |
| 4354 | break; |
| 4355 | case bp_shlib_event: |
| 4356 | bs_class = shlib_event; |
| 4357 | break; |
| 4358 | case bp_jit_event: |
| 4359 | bs_class = jit_event; |
| 4360 | break; |
| 4361 | case bp_thread_event: |
| 4362 | case bp_overlay_event: |
| 4363 | case bp_longjmp_master: |
| 4364 | case bp_std_terminate_master: |
| 4365 | bs_class = bp_nostop; |
| 4366 | break; |
| 4367 | case bp_catchpoint: |
| 4368 | if (bs->stop) |
| 4369 | { |
| 4370 | if (bs->print) |
| 4371 | bs_class = bp_noisy; |
| 4372 | else |
| 4373 | bs_class = bp_silent; |
| 4374 | } |
| 4375 | else |
| 4376 | /* There was a catchpoint, but we're not stopping. |
| 4377 | This requires no further action. */ |
| 4378 | bs_class = no_effect; |
| 4379 | break; |
| 4380 | case bp_call_dummy: |
| 4381 | /* Make sure the action is stop (silent or noisy), |
| 4382 | so infrun.c pops the dummy frame. */ |
| 4383 | bs_class = bp_silent; |
| 4384 | retval.call_dummy = STOP_STACK_DUMMY; |
| 4385 | break; |
| 4386 | case bp_std_terminate: |
| 4387 | /* Make sure the action is stop (silent or noisy), |
| 4388 | so infrun.c pops the dummy frame. */ |
| 4389 | bs_class = bp_silent; |
| 4390 | retval.call_dummy = STOP_STD_TERMINATE; |
| 4391 | break; |
| 4392 | case bp_tracepoint: |
| 4393 | case bp_fast_tracepoint: |
| 4394 | /* Tracepoint hits should not be reported back to GDB, and |
| 4395 | if one got through somehow, it should have been filtered |
| 4396 | out already. */ |
| 4397 | internal_error (__FILE__, __LINE__, |
| 4398 | _("bpstat_what: tracepoint encountered")); |
| 4399 | break; |
| 4400 | } |
| 4401 | current_action = table[(int) bs_class][(int) current_action]; |
| 4402 | } |
| 4403 | retval.main_action = current_action; |
| 4404 | return retval; |
| 4405 | } |
| 4406 | |
| 4407 | /* Nonzero if we should step constantly (e.g. watchpoints on machines |
| 4408 | without hardware support). This isn't related to a specific bpstat, |
| 4409 | just to things like whether watchpoints are set. */ |
| 4410 | |
| 4411 | int |
| 4412 | bpstat_should_step (void) |
| 4413 | { |
| 4414 | struct breakpoint *b; |
| 4415 | ALL_BREAKPOINTS (b) |
| 4416 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
| 4417 | return 1; |
| 4418 | return 0; |
| 4419 | } |
| 4420 | |
| 4421 | int |
| 4422 | bpstat_causes_stop (bpstat bs) |
| 4423 | { |
| 4424 | for (; bs != NULL; bs = bs->next) |
| 4425 | if (bs->stop) |
| 4426 | return 1; |
| 4427 | |
| 4428 | return 0; |
| 4429 | } |
| 4430 | |
| 4431 | \f |
| 4432 | |
| 4433 | /* Print the LOC location out of the list of B->LOC locations. */ |
| 4434 | |
| 4435 | static void print_breakpoint_location (struct breakpoint *b, |
| 4436 | struct bp_location *loc, |
| 4437 | char *wrap_indent, |
| 4438 | struct ui_stream *stb) |
| 4439 | { |
| 4440 | struct cleanup *old_chain = save_current_program_space (); |
| 4441 | |
| 4442 | if (loc != NULL && loc->shlib_disabled) |
| 4443 | loc = NULL; |
| 4444 | |
| 4445 | if (loc != NULL) |
| 4446 | set_current_program_space (loc->pspace); |
| 4447 | |
| 4448 | if (b->source_file && loc) |
| 4449 | { |
| 4450 | struct symbol *sym |
| 4451 | = find_pc_sect_function (loc->address, loc->section); |
| 4452 | if (sym) |
| 4453 | { |
| 4454 | ui_out_text (uiout, "in "); |
| 4455 | ui_out_field_string (uiout, "func", |
| 4456 | SYMBOL_PRINT_NAME (sym)); |
| 4457 | ui_out_wrap_hint (uiout, wrap_indent); |
| 4458 | ui_out_text (uiout, " at "); |
| 4459 | } |
| 4460 | ui_out_field_string (uiout, "file", b->source_file); |
| 4461 | ui_out_text (uiout, ":"); |
| 4462 | |
| 4463 | if (ui_out_is_mi_like_p (uiout)) |
| 4464 | { |
| 4465 | struct symtab_and_line sal = find_pc_line (loc->address, 0); |
| 4466 | char *fullname = symtab_to_fullname (sal.symtab); |
| 4467 | |
| 4468 | if (fullname) |
| 4469 | ui_out_field_string (uiout, "fullname", fullname); |
| 4470 | } |
| 4471 | |
| 4472 | ui_out_field_int (uiout, "line", b->line_number); |
| 4473 | } |
| 4474 | else if (loc) |
| 4475 | { |
| 4476 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
| 4477 | demangle, ""); |
| 4478 | ui_out_field_stream (uiout, "at", stb); |
| 4479 | } |
| 4480 | else |
| 4481 | ui_out_field_string (uiout, "pending", b->addr_string); |
| 4482 | |
| 4483 | do_cleanups (old_chain); |
| 4484 | } |
| 4485 | |
| 4486 | /* Print B to gdb_stdout. */ |
| 4487 | static void |
| 4488 | print_one_breakpoint_location (struct breakpoint *b, |
| 4489 | struct bp_location *loc, |
| 4490 | int loc_number, |
| 4491 | struct bp_location **last_loc, |
| 4492 | int print_address_bits, |
| 4493 | int allflag) |
| 4494 | { |
| 4495 | struct command_line *l; |
| 4496 | struct symbol *sym; |
| 4497 | struct ep_type_description |
| 4498 | { |
| 4499 | enum bptype type; |
| 4500 | char *description; |
| 4501 | }; |
| 4502 | static struct ep_type_description bptypes[] = |
| 4503 | { |
| 4504 | {bp_none, "?deleted?"}, |
| 4505 | {bp_breakpoint, "breakpoint"}, |
| 4506 | {bp_hardware_breakpoint, "hw breakpoint"}, |
| 4507 | {bp_until, "until"}, |
| 4508 | {bp_finish, "finish"}, |
| 4509 | {bp_watchpoint, "watchpoint"}, |
| 4510 | {bp_hardware_watchpoint, "hw watchpoint"}, |
| 4511 | {bp_read_watchpoint, "read watchpoint"}, |
| 4512 | {bp_access_watchpoint, "acc watchpoint"}, |
| 4513 | {bp_longjmp, "longjmp"}, |
| 4514 | {bp_longjmp_resume, "longjmp resume"}, |
| 4515 | {bp_step_resume, "step resume"}, |
| 4516 | {bp_watchpoint_scope, "watchpoint scope"}, |
| 4517 | {bp_call_dummy, "call dummy"}, |
| 4518 | {bp_std_terminate, "std::terminate"}, |
| 4519 | {bp_shlib_event, "shlib events"}, |
| 4520 | {bp_thread_event, "thread events"}, |
| 4521 | {bp_overlay_event, "overlay events"}, |
| 4522 | {bp_longjmp_master, "longjmp master"}, |
| 4523 | {bp_std_terminate_master, "std::terminate master"}, |
| 4524 | {bp_catchpoint, "catchpoint"}, |
| 4525 | {bp_tracepoint, "tracepoint"}, |
| 4526 | {bp_fast_tracepoint, "fast tracepoint"}, |
| 4527 | {bp_jit_event, "jit events"}, |
| 4528 | }; |
| 4529 | |
| 4530 | static char bpenables[] = "nynny"; |
| 4531 | char wrap_indent[80]; |
| 4532 | struct ui_stream *stb = ui_out_stream_new (uiout); |
| 4533 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); |
| 4534 | struct cleanup *bkpt_chain; |
| 4535 | |
| 4536 | int header_of_multiple = 0; |
| 4537 | int part_of_multiple = (loc != NULL); |
| 4538 | struct value_print_options opts; |
| 4539 | |
| 4540 | get_user_print_options (&opts); |
| 4541 | |
| 4542 | gdb_assert (!loc || loc_number != 0); |
| 4543 | /* See comment in print_one_breakpoint concerning |
| 4544 | treatment of breakpoints with single disabled |
| 4545 | location. */ |
| 4546 | if (loc == NULL |
| 4547 | && (b->loc != NULL |
| 4548 | && (b->loc->next != NULL || !b->loc->enabled))) |
| 4549 | header_of_multiple = 1; |
| 4550 | if (loc == NULL) |
| 4551 | loc = b->loc; |
| 4552 | |
| 4553 | annotate_record (); |
| 4554 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
| 4555 | |
| 4556 | /* 1 */ |
| 4557 | annotate_field (0); |
| 4558 | if (part_of_multiple) |
| 4559 | { |
| 4560 | char *formatted; |
| 4561 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
| 4562 | ui_out_field_string (uiout, "number", formatted); |
| 4563 | xfree (formatted); |
| 4564 | } |
| 4565 | else |
| 4566 | { |
| 4567 | ui_out_field_int (uiout, "number", b->number); |
| 4568 | } |
| 4569 | |
| 4570 | /* 2 */ |
| 4571 | annotate_field (1); |
| 4572 | if (part_of_multiple) |
| 4573 | ui_out_field_skip (uiout, "type"); |
| 4574 | else |
| 4575 | { |
| 4576 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) |
| 4577 | || ((int) b->type != bptypes[(int) b->type].type)) |
| 4578 | internal_error (__FILE__, __LINE__, |
| 4579 | _("bptypes table does not describe type #%d."), |
| 4580 | (int) b->type); |
| 4581 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); |
| 4582 | } |
| 4583 | |
| 4584 | /* 3 */ |
| 4585 | annotate_field (2); |
| 4586 | if (part_of_multiple) |
| 4587 | ui_out_field_skip (uiout, "disp"); |
| 4588 | else |
| 4589 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 4590 | |
| 4591 | |
| 4592 | /* 4 */ |
| 4593 | annotate_field (3); |
| 4594 | if (part_of_multiple) |
| 4595 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
| 4596 | else |
| 4597 | ui_out_field_fmt (uiout, "enabled", "%c", |
| 4598 | bpenables[(int) b->enable_state]); |
| 4599 | ui_out_spaces (uiout, 2); |
| 4600 | |
| 4601 | |
| 4602 | /* 5 and 6 */ |
| 4603 | strcpy (wrap_indent, " "); |
| 4604 | if (opts.addressprint) |
| 4605 | { |
| 4606 | if (print_address_bits <= 32) |
| 4607 | strcat (wrap_indent, " "); |
| 4608 | else |
| 4609 | strcat (wrap_indent, " "); |
| 4610 | } |
| 4611 | |
| 4612 | if (b->ops != NULL && b->ops->print_one != NULL) |
| 4613 | { |
| 4614 | /* Although the print_one can possibly print |
| 4615 | all locations, calling it here is not likely |
| 4616 | to get any nice result. So, make sure there's |
| 4617 | just one location. */ |
| 4618 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
| 4619 | b->ops->print_one (b, last_loc); |
| 4620 | } |
| 4621 | else |
| 4622 | switch (b->type) |
| 4623 | { |
| 4624 | case bp_none: |
| 4625 | internal_error (__FILE__, __LINE__, |
| 4626 | _("print_one_breakpoint: bp_none encountered\n")); |
| 4627 | break; |
| 4628 | |
| 4629 | case bp_watchpoint: |
| 4630 | case bp_hardware_watchpoint: |
| 4631 | case bp_read_watchpoint: |
| 4632 | case bp_access_watchpoint: |
| 4633 | /* Field 4, the address, is omitted (which makes the columns |
| 4634 | not line up too nicely with the headers, but the effect |
| 4635 | is relatively readable). */ |
| 4636 | if (opts.addressprint) |
| 4637 | ui_out_field_skip (uiout, "addr"); |
| 4638 | annotate_field (5); |
| 4639 | ui_out_field_string (uiout, "what", b->exp_string); |
| 4640 | break; |
| 4641 | |
| 4642 | case bp_breakpoint: |
| 4643 | case bp_hardware_breakpoint: |
| 4644 | case bp_until: |
| 4645 | case bp_finish: |
| 4646 | case bp_longjmp: |
| 4647 | case bp_longjmp_resume: |
| 4648 | case bp_step_resume: |
| 4649 | case bp_watchpoint_scope: |
| 4650 | case bp_call_dummy: |
| 4651 | case bp_std_terminate: |
| 4652 | case bp_shlib_event: |
| 4653 | case bp_thread_event: |
| 4654 | case bp_overlay_event: |
| 4655 | case bp_longjmp_master: |
| 4656 | case bp_std_terminate_master: |
| 4657 | case bp_tracepoint: |
| 4658 | case bp_fast_tracepoint: |
| 4659 | case bp_jit_event: |
| 4660 | if (opts.addressprint) |
| 4661 | { |
| 4662 | annotate_field (4); |
| 4663 | if (header_of_multiple) |
| 4664 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
| 4665 | else if (b->loc == NULL || loc->shlib_disabled) |
| 4666 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
| 4667 | else |
| 4668 | ui_out_field_core_addr (uiout, "addr", |
| 4669 | loc->gdbarch, loc->address); |
| 4670 | } |
| 4671 | annotate_field (5); |
| 4672 | if (!header_of_multiple) |
| 4673 | print_breakpoint_location (b, loc, wrap_indent, stb); |
| 4674 | if (b->loc) |
| 4675 | *last_loc = b->loc; |
| 4676 | break; |
| 4677 | } |
| 4678 | |
| 4679 | |
| 4680 | /* For backward compatibility, don't display inferiors unless there |
| 4681 | are several. */ |
| 4682 | if (loc != NULL |
| 4683 | && !header_of_multiple |
| 4684 | && (allflag |
| 4685 | || (!gdbarch_has_global_breakpoints (target_gdbarch) |
| 4686 | && (number_of_program_spaces () > 1 |
| 4687 | || number_of_inferiors () > 1) |
| 4688 | && loc->owner->type != bp_catchpoint))) |
| 4689 | { |
| 4690 | struct inferior *inf; |
| 4691 | int first = 1; |
| 4692 | |
| 4693 | for (inf = inferior_list; inf != NULL; inf = inf->next) |
| 4694 | { |
| 4695 | if (inf->pspace == loc->pspace) |
| 4696 | { |
| 4697 | if (first) |
| 4698 | { |
| 4699 | first = 0; |
| 4700 | ui_out_text (uiout, " inf "); |
| 4701 | } |
| 4702 | else |
| 4703 | ui_out_text (uiout, ", "); |
| 4704 | ui_out_text (uiout, plongest (inf->num)); |
| 4705 | } |
| 4706 | } |
| 4707 | } |
| 4708 | |
| 4709 | if (!part_of_multiple) |
| 4710 | { |
| 4711 | if (b->thread != -1) |
| 4712 | { |
| 4713 | /* FIXME: This seems to be redundant and lost here; see the |
| 4714 | "stop only in" line a little further down. */ |
| 4715 | ui_out_text (uiout, " thread "); |
| 4716 | ui_out_field_int (uiout, "thread", b->thread); |
| 4717 | } |
| 4718 | else if (b->task != 0) |
| 4719 | { |
| 4720 | ui_out_text (uiout, " task "); |
| 4721 | ui_out_field_int (uiout, "task", b->task); |
| 4722 | } |
| 4723 | } |
| 4724 | |
| 4725 | ui_out_text (uiout, "\n"); |
| 4726 | |
| 4727 | if (part_of_multiple && frame_id_p (b->frame_id)) |
| 4728 | { |
| 4729 | annotate_field (6); |
| 4730 | ui_out_text (uiout, "\tstop only in stack frame at "); |
| 4731 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
| 4732 | the frame ID. */ |
| 4733 | ui_out_field_core_addr (uiout, "frame", |
| 4734 | b->gdbarch, b->frame_id.stack_addr); |
| 4735 | ui_out_text (uiout, "\n"); |
| 4736 | } |
| 4737 | |
| 4738 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
| 4739 | { |
| 4740 | /* We do not print the condition for Ada exception catchpoints |
| 4741 | because the condition is an internal implementation detail |
| 4742 | that we do not want to expose to the user. */ |
| 4743 | annotate_field (7); |
| 4744 | if (is_tracepoint (b)) |
| 4745 | ui_out_text (uiout, "\ttrace only if "); |
| 4746 | else |
| 4747 | ui_out_text (uiout, "\tstop only if "); |
| 4748 | ui_out_field_string (uiout, "cond", b->cond_string); |
| 4749 | ui_out_text (uiout, "\n"); |
| 4750 | } |
| 4751 | |
| 4752 | if (!part_of_multiple && b->thread != -1) |
| 4753 | { |
| 4754 | /* FIXME should make an annotation for this */ |
| 4755 | ui_out_text (uiout, "\tstop only in thread "); |
| 4756 | ui_out_field_int (uiout, "thread", b->thread); |
| 4757 | ui_out_text (uiout, "\n"); |
| 4758 | } |
| 4759 | |
| 4760 | if (!part_of_multiple && b->hit_count) |
| 4761 | { |
| 4762 | /* FIXME should make an annotation for this */ |
| 4763 | if (ep_is_catchpoint (b)) |
| 4764 | ui_out_text (uiout, "\tcatchpoint"); |
| 4765 | else |
| 4766 | ui_out_text (uiout, "\tbreakpoint"); |
| 4767 | ui_out_text (uiout, " already hit "); |
| 4768 | ui_out_field_int (uiout, "times", b->hit_count); |
| 4769 | if (b->hit_count == 1) |
| 4770 | ui_out_text (uiout, " time\n"); |
| 4771 | else |
| 4772 | ui_out_text (uiout, " times\n"); |
| 4773 | } |
| 4774 | |
| 4775 | /* Output the count also if it is zero, but only if this is |
| 4776 | mi. FIXME: Should have a better test for this. */ |
| 4777 | if (ui_out_is_mi_like_p (uiout)) |
| 4778 | if (!part_of_multiple && b->hit_count == 0) |
| 4779 | ui_out_field_int (uiout, "times", b->hit_count); |
| 4780 | |
| 4781 | if (!part_of_multiple && b->ignore_count) |
| 4782 | { |
| 4783 | annotate_field (8); |
| 4784 | ui_out_text (uiout, "\tignore next "); |
| 4785 | ui_out_field_int (uiout, "ignore", b->ignore_count); |
| 4786 | ui_out_text (uiout, " hits\n"); |
| 4787 | } |
| 4788 | |
| 4789 | l = b->commands ? b->commands->commands : NULL; |
| 4790 | if (!part_of_multiple && l) |
| 4791 | { |
| 4792 | struct cleanup *script_chain; |
| 4793 | |
| 4794 | annotate_field (9); |
| 4795 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
| 4796 | print_command_lines (uiout, l, 4); |
| 4797 | do_cleanups (script_chain); |
| 4798 | } |
| 4799 | |
| 4800 | if (!part_of_multiple && b->pass_count) |
| 4801 | { |
| 4802 | annotate_field (10); |
| 4803 | ui_out_text (uiout, "\tpass count "); |
| 4804 | ui_out_field_int (uiout, "pass", b->pass_count); |
| 4805 | ui_out_text (uiout, " \n"); |
| 4806 | } |
| 4807 | |
| 4808 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
| 4809 | { |
| 4810 | if (b->addr_string) |
| 4811 | ui_out_field_string (uiout, "original-location", b->addr_string); |
| 4812 | else if (b->exp_string) |
| 4813 | ui_out_field_string (uiout, "original-location", b->exp_string); |
| 4814 | } |
| 4815 | |
| 4816 | do_cleanups (bkpt_chain); |
| 4817 | do_cleanups (old_chain); |
| 4818 | } |
| 4819 | |
| 4820 | static void |
| 4821 | print_one_breakpoint (struct breakpoint *b, |
| 4822 | struct bp_location **last_loc, int print_address_bits, |
| 4823 | int allflag) |
| 4824 | { |
| 4825 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
| 4826 | print_address_bits, allflag); |
| 4827 | |
| 4828 | /* If this breakpoint has custom print function, |
| 4829 | it's already printed. Otherwise, print individual |
| 4830 | locations, if any. */ |
| 4831 | if (b->ops == NULL || b->ops->print_one == NULL) |
| 4832 | { |
| 4833 | /* If breakpoint has a single location that is |
| 4834 | disabled, we print it as if it had |
| 4835 | several locations, since otherwise it's hard to |
| 4836 | represent "breakpoint enabled, location disabled" |
| 4837 | situation. |
| 4838 | Note that while hardware watchpoints have |
| 4839 | several locations internally, that's no a property |
| 4840 | exposed to user. */ |
| 4841 | if (b->loc |
| 4842 | && !is_hardware_watchpoint (b) |
| 4843 | && (b->loc->next || !b->loc->enabled) |
| 4844 | && !ui_out_is_mi_like_p (uiout)) |
| 4845 | { |
| 4846 | struct bp_location *loc; |
| 4847 | int n = 1; |
| 4848 | for (loc = b->loc; loc; loc = loc->next, ++n) |
| 4849 | print_one_breakpoint_location (b, loc, n, last_loc, |
| 4850 | print_address_bits, allflag); |
| 4851 | } |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | static int |
| 4856 | breakpoint_address_bits (struct breakpoint *b) |
| 4857 | { |
| 4858 | int print_address_bits = 0; |
| 4859 | struct bp_location *loc; |
| 4860 | |
| 4861 | for (loc = b->loc; loc; loc = loc->next) |
| 4862 | { |
| 4863 | int addr_bit; |
| 4864 | |
| 4865 | /* Software watchpoints that aren't watching memory don't have |
| 4866 | an address to print. */ |
| 4867 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) |
| 4868 | continue; |
| 4869 | |
| 4870 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
| 4871 | if (addr_bit > print_address_bits) |
| 4872 | print_address_bits = addr_bit; |
| 4873 | } |
| 4874 | |
| 4875 | return print_address_bits; |
| 4876 | } |
| 4877 | |
| 4878 | struct captured_breakpoint_query_args |
| 4879 | { |
| 4880 | int bnum; |
| 4881 | }; |
| 4882 | |
| 4883 | static int |
| 4884 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
| 4885 | { |
| 4886 | struct captured_breakpoint_query_args *args = data; |
| 4887 | struct breakpoint *b; |
| 4888 | struct bp_location *dummy_loc = NULL; |
| 4889 | ALL_BREAKPOINTS (b) |
| 4890 | { |
| 4891 | if (args->bnum == b->number) |
| 4892 | { |
| 4893 | int print_address_bits = breakpoint_address_bits (b); |
| 4894 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
| 4895 | return GDB_RC_OK; |
| 4896 | } |
| 4897 | } |
| 4898 | return GDB_RC_NONE; |
| 4899 | } |
| 4900 | |
| 4901 | enum gdb_rc |
| 4902 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
| 4903 | { |
| 4904 | struct captured_breakpoint_query_args args; |
| 4905 | args.bnum = bnum; |
| 4906 | /* For the moment we don't trust print_one_breakpoint() to not throw |
| 4907 | an error. */ |
| 4908 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
| 4909 | error_message, RETURN_MASK_ALL) < 0) |
| 4910 | return GDB_RC_FAIL; |
| 4911 | else |
| 4912 | return GDB_RC_OK; |
| 4913 | } |
| 4914 | |
| 4915 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
| 4916 | catchpoints, et.al.). */ |
| 4917 | |
| 4918 | static int |
| 4919 | user_settable_breakpoint (const struct breakpoint *b) |
| 4920 | { |
| 4921 | return (b->type == bp_breakpoint |
| 4922 | || b->type == bp_catchpoint |
| 4923 | || b->type == bp_hardware_breakpoint |
| 4924 | || is_tracepoint (b) |
| 4925 | || is_watchpoint (b)); |
| 4926 | } |
| 4927 | |
| 4928 | /* Print information on user settable breakpoint (watchpoint, etc) |
| 4929 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
| 4930 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If |
| 4931 | FILTER is non-NULL, call it on each breakpoint and only include the |
| 4932 | ones for which it returns non-zero. Return the total number of |
| 4933 | breakpoints listed. */ |
| 4934 | |
| 4935 | static int |
| 4936 | breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *)) |
| 4937 | { |
| 4938 | struct breakpoint *b; |
| 4939 | struct bp_location *last_loc = NULL; |
| 4940 | int nr_printable_breakpoints; |
| 4941 | struct cleanup *bkpttbl_chain; |
| 4942 | struct value_print_options opts; |
| 4943 | int print_address_bits = 0; |
| 4944 | |
| 4945 | get_user_print_options (&opts); |
| 4946 | |
| 4947 | /* Compute the number of rows in the table, as well as the |
| 4948 | size required for address fields. */ |
| 4949 | nr_printable_breakpoints = 0; |
| 4950 | ALL_BREAKPOINTS (b) |
| 4951 | if (bnum == -1 |
| 4952 | || bnum == b->number) |
| 4953 | { |
| 4954 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 4955 | if (filter && !filter (b)) |
| 4956 | continue; |
| 4957 | |
| 4958 | if (allflag || user_settable_breakpoint (b)) |
| 4959 | { |
| 4960 | int addr_bit = breakpoint_address_bits (b); |
| 4961 | if (addr_bit > print_address_bits) |
| 4962 | print_address_bits = addr_bit; |
| 4963 | |
| 4964 | nr_printable_breakpoints++; |
| 4965 | } |
| 4966 | } |
| 4967 | |
| 4968 | if (opts.addressprint) |
| 4969 | bkpttbl_chain |
| 4970 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, |
| 4971 | "BreakpointTable"); |
| 4972 | else |
| 4973 | bkpttbl_chain |
| 4974 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, |
| 4975 | "BreakpointTable"); |
| 4976 | |
| 4977 | if (nr_printable_breakpoints > 0) |
| 4978 | annotate_breakpoints_headers (); |
| 4979 | if (nr_printable_breakpoints > 0) |
| 4980 | annotate_field (0); |
| 4981 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
| 4982 | if (nr_printable_breakpoints > 0) |
| 4983 | annotate_field (1); |
| 4984 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ |
| 4985 | if (nr_printable_breakpoints > 0) |
| 4986 | annotate_field (2); |
| 4987 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
| 4988 | if (nr_printable_breakpoints > 0) |
| 4989 | annotate_field (3); |
| 4990 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
| 4991 | if (opts.addressprint) |
| 4992 | { |
| 4993 | if (nr_printable_breakpoints > 0) |
| 4994 | annotate_field (4); |
| 4995 | if (print_address_bits <= 32) |
| 4996 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
| 4997 | else |
| 4998 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
| 4999 | } |
| 5000 | if (nr_printable_breakpoints > 0) |
| 5001 | annotate_field (5); |
| 5002 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ |
| 5003 | ui_out_table_body (uiout); |
| 5004 | if (nr_printable_breakpoints > 0) |
| 5005 | annotate_breakpoints_table (); |
| 5006 | |
| 5007 | ALL_BREAKPOINTS (b) |
| 5008 | { |
| 5009 | QUIT; |
| 5010 | if (bnum == -1 |
| 5011 | || bnum == b->number) |
| 5012 | { |
| 5013 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 5014 | if (filter && !filter (b)) |
| 5015 | continue; |
| 5016 | |
| 5017 | /* We only print out user settable breakpoints unless the |
| 5018 | allflag is set. */ |
| 5019 | if (allflag || user_settable_breakpoint (b)) |
| 5020 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
| 5021 | } |
| 5022 | } |
| 5023 | |
| 5024 | do_cleanups (bkpttbl_chain); |
| 5025 | |
| 5026 | if (nr_printable_breakpoints == 0) |
| 5027 | { |
| 5028 | /* If there's a filter, let the caller decide how to report empty list. */ |
| 5029 | if (!filter) |
| 5030 | { |
| 5031 | if (bnum == -1) |
| 5032 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
| 5033 | else |
| 5034 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", |
| 5035 | bnum); |
| 5036 | } |
| 5037 | } |
| 5038 | else |
| 5039 | { |
| 5040 | if (last_loc && !server_command) |
| 5041 | set_next_address (last_loc->gdbarch, last_loc->address); |
| 5042 | } |
| 5043 | |
| 5044 | /* FIXME? Should this be moved up so that it is only called when |
| 5045 | there have been breakpoints? */ |
| 5046 | annotate_breakpoints_table_end (); |
| 5047 | |
| 5048 | return nr_printable_breakpoints; |
| 5049 | } |
| 5050 | |
| 5051 | /* Display the value of default-collect in a way that is generally |
| 5052 | compatible with the breakpoint list. */ |
| 5053 | |
| 5054 | static void |
| 5055 | default_collect_info (void) |
| 5056 | { |
| 5057 | /* If it has no value (which is frequently the case), say nothing; a |
| 5058 | message like "No default-collect." gets in user's face when it's |
| 5059 | not wanted. */ |
| 5060 | if (!*default_collect) |
| 5061 | return; |
| 5062 | |
| 5063 | /* The following phrase lines up nicely with per-tracepoint collect |
| 5064 | actions. */ |
| 5065 | ui_out_text (uiout, "default collect "); |
| 5066 | ui_out_field_string (uiout, "default-collect", default_collect); |
| 5067 | ui_out_text (uiout, " \n"); |
| 5068 | } |
| 5069 | |
| 5070 | static void |
| 5071 | breakpoints_info (char *bnum_exp, int from_tty) |
| 5072 | { |
| 5073 | int bnum = -1; |
| 5074 | |
| 5075 | if (bnum_exp) |
| 5076 | bnum = parse_and_eval_long (bnum_exp); |
| 5077 | |
| 5078 | breakpoint_1 (bnum, 0, NULL); |
| 5079 | |
| 5080 | default_collect_info (); |
| 5081 | } |
| 5082 | |
| 5083 | static void |
| 5084 | watchpoints_info (char *wpnum_exp, int from_tty) |
| 5085 | { |
| 5086 | int wpnum = -1, num_printed; |
| 5087 | |
| 5088 | if (wpnum_exp) |
| 5089 | wpnum = parse_and_eval_long (wpnum_exp); |
| 5090 | |
| 5091 | num_printed = breakpoint_1 (wpnum, 0, is_watchpoint); |
| 5092 | |
| 5093 | if (num_printed == 0) |
| 5094 | { |
| 5095 | if (wpnum == -1) |
| 5096 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
| 5097 | else |
| 5098 | ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum); |
| 5099 | } |
| 5100 | } |
| 5101 | |
| 5102 | static void |
| 5103 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
| 5104 | { |
| 5105 | int bnum = -1; |
| 5106 | |
| 5107 | if (bnum_exp) |
| 5108 | bnum = parse_and_eval_long (bnum_exp); |
| 5109 | |
| 5110 | breakpoint_1 (bnum, 1, NULL); |
| 5111 | |
| 5112 | default_collect_info (); |
| 5113 | } |
| 5114 | |
| 5115 | static int |
| 5116 | breakpoint_has_pc (struct breakpoint *b, |
| 5117 | struct program_space *pspace, |
| 5118 | CORE_ADDR pc, struct obj_section *section) |
| 5119 | { |
| 5120 | struct bp_location *bl = b->loc; |
| 5121 | for (; bl; bl = bl->next) |
| 5122 | { |
| 5123 | if (bl->pspace == pspace |
| 5124 | && bl->address == pc |
| 5125 | && (!overlay_debugging || bl->section == section)) |
| 5126 | return 1; |
| 5127 | } |
| 5128 | return 0; |
| 5129 | } |
| 5130 | |
| 5131 | /* Print a message describing any breakpoints set at PC. This |
| 5132 | concerns with logical breakpoints, so we match program spaces, not |
| 5133 | address spaces. */ |
| 5134 | |
| 5135 | static void |
| 5136 | describe_other_breakpoints (struct gdbarch *gdbarch, |
| 5137 | struct program_space *pspace, CORE_ADDR pc, |
| 5138 | struct obj_section *section, int thread) |
| 5139 | { |
| 5140 | int others = 0; |
| 5141 | struct breakpoint *b; |
| 5142 | |
| 5143 | ALL_BREAKPOINTS (b) |
| 5144 | others += breakpoint_has_pc (b, pspace, pc, section); |
| 5145 | if (others > 0) |
| 5146 | { |
| 5147 | if (others == 1) |
| 5148 | printf_filtered (_("Note: breakpoint ")); |
| 5149 | else /* if (others == ???) */ |
| 5150 | printf_filtered (_("Note: breakpoints ")); |
| 5151 | ALL_BREAKPOINTS (b) |
| 5152 | if (breakpoint_has_pc (b, pspace, pc, section)) |
| 5153 | { |
| 5154 | others--; |
| 5155 | printf_filtered ("%d", b->number); |
| 5156 | if (b->thread == -1 && thread != -1) |
| 5157 | printf_filtered (" (all threads)"); |
| 5158 | else if (b->thread != -1) |
| 5159 | printf_filtered (" (thread %d)", b->thread); |
| 5160 | printf_filtered ("%s%s ", |
| 5161 | ((b->enable_state == bp_disabled |
| 5162 | || b->enable_state == bp_call_disabled |
| 5163 | || b->enable_state == bp_startup_disabled) |
| 5164 | ? " (disabled)" |
| 5165 | : b->enable_state == bp_permanent |
| 5166 | ? " (permanent)" |
| 5167 | : ""), |
| 5168 | (others > 1) ? "," |
| 5169 | : ((others == 1) ? " and" : "")); |
| 5170 | } |
| 5171 | printf_filtered (_("also set at pc ")); |
| 5172 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
| 5173 | printf_filtered (".\n"); |
| 5174 | } |
| 5175 | } |
| 5176 | \f |
| 5177 | /* Set the default place to put a breakpoint |
| 5178 | for the `break' command with no arguments. */ |
| 5179 | |
| 5180 | void |
| 5181 | set_default_breakpoint (int valid, struct program_space *pspace, |
| 5182 | CORE_ADDR addr, struct symtab *symtab, |
| 5183 | int line) |
| 5184 | { |
| 5185 | default_breakpoint_valid = valid; |
| 5186 | default_breakpoint_pspace = pspace; |
| 5187 | default_breakpoint_address = addr; |
| 5188 | default_breakpoint_symtab = symtab; |
| 5189 | default_breakpoint_line = line; |
| 5190 | } |
| 5191 | |
| 5192 | /* Return true iff it is meaningful to use the address member of |
| 5193 | BPT. For some breakpoint types, the address member is irrelevant |
| 5194 | and it makes no sense to attempt to compare it to other addresses |
| 5195 | (or use it for any other purpose either). |
| 5196 | |
| 5197 | More specifically, each of the following breakpoint types will always |
| 5198 | have a zero valued address and we don't want to mark breakpoints of any of |
| 5199 | these types to be a duplicate of an actual breakpoint at address zero: |
| 5200 | |
| 5201 | bp_watchpoint |
| 5202 | bp_catchpoint |
| 5203 | |
| 5204 | */ |
| 5205 | |
| 5206 | static int |
| 5207 | breakpoint_address_is_meaningful (struct breakpoint *bpt) |
| 5208 | { |
| 5209 | enum bptype type = bpt->type; |
| 5210 | |
| 5211 | return (type != bp_watchpoint && type != bp_catchpoint); |
| 5212 | } |
| 5213 | |
| 5214 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns |
| 5215 | true if LOC1 and LOC2 represent the same watchpoint location. */ |
| 5216 | |
| 5217 | static int |
| 5218 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) |
| 5219 | { |
| 5220 | /* Note that this checks the owner's type, not the location's. In |
| 5221 | case the target does not support read watchpoints, but does |
| 5222 | support access watchpoints, we'll have bp_read_watchpoint |
| 5223 | watchpoints with hw_access locations. Those should be considered |
| 5224 | duplicates of hw_read locations. The hw_read locations will |
| 5225 | become hw_access locations later. */ |
| 5226 | return (loc1->owner->type == loc2->owner->type |
| 5227 | && loc1->pspace->aspace == loc2->pspace->aspace |
| 5228 | && loc1->address == loc2->address |
| 5229 | && loc1->length == loc2->length); |
| 5230 | } |
| 5231 | |
| 5232 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
| 5233 | same breakpoint location. In most targets, this can only be true |
| 5234 | if ASPACE1 matches ASPACE2. On targets that have global |
| 5235 | breakpoints, the address space doesn't really matter. */ |
| 5236 | |
| 5237 | static int |
| 5238 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
| 5239 | struct address_space *aspace2, CORE_ADDR addr2) |
| 5240 | { |
| 5241 | return ((gdbarch_has_global_breakpoints (target_gdbarch) |
| 5242 | || aspace1 == aspace2) |
| 5243 | && addr1 == addr2); |
| 5244 | } |
| 5245 | |
| 5246 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
| 5247 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 |
| 5248 | represent the same location. */ |
| 5249 | |
| 5250 | static int |
| 5251 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) |
| 5252 | { |
| 5253 | int hw_point1 = is_hardware_watchpoint (loc1->owner); |
| 5254 | int hw_point2 = is_hardware_watchpoint (loc2->owner); |
| 5255 | |
| 5256 | if (hw_point1 != hw_point2) |
| 5257 | return 0; |
| 5258 | else if (hw_point1) |
| 5259 | return watchpoint_locations_match (loc1, loc2); |
| 5260 | else |
| 5261 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
| 5262 | loc2->pspace->aspace, loc2->address); |
| 5263 | } |
| 5264 | |
| 5265 | static void |
| 5266 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, |
| 5267 | int bnum, int have_bnum) |
| 5268 | { |
| 5269 | char astr1[40]; |
| 5270 | char astr2[40]; |
| 5271 | |
| 5272 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
| 5273 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); |
| 5274 | if (have_bnum) |
| 5275 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
| 5276 | bnum, astr1, astr2); |
| 5277 | else |
| 5278 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
| 5279 | } |
| 5280 | |
| 5281 | /* Adjust a breakpoint's address to account for architectural constraints |
| 5282 | on breakpoint placement. Return the adjusted address. Note: Very |
| 5283 | few targets require this kind of adjustment. For most targets, |
| 5284 | this function is simply the identity function. */ |
| 5285 | |
| 5286 | static CORE_ADDR |
| 5287 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 5288 | CORE_ADDR bpaddr, enum bptype bptype) |
| 5289 | { |
| 5290 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
| 5291 | { |
| 5292 | /* Very few targets need any kind of breakpoint adjustment. */ |
| 5293 | return bpaddr; |
| 5294 | } |
| 5295 | else if (bptype == bp_watchpoint |
| 5296 | || bptype == bp_hardware_watchpoint |
| 5297 | || bptype == bp_read_watchpoint |
| 5298 | || bptype == bp_access_watchpoint |
| 5299 | || bptype == bp_catchpoint) |
| 5300 | { |
| 5301 | /* Watchpoints and the various bp_catch_* eventpoints should not |
| 5302 | have their addresses modified. */ |
| 5303 | return bpaddr; |
| 5304 | } |
| 5305 | else |
| 5306 | { |
| 5307 | CORE_ADDR adjusted_bpaddr; |
| 5308 | |
| 5309 | /* Some targets have architectural constraints on the placement |
| 5310 | of breakpoint instructions. Obtain the adjusted address. */ |
| 5311 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
| 5312 | |
| 5313 | /* An adjusted breakpoint address can significantly alter |
| 5314 | a user's expectations. Print a warning if an adjustment |
| 5315 | is required. */ |
| 5316 | if (adjusted_bpaddr != bpaddr) |
| 5317 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); |
| 5318 | |
| 5319 | return adjusted_bpaddr; |
| 5320 | } |
| 5321 | } |
| 5322 | |
| 5323 | /* Allocate a struct bp_location. */ |
| 5324 | |
| 5325 | static struct bp_location * |
| 5326 | allocate_bp_location (struct breakpoint *bpt) |
| 5327 | { |
| 5328 | struct bp_location *loc, *loc_p; |
| 5329 | |
| 5330 | loc = xmalloc (sizeof (struct bp_location)); |
| 5331 | memset (loc, 0, sizeof (*loc)); |
| 5332 | |
| 5333 | loc->owner = bpt; |
| 5334 | loc->cond = NULL; |
| 5335 | loc->shlib_disabled = 0; |
| 5336 | loc->enabled = 1; |
| 5337 | |
| 5338 | switch (bpt->type) |
| 5339 | { |
| 5340 | case bp_breakpoint: |
| 5341 | case bp_until: |
| 5342 | case bp_finish: |
| 5343 | case bp_longjmp: |
| 5344 | case bp_longjmp_resume: |
| 5345 | case bp_step_resume: |
| 5346 | case bp_watchpoint_scope: |
| 5347 | case bp_call_dummy: |
| 5348 | case bp_std_terminate: |
| 5349 | case bp_shlib_event: |
| 5350 | case bp_thread_event: |
| 5351 | case bp_overlay_event: |
| 5352 | case bp_jit_event: |
| 5353 | case bp_longjmp_master: |
| 5354 | case bp_std_terminate_master: |
| 5355 | loc->loc_type = bp_loc_software_breakpoint; |
| 5356 | break; |
| 5357 | case bp_hardware_breakpoint: |
| 5358 | loc->loc_type = bp_loc_hardware_breakpoint; |
| 5359 | break; |
| 5360 | case bp_hardware_watchpoint: |
| 5361 | case bp_read_watchpoint: |
| 5362 | case bp_access_watchpoint: |
| 5363 | loc->loc_type = bp_loc_hardware_watchpoint; |
| 5364 | break; |
| 5365 | case bp_watchpoint: |
| 5366 | case bp_catchpoint: |
| 5367 | case bp_tracepoint: |
| 5368 | case bp_fast_tracepoint: |
| 5369 | loc->loc_type = bp_loc_other; |
| 5370 | break; |
| 5371 | default: |
| 5372 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
| 5373 | } |
| 5374 | |
| 5375 | return loc; |
| 5376 | } |
| 5377 | |
| 5378 | static void free_bp_location (struct bp_location *loc) |
| 5379 | { |
| 5380 | if (loc->cond) |
| 5381 | xfree (loc->cond); |
| 5382 | |
| 5383 | if (loc->function_name) |
| 5384 | xfree (loc->function_name); |
| 5385 | |
| 5386 | xfree (loc); |
| 5387 | } |
| 5388 | |
| 5389 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
| 5390 | that has type BPTYPE and has no locations as yet. */ |
| 5391 | /* This function is used in gdbtk sources and thus can not be made static. */ |
| 5392 | |
| 5393 | static struct breakpoint * |
| 5394 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
| 5395 | enum bptype bptype) |
| 5396 | { |
| 5397 | struct breakpoint *b, *b1; |
| 5398 | |
| 5399 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); |
| 5400 | memset (b, 0, sizeof (*b)); |
| 5401 | |
| 5402 | b->type = bptype; |
| 5403 | b->gdbarch = gdbarch; |
| 5404 | b->language = current_language->la_language; |
| 5405 | b->input_radix = input_radix; |
| 5406 | b->thread = -1; |
| 5407 | b->enable_state = bp_enabled; |
| 5408 | b->next = 0; |
| 5409 | b->silent = 0; |
| 5410 | b->ignore_count = 0; |
| 5411 | b->commands = NULL; |
| 5412 | b->frame_id = null_frame_id; |
| 5413 | b->forked_inferior_pid = null_ptid; |
| 5414 | b->exec_pathname = NULL; |
| 5415 | b->syscalls_to_be_caught = NULL; |
| 5416 | b->ops = NULL; |
| 5417 | b->condition_not_parsed = 0; |
| 5418 | |
| 5419 | /* Add this breakpoint to the end of the chain |
| 5420 | so that a list of breakpoints will come out in order |
| 5421 | of increasing numbers. */ |
| 5422 | |
| 5423 | b1 = breakpoint_chain; |
| 5424 | if (b1 == 0) |
| 5425 | breakpoint_chain = b; |
| 5426 | else |
| 5427 | { |
| 5428 | while (b1->next) |
| 5429 | b1 = b1->next; |
| 5430 | b1->next = b; |
| 5431 | } |
| 5432 | return b; |
| 5433 | } |
| 5434 | |
| 5435 | /* Initialize loc->function_name. */ |
| 5436 | static void |
| 5437 | set_breakpoint_location_function (struct bp_location *loc) |
| 5438 | { |
| 5439 | if (loc->owner->type == bp_breakpoint |
| 5440 | || loc->owner->type == bp_hardware_breakpoint |
| 5441 | || is_tracepoint (loc->owner)) |
| 5442 | { |
| 5443 | find_pc_partial_function (loc->address, &(loc->function_name), |
| 5444 | NULL, NULL); |
| 5445 | if (loc->function_name) |
| 5446 | loc->function_name = xstrdup (loc->function_name); |
| 5447 | } |
| 5448 | } |
| 5449 | |
| 5450 | /* Attempt to determine architecture of location identified by SAL. */ |
| 5451 | static struct gdbarch * |
| 5452 | get_sal_arch (struct symtab_and_line sal) |
| 5453 | { |
| 5454 | if (sal.section) |
| 5455 | return get_objfile_arch (sal.section->objfile); |
| 5456 | if (sal.symtab) |
| 5457 | return get_objfile_arch (sal.symtab->objfile); |
| 5458 | |
| 5459 | return NULL; |
| 5460 | } |
| 5461 | |
| 5462 | /* set_raw_breakpoint is a low level routine for allocating and |
| 5463 | partially initializing a breakpoint of type BPTYPE. The newly |
| 5464 | created breakpoint's address, section, source file name, and line |
| 5465 | number are provided by SAL. The newly created and partially |
| 5466 | initialized breakpoint is added to the breakpoint chain and |
| 5467 | is also returned as the value of this function. |
| 5468 | |
| 5469 | It is expected that the caller will complete the initialization of |
| 5470 | the newly created breakpoint struct as well as output any status |
| 5471 | information regarding the creation of a new breakpoint. In |
| 5472 | particular, set_raw_breakpoint does NOT set the breakpoint |
| 5473 | number! Care should be taken to not allow an error to occur |
| 5474 | prior to completing the initialization of the breakpoint. If this |
| 5475 | should happen, a bogus breakpoint will be left on the chain. */ |
| 5476 | |
| 5477 | struct breakpoint * |
| 5478 | set_raw_breakpoint (struct gdbarch *gdbarch, |
| 5479 | struct symtab_and_line sal, enum bptype bptype) |
| 5480 | { |
| 5481 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
| 5482 | CORE_ADDR adjusted_address; |
| 5483 | struct gdbarch *loc_gdbarch; |
| 5484 | |
| 5485 | loc_gdbarch = get_sal_arch (sal); |
| 5486 | if (!loc_gdbarch) |
| 5487 | loc_gdbarch = b->gdbarch; |
| 5488 | |
| 5489 | if (bptype != bp_catchpoint) |
| 5490 | gdb_assert (sal.pspace != NULL); |
| 5491 | |
| 5492 | /* Adjust the breakpoint's address prior to allocating a location. |
| 5493 | Once we call allocate_bp_location(), that mostly uninitialized |
| 5494 | location will be placed on the location chain. Adjustment of the |
| 5495 | breakpoint may cause target_read_memory() to be called and we do |
| 5496 | not want its scan of the location chain to find a breakpoint and |
| 5497 | location that's only been partially initialized. */ |
| 5498 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
| 5499 | |
| 5500 | b->loc = allocate_bp_location (b); |
| 5501 | b->loc->gdbarch = loc_gdbarch; |
| 5502 | b->loc->requested_address = sal.pc; |
| 5503 | b->loc->address = adjusted_address; |
| 5504 | b->loc->pspace = sal.pspace; |
| 5505 | |
| 5506 | /* Store the program space that was used to set the breakpoint, for |
| 5507 | breakpoint resetting. */ |
| 5508 | b->pspace = sal.pspace; |
| 5509 | |
| 5510 | if (sal.symtab == NULL) |
| 5511 | b->source_file = NULL; |
| 5512 | else |
| 5513 | b->source_file = xstrdup (sal.symtab->filename); |
| 5514 | b->loc->section = sal.section; |
| 5515 | b->line_number = sal.line; |
| 5516 | |
| 5517 | set_breakpoint_location_function (b->loc); |
| 5518 | |
| 5519 | breakpoints_changed (); |
| 5520 | |
| 5521 | return b; |
| 5522 | } |
| 5523 | |
| 5524 | |
| 5525 | /* Note that the breakpoint object B describes a permanent breakpoint |
| 5526 | instruction, hard-wired into the inferior's code. */ |
| 5527 | void |
| 5528 | make_breakpoint_permanent (struct breakpoint *b) |
| 5529 | { |
| 5530 | struct bp_location *bl; |
| 5531 | b->enable_state = bp_permanent; |
| 5532 | |
| 5533 | /* By definition, permanent breakpoints are already present in the code. |
| 5534 | Mark all locations as inserted. For now, make_breakpoint_permanent |
| 5535 | is called in just one place, so it's hard to say if it's reasonable |
| 5536 | to have permanent breakpoint with multiple locations or not, |
| 5537 | but it's easy to implmement. */ |
| 5538 | for (bl = b->loc; bl; bl = bl->next) |
| 5539 | bl->inserted = 1; |
| 5540 | } |
| 5541 | |
| 5542 | /* Call this routine when stepping and nexting to enable a breakpoint |
| 5543 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
| 5544 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
| 5545 | |
| 5546 | void |
| 5547 | set_longjmp_breakpoint (int thread) |
| 5548 | { |
| 5549 | struct breakpoint *b, *temp; |
| 5550 | |
| 5551 | /* To avoid having to rescan all objfile symbols at every step, |
| 5552 | we maintain a list of continually-inserted but always disabled |
| 5553 | longjmp "master" breakpoints. Here, we simply create momentary |
| 5554 | clones of those and enable them for the requested thread. */ |
| 5555 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 5556 | if (b->pspace == current_program_space |
| 5557 | && b->type == bp_longjmp_master) |
| 5558 | { |
| 5559 | struct breakpoint *clone = clone_momentary_breakpoint (b); |
| 5560 | clone->type = bp_longjmp; |
| 5561 | clone->thread = thread; |
| 5562 | } |
| 5563 | } |
| 5564 | |
| 5565 | /* Delete all longjmp breakpoints from THREAD. */ |
| 5566 | void |
| 5567 | delete_longjmp_breakpoint (int thread) |
| 5568 | { |
| 5569 | struct breakpoint *b, *temp; |
| 5570 | |
| 5571 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 5572 | if (b->type == bp_longjmp) |
| 5573 | { |
| 5574 | if (b->thread == thread) |
| 5575 | delete_breakpoint (b); |
| 5576 | } |
| 5577 | } |
| 5578 | |
| 5579 | void |
| 5580 | enable_overlay_breakpoints (void) |
| 5581 | { |
| 5582 | struct breakpoint *b; |
| 5583 | |
| 5584 | ALL_BREAKPOINTS (b) |
| 5585 | if (b->type == bp_overlay_event) |
| 5586 | { |
| 5587 | b->enable_state = bp_enabled; |
| 5588 | update_global_location_list (1); |
| 5589 | overlay_events_enabled = 1; |
| 5590 | } |
| 5591 | } |
| 5592 | |
| 5593 | void |
| 5594 | disable_overlay_breakpoints (void) |
| 5595 | { |
| 5596 | struct breakpoint *b; |
| 5597 | |
| 5598 | ALL_BREAKPOINTS (b) |
| 5599 | if (b->type == bp_overlay_event) |
| 5600 | { |
| 5601 | b->enable_state = bp_disabled; |
| 5602 | update_global_location_list (0); |
| 5603 | overlay_events_enabled = 0; |
| 5604 | } |
| 5605 | } |
| 5606 | |
| 5607 | /* Set an active std::terminate breakpoint for each std::terminate |
| 5608 | master breakpoint. */ |
| 5609 | void |
| 5610 | set_std_terminate_breakpoint (void) |
| 5611 | { |
| 5612 | struct breakpoint *b, *temp; |
| 5613 | |
| 5614 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 5615 | if (b->pspace == current_program_space |
| 5616 | && b->type == bp_std_terminate_master) |
| 5617 | { |
| 5618 | struct breakpoint *clone = clone_momentary_breakpoint (b); |
| 5619 | clone->type = bp_std_terminate; |
| 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | /* Delete all the std::terminate breakpoints. */ |
| 5624 | void |
| 5625 | delete_std_terminate_breakpoint (void) |
| 5626 | { |
| 5627 | struct breakpoint *b, *temp; |
| 5628 | |
| 5629 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 5630 | if (b->type == bp_std_terminate) |
| 5631 | delete_breakpoint (b); |
| 5632 | } |
| 5633 | |
| 5634 | struct breakpoint * |
| 5635 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 5636 | { |
| 5637 | struct breakpoint *b; |
| 5638 | |
| 5639 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
| 5640 | |
| 5641 | b->enable_state = bp_enabled; |
| 5642 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
| 5643 | b->addr_string |
| 5644 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); |
| 5645 | |
| 5646 | update_global_location_list_nothrow (1); |
| 5647 | |
| 5648 | return b; |
| 5649 | } |
| 5650 | |
| 5651 | void |
| 5652 | remove_thread_event_breakpoints (void) |
| 5653 | { |
| 5654 | struct breakpoint *b, *temp; |
| 5655 | |
| 5656 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 5657 | if (b->type == bp_thread_event |
| 5658 | && b->loc->pspace == current_program_space) |
| 5659 | delete_breakpoint (b); |
| 5660 | } |
| 5661 | |
| 5662 | struct captured_parse_breakpoint_args |
| 5663 | { |
| 5664 | char **arg_p; |
| 5665 | struct symtabs_and_lines *sals_p; |
| 5666 | char ***addr_string_p; |
| 5667 | int *not_found_ptr; |
| 5668 | }; |
| 5669 | |
| 5670 | struct lang_and_radix |
| 5671 | { |
| 5672 | enum language lang; |
| 5673 | int radix; |
| 5674 | }; |
| 5675 | |
| 5676 | /* Create a breakpoint for JIT code registration and unregistration. */ |
| 5677 | |
| 5678 | struct breakpoint * |
| 5679 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 5680 | { |
| 5681 | struct breakpoint *b; |
| 5682 | |
| 5683 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); |
| 5684 | update_global_location_list_nothrow (1); |
| 5685 | return b; |
| 5686 | } |
| 5687 | |
| 5688 | void |
| 5689 | remove_solib_event_breakpoints (void) |
| 5690 | { |
| 5691 | struct breakpoint *b, *temp; |
| 5692 | |
| 5693 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 5694 | if (b->type == bp_shlib_event |
| 5695 | && b->loc->pspace == current_program_space) |
| 5696 | delete_breakpoint (b); |
| 5697 | } |
| 5698 | |
| 5699 | struct breakpoint * |
| 5700 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 5701 | { |
| 5702 | struct breakpoint *b; |
| 5703 | |
| 5704 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
| 5705 | update_global_location_list_nothrow (1); |
| 5706 | return b; |
| 5707 | } |
| 5708 | |
| 5709 | /* Disable any breakpoints that are on code in shared libraries. Only |
| 5710 | apply to enabled breakpoints, disabled ones can just stay disabled. */ |
| 5711 | |
| 5712 | void |
| 5713 | disable_breakpoints_in_shlibs (void) |
| 5714 | { |
| 5715 | struct bp_location *loc, **locp_tmp; |
| 5716 | |
| 5717 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 5718 | { |
| 5719 | struct breakpoint *b = loc->owner; |
| 5720 | /* We apply the check to all breakpoints, including disabled |
| 5721 | for those with loc->duplicate set. This is so that when breakpoint |
| 5722 | becomes enabled, or the duplicate is removed, gdb will try to insert |
| 5723 | all breakpoints. If we don't set shlib_disabled here, we'll try |
| 5724 | to insert those breakpoints and fail. */ |
| 5725 | if (((b->type == bp_breakpoint) |
| 5726 | || (b->type == bp_jit_event) |
| 5727 | || (b->type == bp_hardware_breakpoint) |
| 5728 | || (is_tracepoint (b))) |
| 5729 | && loc->pspace == current_program_space |
| 5730 | && !loc->shlib_disabled |
| 5731 | #ifdef PC_SOLIB |
| 5732 | && PC_SOLIB (loc->address) |
| 5733 | #else |
| 5734 | && solib_name_from_address (loc->pspace, loc->address) |
| 5735 | #endif |
| 5736 | ) |
| 5737 | { |
| 5738 | loc->shlib_disabled = 1; |
| 5739 | } |
| 5740 | } |
| 5741 | } |
| 5742 | |
| 5743 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
| 5744 | apply to enabled breakpoints, disabled ones can just stay disabled. */ |
| 5745 | |
| 5746 | static void |
| 5747 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
| 5748 | { |
| 5749 | struct bp_location *loc, **locp_tmp; |
| 5750 | int disabled_shlib_breaks = 0; |
| 5751 | |
| 5752 | /* SunOS a.out shared libraries are always mapped, so do not |
| 5753 | disable breakpoints; they will only be reported as unloaded |
| 5754 | through clear_solib when GDB discards its shared library |
| 5755 | list. See clear_solib for more information. */ |
| 5756 | if (exec_bfd != NULL |
| 5757 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) |
| 5758 | return; |
| 5759 | |
| 5760 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 5761 | { |
| 5762 | struct breakpoint *b = loc->owner; |
| 5763 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
| 5764 | || loc->loc_type == bp_loc_software_breakpoint) |
| 5765 | && solib->pspace == loc->pspace |
| 5766 | && !loc->shlib_disabled |
| 5767 | && (b->type == bp_breakpoint |
| 5768 | || b->type == bp_jit_event |
| 5769 | || b->type == bp_hardware_breakpoint) |
| 5770 | && solib_contains_address_p (solib, loc->address)) |
| 5771 | { |
| 5772 | loc->shlib_disabled = 1; |
| 5773 | /* At this point, we cannot rely on remove_breakpoint |
| 5774 | succeeding so we must mark the breakpoint as not inserted |
| 5775 | to prevent future errors occurring in remove_breakpoints. */ |
| 5776 | loc->inserted = 0; |
| 5777 | if (!disabled_shlib_breaks) |
| 5778 | { |
| 5779 | target_terminal_ours_for_output (); |
| 5780 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), |
| 5781 | solib->so_name); |
| 5782 | } |
| 5783 | disabled_shlib_breaks = 1; |
| 5784 | } |
| 5785 | } |
| 5786 | } |
| 5787 | |
| 5788 | /* FORK & VFORK catchpoints. */ |
| 5789 | |
| 5790 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ |
| 5791 | |
| 5792 | static void |
| 5793 | insert_catch_fork (struct breakpoint *b) |
| 5794 | { |
| 5795 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
| 5796 | } |
| 5797 | |
| 5798 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ |
| 5799 | |
| 5800 | static int |
| 5801 | remove_catch_fork (struct breakpoint *b) |
| 5802 | { |
| 5803 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); |
| 5804 | } |
| 5805 | |
| 5806 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork |
| 5807 | catchpoints. */ |
| 5808 | |
| 5809 | static int |
| 5810 | breakpoint_hit_catch_fork (struct breakpoint *b) |
| 5811 | { |
| 5812 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); |
| 5813 | } |
| 5814 | |
| 5815 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ |
| 5816 | |
| 5817 | static enum print_stop_action |
| 5818 | print_it_catch_fork (struct breakpoint *b) |
| 5819 | { |
| 5820 | annotate_catchpoint (b->number); |
| 5821 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), |
| 5822 | b->number, ptid_get_pid (b->forked_inferior_pid)); |
| 5823 | return PRINT_SRC_AND_LOC; |
| 5824 | } |
| 5825 | |
| 5826 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ |
| 5827 | |
| 5828 | static void |
| 5829 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
| 5830 | { |
| 5831 | struct value_print_options opts; |
| 5832 | |
| 5833 | get_user_print_options (&opts); |
| 5834 | |
| 5835 | /* Field 4, the address, is omitted (which makes the columns |
| 5836 | not line up too nicely with the headers, but the effect |
| 5837 | is relatively readable). */ |
| 5838 | if (opts.addressprint) |
| 5839 | ui_out_field_skip (uiout, "addr"); |
| 5840 | annotate_field (5); |
| 5841 | ui_out_text (uiout, "fork"); |
| 5842 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) |
| 5843 | { |
| 5844 | ui_out_text (uiout, ", process "); |
| 5845 | ui_out_field_int (uiout, "what", |
| 5846 | ptid_get_pid (b->forked_inferior_pid)); |
| 5847 | ui_out_spaces (uiout, 1); |
| 5848 | } |
| 5849 | } |
| 5850 | |
| 5851 | /* Implement the "print_mention" breakpoint_ops method for fork |
| 5852 | catchpoints. */ |
| 5853 | |
| 5854 | static void |
| 5855 | print_mention_catch_fork (struct breakpoint *b) |
| 5856 | { |
| 5857 | printf_filtered (_("Catchpoint %d (fork)"), b->number); |
| 5858 | } |
| 5859 | |
| 5860 | /* Implement the "print_recreate" breakpoint_ops method for fork |
| 5861 | catchpoints. */ |
| 5862 | |
| 5863 | static void |
| 5864 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) |
| 5865 | { |
| 5866 | fprintf_unfiltered (fp, "catch fork"); |
| 5867 | } |
| 5868 | |
| 5869 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
| 5870 | |
| 5871 | static struct breakpoint_ops catch_fork_breakpoint_ops = |
| 5872 | { |
| 5873 | insert_catch_fork, |
| 5874 | remove_catch_fork, |
| 5875 | breakpoint_hit_catch_fork, |
| 5876 | print_it_catch_fork, |
| 5877 | print_one_catch_fork, |
| 5878 | print_mention_catch_fork, |
| 5879 | print_recreate_catch_fork |
| 5880 | }; |
| 5881 | |
| 5882 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ |
| 5883 | |
| 5884 | static void |
| 5885 | insert_catch_vfork (struct breakpoint *b) |
| 5886 | { |
| 5887 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
| 5888 | } |
| 5889 | |
| 5890 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ |
| 5891 | |
| 5892 | static int |
| 5893 | remove_catch_vfork (struct breakpoint *b) |
| 5894 | { |
| 5895 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); |
| 5896 | } |
| 5897 | |
| 5898 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork |
| 5899 | catchpoints. */ |
| 5900 | |
| 5901 | static int |
| 5902 | breakpoint_hit_catch_vfork (struct breakpoint *b) |
| 5903 | { |
| 5904 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); |
| 5905 | } |
| 5906 | |
| 5907 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ |
| 5908 | |
| 5909 | static enum print_stop_action |
| 5910 | print_it_catch_vfork (struct breakpoint *b) |
| 5911 | { |
| 5912 | annotate_catchpoint (b->number); |
| 5913 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), |
| 5914 | b->number, ptid_get_pid (b->forked_inferior_pid)); |
| 5915 | return PRINT_SRC_AND_LOC; |
| 5916 | } |
| 5917 | |
| 5918 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ |
| 5919 | |
| 5920 | static void |
| 5921 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
| 5922 | { |
| 5923 | struct value_print_options opts; |
| 5924 | |
| 5925 | get_user_print_options (&opts); |
| 5926 | /* Field 4, the address, is omitted (which makes the columns |
| 5927 | not line up too nicely with the headers, but the effect |
| 5928 | is relatively readable). */ |
| 5929 | if (opts.addressprint) |
| 5930 | ui_out_field_skip (uiout, "addr"); |
| 5931 | annotate_field (5); |
| 5932 | ui_out_text (uiout, "vfork"); |
| 5933 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) |
| 5934 | { |
| 5935 | ui_out_text (uiout, ", process "); |
| 5936 | ui_out_field_int (uiout, "what", |
| 5937 | ptid_get_pid (b->forked_inferior_pid)); |
| 5938 | ui_out_spaces (uiout, 1); |
| 5939 | } |
| 5940 | } |
| 5941 | |
| 5942 | /* Implement the "print_mention" breakpoint_ops method for vfork |
| 5943 | catchpoints. */ |
| 5944 | |
| 5945 | static void |
| 5946 | print_mention_catch_vfork (struct breakpoint *b) |
| 5947 | { |
| 5948 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); |
| 5949 | } |
| 5950 | |
| 5951 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
| 5952 | catchpoints. */ |
| 5953 | |
| 5954 | static void |
| 5955 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) |
| 5956 | { |
| 5957 | fprintf_unfiltered (fp, "catch vfork"); |
| 5958 | } |
| 5959 | |
| 5960 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
| 5961 | |
| 5962 | static struct breakpoint_ops catch_vfork_breakpoint_ops = |
| 5963 | { |
| 5964 | insert_catch_vfork, |
| 5965 | remove_catch_vfork, |
| 5966 | breakpoint_hit_catch_vfork, |
| 5967 | print_it_catch_vfork, |
| 5968 | print_one_catch_vfork, |
| 5969 | print_mention_catch_vfork, |
| 5970 | print_recreate_catch_vfork |
| 5971 | }; |
| 5972 | |
| 5973 | /* Implement the "insert" breakpoint_ops method for syscall |
| 5974 | catchpoints. */ |
| 5975 | |
| 5976 | static void |
| 5977 | insert_catch_syscall (struct breakpoint *b) |
| 5978 | { |
| 5979 | struct inferior *inf = current_inferior (); |
| 5980 | |
| 5981 | ++inf->total_syscalls_count; |
| 5982 | if (!b->syscalls_to_be_caught) |
| 5983 | ++inf->any_syscall_count; |
| 5984 | else |
| 5985 | { |
| 5986 | int i, iter; |
| 5987 | for (i = 0; |
| 5988 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); |
| 5989 | i++) |
| 5990 | { |
| 5991 | int elem; |
| 5992 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
| 5993 | { |
| 5994 | int old_size = VEC_length (int, inf->syscalls_counts); |
| 5995 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); |
| 5996 | uintptr_t vec_addr; |
| 5997 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); |
| 5998 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + |
| 5999 | vec_addr_offset; |
| 6000 | memset ((void *) vec_addr, 0, |
| 6001 | (iter + 1 - old_size) * sizeof (int)); |
| 6002 | } |
| 6003 | elem = VEC_index (int, inf->syscalls_counts, iter); |
| 6004 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); |
| 6005 | } |
| 6006 | } |
| 6007 | |
| 6008 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
| 6009 | inf->total_syscalls_count != 0, |
| 6010 | inf->any_syscall_count, |
| 6011 | VEC_length (int, inf->syscalls_counts), |
| 6012 | VEC_address (int, inf->syscalls_counts)); |
| 6013 | } |
| 6014 | |
| 6015 | /* Implement the "remove" breakpoint_ops method for syscall |
| 6016 | catchpoints. */ |
| 6017 | |
| 6018 | static int |
| 6019 | remove_catch_syscall (struct breakpoint *b) |
| 6020 | { |
| 6021 | struct inferior *inf = current_inferior (); |
| 6022 | |
| 6023 | --inf->total_syscalls_count; |
| 6024 | if (!b->syscalls_to_be_caught) |
| 6025 | --inf->any_syscall_count; |
| 6026 | else |
| 6027 | { |
| 6028 | int i, iter; |
| 6029 | for (i = 0; |
| 6030 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); |
| 6031 | i++) |
| 6032 | { |
| 6033 | int elem; |
| 6034 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
| 6035 | /* Shouldn't happen. */ |
| 6036 | continue; |
| 6037 | elem = VEC_index (int, inf->syscalls_counts, iter); |
| 6038 | VEC_replace (int, inf->syscalls_counts, iter, --elem); |
| 6039 | } |
| 6040 | } |
| 6041 | |
| 6042 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
| 6043 | inf->total_syscalls_count != 0, |
| 6044 | inf->any_syscall_count, |
| 6045 | VEC_length (int, inf->syscalls_counts), |
| 6046 | VEC_address (int, inf->syscalls_counts)); |
| 6047 | } |
| 6048 | |
| 6049 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall |
| 6050 | catchpoints. */ |
| 6051 | |
| 6052 | static int |
| 6053 | breakpoint_hit_catch_syscall (struct breakpoint *b) |
| 6054 | { |
| 6055 | /* We must check if we are catching specific syscalls in this breakpoint. |
| 6056 | If we are, then we must guarantee that the called syscall is the same |
| 6057 | syscall we are catching. */ |
| 6058 | int syscall_number = 0; |
| 6059 | |
| 6060 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) |
| 6061 | return 0; |
| 6062 | |
| 6063 | /* Now, checking if the syscall is the same. */ |
| 6064 | if (b->syscalls_to_be_caught) |
| 6065 | { |
| 6066 | int i, iter; |
| 6067 | for (i = 0; |
| 6068 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); |
| 6069 | i++) |
| 6070 | if (syscall_number == iter) |
| 6071 | break; |
| 6072 | /* Not the same. */ |
| 6073 | if (!iter) |
| 6074 | return 0; |
| 6075 | } |
| 6076 | |
| 6077 | return 1; |
| 6078 | } |
| 6079 | |
| 6080 | /* Implement the "print_it" breakpoint_ops method for syscall |
| 6081 | catchpoints. */ |
| 6082 | |
| 6083 | static enum print_stop_action |
| 6084 | print_it_catch_syscall (struct breakpoint *b) |
| 6085 | { |
| 6086 | /* These are needed because we want to know in which state a |
| 6087 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY |
| 6088 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we |
| 6089 | must print "called syscall" or "returned from syscall". */ |
| 6090 | ptid_t ptid; |
| 6091 | struct target_waitstatus last; |
| 6092 | struct syscall s; |
| 6093 | struct cleanup *old_chain; |
| 6094 | char *syscall_id; |
| 6095 | |
| 6096 | get_last_target_status (&ptid, &last); |
| 6097 | |
| 6098 | get_syscall_by_number (last.value.syscall_number, &s); |
| 6099 | |
| 6100 | annotate_catchpoint (b->number); |
| 6101 | |
| 6102 | if (s.name == NULL) |
| 6103 | syscall_id = xstrprintf ("%d", last.value.syscall_number); |
| 6104 | else |
| 6105 | syscall_id = xstrprintf ("'%s'", s.name); |
| 6106 | |
| 6107 | old_chain = make_cleanup (xfree, syscall_id); |
| 6108 | |
| 6109 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) |
| 6110 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), |
| 6111 | b->number, syscall_id); |
| 6112 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) |
| 6113 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), |
| 6114 | b->number, syscall_id); |
| 6115 | |
| 6116 | do_cleanups (old_chain); |
| 6117 | |
| 6118 | return PRINT_SRC_AND_LOC; |
| 6119 | } |
| 6120 | |
| 6121 | /* Implement the "print_one" breakpoint_ops method for syscall |
| 6122 | catchpoints. */ |
| 6123 | |
| 6124 | static void |
| 6125 | print_one_catch_syscall (struct breakpoint *b, |
| 6126 | struct bp_location **last_loc) |
| 6127 | { |
| 6128 | struct value_print_options opts; |
| 6129 | |
| 6130 | get_user_print_options (&opts); |
| 6131 | /* Field 4, the address, is omitted (which makes the columns |
| 6132 | not line up too nicely with the headers, but the effect |
| 6133 | is relatively readable). */ |
| 6134 | if (opts.addressprint) |
| 6135 | ui_out_field_skip (uiout, "addr"); |
| 6136 | annotate_field (5); |
| 6137 | |
| 6138 | if (b->syscalls_to_be_caught |
| 6139 | && VEC_length (int, b->syscalls_to_be_caught) > 1) |
| 6140 | ui_out_text (uiout, "syscalls \""); |
| 6141 | else |
| 6142 | ui_out_text (uiout, "syscall \""); |
| 6143 | |
| 6144 | if (b->syscalls_to_be_caught) |
| 6145 | { |
| 6146 | int i, iter; |
| 6147 | char *text = xstrprintf ("%s", ""); |
| 6148 | for (i = 0; |
| 6149 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); |
| 6150 | i++) |
| 6151 | { |
| 6152 | char *x = text; |
| 6153 | struct syscall s; |
| 6154 | get_syscall_by_number (iter, &s); |
| 6155 | |
| 6156 | if (s.name != NULL) |
| 6157 | text = xstrprintf ("%s%s, ", text, s.name); |
| 6158 | else |
| 6159 | text = xstrprintf ("%s%d, ", text, iter); |
| 6160 | |
| 6161 | /* We have to xfree the last 'text' (now stored at 'x') |
| 6162 | because xstrprintf dinamically allocates new space for it |
| 6163 | on every call. */ |
| 6164 | xfree (x); |
| 6165 | } |
| 6166 | /* Remove the last comma. */ |
| 6167 | text[strlen (text) - 2] = '\0'; |
| 6168 | ui_out_field_string (uiout, "what", text); |
| 6169 | } |
| 6170 | else |
| 6171 | ui_out_field_string (uiout, "what", "<any syscall>"); |
| 6172 | ui_out_text (uiout, "\" "); |
| 6173 | } |
| 6174 | |
| 6175 | /* Implement the "print_mention" breakpoint_ops method for syscall |
| 6176 | catchpoints. */ |
| 6177 | |
| 6178 | static void |
| 6179 | print_mention_catch_syscall (struct breakpoint *b) |
| 6180 | { |
| 6181 | if (b->syscalls_to_be_caught) |
| 6182 | { |
| 6183 | int i, iter; |
| 6184 | |
| 6185 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) |
| 6186 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
| 6187 | else |
| 6188 | printf_filtered (_("Catchpoint %d (syscall"), b->number); |
| 6189 | |
| 6190 | for (i = 0; |
| 6191 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); |
| 6192 | i++) |
| 6193 | { |
| 6194 | struct syscall s; |
| 6195 | get_syscall_by_number (iter, &s); |
| 6196 | |
| 6197 | if (s.name) |
| 6198 | printf_filtered (" '%s' [%d]", s.name, s.number); |
| 6199 | else |
| 6200 | printf_filtered (" %d", s.number); |
| 6201 | } |
| 6202 | printf_filtered (")"); |
| 6203 | } |
| 6204 | else |
| 6205 | printf_filtered (_("Catchpoint %d (any syscall)"), |
| 6206 | b->number); |
| 6207 | } |
| 6208 | |
| 6209 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
| 6210 | catchpoints. */ |
| 6211 | |
| 6212 | static void |
| 6213 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) |
| 6214 | { |
| 6215 | fprintf_unfiltered (fp, "catch syscall"); |
| 6216 | |
| 6217 | if (b->syscalls_to_be_caught) |
| 6218 | { |
| 6219 | int i, iter; |
| 6220 | |
| 6221 | for (i = 0; |
| 6222 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); |
| 6223 | i++) |
| 6224 | { |
| 6225 | struct syscall s; |
| 6226 | |
| 6227 | get_syscall_by_number (iter, &s); |
| 6228 | if (s.name) |
| 6229 | fprintf_unfiltered (fp, " %s", s.name); |
| 6230 | else |
| 6231 | fprintf_unfiltered (fp, " %d", s.number); |
| 6232 | } |
| 6233 | } |
| 6234 | } |
| 6235 | |
| 6236 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
| 6237 | |
| 6238 | static struct breakpoint_ops catch_syscall_breakpoint_ops = |
| 6239 | { |
| 6240 | insert_catch_syscall, |
| 6241 | remove_catch_syscall, |
| 6242 | breakpoint_hit_catch_syscall, |
| 6243 | print_it_catch_syscall, |
| 6244 | print_one_catch_syscall, |
| 6245 | print_mention_catch_syscall, |
| 6246 | print_recreate_catch_syscall |
| 6247 | }; |
| 6248 | |
| 6249 | /* Returns non-zero if 'b' is a syscall catchpoint. */ |
| 6250 | |
| 6251 | static int |
| 6252 | syscall_catchpoint_p (struct breakpoint *b) |
| 6253 | { |
| 6254 | return (b->ops == &catch_syscall_breakpoint_ops); |
| 6255 | } |
| 6256 | |
| 6257 | /* Create a new breakpoint of the bp_catchpoint kind and return it, |
| 6258 | but does NOT mention it nor update the global location list. |
| 6259 | This is useful if you need to fill more fields in the |
| 6260 | struct breakpoint before calling mention. |
| 6261 | |
| 6262 | If TEMPFLAG is non-zero, then make the breakpoint temporary. |
| 6263 | If COND_STRING is not NULL, then store it in the breakpoint. |
| 6264 | OPS, if not NULL, is the breakpoint_ops structure associated |
| 6265 | to the catchpoint. */ |
| 6266 | |
| 6267 | static struct breakpoint * |
| 6268 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
| 6269 | char *cond_string, |
| 6270 | struct breakpoint_ops *ops) |
| 6271 | { |
| 6272 | struct symtab_and_line sal; |
| 6273 | struct breakpoint *b; |
| 6274 | |
| 6275 | init_sal (&sal); |
| 6276 | sal.pspace = current_program_space; |
| 6277 | |
| 6278 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
| 6279 | set_breakpoint_count (breakpoint_count + 1); |
| 6280 | b->number = breakpoint_count; |
| 6281 | |
| 6282 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
| 6283 | b->thread = -1; |
| 6284 | b->addr_string = NULL; |
| 6285 | b->enable_state = bp_enabled; |
| 6286 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 6287 | b->ops = ops; |
| 6288 | |
| 6289 | return b; |
| 6290 | } |
| 6291 | |
| 6292 | /* Create a new breakpoint of the bp_catchpoint kind and return it. |
| 6293 | |
| 6294 | If TEMPFLAG is non-zero, then make the breakpoint temporary. |
| 6295 | If COND_STRING is not NULL, then store it in the breakpoint. |
| 6296 | OPS, if not NULL, is the breakpoint_ops structure associated |
| 6297 | to the catchpoint. */ |
| 6298 | |
| 6299 | static struct breakpoint * |
| 6300 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, |
| 6301 | char *cond_string, struct breakpoint_ops *ops) |
| 6302 | { |
| 6303 | struct breakpoint *b = |
| 6304 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); |
| 6305 | |
| 6306 | mention (b); |
| 6307 | update_global_location_list (1); |
| 6308 | |
| 6309 | return b; |
| 6310 | } |
| 6311 | |
| 6312 | static void |
| 6313 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
| 6314 | int tempflag, char *cond_string, |
| 6315 | struct breakpoint_ops *ops) |
| 6316 | { |
| 6317 | struct breakpoint *b |
| 6318 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); |
| 6319 | |
| 6320 | /* FIXME: We should put this information in a breakpoint private data |
| 6321 | area. */ |
| 6322 | b->forked_inferior_pid = null_ptid; |
| 6323 | } |
| 6324 | |
| 6325 | /* Exec catchpoints. */ |
| 6326 | |
| 6327 | static void |
| 6328 | insert_catch_exec (struct breakpoint *b) |
| 6329 | { |
| 6330 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
| 6331 | } |
| 6332 | |
| 6333 | static int |
| 6334 | remove_catch_exec (struct breakpoint *b) |
| 6335 | { |
| 6336 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); |
| 6337 | } |
| 6338 | |
| 6339 | static int |
| 6340 | breakpoint_hit_catch_exec (struct breakpoint *b) |
| 6341 | { |
| 6342 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); |
| 6343 | } |
| 6344 | |
| 6345 | static enum print_stop_action |
| 6346 | print_it_catch_exec (struct breakpoint *b) |
| 6347 | { |
| 6348 | annotate_catchpoint (b->number); |
| 6349 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, |
| 6350 | b->exec_pathname); |
| 6351 | return PRINT_SRC_AND_LOC; |
| 6352 | } |
| 6353 | |
| 6354 | static void |
| 6355 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
| 6356 | { |
| 6357 | struct value_print_options opts; |
| 6358 | |
| 6359 | get_user_print_options (&opts); |
| 6360 | |
| 6361 | /* Field 4, the address, is omitted (which makes the columns |
| 6362 | not line up too nicely with the headers, but the effect |
| 6363 | is relatively readable). */ |
| 6364 | if (opts.addressprint) |
| 6365 | ui_out_field_skip (uiout, "addr"); |
| 6366 | annotate_field (5); |
| 6367 | ui_out_text (uiout, "exec"); |
| 6368 | if (b->exec_pathname != NULL) |
| 6369 | { |
| 6370 | ui_out_text (uiout, ", program \""); |
| 6371 | ui_out_field_string (uiout, "what", b->exec_pathname); |
| 6372 | ui_out_text (uiout, "\" "); |
| 6373 | } |
| 6374 | } |
| 6375 | |
| 6376 | static void |
| 6377 | print_mention_catch_exec (struct breakpoint *b) |
| 6378 | { |
| 6379 | printf_filtered (_("Catchpoint %d (exec)"), b->number); |
| 6380 | } |
| 6381 | |
| 6382 | /* Implement the "print_recreate" breakpoint_ops method for exec |
| 6383 | catchpoints. */ |
| 6384 | |
| 6385 | static void |
| 6386 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) |
| 6387 | { |
| 6388 | fprintf_unfiltered (fp, "catch exec"); |
| 6389 | } |
| 6390 | |
| 6391 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
| 6392 | { |
| 6393 | insert_catch_exec, |
| 6394 | remove_catch_exec, |
| 6395 | breakpoint_hit_catch_exec, |
| 6396 | print_it_catch_exec, |
| 6397 | print_one_catch_exec, |
| 6398 | print_mention_catch_exec, |
| 6399 | print_recreate_catch_exec |
| 6400 | }; |
| 6401 | |
| 6402 | static void |
| 6403 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, |
| 6404 | struct breakpoint_ops *ops) |
| 6405 | { |
| 6406 | struct gdbarch *gdbarch = get_current_arch (); |
| 6407 | struct breakpoint *b = |
| 6408 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); |
| 6409 | |
| 6410 | b->syscalls_to_be_caught = filter; |
| 6411 | |
| 6412 | /* Now, we have to mention the breakpoint and update the global |
| 6413 | location list. */ |
| 6414 | mention (b); |
| 6415 | update_global_location_list (1); |
| 6416 | } |
| 6417 | |
| 6418 | static int |
| 6419 | hw_breakpoint_used_count (void) |
| 6420 | { |
| 6421 | struct breakpoint *b; |
| 6422 | int i = 0; |
| 6423 | |
| 6424 | ALL_BREAKPOINTS (b) |
| 6425 | { |
| 6426 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
| 6427 | i++; |
| 6428 | } |
| 6429 | |
| 6430 | return i; |
| 6431 | } |
| 6432 | |
| 6433 | static int |
| 6434 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
| 6435 | { |
| 6436 | struct breakpoint *b; |
| 6437 | int i = 0; |
| 6438 | |
| 6439 | *other_type_used = 0; |
| 6440 | ALL_BREAKPOINTS (b) |
| 6441 | { |
| 6442 | if (breakpoint_enabled (b)) |
| 6443 | { |
| 6444 | if (b->type == type) |
| 6445 | i++; |
| 6446 | else if (is_hardware_watchpoint (b)) |
| 6447 | *other_type_used = 1; |
| 6448 | } |
| 6449 | } |
| 6450 | return i; |
| 6451 | } |
| 6452 | |
| 6453 | void |
| 6454 | disable_watchpoints_before_interactive_call_start (void) |
| 6455 | { |
| 6456 | struct breakpoint *b; |
| 6457 | |
| 6458 | ALL_BREAKPOINTS (b) |
| 6459 | { |
| 6460 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
| 6461 | { |
| 6462 | b->enable_state = bp_call_disabled; |
| 6463 | update_global_location_list (0); |
| 6464 | } |
| 6465 | } |
| 6466 | } |
| 6467 | |
| 6468 | void |
| 6469 | enable_watchpoints_after_interactive_call_stop (void) |
| 6470 | { |
| 6471 | struct breakpoint *b; |
| 6472 | |
| 6473 | ALL_BREAKPOINTS (b) |
| 6474 | { |
| 6475 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
| 6476 | { |
| 6477 | b->enable_state = bp_enabled; |
| 6478 | update_global_location_list (1); |
| 6479 | } |
| 6480 | } |
| 6481 | } |
| 6482 | |
| 6483 | void |
| 6484 | disable_breakpoints_before_startup (void) |
| 6485 | { |
| 6486 | struct breakpoint *b; |
| 6487 | int found = 0; |
| 6488 | |
| 6489 | ALL_BREAKPOINTS (b) |
| 6490 | { |
| 6491 | if (b->pspace != current_program_space) |
| 6492 | continue; |
| 6493 | |
| 6494 | if ((b->type == bp_breakpoint |
| 6495 | || b->type == bp_hardware_breakpoint) |
| 6496 | && breakpoint_enabled (b)) |
| 6497 | { |
| 6498 | b->enable_state = bp_startup_disabled; |
| 6499 | found = 1; |
| 6500 | } |
| 6501 | } |
| 6502 | |
| 6503 | if (found) |
| 6504 | update_global_location_list (0); |
| 6505 | |
| 6506 | current_program_space->executing_startup = 1; |
| 6507 | } |
| 6508 | |
| 6509 | void |
| 6510 | enable_breakpoints_after_startup (void) |
| 6511 | { |
| 6512 | struct breakpoint *b; |
| 6513 | int found = 0; |
| 6514 | |
| 6515 | current_program_space->executing_startup = 0; |
| 6516 | |
| 6517 | ALL_BREAKPOINTS (b) |
| 6518 | { |
| 6519 | if (b->pspace != current_program_space) |
| 6520 | continue; |
| 6521 | |
| 6522 | if ((b->type == bp_breakpoint |
| 6523 | || b->type == bp_hardware_breakpoint) |
| 6524 | && b->enable_state == bp_startup_disabled) |
| 6525 | { |
| 6526 | b->enable_state = bp_enabled; |
| 6527 | found = 1; |
| 6528 | } |
| 6529 | } |
| 6530 | |
| 6531 | if (found) |
| 6532 | breakpoint_re_set (); |
| 6533 | } |
| 6534 | |
| 6535 | |
| 6536 | /* Set a breakpoint that will evaporate an end of command |
| 6537 | at address specified by SAL. |
| 6538 | Restrict it to frame FRAME if FRAME is nonzero. */ |
| 6539 | |
| 6540 | struct breakpoint * |
| 6541 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
| 6542 | struct frame_id frame_id, enum bptype type) |
| 6543 | { |
| 6544 | struct breakpoint *b; |
| 6545 | |
| 6546 | /* If FRAME_ID is valid, it should be a real frame, not an inlined |
| 6547 | one. */ |
| 6548 | gdb_assert (!frame_id_inlined_p (frame_id)); |
| 6549 | |
| 6550 | b = set_raw_breakpoint (gdbarch, sal, type); |
| 6551 | b->enable_state = bp_enabled; |
| 6552 | b->disposition = disp_donttouch; |
| 6553 | b->frame_id = frame_id; |
| 6554 | |
| 6555 | /* If we're debugging a multi-threaded program, then we |
| 6556 | want momentary breakpoints to be active in only a |
| 6557 | single thread of control. */ |
| 6558 | if (in_thread_list (inferior_ptid)) |
| 6559 | b->thread = pid_to_thread_id (inferior_ptid); |
| 6560 | |
| 6561 | update_global_location_list_nothrow (1); |
| 6562 | |
| 6563 | return b; |
| 6564 | } |
| 6565 | |
| 6566 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
| 6567 | ORIG is NULL. */ |
| 6568 | |
| 6569 | struct breakpoint * |
| 6570 | clone_momentary_breakpoint (struct breakpoint *orig) |
| 6571 | { |
| 6572 | struct breakpoint *copy; |
| 6573 | |
| 6574 | /* If there's nothing to clone, then return nothing. */ |
| 6575 | if (orig == NULL) |
| 6576 | return NULL; |
| 6577 | |
| 6578 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
| 6579 | copy->loc = allocate_bp_location (copy); |
| 6580 | set_breakpoint_location_function (copy->loc); |
| 6581 | |
| 6582 | copy->loc->gdbarch = orig->loc->gdbarch; |
| 6583 | copy->loc->requested_address = orig->loc->requested_address; |
| 6584 | copy->loc->address = orig->loc->address; |
| 6585 | copy->loc->section = orig->loc->section; |
| 6586 | copy->loc->pspace = orig->loc->pspace; |
| 6587 | |
| 6588 | if (orig->source_file == NULL) |
| 6589 | copy->source_file = NULL; |
| 6590 | else |
| 6591 | copy->source_file = xstrdup (orig->source_file); |
| 6592 | |
| 6593 | copy->line_number = orig->line_number; |
| 6594 | copy->frame_id = orig->frame_id; |
| 6595 | copy->thread = orig->thread; |
| 6596 | copy->pspace = orig->pspace; |
| 6597 | |
| 6598 | copy->enable_state = bp_enabled; |
| 6599 | copy->disposition = disp_donttouch; |
| 6600 | copy->number = internal_breakpoint_number--; |
| 6601 | |
| 6602 | update_global_location_list_nothrow (0); |
| 6603 | return copy; |
| 6604 | } |
| 6605 | |
| 6606 | struct breakpoint * |
| 6607 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 6608 | enum bptype type) |
| 6609 | { |
| 6610 | struct symtab_and_line sal; |
| 6611 | |
| 6612 | sal = find_pc_line (pc, 0); |
| 6613 | sal.pc = pc; |
| 6614 | sal.section = find_pc_overlay (pc); |
| 6615 | sal.explicit_pc = 1; |
| 6616 | |
| 6617 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
| 6618 | } |
| 6619 | \f |
| 6620 | |
| 6621 | /* Tell the user we have just set a breakpoint B. */ |
| 6622 | |
| 6623 | static void |
| 6624 | mention (struct breakpoint *b) |
| 6625 | { |
| 6626 | int say_where = 0; |
| 6627 | struct cleanup *ui_out_chain; |
| 6628 | struct value_print_options opts; |
| 6629 | |
| 6630 | get_user_print_options (&opts); |
| 6631 | |
| 6632 | /* FIXME: This is misplaced; mention() is called by things (like |
| 6633 | hitting a watchpoint) other than breakpoint creation. It should |
| 6634 | be possible to clean this up and at the same time replace the |
| 6635 | random calls to breakpoint_changed with this hook. */ |
| 6636 | observer_notify_breakpoint_created (b->number); |
| 6637 | |
| 6638 | if (b->ops != NULL && b->ops->print_mention != NULL) |
| 6639 | b->ops->print_mention (b); |
| 6640 | else |
| 6641 | switch (b->type) |
| 6642 | { |
| 6643 | case bp_none: |
| 6644 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
| 6645 | break; |
| 6646 | case bp_watchpoint: |
| 6647 | ui_out_text (uiout, "Watchpoint "); |
| 6648 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 6649 | ui_out_field_int (uiout, "number", b->number); |
| 6650 | ui_out_text (uiout, ": "); |
| 6651 | ui_out_field_string (uiout, "exp", b->exp_string); |
| 6652 | do_cleanups (ui_out_chain); |
| 6653 | break; |
| 6654 | case bp_hardware_watchpoint: |
| 6655 | ui_out_text (uiout, "Hardware watchpoint "); |
| 6656 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 6657 | ui_out_field_int (uiout, "number", b->number); |
| 6658 | ui_out_text (uiout, ": "); |
| 6659 | ui_out_field_string (uiout, "exp", b->exp_string); |
| 6660 | do_cleanups (ui_out_chain); |
| 6661 | break; |
| 6662 | case bp_read_watchpoint: |
| 6663 | ui_out_text (uiout, "Hardware read watchpoint "); |
| 6664 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
| 6665 | ui_out_field_int (uiout, "number", b->number); |
| 6666 | ui_out_text (uiout, ": "); |
| 6667 | ui_out_field_string (uiout, "exp", b->exp_string); |
| 6668 | do_cleanups (ui_out_chain); |
| 6669 | break; |
| 6670 | case bp_access_watchpoint: |
| 6671 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); |
| 6672 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
| 6673 | ui_out_field_int (uiout, "number", b->number); |
| 6674 | ui_out_text (uiout, ": "); |
| 6675 | ui_out_field_string (uiout, "exp", b->exp_string); |
| 6676 | do_cleanups (ui_out_chain); |
| 6677 | break; |
| 6678 | case bp_breakpoint: |
| 6679 | if (ui_out_is_mi_like_p (uiout)) |
| 6680 | { |
| 6681 | say_where = 0; |
| 6682 | break; |
| 6683 | } |
| 6684 | if (b->disposition == disp_del) |
| 6685 | printf_filtered (_("Temporary breakpoint")); |
| 6686 | else |
| 6687 | printf_filtered (_("Breakpoint")); |
| 6688 | printf_filtered (_(" %d"), b->number); |
| 6689 | say_where = 1; |
| 6690 | break; |
| 6691 | case bp_hardware_breakpoint: |
| 6692 | if (ui_out_is_mi_like_p (uiout)) |
| 6693 | { |
| 6694 | say_where = 0; |
| 6695 | break; |
| 6696 | } |
| 6697 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
| 6698 | say_where = 1; |
| 6699 | break; |
| 6700 | case bp_tracepoint: |
| 6701 | if (ui_out_is_mi_like_p (uiout)) |
| 6702 | { |
| 6703 | say_where = 0; |
| 6704 | break; |
| 6705 | } |
| 6706 | printf_filtered (_("Tracepoint")); |
| 6707 | printf_filtered (_(" %d"), b->number); |
| 6708 | say_where = 1; |
| 6709 | break; |
| 6710 | case bp_fast_tracepoint: |
| 6711 | if (ui_out_is_mi_like_p (uiout)) |
| 6712 | { |
| 6713 | say_where = 0; |
| 6714 | break; |
| 6715 | } |
| 6716 | printf_filtered (_("Fast tracepoint")); |
| 6717 | printf_filtered (_(" %d"), b->number); |
| 6718 | say_where = 1; |
| 6719 | break; |
| 6720 | |
| 6721 | case bp_until: |
| 6722 | case bp_finish: |
| 6723 | case bp_longjmp: |
| 6724 | case bp_longjmp_resume: |
| 6725 | case bp_step_resume: |
| 6726 | case bp_call_dummy: |
| 6727 | case bp_std_terminate: |
| 6728 | case bp_watchpoint_scope: |
| 6729 | case bp_shlib_event: |
| 6730 | case bp_thread_event: |
| 6731 | case bp_overlay_event: |
| 6732 | case bp_jit_event: |
| 6733 | case bp_longjmp_master: |
| 6734 | case bp_std_terminate_master: |
| 6735 | break; |
| 6736 | } |
| 6737 | |
| 6738 | if (say_where) |
| 6739 | { |
| 6740 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
| 6741 | single string. */ |
| 6742 | if (b->loc == NULL) |
| 6743 | { |
| 6744 | printf_filtered (_(" (%s) pending."), b->addr_string); |
| 6745 | } |
| 6746 | else |
| 6747 | { |
| 6748 | if (opts.addressprint || b->source_file == NULL) |
| 6749 | { |
| 6750 | printf_filtered (" at "); |
| 6751 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
| 6752 | gdb_stdout); |
| 6753 | } |
| 6754 | if (b->source_file) |
| 6755 | printf_filtered (": file %s, line %d.", |
| 6756 | b->source_file, b->line_number); |
| 6757 | |
| 6758 | if (b->loc->next) |
| 6759 | { |
| 6760 | struct bp_location *loc = b->loc; |
| 6761 | int n = 0; |
| 6762 | for (; loc; loc = loc->next) |
| 6763 | ++n; |
| 6764 | printf_filtered (" (%d locations)", n); |
| 6765 | } |
| 6766 | |
| 6767 | } |
| 6768 | } |
| 6769 | if (ui_out_is_mi_like_p (uiout)) |
| 6770 | return; |
| 6771 | printf_filtered ("\n"); |
| 6772 | } |
| 6773 | \f |
| 6774 | |
| 6775 | static struct bp_location * |
| 6776 | add_location_to_breakpoint (struct breakpoint *b, |
| 6777 | const struct symtab_and_line *sal) |
| 6778 | { |
| 6779 | struct bp_location *loc, **tmp; |
| 6780 | |
| 6781 | loc = allocate_bp_location (b); |
| 6782 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
| 6783 | ; |
| 6784 | *tmp = loc; |
| 6785 | loc->gdbarch = get_sal_arch (*sal); |
| 6786 | if (!loc->gdbarch) |
| 6787 | loc->gdbarch = b->gdbarch; |
| 6788 | loc->requested_address = sal->pc; |
| 6789 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
| 6790 | loc->requested_address, b->type); |
| 6791 | loc->pspace = sal->pspace; |
| 6792 | gdb_assert (loc->pspace != NULL); |
| 6793 | loc->section = sal->section; |
| 6794 | |
| 6795 | set_breakpoint_location_function (loc); |
| 6796 | return loc; |
| 6797 | } |
| 6798 | \f |
| 6799 | |
| 6800 | /* Return 1 if LOC is pointing to a permanent breakpoint, |
| 6801 | return 0 otherwise. */ |
| 6802 | |
| 6803 | static int |
| 6804 | bp_loc_is_permanent (struct bp_location *loc) |
| 6805 | { |
| 6806 | int len; |
| 6807 | CORE_ADDR addr; |
| 6808 | const gdb_byte *brk; |
| 6809 | gdb_byte *target_mem; |
| 6810 | struct cleanup *cleanup; |
| 6811 | int retval = 0; |
| 6812 | |
| 6813 | gdb_assert (loc != NULL); |
| 6814 | |
| 6815 | addr = loc->address; |
| 6816 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
| 6817 | |
| 6818 | /* Software breakpoints unsupported? */ |
| 6819 | if (brk == NULL) |
| 6820 | return 0; |
| 6821 | |
| 6822 | target_mem = alloca (len); |
| 6823 | |
| 6824 | /* Enable the automatic memory restoration from breakpoints while |
| 6825 | we read the memory. Otherwise we could say about our temporary |
| 6826 | breakpoints they are permanent. */ |
| 6827 | cleanup = save_current_space_and_thread (); |
| 6828 | |
| 6829 | switch_to_program_space_and_thread (loc->pspace); |
| 6830 | make_show_memory_breakpoints_cleanup (0); |
| 6831 | |
| 6832 | if (target_read_memory (loc->address, target_mem, len) == 0 |
| 6833 | && memcmp (target_mem, brk, len) == 0) |
| 6834 | retval = 1; |
| 6835 | |
| 6836 | do_cleanups (cleanup); |
| 6837 | |
| 6838 | return retval; |
| 6839 | } |
| 6840 | |
| 6841 | |
| 6842 | |
| 6843 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
| 6844 | as textual description of the location, and COND_STRING |
| 6845 | as condition expression. */ |
| 6846 | |
| 6847 | static void |
| 6848 | create_breakpoint_sal (struct gdbarch *gdbarch, |
| 6849 | struct symtabs_and_lines sals, char *addr_string, |
| 6850 | char *cond_string, |
| 6851 | enum bptype type, enum bpdisp disposition, |
| 6852 | int thread, int task, int ignore_count, |
| 6853 | struct breakpoint_ops *ops, int from_tty, int enabled) |
| 6854 | { |
| 6855 | struct breakpoint *b = NULL; |
| 6856 | int i; |
| 6857 | |
| 6858 | if (type == bp_hardware_breakpoint) |
| 6859 | { |
| 6860 | int i = hw_breakpoint_used_count (); |
| 6861 | int target_resources_ok = |
| 6862 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 6863 | i + 1, 0); |
| 6864 | if (target_resources_ok == 0) |
| 6865 | error (_("No hardware breakpoint support in the target.")); |
| 6866 | else if (target_resources_ok < 0) |
| 6867 | error (_("Hardware breakpoints used exceeds limit.")); |
| 6868 | } |
| 6869 | |
| 6870 | gdb_assert (sals.nelts > 0); |
| 6871 | |
| 6872 | for (i = 0; i < sals.nelts; ++i) |
| 6873 | { |
| 6874 | struct symtab_and_line sal = sals.sals[i]; |
| 6875 | struct bp_location *loc; |
| 6876 | |
| 6877 | if (from_tty) |
| 6878 | { |
| 6879 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 6880 | if (!loc_gdbarch) |
| 6881 | loc_gdbarch = gdbarch; |
| 6882 | |
| 6883 | describe_other_breakpoints (loc_gdbarch, |
| 6884 | sal.pspace, sal.pc, sal.section, thread); |
| 6885 | } |
| 6886 | |
| 6887 | if (i == 0) |
| 6888 | { |
| 6889 | b = set_raw_breakpoint (gdbarch, sal, type); |
| 6890 | set_breakpoint_count (breakpoint_count + 1); |
| 6891 | b->number = breakpoint_count; |
| 6892 | b->thread = thread; |
| 6893 | b->task = task; |
| 6894 | |
| 6895 | b->cond_string = cond_string; |
| 6896 | b->ignore_count = ignore_count; |
| 6897 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 6898 | b->disposition = disposition; |
| 6899 | |
| 6900 | b->pspace = sals.sals[0].pspace; |
| 6901 | |
| 6902 | if (enabled && b->pspace->executing_startup |
| 6903 | && (b->type == bp_breakpoint |
| 6904 | || b->type == bp_hardware_breakpoint)) |
| 6905 | b->enable_state = bp_startup_disabled; |
| 6906 | |
| 6907 | loc = b->loc; |
| 6908 | } |
| 6909 | else |
| 6910 | { |
| 6911 | loc = add_location_to_breakpoint (b, &sal); |
| 6912 | } |
| 6913 | |
| 6914 | if (bp_loc_is_permanent (loc)) |
| 6915 | make_breakpoint_permanent (b); |
| 6916 | |
| 6917 | if (b->cond_string) |
| 6918 | { |
| 6919 | char *arg = b->cond_string; |
| 6920 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
| 6921 | if (*arg) |
| 6922 | error (_("Garbage %s follows condition"), arg); |
| 6923 | } |
| 6924 | } |
| 6925 | |
| 6926 | if (addr_string) |
| 6927 | b->addr_string = addr_string; |
| 6928 | else |
| 6929 | /* addr_string has to be used or breakpoint_re_set will delete |
| 6930 | me. */ |
| 6931 | b->addr_string |
| 6932 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); |
| 6933 | |
| 6934 | b->ops = ops; |
| 6935 | mention (b); |
| 6936 | } |
| 6937 | |
| 6938 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
| 6939 | elements to fill the void space. */ |
| 6940 | static void |
| 6941 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) |
| 6942 | { |
| 6943 | int i = index_to_remove+1; |
| 6944 | int last_index = sal->nelts-1; |
| 6945 | |
| 6946 | for (;i <= last_index; ++i) |
| 6947 | sal->sals[i-1] = sal->sals[i]; |
| 6948 | |
| 6949 | --(sal->nelts); |
| 6950 | } |
| 6951 | |
| 6952 | /* If appropriate, obtains all sals that correspond to the same file |
| 6953 | and line as SAL, in all program spaces. Users debugging with IDEs, |
| 6954 | will want to set a breakpoint at foo.c:line, and not really care |
| 6955 | about program spaces. This is done only if SAL does not have |
| 6956 | explicit PC and has line and file information. If we got just a |
| 6957 | single expanded sal, return the original. |
| 6958 | |
| 6959 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
| 6960 | which the name of enclosing function is different from SAL. This |
| 6961 | makes sure that if we have breakpoint originally set in template |
| 6962 | instantiation, say foo<int>(), we won't expand SAL to locations at |
| 6963 | the same line in all existing instantiations of 'foo'. */ |
| 6964 | |
| 6965 | static struct symtabs_and_lines |
| 6966 | expand_line_sal_maybe (struct symtab_and_line sal) |
| 6967 | { |
| 6968 | struct symtabs_and_lines expanded; |
| 6969 | CORE_ADDR original_pc = sal.pc; |
| 6970 | char *original_function = NULL; |
| 6971 | int found; |
| 6972 | int i; |
| 6973 | struct cleanup *old_chain; |
| 6974 | |
| 6975 | /* If we have explicit pc, don't expand. |
| 6976 | If we have no line number, we can't expand. */ |
| 6977 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) |
| 6978 | { |
| 6979 | expanded.nelts = 1; |
| 6980 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); |
| 6981 | expanded.sals[0] = sal; |
| 6982 | return expanded; |
| 6983 | } |
| 6984 | |
| 6985 | sal.pc = 0; |
| 6986 | |
| 6987 | old_chain = save_current_space_and_thread (); |
| 6988 | |
| 6989 | switch_to_program_space_and_thread (sal.pspace); |
| 6990 | |
| 6991 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
| 6992 | |
| 6993 | /* Note that expand_line_sal visits *all* program spaces. */ |
| 6994 | expanded = expand_line_sal (sal); |
| 6995 | |
| 6996 | if (expanded.nelts == 1) |
| 6997 | { |
| 6998 | /* We had one sal, we got one sal. Return that sal, adjusting it |
| 6999 | past the function prologue if necessary. */ |
| 7000 | xfree (expanded.sals); |
| 7001 | expanded.nelts = 1; |
| 7002 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); |
| 7003 | sal.pc = original_pc; |
| 7004 | expanded.sals[0] = sal; |
| 7005 | skip_prologue_sal (&expanded.sals[0]); |
| 7006 | do_cleanups (old_chain); |
| 7007 | return expanded; |
| 7008 | } |
| 7009 | |
| 7010 | if (!sal.explicit_line) |
| 7011 | { |
| 7012 | CORE_ADDR func_addr, func_end; |
| 7013 | for (i = 0; i < expanded.nelts; ++i) |
| 7014 | { |
| 7015 | CORE_ADDR pc = expanded.sals[i].pc; |
| 7016 | char *this_function; |
| 7017 | |
| 7018 | /* We need to switch threads as well since we're about to |
| 7019 | read memory. */ |
| 7020 | switch_to_program_space_and_thread (expanded.sals[i].pspace); |
| 7021 | |
| 7022 | if (find_pc_partial_function (pc, &this_function, |
| 7023 | &func_addr, &func_end)) |
| 7024 | { |
| 7025 | if (this_function |
| 7026 | && strcmp (this_function, original_function) != 0) |
| 7027 | { |
| 7028 | remove_sal (&expanded, i); |
| 7029 | --i; |
| 7030 | } |
| 7031 | } |
| 7032 | } |
| 7033 | } |
| 7034 | |
| 7035 | /* Skip the function prologue if necessary. */ |
| 7036 | for (i = 0; i < expanded.nelts; ++i) |
| 7037 | skip_prologue_sal (&expanded.sals[i]); |
| 7038 | |
| 7039 | do_cleanups (old_chain); |
| 7040 | |
| 7041 | if (expanded.nelts <= 1) |
| 7042 | { |
| 7043 | /* This is un ugly workaround. If we get zero |
| 7044 | expanded sals then something is really wrong. |
| 7045 | Fix that by returnign the original sal. */ |
| 7046 | xfree (expanded.sals); |
| 7047 | expanded.nelts = 1; |
| 7048 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); |
| 7049 | sal.pc = original_pc; |
| 7050 | expanded.sals[0] = sal; |
| 7051 | return expanded; |
| 7052 | } |
| 7053 | |
| 7054 | if (original_pc) |
| 7055 | { |
| 7056 | found = 0; |
| 7057 | for (i = 0; i < expanded.nelts; ++i) |
| 7058 | if (expanded.sals[i].pc == original_pc) |
| 7059 | { |
| 7060 | found = 1; |
| 7061 | break; |
| 7062 | } |
| 7063 | gdb_assert (found); |
| 7064 | } |
| 7065 | |
| 7066 | return expanded; |
| 7067 | } |
| 7068 | |
| 7069 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
| 7070 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] |
| 7071 | value. COND_STRING, if not NULL, specified the condition to be |
| 7072 | used for all breakpoints. Essentially the only case where |
| 7073 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded |
| 7074 | function. In that case, it's still not possible to specify |
| 7075 | separate conditions for different overloaded functions, so |
| 7076 | we take just a single condition string. |
| 7077 | |
| 7078 | NOTE: If the function succeeds, the caller is expected to cleanup |
| 7079 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
| 7080 | array contents). If the function fails (error() is called), the |
| 7081 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, |
| 7082 | COND and SALS arrays and each of those arrays contents. */ |
| 7083 | |
| 7084 | static void |
| 7085 | create_breakpoints_sal (struct gdbarch *gdbarch, |
| 7086 | struct symtabs_and_lines sals, char **addr_string, |
| 7087 | char *cond_string, |
| 7088 | enum bptype type, enum bpdisp disposition, |
| 7089 | int thread, int task, int ignore_count, |
| 7090 | struct breakpoint_ops *ops, int from_tty, |
| 7091 | int enabled) |
| 7092 | { |
| 7093 | int i; |
| 7094 | for (i = 0; i < sals.nelts; ++i) |
| 7095 | { |
| 7096 | struct symtabs_and_lines expanded = |
| 7097 | expand_line_sal_maybe (sals.sals[i]); |
| 7098 | |
| 7099 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
| 7100 | cond_string, type, disposition, |
| 7101 | thread, task, ignore_count, ops, from_tty, enabled); |
| 7102 | } |
| 7103 | } |
| 7104 | |
| 7105 | /* Parse ARG which is assumed to be a SAL specification possibly |
| 7106 | followed by conditionals. On return, SALS contains an array of SAL |
| 7107 | addresses found. ADDR_STRING contains a vector of (canonical) |
| 7108 | address strings. ARG points to the end of the SAL. */ |
| 7109 | |
| 7110 | static void |
| 7111 | parse_breakpoint_sals (char **address, |
| 7112 | struct symtabs_and_lines *sals, |
| 7113 | char ***addr_string, |
| 7114 | int *not_found_ptr) |
| 7115 | { |
| 7116 | char *addr_start = *address; |
| 7117 | *addr_string = NULL; |
| 7118 | /* If no arg given, or if first arg is 'if ', use the default |
| 7119 | breakpoint. */ |
| 7120 | if ((*address) == NULL |
| 7121 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) |
| 7122 | { |
| 7123 | if (default_breakpoint_valid) |
| 7124 | { |
| 7125 | struct symtab_and_line sal; |
| 7126 | init_sal (&sal); /* initialize to zeroes */ |
| 7127 | sals->sals = (struct symtab_and_line *) |
| 7128 | xmalloc (sizeof (struct symtab_and_line)); |
| 7129 | sal.pc = default_breakpoint_address; |
| 7130 | sal.line = default_breakpoint_line; |
| 7131 | sal.symtab = default_breakpoint_symtab; |
| 7132 | sal.pspace = default_breakpoint_pspace; |
| 7133 | sal.section = find_pc_overlay (sal.pc); |
| 7134 | |
| 7135 | /* "break" without arguments is equivalent to "break *PC" where PC is |
| 7136 | the default_breakpoint_address. So make sure to set |
| 7137 | sal.explicit_pc to prevent GDB from trying to expand the list of |
| 7138 | sals to include all other instances with the same symtab and line. |
| 7139 | */ |
| 7140 | sal.explicit_pc = 1; |
| 7141 | |
| 7142 | sals->sals[0] = sal; |
| 7143 | sals->nelts = 1; |
| 7144 | } |
| 7145 | else |
| 7146 | error (_("No default breakpoint address now.")); |
| 7147 | } |
| 7148 | else |
| 7149 | { |
| 7150 | /* Force almost all breakpoints to be in terms of the |
| 7151 | current_source_symtab (which is decode_line_1's default). This |
| 7152 | should produce the results we want almost all of the time while |
| 7153 | leaving default_breakpoint_* alone. |
| 7154 | ObjC: However, don't match an Objective-C method name which |
| 7155 | may have a '+' or '-' succeeded by a '[' */ |
| 7156 | |
| 7157 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
| 7158 | |
| 7159 | if (default_breakpoint_valid |
| 7160 | && (!cursal.symtab |
| 7161 | || ((strchr ("+-", (*address)[0]) != NULL) |
| 7162 | && ((*address)[1] != '[')))) |
| 7163 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
| 7164 | default_breakpoint_line, addr_string, |
| 7165 | not_found_ptr); |
| 7166 | else |
| 7167 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
| 7168 | addr_string, not_found_ptr); |
| 7169 | } |
| 7170 | /* For any SAL that didn't have a canonical string, fill one in. */ |
| 7171 | if (sals->nelts > 0 && *addr_string == NULL) |
| 7172 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); |
| 7173 | if (addr_start != (*address)) |
| 7174 | { |
| 7175 | int i; |
| 7176 | for (i = 0; i < sals->nelts; i++) |
| 7177 | { |
| 7178 | /* Add the string if not present. */ |
| 7179 | if ((*addr_string)[i] == NULL) |
| 7180 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); |
| 7181 | } |
| 7182 | } |
| 7183 | } |
| 7184 | |
| 7185 | |
| 7186 | /* Convert each SAL into a real PC. Verify that the PC can be |
| 7187 | inserted as a breakpoint. If it can't throw an error. */ |
| 7188 | |
| 7189 | static void |
| 7190 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
| 7191 | char *address) |
| 7192 | { |
| 7193 | int i; |
| 7194 | for (i = 0; i < sals->nelts; i++) |
| 7195 | resolve_sal_pc (&sals->sals[i]); |
| 7196 | } |
| 7197 | |
| 7198 | /* Fast tracepoints may have restrictions on valid locations. For |
| 7199 | instance, a fast tracepoint using a jump instead of a trap will |
| 7200 | likely have to overwrite more bytes than a trap would, and so can |
| 7201 | only be placed where the instruction is longer than the jump, or a |
| 7202 | multi-instruction sequence does not have a jump into the middle of |
| 7203 | it, etc. */ |
| 7204 | |
| 7205 | static void |
| 7206 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, |
| 7207 | struct symtabs_and_lines *sals) |
| 7208 | { |
| 7209 | int i, rslt; |
| 7210 | struct symtab_and_line *sal; |
| 7211 | char *msg; |
| 7212 | struct cleanup *old_chain; |
| 7213 | |
| 7214 | for (i = 0; i < sals->nelts; i++) |
| 7215 | { |
| 7216 | sal = &sals->sals[i]; |
| 7217 | |
| 7218 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, |
| 7219 | NULL, &msg); |
| 7220 | old_chain = make_cleanup (xfree, msg); |
| 7221 | |
| 7222 | if (!rslt) |
| 7223 | error (_("May not have a fast tracepoint at 0x%s%s"), |
| 7224 | paddress (gdbarch, sal->pc), (msg ? msg : "")); |
| 7225 | |
| 7226 | do_cleanups (old_chain); |
| 7227 | } |
| 7228 | } |
| 7229 | |
| 7230 | static void |
| 7231 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
| 7232 | { |
| 7233 | struct captured_parse_breakpoint_args *args = data; |
| 7234 | |
| 7235 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, |
| 7236 | args->not_found_ptr); |
| 7237 | } |
| 7238 | |
| 7239 | /* Given TOK, a string specification of condition and thread, as |
| 7240 | accepted by the 'break' command, extract the condition |
| 7241 | string and thread number and set *COND_STRING and *THREAD. |
| 7242 | PC identifies the context at which the condition should be parsed. |
| 7243 | If no condition is found, *COND_STRING is set to NULL. |
| 7244 | If no thread is found, *THREAD is set to -1. */ |
| 7245 | static void |
| 7246 | find_condition_and_thread (char *tok, CORE_ADDR pc, |
| 7247 | char **cond_string, int *thread, int *task) |
| 7248 | { |
| 7249 | *cond_string = NULL; |
| 7250 | *thread = -1; |
| 7251 | while (tok && *tok) |
| 7252 | { |
| 7253 | char *end_tok; |
| 7254 | int toklen; |
| 7255 | char *cond_start = NULL; |
| 7256 | char *cond_end = NULL; |
| 7257 | while (*tok == ' ' || *tok == '\t') |
| 7258 | tok++; |
| 7259 | |
| 7260 | end_tok = tok; |
| 7261 | |
| 7262 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') |
| 7263 | end_tok++; |
| 7264 | |
| 7265 | toklen = end_tok - tok; |
| 7266 | |
| 7267 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 7268 | { |
| 7269 | struct expression *expr; |
| 7270 | |
| 7271 | tok = cond_start = end_tok + 1; |
| 7272 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
| 7273 | xfree (expr); |
| 7274 | cond_end = tok; |
| 7275 | *cond_string = savestring (cond_start, |
| 7276 | cond_end - cond_start); |
| 7277 | } |
| 7278 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 7279 | { |
| 7280 | char *tmptok; |
| 7281 | |
| 7282 | tok = end_tok + 1; |
| 7283 | tmptok = tok; |
| 7284 | *thread = strtol (tok, &tok, 0); |
| 7285 | if (tok == tmptok) |
| 7286 | error (_("Junk after thread keyword.")); |
| 7287 | if (!valid_thread_id (*thread)) |
| 7288 | error (_("Unknown thread %d."), *thread); |
| 7289 | } |
| 7290 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
| 7291 | { |
| 7292 | char *tmptok; |
| 7293 | |
| 7294 | tok = end_tok + 1; |
| 7295 | tmptok = tok; |
| 7296 | *task = strtol (tok, &tok, 0); |
| 7297 | if (tok == tmptok) |
| 7298 | error (_("Junk after task keyword.")); |
| 7299 | if (!valid_task_id (*task)) |
| 7300 | error (_("Unknown task %d."), *task); |
| 7301 | } |
| 7302 | else |
| 7303 | error (_("Junk at end of arguments.")); |
| 7304 | } |
| 7305 | } |
| 7306 | |
| 7307 | /* Set a breakpoint. This function is shared between CLI and MI |
| 7308 | functions for setting a breakpoint. This function has two major |
| 7309 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD |
| 7310 | parameter. If non-zero, the function will parse arg, extracting |
| 7311 | breakpoint location, address and thread. Otherwise, ARG is just the |
| 7312 | location of breakpoint, with condition and thread specified by the |
| 7313 | COND_STRING and THREAD parameters. Returns true if any breakpoint |
| 7314 | was created; false otherwise. */ |
| 7315 | |
| 7316 | int |
| 7317 | create_breakpoint (struct gdbarch *gdbarch, |
| 7318 | char *arg, char *cond_string, int thread, |
| 7319 | int parse_condition_and_thread, |
| 7320 | int tempflag, int hardwareflag, int traceflag, |
| 7321 | int ignore_count, |
| 7322 | enum auto_boolean pending_break_support, |
| 7323 | struct breakpoint_ops *ops, |
| 7324 | int from_tty, |
| 7325 | int enabled) |
| 7326 | { |
| 7327 | struct gdb_exception e; |
| 7328 | struct symtabs_and_lines sals; |
| 7329 | struct symtab_and_line pending_sal; |
| 7330 | char *copy_arg; |
| 7331 | char *err_msg; |
| 7332 | char *addr_start = arg; |
| 7333 | char **addr_string; |
| 7334 | struct cleanup *old_chain; |
| 7335 | struct cleanup *bkpt_chain = NULL; |
| 7336 | struct captured_parse_breakpoint_args parse_args; |
| 7337 | int i; |
| 7338 | int pending = 0; |
| 7339 | int not_found = 0; |
| 7340 | enum bptype type_wanted; |
| 7341 | int task = 0; |
| 7342 | int prev_bkpt_count = breakpoint_count; |
| 7343 | |
| 7344 | sals.sals = NULL; |
| 7345 | sals.nelts = 0; |
| 7346 | addr_string = NULL; |
| 7347 | |
| 7348 | parse_args.arg_p = &arg; |
| 7349 | parse_args.sals_p = &sals; |
| 7350 | parse_args.addr_string_p = &addr_string; |
| 7351 | parse_args.not_found_ptr = ¬_found; |
| 7352 | |
| 7353 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
| 7354 | &parse_args, RETURN_MASK_ALL); |
| 7355 | |
| 7356 | /* If caller is interested in rc value from parse, set value. */ |
| 7357 | switch (e.reason) |
| 7358 | { |
| 7359 | case RETURN_QUIT: |
| 7360 | throw_exception (e); |
| 7361 | case RETURN_ERROR: |
| 7362 | switch (e.error) |
| 7363 | { |
| 7364 | case NOT_FOUND_ERROR: |
| 7365 | |
| 7366 | /* If pending breakpoint support is turned off, throw |
| 7367 | error. */ |
| 7368 | |
| 7369 | if (pending_break_support == AUTO_BOOLEAN_FALSE) |
| 7370 | throw_exception (e); |
| 7371 | |
| 7372 | exception_print (gdb_stderr, e); |
| 7373 | |
| 7374 | /* If pending breakpoint support is auto query and the user |
| 7375 | selects no, then simply return the error code. */ |
| 7376 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
| 7377 | && !nquery ("Make breakpoint pending on future shared library load? ")) |
| 7378 | return 0; |
| 7379 | |
| 7380 | /* At this point, either the user was queried about setting |
| 7381 | a pending breakpoint and selected yes, or pending |
| 7382 | breakpoint behavior is on and thus a pending breakpoint |
| 7383 | is defaulted on behalf of the user. */ |
| 7384 | copy_arg = xstrdup (addr_start); |
| 7385 | addr_string = ©_arg; |
| 7386 | sals.nelts = 1; |
| 7387 | sals.sals = &pending_sal; |
| 7388 | pending_sal.pc = 0; |
| 7389 | pending = 1; |
| 7390 | break; |
| 7391 | default: |
| 7392 | throw_exception (e); |
| 7393 | } |
| 7394 | default: |
| 7395 | if (!sals.nelts) |
| 7396 | return 0; |
| 7397 | } |
| 7398 | |
| 7399 | /* Create a chain of things that always need to be cleaned up. */ |
| 7400 | old_chain = make_cleanup (null_cleanup, 0); |
| 7401 | |
| 7402 | if (!pending) |
| 7403 | { |
| 7404 | /* Make sure that all storage allocated to SALS gets freed. */ |
| 7405 | make_cleanup (xfree, sals.sals); |
| 7406 | |
| 7407 | /* Cleanup the addr_string array but not its contents. */ |
| 7408 | make_cleanup (xfree, addr_string); |
| 7409 | } |
| 7410 | |
| 7411 | /* ----------------------------- SNIP ----------------------------- |
| 7412 | Anything added to the cleanup chain beyond this point is assumed |
| 7413 | to be part of a breakpoint. If the breakpoint create succeeds |
| 7414 | then the memory is not reclaimed. */ |
| 7415 | bkpt_chain = make_cleanup (null_cleanup, 0); |
| 7416 | |
| 7417 | /* Mark the contents of the addr_string for cleanup. These go on |
| 7418 | the bkpt_chain and only occur if the breakpoint create fails. */ |
| 7419 | for (i = 0; i < sals.nelts; i++) |
| 7420 | { |
| 7421 | if (addr_string[i] != NULL) |
| 7422 | make_cleanup (xfree, addr_string[i]); |
| 7423 | } |
| 7424 | |
| 7425 | /* Resolve all line numbers to PC's and verify that the addresses |
| 7426 | are ok for the target. */ |
| 7427 | if (!pending) |
| 7428 | breakpoint_sals_to_pc (&sals, addr_start); |
| 7429 | |
| 7430 | type_wanted = (traceflag |
| 7431 | ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint) |
| 7432 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
| 7433 | |
| 7434 | /* Fast tracepoints may have additional restrictions on location. */ |
| 7435 | if (type_wanted == bp_fast_tracepoint) |
| 7436 | check_fast_tracepoint_sals (gdbarch, &sals); |
| 7437 | |
| 7438 | /* Verify that condition can be parsed, before setting any |
| 7439 | breakpoints. Allocate a separate condition expression for each |
| 7440 | breakpoint. */ |
| 7441 | if (!pending) |
| 7442 | { |
| 7443 | if (parse_condition_and_thread) |
| 7444 | { |
| 7445 | /* Here we only parse 'arg' to separate condition |
| 7446 | from thread number, so parsing in context of first |
| 7447 | sal is OK. When setting the breakpoint we'll |
| 7448 | re-parse it in context of each sal. */ |
| 7449 | cond_string = NULL; |
| 7450 | thread = -1; |
| 7451 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
| 7452 | &thread, &task); |
| 7453 | if (cond_string) |
| 7454 | make_cleanup (xfree, cond_string); |
| 7455 | } |
| 7456 | else |
| 7457 | { |
| 7458 | /* Create a private copy of condition string. */ |
| 7459 | if (cond_string) |
| 7460 | { |
| 7461 | cond_string = xstrdup (cond_string); |
| 7462 | make_cleanup (xfree, cond_string); |
| 7463 | } |
| 7464 | } |
| 7465 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, |
| 7466 | type_wanted, tempflag ? disp_del : disp_donttouch, |
| 7467 | thread, task, ignore_count, ops, from_tty, |
| 7468 | enabled); |
| 7469 | } |
| 7470 | else |
| 7471 | { |
| 7472 | struct symtab_and_line sal = {0}; |
| 7473 | struct breakpoint *b; |
| 7474 | |
| 7475 | make_cleanup (xfree, copy_arg); |
| 7476 | |
| 7477 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
| 7478 | set_breakpoint_count (breakpoint_count + 1); |
| 7479 | b->number = breakpoint_count; |
| 7480 | b->thread = -1; |
| 7481 | b->addr_string = addr_string[0]; |
| 7482 | b->cond_string = NULL; |
| 7483 | b->ignore_count = ignore_count; |
| 7484 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 7485 | b->condition_not_parsed = 1; |
| 7486 | b->ops = ops; |
| 7487 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 7488 | b->pspace = current_program_space; |
| 7489 | |
| 7490 | if (enabled && b->pspace->executing_startup |
| 7491 | && (b->type == bp_breakpoint |
| 7492 | || b->type == bp_hardware_breakpoint)) |
| 7493 | b->enable_state = bp_startup_disabled; |
| 7494 | |
| 7495 | mention (b); |
| 7496 | } |
| 7497 | |
| 7498 | if (sals.nelts > 1) |
| 7499 | { |
| 7500 | warning (_("Multiple breakpoints were set.\n" |
| 7501 | "Use the \"delete\" command to delete unwanted breakpoints.")); |
| 7502 | prev_breakpoint_count = prev_bkpt_count; |
| 7503 | } |
| 7504 | |
| 7505 | /* That's it. Discard the cleanups for data inserted into the |
| 7506 | breakpoint. */ |
| 7507 | discard_cleanups (bkpt_chain); |
| 7508 | /* But cleanup everything else. */ |
| 7509 | do_cleanups (old_chain); |
| 7510 | |
| 7511 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
| 7512 | update_global_location_list (1); |
| 7513 | |
| 7514 | return 1; |
| 7515 | } |
| 7516 | |
| 7517 | /* Set a breakpoint. |
| 7518 | ARG is a string describing breakpoint address, |
| 7519 | condition, and thread. |
| 7520 | FLAG specifies if a breakpoint is hardware on, |
| 7521 | and if breakpoint is temporary, using BP_HARDWARE_FLAG |
| 7522 | and BP_TEMPFLAG. */ |
| 7523 | |
| 7524 | static void |
| 7525 | break_command_1 (char *arg, int flag, int from_tty) |
| 7526 | { |
| 7527 | int hardwareflag = flag & BP_HARDWAREFLAG; |
| 7528 | int tempflag = flag & BP_TEMPFLAG; |
| 7529 | |
| 7530 | create_breakpoint (get_current_arch (), |
| 7531 | arg, |
| 7532 | NULL, 0, 1 /* parse arg */, |
| 7533 | tempflag, hardwareflag, 0 /* traceflag */, |
| 7534 | 0 /* Ignore count */, |
| 7535 | pending_break_support, |
| 7536 | NULL /* breakpoint_ops */, |
| 7537 | from_tty, |
| 7538 | 1 /* enabled */); |
| 7539 | } |
| 7540 | |
| 7541 | |
| 7542 | |
| 7543 | /* Helper function for break_command_1 and disassemble_command. */ |
| 7544 | |
| 7545 | void |
| 7546 | resolve_sal_pc (struct symtab_and_line *sal) |
| 7547 | { |
| 7548 | CORE_ADDR pc; |
| 7549 | |
| 7550 | if (sal->pc == 0 && sal->symtab != NULL) |
| 7551 | { |
| 7552 | if (!find_line_pc (sal->symtab, sal->line, &pc)) |
| 7553 | error (_("No line %d in file \"%s\"."), |
| 7554 | sal->line, sal->symtab->filename); |
| 7555 | sal->pc = pc; |
| 7556 | |
| 7557 | /* If this SAL corresponds to a breakpoint inserted using |
| 7558 | a line number, then skip the function prologue if necessary. */ |
| 7559 | if (sal->explicit_line) |
| 7560 | skip_prologue_sal (sal); |
| 7561 | } |
| 7562 | |
| 7563 | if (sal->section == 0 && sal->symtab != NULL) |
| 7564 | { |
| 7565 | struct blockvector *bv; |
| 7566 | struct block *b; |
| 7567 | struct symbol *sym; |
| 7568 | |
| 7569 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
| 7570 | if (bv != NULL) |
| 7571 | { |
| 7572 | sym = block_linkage_function (b); |
| 7573 | if (sym != NULL) |
| 7574 | { |
| 7575 | fixup_symbol_section (sym, sal->symtab->objfile); |
| 7576 | sal->section = SYMBOL_OBJ_SECTION (sym); |
| 7577 | } |
| 7578 | else |
| 7579 | { |
| 7580 | /* It really is worthwhile to have the section, so we'll just |
| 7581 | have to look harder. This case can be executed if we have |
| 7582 | line numbers but no functions (as can happen in assembly |
| 7583 | source). */ |
| 7584 | |
| 7585 | struct minimal_symbol *msym; |
| 7586 | struct cleanup *old_chain = save_current_space_and_thread (); |
| 7587 | |
| 7588 | switch_to_program_space_and_thread (sal->pspace); |
| 7589 | |
| 7590 | msym = lookup_minimal_symbol_by_pc (sal->pc); |
| 7591 | if (msym) |
| 7592 | sal->section = SYMBOL_OBJ_SECTION (msym); |
| 7593 | |
| 7594 | do_cleanups (old_chain); |
| 7595 | } |
| 7596 | } |
| 7597 | } |
| 7598 | } |
| 7599 | |
| 7600 | void |
| 7601 | break_command (char *arg, int from_tty) |
| 7602 | { |
| 7603 | break_command_1 (arg, 0, from_tty); |
| 7604 | } |
| 7605 | |
| 7606 | void |
| 7607 | tbreak_command (char *arg, int from_tty) |
| 7608 | { |
| 7609 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
| 7610 | } |
| 7611 | |
| 7612 | static void |
| 7613 | hbreak_command (char *arg, int from_tty) |
| 7614 | { |
| 7615 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
| 7616 | } |
| 7617 | |
| 7618 | static void |
| 7619 | thbreak_command (char *arg, int from_tty) |
| 7620 | { |
| 7621 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
| 7622 | } |
| 7623 | |
| 7624 | static void |
| 7625 | stop_command (char *arg, int from_tty) |
| 7626 | { |
| 7627 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
| 7628 | Usage: stop in <function | address>\n\ |
| 7629 | stop at <line>\n")); |
| 7630 | } |
| 7631 | |
| 7632 | static void |
| 7633 | stopin_command (char *arg, int from_tty) |
| 7634 | { |
| 7635 | int badInput = 0; |
| 7636 | |
| 7637 | if (arg == (char *) NULL) |
| 7638 | badInput = 1; |
| 7639 | else if (*arg != '*') |
| 7640 | { |
| 7641 | char *argptr = arg; |
| 7642 | int hasColon = 0; |
| 7643 | |
| 7644 | /* look for a ':'. If this is a line number specification, then |
| 7645 | say it is bad, otherwise, it should be an address or |
| 7646 | function/method name */ |
| 7647 | while (*argptr && !hasColon) |
| 7648 | { |
| 7649 | hasColon = (*argptr == ':'); |
| 7650 | argptr++; |
| 7651 | } |
| 7652 | |
| 7653 | if (hasColon) |
| 7654 | badInput = (*argptr != ':'); /* Not a class::method */ |
| 7655 | else |
| 7656 | badInput = isdigit (*arg); /* a simple line number */ |
| 7657 | } |
| 7658 | |
| 7659 | if (badInput) |
| 7660 | printf_filtered (_("Usage: stop in <function | address>\n")); |
| 7661 | else |
| 7662 | break_command_1 (arg, 0, from_tty); |
| 7663 | } |
| 7664 | |
| 7665 | static void |
| 7666 | stopat_command (char *arg, int from_tty) |
| 7667 | { |
| 7668 | int badInput = 0; |
| 7669 | |
| 7670 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
| 7671 | badInput = 1; |
| 7672 | else |
| 7673 | { |
| 7674 | char *argptr = arg; |
| 7675 | int hasColon = 0; |
| 7676 | |
| 7677 | /* look for a ':'. If there is a '::' then get out, otherwise |
| 7678 | it is probably a line number. */ |
| 7679 | while (*argptr && !hasColon) |
| 7680 | { |
| 7681 | hasColon = (*argptr == ':'); |
| 7682 | argptr++; |
| 7683 | } |
| 7684 | |
| 7685 | if (hasColon) |
| 7686 | badInput = (*argptr == ':'); /* we have class::method */ |
| 7687 | else |
| 7688 | badInput = !isdigit (*arg); /* not a line number */ |
| 7689 | } |
| 7690 | |
| 7691 | if (badInput) |
| 7692 | printf_filtered (_("Usage: stop at <line>\n")); |
| 7693 | else |
| 7694 | break_command_1 (arg, 0, from_tty); |
| 7695 | } |
| 7696 | |
| 7697 | /* accessflag: hw_write: watch write, |
| 7698 | hw_read: watch read, |
| 7699 | hw_access: watch access (read or write) */ |
| 7700 | static void |
| 7701 | watch_command_1 (char *arg, int accessflag, int from_tty) |
| 7702 | { |
| 7703 | struct gdbarch *gdbarch = get_current_arch (); |
| 7704 | struct breakpoint *b, *scope_breakpoint = NULL; |
| 7705 | struct expression *exp; |
| 7706 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
| 7707 | struct value *val, *mark; |
| 7708 | struct frame_info *frame; |
| 7709 | char *exp_start = NULL; |
| 7710 | char *exp_end = NULL; |
| 7711 | char *tok, *id_tok_start, *end_tok; |
| 7712 | int toklen; |
| 7713 | char *cond_start = NULL; |
| 7714 | char *cond_end = NULL; |
| 7715 | int i, other_type_used, target_resources_ok = 0; |
| 7716 | enum bptype bp_type; |
| 7717 | int mem_cnt = 0; |
| 7718 | int thread = -1; |
| 7719 | |
| 7720 | /* Make sure that we actually have parameters to parse. */ |
| 7721 | if (arg != NULL && arg[0] != '\0') |
| 7722 | { |
| 7723 | toklen = strlen (arg); /* Size of argument list. */ |
| 7724 | |
| 7725 | /* Points tok to the end of the argument list. */ |
| 7726 | tok = arg + toklen - 1; |
| 7727 | |
| 7728 | /* Go backwards in the parameters list. Skip the last parameter. |
| 7729 | If we're expecting a 'thread <thread_num>' parameter, this should |
| 7730 | be the thread identifier. */ |
| 7731 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 7732 | tok--; |
| 7733 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 7734 | tok--; |
| 7735 | |
| 7736 | /* Points end_tok to the beginning of the last token. */ |
| 7737 | id_tok_start = tok + 1; |
| 7738 | |
| 7739 | /* Go backwards in the parameters list. Skip one more parameter. |
| 7740 | If we're expecting a 'thread <thread_num>' parameter, we should |
| 7741 | reach a "thread" token. */ |
| 7742 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 7743 | tok--; |
| 7744 | |
| 7745 | end_tok = tok; |
| 7746 | |
| 7747 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 7748 | tok--; |
| 7749 | |
| 7750 | /* Move the pointer forward to skip the whitespace and |
| 7751 | calculate the length of the token. */ |
| 7752 | tok++; |
| 7753 | toklen = end_tok - tok; |
| 7754 | |
| 7755 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 7756 | { |
| 7757 | /* At this point we've found a "thread" token, which means |
| 7758 | the user is trying to set a watchpoint that triggers |
| 7759 | only in a specific thread. */ |
| 7760 | char *endp; |
| 7761 | |
| 7762 | /* Extract the thread ID from the next token. */ |
| 7763 | thread = strtol (id_tok_start, &endp, 0); |
| 7764 | |
| 7765 | /* Check if the user provided a valid numeric value for the |
| 7766 | thread ID. */ |
| 7767 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
| 7768 | error (_("Invalid thread ID specification %s."), id_tok_start); |
| 7769 | |
| 7770 | /* Check if the thread actually exists. */ |
| 7771 | if (!valid_thread_id (thread)) |
| 7772 | error (_("Unknown thread %d."), thread); |
| 7773 | |
| 7774 | /* Truncate the string and get rid of the thread <thread_num> |
| 7775 | parameter before the parameter list is parsed by the |
| 7776 | evaluate_expression() function. */ |
| 7777 | *tok = '\0'; |
| 7778 | } |
| 7779 | } |
| 7780 | |
| 7781 | /* Parse the rest of the arguments. */ |
| 7782 | innermost_block = NULL; |
| 7783 | exp_start = arg; |
| 7784 | exp = parse_exp_1 (&arg, 0, 0); |
| 7785 | exp_end = arg; |
| 7786 | /* Remove trailing whitespace from the expression before saving it. |
| 7787 | This makes the eventual display of the expression string a bit |
| 7788 | prettier. */ |
| 7789 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) |
| 7790 | --exp_end; |
| 7791 | |
| 7792 | exp_valid_block = innermost_block; |
| 7793 | mark = value_mark (); |
| 7794 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
| 7795 | if (val != NULL) |
| 7796 | release_value (val); |
| 7797 | |
| 7798 | tok = arg; |
| 7799 | while (*tok == ' ' || *tok == '\t') |
| 7800 | tok++; |
| 7801 | end_tok = tok; |
| 7802 | |
| 7803 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') |
| 7804 | end_tok++; |
| 7805 | |
| 7806 | toklen = end_tok - tok; |
| 7807 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 7808 | { |
| 7809 | struct expression *cond; |
| 7810 | |
| 7811 | innermost_block = NULL; |
| 7812 | tok = cond_start = end_tok + 1; |
| 7813 | cond = parse_exp_1 (&tok, 0, 0); |
| 7814 | |
| 7815 | /* The watchpoint expression may not be local, but the condition |
| 7816 | may still be. E.g.: `watch global if local > 0'. */ |
| 7817 | cond_exp_valid_block = innermost_block; |
| 7818 | |
| 7819 | xfree (cond); |
| 7820 | cond_end = tok; |
| 7821 | } |
| 7822 | if (*tok) |
| 7823 | error (_("Junk at end of command.")); |
| 7824 | |
| 7825 | if (accessflag == hw_read) |
| 7826 | bp_type = bp_read_watchpoint; |
| 7827 | else if (accessflag == hw_access) |
| 7828 | bp_type = bp_access_watchpoint; |
| 7829 | else |
| 7830 | bp_type = bp_hardware_watchpoint; |
| 7831 | |
| 7832 | mem_cnt = can_use_hardware_watchpoint (val); |
| 7833 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) |
| 7834 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
| 7835 | if (mem_cnt != 0) |
| 7836 | { |
| 7837 | i = hw_watchpoint_used_count (bp_type, &other_type_used); |
| 7838 | target_resources_ok = |
| 7839 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
| 7840 | other_type_used); |
| 7841 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
| 7842 | error (_("Target does not support this type of hardware watchpoint.")); |
| 7843 | |
| 7844 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
| 7845 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
| 7846 | } |
| 7847 | |
| 7848 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
| 7849 | watchpoint could not be set. */ |
| 7850 | if (!mem_cnt || target_resources_ok <= 0) |
| 7851 | bp_type = bp_watchpoint; |
| 7852 | |
| 7853 | frame = block_innermost_frame (exp_valid_block); |
| 7854 | |
| 7855 | /* If the expression is "local", then set up a "watchpoint scope" |
| 7856 | breakpoint at the point where we've left the scope of the watchpoint |
| 7857 | expression. Create the scope breakpoint before the watchpoint, so |
| 7858 | that we will encounter it first in bpstat_stop_status. */ |
| 7859 | if (exp_valid_block && frame) |
| 7860 | { |
| 7861 | if (frame_id_p (frame_unwind_caller_id (frame))) |
| 7862 | { |
| 7863 | scope_breakpoint |
| 7864 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
| 7865 | frame_unwind_caller_pc (frame), |
| 7866 | bp_watchpoint_scope); |
| 7867 | |
| 7868 | scope_breakpoint->enable_state = bp_enabled; |
| 7869 | |
| 7870 | /* Automatically delete the breakpoint when it hits. */ |
| 7871 | scope_breakpoint->disposition = disp_del; |
| 7872 | |
| 7873 | /* Only break in the proper frame (help with recursion). */ |
| 7874 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); |
| 7875 | |
| 7876 | /* Set the address at which we will stop. */ |
| 7877 | scope_breakpoint->loc->gdbarch |
| 7878 | = frame_unwind_caller_arch (frame); |
| 7879 | scope_breakpoint->loc->requested_address |
| 7880 | = frame_unwind_caller_pc (frame); |
| 7881 | scope_breakpoint->loc->address |
| 7882 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
| 7883 | scope_breakpoint->loc->requested_address, |
| 7884 | scope_breakpoint->type); |
| 7885 | } |
| 7886 | } |
| 7887 | |
| 7888 | /* Now set up the breakpoint. */ |
| 7889 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
| 7890 | set_breakpoint_count (breakpoint_count + 1); |
| 7891 | b->number = breakpoint_count; |
| 7892 | b->thread = thread; |
| 7893 | b->disposition = disp_donttouch; |
| 7894 | b->exp = exp; |
| 7895 | b->exp_valid_block = exp_valid_block; |
| 7896 | b->cond_exp_valid_block = cond_exp_valid_block; |
| 7897 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
| 7898 | b->val = val; |
| 7899 | b->val_valid = 1; |
| 7900 | if (cond_start) |
| 7901 | b->cond_string = savestring (cond_start, cond_end - cond_start); |
| 7902 | else |
| 7903 | b->cond_string = 0; |
| 7904 | |
| 7905 | if (frame) |
| 7906 | { |
| 7907 | b->watchpoint_frame = get_frame_id (frame); |
| 7908 | b->watchpoint_thread = inferior_ptid; |
| 7909 | } |
| 7910 | else |
| 7911 | { |
| 7912 | b->watchpoint_frame = null_frame_id; |
| 7913 | b->watchpoint_thread = null_ptid; |
| 7914 | } |
| 7915 | |
| 7916 | if (scope_breakpoint != NULL) |
| 7917 | { |
| 7918 | /* The scope breakpoint is related to the watchpoint. We will |
| 7919 | need to act on them together. */ |
| 7920 | b->related_breakpoint = scope_breakpoint; |
| 7921 | scope_breakpoint->related_breakpoint = b; |
| 7922 | } |
| 7923 | |
| 7924 | value_free_to_mark (mark); |
| 7925 | |
| 7926 | /* Finally update the new watchpoint. This creates the locations |
| 7927 | that should be inserted. */ |
| 7928 | update_watchpoint (b, 1); |
| 7929 | |
| 7930 | mention (b); |
| 7931 | update_global_location_list (1); |
| 7932 | } |
| 7933 | |
| 7934 | /* Return count of locations need to be watched and can be handled |
| 7935 | in hardware. If the watchpoint can not be handled |
| 7936 | in hardware return zero. */ |
| 7937 | |
| 7938 | static int |
| 7939 | can_use_hardware_watchpoint (struct value *v) |
| 7940 | { |
| 7941 | int found_memory_cnt = 0; |
| 7942 | struct value *head = v; |
| 7943 | |
| 7944 | /* Did the user specifically forbid us to use hardware watchpoints? */ |
| 7945 | if (!can_use_hw_watchpoints) |
| 7946 | return 0; |
| 7947 | |
| 7948 | /* Make sure that the value of the expression depends only upon |
| 7949 | memory contents, and values computed from them within GDB. If we |
| 7950 | find any register references or function calls, we can't use a |
| 7951 | hardware watchpoint. |
| 7952 | |
| 7953 | The idea here is that evaluating an expression generates a series |
| 7954 | of values, one holding the value of every subexpression. (The |
| 7955 | expression a*b+c has five subexpressions: a, b, a*b, c, and |
| 7956 | a*b+c.) GDB's values hold almost enough information to establish |
| 7957 | the criteria given above --- they identify memory lvalues, |
| 7958 | register lvalues, computed values, etcetera. So we can evaluate |
| 7959 | the expression, and then scan the chain of values that leaves |
| 7960 | behind to decide whether we can detect any possible change to the |
| 7961 | expression's final value using only hardware watchpoints. |
| 7962 | |
| 7963 | However, I don't think that the values returned by inferior |
| 7964 | function calls are special in any way. So this function may not |
| 7965 | notice that an expression involving an inferior function call |
| 7966 | can't be watched with hardware watchpoints. FIXME. */ |
| 7967 | for (; v; v = value_next (v)) |
| 7968 | { |
| 7969 | if (VALUE_LVAL (v) == lval_memory) |
| 7970 | { |
| 7971 | if (value_lazy (v)) |
| 7972 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
| 7973 | we either just used its address (e.g., `a' in `a.b') or |
| 7974 | we never needed it at all (e.g., `a' in `a,b'). */ |
| 7975 | ; |
| 7976 | else |
| 7977 | { |
| 7978 | /* Ahh, memory we actually used! Check if we can cover |
| 7979 | it with hardware watchpoints. */ |
| 7980 | struct type *vtype = check_typedef (value_type (v)); |
| 7981 | |
| 7982 | /* We only watch structs and arrays if user asked for it |
| 7983 | explicitly, never if they just happen to appear in a |
| 7984 | middle of some value chain. */ |
| 7985 | if (v == head |
| 7986 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 7987 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 7988 | { |
| 7989 | CORE_ADDR vaddr = value_address (v); |
| 7990 | int len = TYPE_LENGTH (value_type (v)); |
| 7991 | |
| 7992 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
| 7993 | return 0; |
| 7994 | else |
| 7995 | found_memory_cnt++; |
| 7996 | } |
| 7997 | } |
| 7998 | } |
| 7999 | else if (VALUE_LVAL (v) != not_lval |
| 8000 | && deprecated_value_modifiable (v) == 0) |
| 8001 | return 0; /* ??? What does this represent? */ |
| 8002 | else if (VALUE_LVAL (v) == lval_register) |
| 8003 | return 0; /* cannot watch a register with a HW watchpoint */ |
| 8004 | } |
| 8005 | |
| 8006 | /* The expression itself looks suitable for using a hardware |
| 8007 | watchpoint, but give the target machine a chance to reject it. */ |
| 8008 | return found_memory_cnt; |
| 8009 | } |
| 8010 | |
| 8011 | void |
| 8012 | watch_command_wrapper (char *arg, int from_tty) |
| 8013 | { |
| 8014 | watch_command (arg, from_tty); |
| 8015 | } |
| 8016 | |
| 8017 | static void |
| 8018 | watch_command (char *arg, int from_tty) |
| 8019 | { |
| 8020 | watch_command_1 (arg, hw_write, from_tty); |
| 8021 | } |
| 8022 | |
| 8023 | void |
| 8024 | rwatch_command_wrapper (char *arg, int from_tty) |
| 8025 | { |
| 8026 | rwatch_command (arg, from_tty); |
| 8027 | } |
| 8028 | |
| 8029 | static void |
| 8030 | rwatch_command (char *arg, int from_tty) |
| 8031 | { |
| 8032 | watch_command_1 (arg, hw_read, from_tty); |
| 8033 | } |
| 8034 | |
| 8035 | void |
| 8036 | awatch_command_wrapper (char *arg, int from_tty) |
| 8037 | { |
| 8038 | awatch_command (arg, from_tty); |
| 8039 | } |
| 8040 | |
| 8041 | static void |
| 8042 | awatch_command (char *arg, int from_tty) |
| 8043 | { |
| 8044 | watch_command_1 (arg, hw_access, from_tty); |
| 8045 | } |
| 8046 | \f |
| 8047 | |
| 8048 | /* Helper routines for the until_command routine in infcmd.c. Here |
| 8049 | because it uses the mechanisms of breakpoints. */ |
| 8050 | |
| 8051 | struct until_break_command_continuation_args |
| 8052 | { |
| 8053 | struct breakpoint *breakpoint; |
| 8054 | struct breakpoint *breakpoint2; |
| 8055 | }; |
| 8056 | |
| 8057 | /* This function is called by fetch_inferior_event via the |
| 8058 | cmd_continuation pointer, to complete the until command. It takes |
| 8059 | care of cleaning up the temporary breakpoints set up by the until |
| 8060 | command. */ |
| 8061 | static void |
| 8062 | until_break_command_continuation (void *arg) |
| 8063 | { |
| 8064 | struct until_break_command_continuation_args *a = arg; |
| 8065 | |
| 8066 | delete_breakpoint (a->breakpoint); |
| 8067 | if (a->breakpoint2) |
| 8068 | delete_breakpoint (a->breakpoint2); |
| 8069 | } |
| 8070 | |
| 8071 | void |
| 8072 | until_break_command (char *arg, int from_tty, int anywhere) |
| 8073 | { |
| 8074 | struct symtabs_and_lines sals; |
| 8075 | struct symtab_and_line sal; |
| 8076 | struct frame_info *frame = get_selected_frame (NULL); |
| 8077 | struct breakpoint *breakpoint; |
| 8078 | struct breakpoint *breakpoint2 = NULL; |
| 8079 | struct cleanup *old_chain; |
| 8080 | |
| 8081 | clear_proceed_status (); |
| 8082 | |
| 8083 | /* Set a breakpoint where the user wants it and at return from |
| 8084 | this function */ |
| 8085 | |
| 8086 | if (default_breakpoint_valid) |
| 8087 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, |
| 8088 | default_breakpoint_line, (char ***) NULL, NULL); |
| 8089 | else |
| 8090 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
| 8091 | 0, (char ***) NULL, NULL); |
| 8092 | |
| 8093 | if (sals.nelts != 1) |
| 8094 | error (_("Couldn't get information on specified line.")); |
| 8095 | |
| 8096 | sal = sals.sals[0]; |
| 8097 | xfree (sals.sals); /* malloc'd, so freed */ |
| 8098 | |
| 8099 | if (*arg) |
| 8100 | error (_("Junk at end of arguments.")); |
| 8101 | |
| 8102 | resolve_sal_pc (&sal); |
| 8103 | |
| 8104 | if (anywhere) |
| 8105 | /* If the user told us to continue until a specified location, |
| 8106 | we don't specify a frame at which we need to stop. */ |
| 8107 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
| 8108 | null_frame_id, bp_until); |
| 8109 | else |
| 8110 | /* Otherwise, specify the selected frame, because we want to stop only |
| 8111 | at the very same frame. */ |
| 8112 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
| 8113 | get_stack_frame_id (frame), |
| 8114 | bp_until); |
| 8115 | |
| 8116 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
| 8117 | |
| 8118 | /* Keep within the current frame, or in frames called by the current |
| 8119 | one. */ |
| 8120 | |
| 8121 | if (frame_id_p (frame_unwind_caller_id (frame))) |
| 8122 | { |
| 8123 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
| 8124 | sal.pc = frame_unwind_caller_pc (frame); |
| 8125 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
| 8126 | sal, |
| 8127 | frame_unwind_caller_id (frame), |
| 8128 | bp_until); |
| 8129 | make_cleanup_delete_breakpoint (breakpoint2); |
| 8130 | } |
| 8131 | |
| 8132 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
| 8133 | |
| 8134 | /* If we are running asynchronously, and proceed call above has actually |
| 8135 | managed to start the target, arrange for breakpoints to be |
| 8136 | deleted when the target stops. Otherwise, we're already stopped and |
| 8137 | delete breakpoints via cleanup chain. */ |
| 8138 | |
| 8139 | if (target_can_async_p () && is_running (inferior_ptid)) |
| 8140 | { |
| 8141 | struct until_break_command_continuation_args *args; |
| 8142 | args = xmalloc (sizeof (*args)); |
| 8143 | |
| 8144 | args->breakpoint = breakpoint; |
| 8145 | args->breakpoint2 = breakpoint2; |
| 8146 | |
| 8147 | discard_cleanups (old_chain); |
| 8148 | add_continuation (inferior_thread (), |
| 8149 | until_break_command_continuation, args, |
| 8150 | xfree); |
| 8151 | } |
| 8152 | else |
| 8153 | do_cleanups (old_chain); |
| 8154 | } |
| 8155 | |
| 8156 | static void |
| 8157 | ep_skip_leading_whitespace (char **s) |
| 8158 | { |
| 8159 | if ((s == NULL) || (*s == NULL)) |
| 8160 | return; |
| 8161 | while (isspace (**s)) |
| 8162 | *s += 1; |
| 8163 | } |
| 8164 | |
| 8165 | /* This function attempts to parse an optional "if <cond>" clause |
| 8166 | from the arg string. If one is not found, it returns NULL. |
| 8167 | |
| 8168 | Else, it returns a pointer to the condition string. (It does not |
| 8169 | attempt to evaluate the string against a particular block.) And, |
| 8170 | it updates arg to point to the first character following the parsed |
| 8171 | if clause in the arg string. */ |
| 8172 | |
| 8173 | static char * |
| 8174 | ep_parse_optional_if_clause (char **arg) |
| 8175 | { |
| 8176 | char *cond_string; |
| 8177 | |
| 8178 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) |
| 8179 | return NULL; |
| 8180 | |
| 8181 | /* Skip the "if" keyword. */ |
| 8182 | (*arg) += 2; |
| 8183 | |
| 8184 | /* Skip any extra leading whitespace, and record the start of the |
| 8185 | condition string. */ |
| 8186 | ep_skip_leading_whitespace (arg); |
| 8187 | cond_string = *arg; |
| 8188 | |
| 8189 | /* Assume that the condition occupies the remainder of the arg string. */ |
| 8190 | (*arg) += strlen (cond_string); |
| 8191 | |
| 8192 | return cond_string; |
| 8193 | } |
| 8194 | |
| 8195 | /* Commands to deal with catching events, such as signals, exceptions, |
| 8196 | process start/exit, etc. */ |
| 8197 | |
| 8198 | typedef enum |
| 8199 | { |
| 8200 | catch_fork_temporary, catch_vfork_temporary, |
| 8201 | catch_fork_permanent, catch_vfork_permanent |
| 8202 | } |
| 8203 | catch_fork_kind; |
| 8204 | |
| 8205 | static void |
| 8206 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
| 8207 | { |
| 8208 | struct gdbarch *gdbarch = get_current_arch (); |
| 8209 | char *cond_string = NULL; |
| 8210 | catch_fork_kind fork_kind; |
| 8211 | int tempflag; |
| 8212 | |
| 8213 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); |
| 8214 | tempflag = (fork_kind == catch_fork_temporary |
| 8215 | || fork_kind == catch_vfork_temporary); |
| 8216 | |
| 8217 | if (!arg) |
| 8218 | arg = ""; |
| 8219 | ep_skip_leading_whitespace (&arg); |
| 8220 | |
| 8221 | /* The allowed syntax is: |
| 8222 | catch [v]fork |
| 8223 | catch [v]fork if <cond> |
| 8224 | |
| 8225 | First, check if there's an if clause. */ |
| 8226 | cond_string = ep_parse_optional_if_clause (&arg); |
| 8227 | |
| 8228 | if ((*arg != '\0') && !isspace (*arg)) |
| 8229 | error (_("Junk at end of arguments.")); |
| 8230 | |
| 8231 | /* If this target supports it, create a fork or vfork catchpoint |
| 8232 | and enable reporting of such events. */ |
| 8233 | switch (fork_kind) |
| 8234 | { |
| 8235 | case catch_fork_temporary: |
| 8236 | case catch_fork_permanent: |
| 8237 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 8238 | &catch_fork_breakpoint_ops); |
| 8239 | break; |
| 8240 | case catch_vfork_temporary: |
| 8241 | case catch_vfork_permanent: |
| 8242 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 8243 | &catch_vfork_breakpoint_ops); |
| 8244 | break; |
| 8245 | default: |
| 8246 | error (_("unsupported or unknown fork kind; cannot catch it")); |
| 8247 | break; |
| 8248 | } |
| 8249 | } |
| 8250 | |
| 8251 | static void |
| 8252 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
| 8253 | { |
| 8254 | struct gdbarch *gdbarch = get_current_arch (); |
| 8255 | int tempflag; |
| 8256 | char *cond_string = NULL; |
| 8257 | |
| 8258 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8259 | |
| 8260 | if (!arg) |
| 8261 | arg = ""; |
| 8262 | ep_skip_leading_whitespace (&arg); |
| 8263 | |
| 8264 | /* The allowed syntax is: |
| 8265 | catch exec |
| 8266 | catch exec if <cond> |
| 8267 | |
| 8268 | First, check if there's an if clause. */ |
| 8269 | cond_string = ep_parse_optional_if_clause (&arg); |
| 8270 | |
| 8271 | if ((*arg != '\0') && !isspace (*arg)) |
| 8272 | error (_("Junk at end of arguments.")); |
| 8273 | |
| 8274 | /* If this target supports it, create an exec catchpoint |
| 8275 | and enable reporting of such events. */ |
| 8276 | create_catchpoint (gdbarch, tempflag, cond_string, |
| 8277 | &catch_exec_breakpoint_ops); |
| 8278 | } |
| 8279 | |
| 8280 | static enum print_stop_action |
| 8281 | print_exception_catchpoint (struct breakpoint *b) |
| 8282 | { |
| 8283 | int bp_temp, bp_throw; |
| 8284 | |
| 8285 | annotate_catchpoint (b->number); |
| 8286 | |
| 8287 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
| 8288 | if (b->loc->address != b->loc->requested_address) |
| 8289 | breakpoint_adjustment_warning (b->loc->requested_address, |
| 8290 | b->loc->address, |
| 8291 | b->number, 1); |
| 8292 | bp_temp = b->disposition == disp_del; |
| 8293 | ui_out_text (uiout, |
| 8294 | bp_temp ? "Temporary catchpoint " |
| 8295 | : "Catchpoint "); |
| 8296 | if (!ui_out_is_mi_like_p (uiout)) |
| 8297 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8298 | ui_out_text (uiout, |
| 8299 | bp_throw ? " (exception thrown), " |
| 8300 | : " (exception caught), "); |
| 8301 | if (ui_out_is_mi_like_p (uiout)) |
| 8302 | { |
| 8303 | ui_out_field_string (uiout, "reason", |
| 8304 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 8305 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8306 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8307 | } |
| 8308 | return PRINT_SRC_AND_LOC; |
| 8309 | } |
| 8310 | |
| 8311 | static void |
| 8312 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
| 8313 | { |
| 8314 | struct value_print_options opts; |
| 8315 | get_user_print_options (&opts); |
| 8316 | if (opts.addressprint) |
| 8317 | { |
| 8318 | annotate_field (4); |
| 8319 | if (b->loc == NULL || b->loc->shlib_disabled) |
| 8320 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
| 8321 | else |
| 8322 | ui_out_field_core_addr (uiout, "addr", |
| 8323 | b->loc->gdbarch, b->loc->address); |
| 8324 | } |
| 8325 | annotate_field (5); |
| 8326 | if (b->loc) |
| 8327 | *last_loc = b->loc; |
| 8328 | if (strstr (b->addr_string, "throw") != NULL) |
| 8329 | ui_out_field_string (uiout, "what", "exception throw"); |
| 8330 | else |
| 8331 | ui_out_field_string (uiout, "what", "exception catch"); |
| 8332 | } |
| 8333 | |
| 8334 | static void |
| 8335 | print_mention_exception_catchpoint (struct breakpoint *b) |
| 8336 | { |
| 8337 | int bp_temp; |
| 8338 | int bp_throw; |
| 8339 | |
| 8340 | bp_temp = b->disposition == disp_del; |
| 8341 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
| 8342 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") |
| 8343 | : _("Catchpoint ")); |
| 8344 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8345 | ui_out_text (uiout, bp_throw ? _(" (throw)") |
| 8346 | : _(" (catch)")); |
| 8347 | } |
| 8348 | |
| 8349 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
| 8350 | catch catchpoints. */ |
| 8351 | |
| 8352 | static void |
| 8353 | print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp) |
| 8354 | { |
| 8355 | int bp_temp; |
| 8356 | int bp_throw; |
| 8357 | |
| 8358 | bp_temp = b->disposition == disp_del; |
| 8359 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
| 8360 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); |
| 8361 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); |
| 8362 | } |
| 8363 | |
| 8364 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
| 8365 | NULL, /* insert */ |
| 8366 | NULL, /* remove */ |
| 8367 | NULL, /* breakpoint_hit */ |
| 8368 | print_exception_catchpoint, |
| 8369 | print_one_exception_catchpoint, |
| 8370 | print_mention_exception_catchpoint, |
| 8371 | print_recreate_exception_catchpoint |
| 8372 | }; |
| 8373 | |
| 8374 | static int |
| 8375 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, |
| 8376 | enum exception_event_kind ex_event, int from_tty) |
| 8377 | { |
| 8378 | char *trigger_func_name; |
| 8379 | |
| 8380 | if (ex_event == EX_EVENT_CATCH) |
| 8381 | trigger_func_name = "__cxa_begin_catch"; |
| 8382 | else |
| 8383 | trigger_func_name = "__cxa_throw"; |
| 8384 | |
| 8385 | create_breakpoint (get_current_arch (), |
| 8386 | trigger_func_name, cond_string, -1, |
| 8387 | 0 /* condition and thread are valid. */, |
| 8388 | tempflag, 0, 0, |
| 8389 | 0, |
| 8390 | AUTO_BOOLEAN_TRUE /* pending */, |
| 8391 | &gnu_v3_exception_catchpoint_ops, from_tty, |
| 8392 | 1 /* enabled */); |
| 8393 | |
| 8394 | return 1; |
| 8395 | } |
| 8396 | |
| 8397 | /* Deal with "catch catch" and "catch throw" commands */ |
| 8398 | |
| 8399 | static void |
| 8400 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
| 8401 | int tempflag, int from_tty) |
| 8402 | { |
| 8403 | char *cond_string = NULL; |
| 8404 | struct symtab_and_line *sal = NULL; |
| 8405 | |
| 8406 | if (!arg) |
| 8407 | arg = ""; |
| 8408 | ep_skip_leading_whitespace (&arg); |
| 8409 | |
| 8410 | cond_string = ep_parse_optional_if_clause (&arg); |
| 8411 | |
| 8412 | if ((*arg != '\0') && !isspace (*arg)) |
| 8413 | error (_("Junk at end of arguments.")); |
| 8414 | |
| 8415 | if (ex_event != EX_EVENT_THROW |
| 8416 | && ex_event != EX_EVENT_CATCH) |
| 8417 | error (_("Unsupported or unknown exception event; cannot catch it")); |
| 8418 | |
| 8419 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
| 8420 | return; |
| 8421 | |
| 8422 | warning (_("Unsupported with this platform/compiler combination.")); |
| 8423 | } |
| 8424 | |
| 8425 | /* Implementation of "catch catch" command. */ |
| 8426 | |
| 8427 | static void |
| 8428 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) |
| 8429 | { |
| 8430 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8431 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
| 8432 | } |
| 8433 | |
| 8434 | /* Implementation of "catch throw" command. */ |
| 8435 | |
| 8436 | static void |
| 8437 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) |
| 8438 | { |
| 8439 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8440 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
| 8441 | } |
| 8442 | |
| 8443 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
| 8444 | |
| 8445 | static void |
| 8446 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
| 8447 | struct symtab_and_line sal, |
| 8448 | char *addr_string, |
| 8449 | char *exp_string, |
| 8450 | char *cond_string, |
| 8451 | struct expression *cond, |
| 8452 | struct breakpoint_ops *ops, |
| 8453 | int tempflag, |
| 8454 | int from_tty) |
| 8455 | { |
| 8456 | struct breakpoint *b; |
| 8457 | |
| 8458 | if (from_tty) |
| 8459 | { |
| 8460 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 8461 | if (!loc_gdbarch) |
| 8462 | loc_gdbarch = gdbarch; |
| 8463 | |
| 8464 | describe_other_breakpoints (loc_gdbarch, |
| 8465 | sal.pspace, sal.pc, sal.section, -1); |
| 8466 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
| 8467 | version for exception catchpoints, because two catchpoints |
| 8468 | used for different exception names will use the same address. |
| 8469 | In this case, a "breakpoint ... also set at..." warning is |
| 8470 | unproductive. Besides. the warning phrasing is also a bit |
| 8471 | inapropriate, we should use the word catchpoint, and tell |
| 8472 | the user what type of catchpoint it is. The above is good |
| 8473 | enough for now, though. */ |
| 8474 | } |
| 8475 | |
| 8476 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
| 8477 | set_breakpoint_count (breakpoint_count + 1); |
| 8478 | |
| 8479 | b->enable_state = bp_enabled; |
| 8480 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 8481 | b->number = breakpoint_count; |
| 8482 | b->ignore_count = 0; |
| 8483 | b->loc->cond = cond; |
| 8484 | b->addr_string = addr_string; |
| 8485 | b->language = language_ada; |
| 8486 | b->cond_string = cond_string; |
| 8487 | b->exp_string = exp_string; |
| 8488 | b->thread = -1; |
| 8489 | b->ops = ops; |
| 8490 | |
| 8491 | mention (b); |
| 8492 | update_global_location_list (1); |
| 8493 | } |
| 8494 | |
| 8495 | /* Implement the "catch exception" command. */ |
| 8496 | |
| 8497 | static void |
| 8498 | catch_ada_exception_command (char *arg, int from_tty, |
| 8499 | struct cmd_list_element *command) |
| 8500 | { |
| 8501 | struct gdbarch *gdbarch = get_current_arch (); |
| 8502 | int tempflag; |
| 8503 | struct symtab_and_line sal; |
| 8504 | enum bptype type; |
| 8505 | char *addr_string = NULL; |
| 8506 | char *exp_string = NULL; |
| 8507 | char *cond_string = NULL; |
| 8508 | struct expression *cond = NULL; |
| 8509 | struct breakpoint_ops *ops = NULL; |
| 8510 | |
| 8511 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8512 | |
| 8513 | if (!arg) |
| 8514 | arg = ""; |
| 8515 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
| 8516 | &cond_string, &cond, &ops); |
| 8517 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
| 8518 | cond_string, cond, ops, tempflag, |
| 8519 | from_tty); |
| 8520 | } |
| 8521 | |
| 8522 | /* Cleanup function for a syscall filter list. */ |
| 8523 | static void |
| 8524 | clean_up_filters (void *arg) |
| 8525 | { |
| 8526 | VEC(int) *iter = *(VEC(int) **) arg; |
| 8527 | VEC_free (int, iter); |
| 8528 | } |
| 8529 | |
| 8530 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
| 8531 | filter list, or NULL if no filtering is required. */ |
| 8532 | static VEC(int) * |
| 8533 | catch_syscall_split_args (char *arg) |
| 8534 | { |
| 8535 | VEC(int) *result = NULL; |
| 8536 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); |
| 8537 | |
| 8538 | while (*arg != '\0') |
| 8539 | { |
| 8540 | int i, syscall_number; |
| 8541 | char *endptr; |
| 8542 | char cur_name[128]; |
| 8543 | struct syscall s; |
| 8544 | |
| 8545 | /* Skip whitespace. */ |
| 8546 | while (isspace (*arg)) |
| 8547 | arg++; |
| 8548 | |
| 8549 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) |
| 8550 | cur_name[i] = arg[i]; |
| 8551 | cur_name[i] = '\0'; |
| 8552 | arg += i; |
| 8553 | |
| 8554 | /* Check if the user provided a syscall name or a number. */ |
| 8555 | syscall_number = (int) strtol (cur_name, &endptr, 0); |
| 8556 | if (*endptr == '\0') |
| 8557 | get_syscall_by_number (syscall_number, &s); |
| 8558 | else |
| 8559 | { |
| 8560 | /* We have a name. Let's check if it's valid and convert it |
| 8561 | to a number. */ |
| 8562 | get_syscall_by_name (cur_name, &s); |
| 8563 | |
| 8564 | if (s.number == UNKNOWN_SYSCALL) |
| 8565 | /* Here we have to issue an error instead of a warning, because |
| 8566 | GDB cannot do anything useful if there's no syscall number to |
| 8567 | be caught. */ |
| 8568 | error (_("Unknown syscall name '%s'."), cur_name); |
| 8569 | } |
| 8570 | |
| 8571 | /* Ok, it's valid. */ |
| 8572 | VEC_safe_push (int, result, s.number); |
| 8573 | } |
| 8574 | |
| 8575 | discard_cleanups (cleanup); |
| 8576 | return result; |
| 8577 | } |
| 8578 | |
| 8579 | /* Implement the "catch syscall" command. */ |
| 8580 | |
| 8581 | static void |
| 8582 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
| 8583 | { |
| 8584 | int tempflag; |
| 8585 | VEC(int) *filter; |
| 8586 | struct syscall s; |
| 8587 | struct gdbarch *gdbarch = get_current_arch (); |
| 8588 | |
| 8589 | /* Checking if the feature if supported. */ |
| 8590 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) |
| 8591 | error (_("The feature 'catch syscall' is not supported on \ |
| 8592 | this architeture yet.")); |
| 8593 | |
| 8594 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8595 | |
| 8596 | ep_skip_leading_whitespace (&arg); |
| 8597 | |
| 8598 | /* We need to do this first "dummy" translation in order |
| 8599 | to get the syscall XML file loaded or, most important, |
| 8600 | to display a warning to the user if there's no XML file |
| 8601 | for his/her architecture. */ |
| 8602 | get_syscall_by_number (0, &s); |
| 8603 | |
| 8604 | /* The allowed syntax is: |
| 8605 | catch syscall |
| 8606 | catch syscall <name | number> [<name | number> ... <name | number>] |
| 8607 | |
| 8608 | Let's check if there's a syscall name. */ |
| 8609 | |
| 8610 | if (arg != NULL) |
| 8611 | filter = catch_syscall_split_args (arg); |
| 8612 | else |
| 8613 | filter = NULL; |
| 8614 | |
| 8615 | create_syscall_event_catchpoint (tempflag, filter, |
| 8616 | &catch_syscall_breakpoint_ops); |
| 8617 | } |
| 8618 | |
| 8619 | /* Implement the "catch assert" command. */ |
| 8620 | |
| 8621 | static void |
| 8622 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
| 8623 | { |
| 8624 | struct gdbarch *gdbarch = get_current_arch (); |
| 8625 | int tempflag; |
| 8626 | struct symtab_and_line sal; |
| 8627 | char *addr_string = NULL; |
| 8628 | struct breakpoint_ops *ops = NULL; |
| 8629 | |
| 8630 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8631 | |
| 8632 | if (!arg) |
| 8633 | arg = ""; |
| 8634 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
| 8635 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
| 8636 | ops, tempflag, from_tty); |
| 8637 | } |
| 8638 | |
| 8639 | static void |
| 8640 | catch_command (char *arg, int from_tty) |
| 8641 | { |
| 8642 | error (_("Catch requires an event name.")); |
| 8643 | } |
| 8644 | \f |
| 8645 | |
| 8646 | static void |
| 8647 | tcatch_command (char *arg, int from_tty) |
| 8648 | { |
| 8649 | error (_("Catch requires an event name.")); |
| 8650 | } |
| 8651 | |
| 8652 | /* Delete breakpoints by address or line. */ |
| 8653 | |
| 8654 | static void |
| 8655 | clear_command (char *arg, int from_tty) |
| 8656 | { |
| 8657 | struct breakpoint *b; |
| 8658 | VEC(breakpoint_p) *found = 0; |
| 8659 | int ix; |
| 8660 | int default_match; |
| 8661 | struct symtabs_and_lines sals; |
| 8662 | struct symtab_and_line sal; |
| 8663 | int i; |
| 8664 | |
| 8665 | if (arg) |
| 8666 | { |
| 8667 | sals = decode_line_spec (arg, 1); |
| 8668 | default_match = 0; |
| 8669 | } |
| 8670 | else |
| 8671 | { |
| 8672 | sals.sals = (struct symtab_and_line *) |
| 8673 | xmalloc (sizeof (struct symtab_and_line)); |
| 8674 | make_cleanup (xfree, sals.sals); |
| 8675 | init_sal (&sal); /* initialize to zeroes */ |
| 8676 | sal.line = default_breakpoint_line; |
| 8677 | sal.symtab = default_breakpoint_symtab; |
| 8678 | sal.pc = default_breakpoint_address; |
| 8679 | sal.pspace = default_breakpoint_pspace; |
| 8680 | if (sal.symtab == 0) |
| 8681 | error (_("No source file specified.")); |
| 8682 | |
| 8683 | sals.sals[0] = sal; |
| 8684 | sals.nelts = 1; |
| 8685 | |
| 8686 | default_match = 1; |
| 8687 | } |
| 8688 | |
| 8689 | /* We don't call resolve_sal_pc here. That's not |
| 8690 | as bad as it seems, because all existing breakpoints |
| 8691 | typically have both file/line and pc set. So, if |
| 8692 | clear is given file/line, we can match this to existing |
| 8693 | breakpoint without obtaining pc at all. |
| 8694 | |
| 8695 | We only support clearing given the address explicitly |
| 8696 | present in breakpoint table. Say, we've set breakpoint |
| 8697 | at file:line. There were several PC values for that file:line, |
| 8698 | due to optimization, all in one block. |
| 8699 | We've picked one PC value. If "clear" is issued with another |
| 8700 | PC corresponding to the same file:line, the breakpoint won't |
| 8701 | be cleared. We probably can still clear the breakpoint, but |
| 8702 | since the other PC value is never presented to user, user |
| 8703 | can only find it by guessing, and it does not seem important |
| 8704 | to support that. */ |
| 8705 | |
| 8706 | /* For each line spec given, delete bps which correspond |
| 8707 | to it. Do it in two passes, solely to preserve the current |
| 8708 | behavior that from_tty is forced true if we delete more than |
| 8709 | one breakpoint. */ |
| 8710 | |
| 8711 | found = NULL; |
| 8712 | for (i = 0; i < sals.nelts; i++) |
| 8713 | { |
| 8714 | /* If exact pc given, clear bpts at that pc. |
| 8715 | If line given (pc == 0), clear all bpts on specified line. |
| 8716 | If defaulting, clear all bpts on default line |
| 8717 | or at default pc. |
| 8718 | |
| 8719 | defaulting sal.pc != 0 tests to do |
| 8720 | |
| 8721 | 0 1 pc |
| 8722 | 1 1 pc _and_ line |
| 8723 | 0 0 line |
| 8724 | 1 0 <can't happen> */ |
| 8725 | |
| 8726 | sal = sals.sals[i]; |
| 8727 | |
| 8728 | /* Find all matching breakpoints and add them to |
| 8729 | 'found'. */ |
| 8730 | ALL_BREAKPOINTS (b) |
| 8731 | { |
| 8732 | int match = 0; |
| 8733 | /* Are we going to delete b? */ |
| 8734 | if (b->type != bp_none && !is_watchpoint (b)) |
| 8735 | { |
| 8736 | struct bp_location *loc = b->loc; |
| 8737 | for (; loc; loc = loc->next) |
| 8738 | { |
| 8739 | int pc_match = sal.pc |
| 8740 | && (loc->pspace == sal.pspace) |
| 8741 | && (loc->address == sal.pc) |
| 8742 | && (!section_is_overlay (loc->section) |
| 8743 | || loc->section == sal.section); |
| 8744 | int line_match = ((default_match || (0 == sal.pc)) |
| 8745 | && b->source_file != NULL |
| 8746 | && sal.symtab != NULL |
| 8747 | && sal.pspace == loc->pspace |
| 8748 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
| 8749 | && b->line_number == sal.line); |
| 8750 | if (pc_match || line_match) |
| 8751 | { |
| 8752 | match = 1; |
| 8753 | break; |
| 8754 | } |
| 8755 | } |
| 8756 | } |
| 8757 | |
| 8758 | if (match) |
| 8759 | VEC_safe_push(breakpoint_p, found, b); |
| 8760 | } |
| 8761 | } |
| 8762 | /* Now go thru the 'found' chain and delete them. */ |
| 8763 | if (VEC_empty(breakpoint_p, found)) |
| 8764 | { |
| 8765 | if (arg) |
| 8766 | error (_("No breakpoint at %s."), arg); |
| 8767 | else |
| 8768 | error (_("No breakpoint at this line.")); |
| 8769 | } |
| 8770 | |
| 8771 | if (VEC_length(breakpoint_p, found) > 1) |
| 8772 | from_tty = 1; /* Always report if deleted more than one */ |
| 8773 | if (from_tty) |
| 8774 | { |
| 8775 | if (VEC_length(breakpoint_p, found) == 1) |
| 8776 | printf_unfiltered (_("Deleted breakpoint ")); |
| 8777 | else |
| 8778 | printf_unfiltered (_("Deleted breakpoints ")); |
| 8779 | } |
| 8780 | breakpoints_changed (); |
| 8781 | |
| 8782 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) |
| 8783 | { |
| 8784 | if (from_tty) |
| 8785 | printf_unfiltered ("%d ", b->number); |
| 8786 | delete_breakpoint (b); |
| 8787 | } |
| 8788 | if (from_tty) |
| 8789 | putchar_unfiltered ('\n'); |
| 8790 | } |
| 8791 | \f |
| 8792 | /* Delete breakpoint in BS if they are `delete' breakpoints and |
| 8793 | all breakpoints that are marked for deletion, whether hit or not. |
| 8794 | This is called after any breakpoint is hit, or after errors. */ |
| 8795 | |
| 8796 | void |
| 8797 | breakpoint_auto_delete (bpstat bs) |
| 8798 | { |
| 8799 | struct breakpoint *b, *temp; |
| 8800 | |
| 8801 | for (; bs; bs = bs->next) |
| 8802 | if (bs->breakpoint_at |
| 8803 | && bs->breakpoint_at->owner |
| 8804 | && bs->breakpoint_at->owner->disposition == disp_del |
| 8805 | && bs->stop) |
| 8806 | delete_breakpoint (bs->breakpoint_at->owner); |
| 8807 | |
| 8808 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 8809 | { |
| 8810 | if (b->disposition == disp_del_at_next_stop) |
| 8811 | delete_breakpoint (b); |
| 8812 | } |
| 8813 | } |
| 8814 | |
| 8815 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
| 8816 | Sort elements primarily by their ADDRESS (no matter what does |
| 8817 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering |
| 8818 | first bp_permanent OWNERed elements and terciarily just ensuring the array |
| 8819 | is sorted stable way despite qsort being an instable algorithm. */ |
| 8820 | |
| 8821 | static int |
| 8822 | bp_location_compare (const void *ap, const void *bp) |
| 8823 | { |
| 8824 | struct bp_location *a = *(void **) ap; |
| 8825 | struct bp_location *b = *(void **) bp; |
| 8826 | int a_perm = a->owner->enable_state == bp_permanent; |
| 8827 | int b_perm = b->owner->enable_state == bp_permanent; |
| 8828 | |
| 8829 | if (a->address != b->address) |
| 8830 | return (a->address > b->address) - (a->address < b->address); |
| 8831 | |
| 8832 | /* Sort permanent breakpoints first. */ |
| 8833 | if (a_perm != b_perm) |
| 8834 | return (a_perm < b_perm) - (a_perm > b_perm); |
| 8835 | |
| 8836 | /* Make the user-visible order stable across GDB runs. Locations of the same |
| 8837 | breakpoint can be sorted in arbitrary order. */ |
| 8838 | |
| 8839 | if (a->owner->number != b->owner->number) |
| 8840 | return (a->owner->number > b->owner->number) |
| 8841 | - (a->owner->number < b->owner->number); |
| 8842 | |
| 8843 | return (a > b) - (a < b); |
| 8844 | } |
| 8845 | |
| 8846 | /* Set bp_location_placed_address_before_address_max and |
| 8847 | bp_location_shadow_len_after_address_max according to the current content of |
| 8848 | the bp_location array. */ |
| 8849 | |
| 8850 | static void |
| 8851 | bp_location_target_extensions_update (void) |
| 8852 | { |
| 8853 | struct bp_location *bl, **blp_tmp; |
| 8854 | |
| 8855 | bp_location_placed_address_before_address_max = 0; |
| 8856 | bp_location_shadow_len_after_address_max = 0; |
| 8857 | |
| 8858 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 8859 | { |
| 8860 | CORE_ADDR start, end, addr; |
| 8861 | |
| 8862 | if (!bp_location_has_shadow (bl)) |
| 8863 | continue; |
| 8864 | |
| 8865 | start = bl->target_info.placed_address; |
| 8866 | end = start + bl->target_info.shadow_len; |
| 8867 | |
| 8868 | gdb_assert (bl->address >= start); |
| 8869 | addr = bl->address - start; |
| 8870 | if (addr > bp_location_placed_address_before_address_max) |
| 8871 | bp_location_placed_address_before_address_max = addr; |
| 8872 | |
| 8873 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ |
| 8874 | |
| 8875 | gdb_assert (bl->address < end); |
| 8876 | addr = end - bl->address; |
| 8877 | if (addr > bp_location_shadow_len_after_address_max) |
| 8878 | bp_location_shadow_len_after_address_max = addr; |
| 8879 | } |
| 8880 | } |
| 8881 | |
| 8882 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
| 8883 | into the inferior, only remove already-inserted locations that no |
| 8884 | longer should be inserted. Functions that delete a breakpoint or |
| 8885 | breakpoints should pass false, so that deleting a breakpoint |
| 8886 | doesn't have the side effect of inserting the locations of other |
| 8887 | breakpoints that are marked not-inserted, but should_be_inserted |
| 8888 | returns true on them. |
| 8889 | |
| 8890 | This behaviour is useful is situations close to tear-down -- e.g., |
| 8891 | after an exec, while the target still has execution, but breakpoint |
| 8892 | shadows of the previous executable image should *NOT* be restored |
| 8893 | to the new image; or before detaching, where the target still has |
| 8894 | execution and wants to delete breakpoints from GDB's lists, and all |
| 8895 | breakpoints had already been removed from the inferior. */ |
| 8896 | |
| 8897 | static void |
| 8898 | update_global_location_list (int should_insert) |
| 8899 | { |
| 8900 | struct breakpoint *b; |
| 8901 | struct bp_location **locp, *loc; |
| 8902 | struct cleanup *cleanups; |
| 8903 | |
| 8904 | /* Used in the duplicates detection below. When iterating over all |
| 8905 | bp_locations, points to the first bp_location of a given address. |
| 8906 | Breakpoints and watchpoints of different types are never |
| 8907 | duplicates of each other. Keep one pointer for each type of |
| 8908 | breakpoint/watchpoint, so we only need to loop over all locations |
| 8909 | once. */ |
| 8910 | struct bp_location *bp_loc_first; /* breakpoint */ |
| 8911 | struct bp_location *wp_loc_first; /* hardware watchpoint */ |
| 8912 | struct bp_location *awp_loc_first; /* access watchpoint */ |
| 8913 | struct bp_location *rwp_loc_first; /* read watchpoint */ |
| 8914 | |
| 8915 | /* Saved former bp_location array which we compare against the newly built |
| 8916 | bp_location from the current state of ALL_BREAKPOINTS. */ |
| 8917 | struct bp_location **old_location, **old_locp; |
| 8918 | unsigned old_location_count; |
| 8919 | |
| 8920 | old_location = bp_location; |
| 8921 | old_location_count = bp_location_count; |
| 8922 | bp_location = NULL; |
| 8923 | bp_location_count = 0; |
| 8924 | cleanups = make_cleanup (xfree, old_location); |
| 8925 | |
| 8926 | ALL_BREAKPOINTS (b) |
| 8927 | for (loc = b->loc; loc; loc = loc->next) |
| 8928 | bp_location_count++; |
| 8929 | |
| 8930 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); |
| 8931 | locp = bp_location; |
| 8932 | ALL_BREAKPOINTS (b) |
| 8933 | for (loc = b->loc; loc; loc = loc->next) |
| 8934 | *locp++ = loc; |
| 8935 | qsort (bp_location, bp_location_count, sizeof (*bp_location), |
| 8936 | bp_location_compare); |
| 8937 | |
| 8938 | bp_location_target_extensions_update (); |
| 8939 | |
| 8940 | /* Identify bp_location instances that are no longer present in the new |
| 8941 | list, and therefore should be freed. Note that it's not necessary that |
| 8942 | those locations should be removed from inferior -- if there's another |
| 8943 | location at the same address (previously marked as duplicate), |
| 8944 | we don't need to remove/insert the location. |
| 8945 | |
| 8946 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and |
| 8947 | former bp_location array state respectively. */ |
| 8948 | |
| 8949 | locp = bp_location; |
| 8950 | for (old_locp = old_location; old_locp < old_location + old_location_count; |
| 8951 | old_locp++) |
| 8952 | { |
| 8953 | struct bp_location *old_loc = *old_locp; |
| 8954 | struct bp_location **loc2p; |
| 8955 | |
| 8956 | /* Tells if 'old_loc' is found amoung the new locations. If not, we |
| 8957 | have to free it. */ |
| 8958 | int found_object = 0; |
| 8959 | /* Tells if the location should remain inserted in the target. */ |
| 8960 | int keep_in_target = 0; |
| 8961 | int removed = 0; |
| 8962 | |
| 8963 | /* Skip LOCP entries which will definitely never be needed. Stop either |
| 8964 | at or being the one matching OLD_LOC. */ |
| 8965 | while (locp < bp_location + bp_location_count |
| 8966 | && (*locp)->address < old_loc->address) |
| 8967 | locp++; |
| 8968 | |
| 8969 | for (loc2p = locp; |
| 8970 | (loc2p < bp_location + bp_location_count |
| 8971 | && (*loc2p)->address == old_loc->address); |
| 8972 | loc2p++) |
| 8973 | { |
| 8974 | if (*loc2p == old_loc) |
| 8975 | { |
| 8976 | found_object = 1; |
| 8977 | break; |
| 8978 | } |
| 8979 | } |
| 8980 | |
| 8981 | /* If this location is no longer present, and inserted, look if there's |
| 8982 | maybe a new location at the same address. If so, mark that one |
| 8983 | inserted, and don't remove this one. This is needed so that we |
| 8984 | don't have a time window where a breakpoint at certain location is not |
| 8985 | inserted. */ |
| 8986 | |
| 8987 | if (old_loc->inserted) |
| 8988 | { |
| 8989 | /* If the location is inserted now, we might have to remove it. */ |
| 8990 | |
| 8991 | if (found_object && should_be_inserted (old_loc)) |
| 8992 | { |
| 8993 | /* The location is still present in the location list, and still |
| 8994 | should be inserted. Don't do anything. */ |
| 8995 | keep_in_target = 1; |
| 8996 | } |
| 8997 | else |
| 8998 | { |
| 8999 | /* The location is either no longer present, or got disabled. |
| 9000 | See if there's another location at the same address, in which |
| 9001 | case we don't need to remove this one from the target. */ |
| 9002 | |
| 9003 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
| 9004 | { |
| 9005 | for (loc2p = locp; |
| 9006 | (loc2p < bp_location + bp_location_count |
| 9007 | && (*loc2p)->address == old_loc->address); |
| 9008 | loc2p++) |
| 9009 | { |
| 9010 | struct bp_location *loc2 = *loc2p; |
| 9011 | |
| 9012 | if (breakpoint_locations_match (loc2, old_loc)) |
| 9013 | { |
| 9014 | /* For the sake of should_be_inserted. |
| 9015 | Duplicates check below will fix up this later. */ |
| 9016 | loc2->duplicate = 0; |
| 9017 | |
| 9018 | /* Read watchpoint locations are switched to |
| 9019 | access watchpoints, if the former are not |
| 9020 | supported, but the latter are. */ |
| 9021 | if (is_hardware_watchpoint (old_loc->owner)) |
| 9022 | { |
| 9023 | gdb_assert (is_hardware_watchpoint (loc2->owner)); |
| 9024 | loc2->watchpoint_type = old_loc->watchpoint_type; |
| 9025 | } |
| 9026 | |
| 9027 | if (loc2 != old_loc && should_be_inserted (loc2)) |
| 9028 | { |
| 9029 | loc2->inserted = 1; |
| 9030 | loc2->target_info = old_loc->target_info; |
| 9031 | keep_in_target = 1; |
| 9032 | break; |
| 9033 | } |
| 9034 | } |
| 9035 | } |
| 9036 | } |
| 9037 | } |
| 9038 | |
| 9039 | if (!keep_in_target) |
| 9040 | { |
| 9041 | if (remove_breakpoint (old_loc, mark_uninserted)) |
| 9042 | { |
| 9043 | /* This is just about all we can do. We could keep this |
| 9044 | location on the global list, and try to remove it next |
| 9045 | time, but there's no particular reason why we will |
| 9046 | succeed next time. |
| 9047 | |
| 9048 | Note that at this point, old_loc->owner is still valid, |
| 9049 | as delete_breakpoint frees the breakpoint only |
| 9050 | after calling us. */ |
| 9051 | printf_filtered (_("warning: Error removing breakpoint %d\n"), |
| 9052 | old_loc->owner->number); |
| 9053 | } |
| 9054 | removed = 1; |
| 9055 | } |
| 9056 | } |
| 9057 | |
| 9058 | if (!found_object) |
| 9059 | { |
| 9060 | if (removed && non_stop |
| 9061 | && breakpoint_address_is_meaningful (old_loc->owner) |
| 9062 | && !is_hardware_watchpoint (old_loc->owner)) |
| 9063 | { |
| 9064 | /* This location was removed from the target. In |
| 9065 | non-stop mode, a race condition is possible where |
| 9066 | we've removed a breakpoint, but stop events for that |
| 9067 | breakpoint are already queued and will arrive later. |
| 9068 | We apply an heuristic to be able to distinguish such |
| 9069 | SIGTRAPs from other random SIGTRAPs: we keep this |
| 9070 | breakpoint location for a bit, and will retire it |
| 9071 | after we see some number of events. The theory here |
| 9072 | is that reporting of events should, "on the average", |
| 9073 | be fair, so after a while we'll see events from all |
| 9074 | threads that have anything of interest, and no longer |
| 9075 | need to keep this breakpoint location around. We |
| 9076 | don't hold locations forever so to reduce chances of |
| 9077 | mistaking a non-breakpoint SIGTRAP for a breakpoint |
| 9078 | SIGTRAP. |
| 9079 | |
| 9080 | The heuristic failing can be disastrous on |
| 9081 | decr_pc_after_break targets. |
| 9082 | |
| 9083 | On decr_pc_after_break targets, like e.g., x86-linux, |
| 9084 | if we fail to recognize a late breakpoint SIGTRAP, |
| 9085 | because events_till_retirement has reached 0 too |
| 9086 | soon, we'll fail to do the PC adjustment, and report |
| 9087 | a random SIGTRAP to the user. When the user resumes |
| 9088 | the inferior, it will most likely immediately crash |
| 9089 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently |
| 9090 | corrupted, because of being resumed e.g., in the |
| 9091 | middle of a multi-byte instruction, or skipped a |
| 9092 | one-byte instruction. This was actually seen happen |
| 9093 | on native x86-linux, and should be less rare on |
| 9094 | targets that do not support new thread events, like |
| 9095 | remote, due to the heuristic depending on |
| 9096 | thread_count. |
| 9097 | |
| 9098 | Mistaking a random SIGTRAP for a breakpoint trap |
| 9099 | causes similar symptoms (PC adjustment applied when |
| 9100 | it shouldn't), but then again, playing with SIGTRAPs |
| 9101 | behind the debugger's back is asking for trouble. |
| 9102 | |
| 9103 | Since hardware watchpoint traps are always |
| 9104 | distinguishable from other traps, so we don't need to |
| 9105 | apply keep hardware watchpoint moribund locations |
| 9106 | around. We simply always ignore hardware watchpoint |
| 9107 | traps we can no longer explain. */ |
| 9108 | |
| 9109 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
| 9110 | old_loc->owner = NULL; |
| 9111 | |
| 9112 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
| 9113 | } |
| 9114 | else |
| 9115 | free_bp_location (old_loc); |
| 9116 | } |
| 9117 | } |
| 9118 | |
| 9119 | /* Rescan breakpoints at the same address and section, marking the |
| 9120 | first one as "first" and any others as "duplicates". This is so |
| 9121 | that the bpt instruction is only inserted once. If we have a |
| 9122 | permanent breakpoint at the same place as BPT, make that one the |
| 9123 | official one, and the rest as duplicates. Permanent breakpoints |
| 9124 | are sorted first for the same address. |
| 9125 | |
| 9126 | Do the same for hardware watchpoints, but also considering the |
| 9127 | watchpoint's type (regular/access/read) and length. */ |
| 9128 | |
| 9129 | bp_loc_first = NULL; |
| 9130 | wp_loc_first = NULL; |
| 9131 | awp_loc_first = NULL; |
| 9132 | rwp_loc_first = NULL; |
| 9133 | ALL_BP_LOCATIONS (loc, locp) |
| 9134 | { |
| 9135 | struct breakpoint *b = loc->owner; |
| 9136 | struct bp_location **loc_first_p; |
| 9137 | |
| 9138 | if (b->enable_state == bp_disabled |
| 9139 | || b->enable_state == bp_call_disabled |
| 9140 | || b->enable_state == bp_startup_disabled |
| 9141 | || !loc->enabled |
| 9142 | || loc->shlib_disabled |
| 9143 | || !breakpoint_address_is_meaningful (b) |
| 9144 | || is_tracepoint (b)) |
| 9145 | continue; |
| 9146 | |
| 9147 | /* Permanent breakpoint should always be inserted. */ |
| 9148 | if (b->enable_state == bp_permanent && ! loc->inserted) |
| 9149 | internal_error (__FILE__, __LINE__, |
| 9150 | _("allegedly permanent breakpoint is not " |
| 9151 | "actually inserted")); |
| 9152 | |
| 9153 | if (b->type == bp_hardware_watchpoint) |
| 9154 | loc_first_p = &wp_loc_first; |
| 9155 | else if (b->type == bp_read_watchpoint) |
| 9156 | loc_first_p = &rwp_loc_first; |
| 9157 | else if (b->type == bp_access_watchpoint) |
| 9158 | loc_first_p = &awp_loc_first; |
| 9159 | else |
| 9160 | loc_first_p = &bp_loc_first; |
| 9161 | |
| 9162 | if (*loc_first_p == NULL |
| 9163 | || (overlay_debugging && loc->section != (*loc_first_p)->section) |
| 9164 | || !breakpoint_locations_match (loc, *loc_first_p)) |
| 9165 | { |
| 9166 | *loc_first_p = loc; |
| 9167 | loc->duplicate = 0; |
| 9168 | continue; |
| 9169 | } |
| 9170 | |
| 9171 | loc->duplicate = 1; |
| 9172 | |
| 9173 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
| 9174 | && b->enable_state != bp_permanent) |
| 9175 | internal_error (__FILE__, __LINE__, |
| 9176 | _("another breakpoint was inserted on top of " |
| 9177 | "a permanent breakpoint")); |
| 9178 | } |
| 9179 | |
| 9180 | if (breakpoints_always_inserted_mode () && should_insert |
| 9181 | && (have_live_inferiors () |
| 9182 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
| 9183 | insert_breakpoint_locations (); |
| 9184 | |
| 9185 | do_cleanups (cleanups); |
| 9186 | } |
| 9187 | |
| 9188 | void |
| 9189 | breakpoint_retire_moribund (void) |
| 9190 | { |
| 9191 | struct bp_location *loc; |
| 9192 | int ix; |
| 9193 | |
| 9194 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 9195 | if (--(loc->events_till_retirement) == 0) |
| 9196 | { |
| 9197 | free_bp_location (loc); |
| 9198 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
| 9199 | --ix; |
| 9200 | } |
| 9201 | } |
| 9202 | |
| 9203 | static void |
| 9204 | update_global_location_list_nothrow (int inserting) |
| 9205 | { |
| 9206 | struct gdb_exception e; |
| 9207 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 9208 | update_global_location_list (inserting); |
| 9209 | } |
| 9210 | |
| 9211 | /* Clear BPT from a BPS. */ |
| 9212 | static void |
| 9213 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) |
| 9214 | { |
| 9215 | bpstat bs; |
| 9216 | for (bs = bps; bs; bs = bs->next) |
| 9217 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) |
| 9218 | { |
| 9219 | bs->breakpoint_at = NULL; |
| 9220 | bs->old_val = NULL; |
| 9221 | /* bs->commands will be freed later. */ |
| 9222 | } |
| 9223 | } |
| 9224 | |
| 9225 | /* Callback for iterate_over_threads. */ |
| 9226 | static int |
| 9227 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
| 9228 | { |
| 9229 | struct breakpoint *bpt = data; |
| 9230 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); |
| 9231 | return 0; |
| 9232 | } |
| 9233 | |
| 9234 | /* Delete a breakpoint and clean up all traces of it in the data |
| 9235 | structures. */ |
| 9236 | |
| 9237 | void |
| 9238 | delete_breakpoint (struct breakpoint *bpt) |
| 9239 | { |
| 9240 | struct breakpoint *b; |
| 9241 | struct bp_location *loc, *next; |
| 9242 | |
| 9243 | gdb_assert (bpt != NULL); |
| 9244 | |
| 9245 | /* Has this bp already been deleted? This can happen because multiple |
| 9246 | lists can hold pointers to bp's. bpstat lists are especial culprits. |
| 9247 | |
| 9248 | One example of this happening is a watchpoint's scope bp. When the |
| 9249 | scope bp triggers, we notice that the watchpoint is out of scope, and |
| 9250 | delete it. We also delete its scope bp. But the scope bp is marked |
| 9251 | "auto-deleting", and is already on a bpstat. That bpstat is then |
| 9252 | checked for auto-deleting bp's, which are deleted. |
| 9253 | |
| 9254 | A real solution to this problem might involve reference counts in bp's, |
| 9255 | and/or giving them pointers back to their referencing bpstat's, and |
| 9256 | teaching delete_breakpoint to only free a bp's storage when no more |
| 9257 | references were extent. A cheaper bandaid was chosen. */ |
| 9258 | if (bpt->type == bp_none) |
| 9259 | return; |
| 9260 | |
| 9261 | /* At least avoid this stale reference until the reference counting of |
| 9262 | breakpoints gets resolved. */ |
| 9263 | if (bpt->related_breakpoint != NULL) |
| 9264 | { |
| 9265 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); |
| 9266 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; |
| 9267 | bpt->related_breakpoint->related_breakpoint = NULL; |
| 9268 | bpt->related_breakpoint = NULL; |
| 9269 | } |
| 9270 | |
| 9271 | observer_notify_breakpoint_deleted (bpt->number); |
| 9272 | |
| 9273 | if (breakpoint_chain == bpt) |
| 9274 | breakpoint_chain = bpt->next; |
| 9275 | |
| 9276 | ALL_BREAKPOINTS (b) |
| 9277 | if (b->next == bpt) |
| 9278 | { |
| 9279 | b->next = bpt->next; |
| 9280 | break; |
| 9281 | } |
| 9282 | |
| 9283 | decref_counted_command_line (&bpt->commands); |
| 9284 | xfree (bpt->cond_string); |
| 9285 | xfree (bpt->cond_exp); |
| 9286 | xfree (bpt->addr_string); |
| 9287 | xfree (bpt->exp); |
| 9288 | xfree (bpt->exp_string); |
| 9289 | value_free (bpt->val); |
| 9290 | xfree (bpt->source_file); |
| 9291 | xfree (bpt->exec_pathname); |
| 9292 | clean_up_filters (&bpt->syscalls_to_be_caught); |
| 9293 | |
| 9294 | /* Be sure no bpstat's are pointing at it after it's been freed. */ |
| 9295 | /* FIXME, how can we find all bpstat's? |
| 9296 | We just check stop_bpstat for now. Note that we cannot just |
| 9297 | remove bpstats pointing at bpt from the stop_bpstat list |
| 9298 | entirely, as breakpoint commands are associated with the bpstat; |
| 9299 | if we remove it here, then the later call to |
| 9300 | bpstat_do_actions (&stop_bpstat); |
| 9301 | in event-top.c won't do anything, and temporary breakpoints |
| 9302 | with commands won't work. */ |
| 9303 | |
| 9304 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
| 9305 | |
| 9306 | /* Now that breakpoint is removed from breakpoint |
| 9307 | list, update the global location list. This |
| 9308 | will remove locations that used to belong to |
| 9309 | this breakpoint. Do this before freeing |
| 9310 | the breakpoint itself, since remove_breakpoint |
| 9311 | looks at location's owner. It might be better |
| 9312 | design to have location completely self-contained, |
| 9313 | but it's not the case now. */ |
| 9314 | update_global_location_list (0); |
| 9315 | |
| 9316 | |
| 9317 | /* On the chance that someone will soon try again to delete this same |
| 9318 | bp, we mark it as deleted before freeing its storage. */ |
| 9319 | bpt->type = bp_none; |
| 9320 | |
| 9321 | xfree (bpt); |
| 9322 | } |
| 9323 | |
| 9324 | static void |
| 9325 | do_delete_breakpoint_cleanup (void *b) |
| 9326 | { |
| 9327 | delete_breakpoint (b); |
| 9328 | } |
| 9329 | |
| 9330 | struct cleanup * |
| 9331 | make_cleanup_delete_breakpoint (struct breakpoint *b) |
| 9332 | { |
| 9333 | return make_cleanup (do_delete_breakpoint_cleanup, b); |
| 9334 | } |
| 9335 | |
| 9336 | /* A callback for map_breakpoint_numbers that calls |
| 9337 | delete_breakpoint. */ |
| 9338 | |
| 9339 | static void |
| 9340 | do_delete_breakpoint (struct breakpoint *b, void *ignore) |
| 9341 | { |
| 9342 | delete_breakpoint (b); |
| 9343 | } |
| 9344 | |
| 9345 | void |
| 9346 | delete_command (char *arg, int from_tty) |
| 9347 | { |
| 9348 | struct breakpoint *b, *temp; |
| 9349 | |
| 9350 | dont_repeat (); |
| 9351 | |
| 9352 | if (arg == 0) |
| 9353 | { |
| 9354 | int breaks_to_delete = 0; |
| 9355 | |
| 9356 | /* Delete all breakpoints if no argument. |
| 9357 | Do not delete internal or call-dummy breakpoints, these |
| 9358 | have to be deleted with an explicit breakpoint number argument. */ |
| 9359 | ALL_BREAKPOINTS (b) |
| 9360 | { |
| 9361 | if (b->type != bp_call_dummy |
| 9362 | && b->type != bp_std_terminate |
| 9363 | && b->type != bp_shlib_event |
| 9364 | && b->type != bp_jit_event |
| 9365 | && b->type != bp_thread_event |
| 9366 | && b->type != bp_overlay_event |
| 9367 | && b->type != bp_longjmp_master |
| 9368 | && b->type != bp_std_terminate_master |
| 9369 | && b->number >= 0) |
| 9370 | { |
| 9371 | breaks_to_delete = 1; |
| 9372 | break; |
| 9373 | } |
| 9374 | } |
| 9375 | |
| 9376 | /* Ask user only if there are some breakpoints to delete. */ |
| 9377 | if (!from_tty |
| 9378 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
| 9379 | { |
| 9380 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 9381 | { |
| 9382 | if (b->type != bp_call_dummy |
| 9383 | && b->type != bp_std_terminate |
| 9384 | && b->type != bp_shlib_event |
| 9385 | && b->type != bp_thread_event |
| 9386 | && b->type != bp_jit_event |
| 9387 | && b->type != bp_overlay_event |
| 9388 | && b->type != bp_longjmp_master |
| 9389 | && b->type != bp_std_terminate_master |
| 9390 | && b->number >= 0) |
| 9391 | delete_breakpoint (b); |
| 9392 | } |
| 9393 | } |
| 9394 | } |
| 9395 | else |
| 9396 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
| 9397 | } |
| 9398 | |
| 9399 | static int |
| 9400 | all_locations_are_pending (struct bp_location *loc) |
| 9401 | { |
| 9402 | for (; loc; loc = loc->next) |
| 9403 | if (!loc->shlib_disabled) |
| 9404 | return 0; |
| 9405 | return 1; |
| 9406 | } |
| 9407 | |
| 9408 | /* Subroutine of update_breakpoint_locations to simplify it. |
| 9409 | Return non-zero if multiple fns in list LOC have the same name. |
| 9410 | Null names are ignored. */ |
| 9411 | |
| 9412 | static int |
| 9413 | ambiguous_names_p (struct bp_location *loc) |
| 9414 | { |
| 9415 | struct bp_location *l; |
| 9416 | htab_t htab = htab_create_alloc (13, htab_hash_string, |
| 9417 | (int (*) (const void *, const void *)) streq, |
| 9418 | NULL, xcalloc, xfree); |
| 9419 | |
| 9420 | for (l = loc; l != NULL; l = l->next) |
| 9421 | { |
| 9422 | const char **slot; |
| 9423 | const char *name = l->function_name; |
| 9424 | |
| 9425 | /* Allow for some names to be NULL, ignore them. */ |
| 9426 | if (name == NULL) |
| 9427 | continue; |
| 9428 | |
| 9429 | slot = (const char **) htab_find_slot (htab, (const void *) name, |
| 9430 | INSERT); |
| 9431 | /* NOTE: We can assume slot != NULL here because xcalloc never returns |
| 9432 | NULL. */ |
| 9433 | if (*slot != NULL) |
| 9434 | { |
| 9435 | htab_delete (htab); |
| 9436 | return 1; |
| 9437 | } |
| 9438 | *slot = name; |
| 9439 | } |
| 9440 | |
| 9441 | htab_delete (htab); |
| 9442 | return 0; |
| 9443 | } |
| 9444 | |
| 9445 | static void |
| 9446 | update_breakpoint_locations (struct breakpoint *b, |
| 9447 | struct symtabs_and_lines sals) |
| 9448 | { |
| 9449 | int i; |
| 9450 | char *s; |
| 9451 | struct bp_location *existing_locations = b->loc; |
| 9452 | |
| 9453 | /* If there's no new locations, and all existing locations |
| 9454 | are pending, don't do anything. This optimizes |
| 9455 | the common case where all locations are in the same |
| 9456 | shared library, that was unloaded. We'd like to |
| 9457 | retain the location, so that when the library |
| 9458 | is loaded again, we don't loose the enabled/disabled |
| 9459 | status of the individual locations. */ |
| 9460 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
| 9461 | return; |
| 9462 | |
| 9463 | b->loc = NULL; |
| 9464 | |
| 9465 | for (i = 0; i < sals.nelts; ++i) |
| 9466 | { |
| 9467 | struct bp_location *new_loc = |
| 9468 | add_location_to_breakpoint (b, &(sals.sals[i])); |
| 9469 | |
| 9470 | /* Reparse conditions, they might contain references to the |
| 9471 | old symtab. */ |
| 9472 | if (b->cond_string != NULL) |
| 9473 | { |
| 9474 | struct gdb_exception e; |
| 9475 | |
| 9476 | s = b->cond_string; |
| 9477 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 9478 | { |
| 9479 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), |
| 9480 | 0); |
| 9481 | } |
| 9482 | if (e.reason < 0) |
| 9483 | { |
| 9484 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), |
| 9485 | b->number, e.message); |
| 9486 | new_loc->enabled = 0; |
| 9487 | } |
| 9488 | } |
| 9489 | |
| 9490 | if (b->source_file != NULL) |
| 9491 | xfree (b->source_file); |
| 9492 | if (sals.sals[i].symtab == NULL) |
| 9493 | b->source_file = NULL; |
| 9494 | else |
| 9495 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
| 9496 | |
| 9497 | if (b->line_number == 0) |
| 9498 | b->line_number = sals.sals[i].line; |
| 9499 | } |
| 9500 | |
| 9501 | /* Update locations of permanent breakpoints. */ |
| 9502 | if (b->enable_state == bp_permanent) |
| 9503 | make_breakpoint_permanent (b); |
| 9504 | |
| 9505 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
| 9506 | { |
| 9507 | struct bp_location *e = existing_locations; |
| 9508 | /* If there are multiple breakpoints with the same function name, |
| 9509 | e.g. for inline functions, comparing function names won't work. |
| 9510 | Instead compare pc addresses; this is just a heuristic as things |
| 9511 | may have moved, but in practice it gives the correct answer |
| 9512 | often enough until a better solution is found. */ |
| 9513 | int have_ambiguous_names = ambiguous_names_p (b->loc); |
| 9514 | |
| 9515 | for (; e; e = e->next) |
| 9516 | { |
| 9517 | if (!e->enabled && e->function_name) |
| 9518 | { |
| 9519 | struct bp_location *l = b->loc; |
| 9520 | if (have_ambiguous_names) |
| 9521 | { |
| 9522 | for (; l; l = l->next) |
| 9523 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
| 9524 | l->pspace->aspace, l->address)) |
| 9525 | { |
| 9526 | l->enabled = 0; |
| 9527 | break; |
| 9528 | } |
| 9529 | } |
| 9530 | else |
| 9531 | { |
| 9532 | for (; l; l = l->next) |
| 9533 | if (l->function_name |
| 9534 | && strcmp (e->function_name, l->function_name) == 0) |
| 9535 | { |
| 9536 | l->enabled = 0; |
| 9537 | break; |
| 9538 | } |
| 9539 | } |
| 9540 | } |
| 9541 | } |
| 9542 | } |
| 9543 | |
| 9544 | update_global_location_list (1); |
| 9545 | } |
| 9546 | |
| 9547 | |
| 9548 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
| 9549 | The value we return ends up being the return value from catch_errors. |
| 9550 | Unused in this case. */ |
| 9551 | |
| 9552 | static int |
| 9553 | breakpoint_re_set_one (void *bint) |
| 9554 | { |
| 9555 | /* get past catch_errs */ |
| 9556 | struct breakpoint *b = (struct breakpoint *) bint; |
| 9557 | struct value *mark; |
| 9558 | int i; |
| 9559 | int not_found = 0; |
| 9560 | int *not_found_ptr = ¬_found; |
| 9561 | struct symtabs_and_lines sals = {0}; |
| 9562 | struct symtabs_and_lines expanded = {0}; |
| 9563 | char *s; |
| 9564 | enum enable_state save_enable; |
| 9565 | struct gdb_exception e; |
| 9566 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
| 9567 | |
| 9568 | switch (b->type) |
| 9569 | { |
| 9570 | case bp_none: |
| 9571 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
| 9572 | b->number); |
| 9573 | return 0; |
| 9574 | case bp_breakpoint: |
| 9575 | case bp_hardware_breakpoint: |
| 9576 | case bp_tracepoint: |
| 9577 | case bp_fast_tracepoint: |
| 9578 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
| 9579 | if (b->enable_state == bp_startup_disabled) |
| 9580 | return 0; |
| 9581 | |
| 9582 | if (b->addr_string == NULL) |
| 9583 | { |
| 9584 | /* Anything without a string can't be re-set. */ |
| 9585 | delete_breakpoint (b); |
| 9586 | return 0; |
| 9587 | } |
| 9588 | |
| 9589 | set_language (b->language); |
| 9590 | input_radix = b->input_radix; |
| 9591 | s = b->addr_string; |
| 9592 | |
| 9593 | save_current_space_and_thread (); |
| 9594 | switch_to_program_space_and_thread (b->pspace); |
| 9595 | |
| 9596 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 9597 | { |
| 9598 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
| 9599 | not_found_ptr); |
| 9600 | } |
| 9601 | if (e.reason < 0) |
| 9602 | { |
| 9603 | int not_found_and_ok = 0; |
| 9604 | /* For pending breakpoints, it's expected that parsing |
| 9605 | will fail until the right shared library is loaded. |
| 9606 | User has already told to create pending breakpoints and |
| 9607 | don't need extra messages. If breakpoint is in bp_shlib_disabled |
| 9608 | state, then user already saw the message about that breakpoint |
| 9609 | being disabled, and don't want to see more errors. */ |
| 9610 | if (not_found |
| 9611 | && (b->condition_not_parsed |
| 9612 | || (b->loc && b->loc->shlib_disabled) |
| 9613 | || b->enable_state == bp_disabled)) |
| 9614 | not_found_and_ok = 1; |
| 9615 | |
| 9616 | if (!not_found_and_ok) |
| 9617 | { |
| 9618 | /* We surely don't want to warn about the same breakpoint |
| 9619 | 10 times. One solution, implemented here, is disable |
| 9620 | the breakpoint on error. Another solution would be to |
| 9621 | have separate 'warning emitted' flag. Since this |
| 9622 | happens only when a binary has changed, I don't know |
| 9623 | which approach is better. */ |
| 9624 | b->enable_state = bp_disabled; |
| 9625 | throw_exception (e); |
| 9626 | } |
| 9627 | } |
| 9628 | |
| 9629 | if (!not_found) |
| 9630 | { |
| 9631 | gdb_assert (sals.nelts == 1); |
| 9632 | |
| 9633 | resolve_sal_pc (&sals.sals[0]); |
| 9634 | if (b->condition_not_parsed && s && s[0]) |
| 9635 | { |
| 9636 | char *cond_string = 0; |
| 9637 | int thread = -1; |
| 9638 | int task = 0; |
| 9639 | |
| 9640 | find_condition_and_thread (s, sals.sals[0].pc, |
| 9641 | &cond_string, &thread, &task); |
| 9642 | if (cond_string) |
| 9643 | b->cond_string = cond_string; |
| 9644 | b->thread = thread; |
| 9645 | b->task = task; |
| 9646 | b->condition_not_parsed = 0; |
| 9647 | } |
| 9648 | |
| 9649 | expanded = expand_line_sal_maybe (sals.sals[0]); |
| 9650 | } |
| 9651 | |
| 9652 | make_cleanup (xfree, sals.sals); |
| 9653 | update_breakpoint_locations (b, expanded); |
| 9654 | break; |
| 9655 | |
| 9656 | case bp_watchpoint: |
| 9657 | case bp_hardware_watchpoint: |
| 9658 | case bp_read_watchpoint: |
| 9659 | case bp_access_watchpoint: |
| 9660 | /* Watchpoint can be either on expression using entirely global variables, |
| 9661 | or it can be on local variables. |
| 9662 | |
| 9663 | Watchpoints of the first kind are never auto-deleted, and even persist |
| 9664 | across program restarts. Since they can use variables from shared |
| 9665 | libraries, we need to reparse expression as libraries are loaded |
| 9666 | and unloaded. |
| 9667 | |
| 9668 | Watchpoints on local variables can also change meaning as result |
| 9669 | of solib event. For example, if a watchpoint uses both a local and |
| 9670 | a global variables in expression, it's a local watchpoint, but |
| 9671 | unloading of a shared library will make the expression invalid. |
| 9672 | This is not a very common use case, but we still re-evaluate |
| 9673 | expression, to avoid surprises to the user. |
| 9674 | |
| 9675 | Note that for local watchpoints, we re-evaluate it only if |
| 9676 | watchpoints frame id is still valid. If it's not, it means |
| 9677 | the watchpoint is out of scope and will be deleted soon. In fact, |
| 9678 | I'm not sure we'll ever be called in this case. |
| 9679 | |
| 9680 | If a local watchpoint's frame id is still valid, then |
| 9681 | b->exp_valid_block is likewise valid, and we can safely use it. |
| 9682 | |
| 9683 | Don't do anything about disabled watchpoints, since they will |
| 9684 | be reevaluated again when enabled. */ |
| 9685 | update_watchpoint (b, 1 /* reparse */); |
| 9686 | break; |
| 9687 | /* We needn't really do anything to reset these, since the mask |
| 9688 | that requests them is unaffected by e.g., new libraries being |
| 9689 | loaded. */ |
| 9690 | case bp_catchpoint: |
| 9691 | break; |
| 9692 | |
| 9693 | default: |
| 9694 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
| 9695 | /* fall through */ |
| 9696 | /* Delete overlay event and longjmp master breakpoints; they will be |
| 9697 | reset later by breakpoint_re_set. */ |
| 9698 | case bp_overlay_event: |
| 9699 | case bp_longjmp_master: |
| 9700 | case bp_std_terminate_master: |
| 9701 | delete_breakpoint (b); |
| 9702 | break; |
| 9703 | |
| 9704 | /* This breakpoint is special, it's set up when the inferior |
| 9705 | starts and we really don't want to touch it. */ |
| 9706 | case bp_shlib_event: |
| 9707 | |
| 9708 | /* Like bp_shlib_event, this breakpoint type is special. |
| 9709 | Once it is set up, we do not want to touch it. */ |
| 9710 | case bp_thread_event: |
| 9711 | |
| 9712 | /* Keep temporary breakpoints, which can be encountered when we step |
| 9713 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. |
| 9714 | Otherwise these should have been blown away via the cleanup chain |
| 9715 | or by breakpoint_init_inferior when we rerun the executable. */ |
| 9716 | case bp_until: |
| 9717 | case bp_finish: |
| 9718 | case bp_watchpoint_scope: |
| 9719 | case bp_call_dummy: |
| 9720 | case bp_std_terminate: |
| 9721 | case bp_step_resume: |
| 9722 | case bp_longjmp: |
| 9723 | case bp_longjmp_resume: |
| 9724 | case bp_jit_event: |
| 9725 | break; |
| 9726 | } |
| 9727 | |
| 9728 | do_cleanups (cleanups); |
| 9729 | return 0; |
| 9730 | } |
| 9731 | |
| 9732 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
| 9733 | void |
| 9734 | breakpoint_re_set (void) |
| 9735 | { |
| 9736 | struct breakpoint *b, *temp; |
| 9737 | enum language save_language; |
| 9738 | int save_input_radix; |
| 9739 | struct cleanup *old_chain; |
| 9740 | |
| 9741 | save_language = current_language->la_language; |
| 9742 | save_input_radix = input_radix; |
| 9743 | old_chain = save_current_program_space (); |
| 9744 | |
| 9745 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 9746 | { |
| 9747 | /* Format possible error msg */ |
| 9748 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
| 9749 | b->number); |
| 9750 | struct cleanup *cleanups = make_cleanup (xfree, message); |
| 9751 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
| 9752 | do_cleanups (cleanups); |
| 9753 | } |
| 9754 | set_language (save_language); |
| 9755 | input_radix = save_input_radix; |
| 9756 | |
| 9757 | jit_breakpoint_re_set (); |
| 9758 | |
| 9759 | do_cleanups (old_chain); |
| 9760 | |
| 9761 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
| 9762 | create_longjmp_master_breakpoint ("longjmp"); |
| 9763 | create_longjmp_master_breakpoint ("_longjmp"); |
| 9764 | create_longjmp_master_breakpoint ("siglongjmp"); |
| 9765 | create_longjmp_master_breakpoint ("_siglongjmp"); |
| 9766 | create_std_terminate_master_breakpoint ("std::terminate()"); |
| 9767 | } |
| 9768 | \f |
| 9769 | /* Reset the thread number of this breakpoint: |
| 9770 | |
| 9771 | - If the breakpoint is for all threads, leave it as-is. |
| 9772 | - Else, reset it to the current thread for inferior_ptid. */ |
| 9773 | void |
| 9774 | breakpoint_re_set_thread (struct breakpoint *b) |
| 9775 | { |
| 9776 | if (b->thread != -1) |
| 9777 | { |
| 9778 | if (in_thread_list (inferior_ptid)) |
| 9779 | b->thread = pid_to_thread_id (inferior_ptid); |
| 9780 | |
| 9781 | /* We're being called after following a fork. The new fork is |
| 9782 | selected as current, and unless this was a vfork will have a |
| 9783 | different program space from the original thread. Reset that |
| 9784 | as well. */ |
| 9785 | b->loc->pspace = current_program_space; |
| 9786 | } |
| 9787 | } |
| 9788 | |
| 9789 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 9790 | If from_tty is nonzero, it prints a message to that effect, |
| 9791 | which ends with a period (no newline). */ |
| 9792 | |
| 9793 | void |
| 9794 | set_ignore_count (int bptnum, int count, int from_tty) |
| 9795 | { |
| 9796 | struct breakpoint *b; |
| 9797 | |
| 9798 | if (count < 0) |
| 9799 | count = 0; |
| 9800 | |
| 9801 | ALL_BREAKPOINTS (b) |
| 9802 | if (b->number == bptnum) |
| 9803 | { |
| 9804 | if (is_tracepoint (b)) |
| 9805 | { |
| 9806 | if (from_tty && count != 0) |
| 9807 | printf_filtered (_("Ignore count ignored for tracepoint %d."), |
| 9808 | bptnum); |
| 9809 | return; |
| 9810 | } |
| 9811 | |
| 9812 | b->ignore_count = count; |
| 9813 | if (from_tty) |
| 9814 | { |
| 9815 | if (count == 0) |
| 9816 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
| 9817 | bptnum); |
| 9818 | else if (count == 1) |
| 9819 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
| 9820 | bptnum); |
| 9821 | else |
| 9822 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
| 9823 | count, bptnum); |
| 9824 | } |
| 9825 | breakpoints_changed (); |
| 9826 | observer_notify_breakpoint_modified (b->number); |
| 9827 | return; |
| 9828 | } |
| 9829 | |
| 9830 | error (_("No breakpoint number %d."), bptnum); |
| 9831 | } |
| 9832 | |
| 9833 | void |
| 9834 | make_breakpoint_silent (struct breakpoint *b) |
| 9835 | { |
| 9836 | /* Silence the breakpoint. */ |
| 9837 | b->silent = 1; |
| 9838 | } |
| 9839 | |
| 9840 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
| 9841 | |
| 9842 | static void |
| 9843 | ignore_command (char *args, int from_tty) |
| 9844 | { |
| 9845 | char *p = args; |
| 9846 | int num; |
| 9847 | |
| 9848 | if (p == 0) |
| 9849 | error_no_arg (_("a breakpoint number")); |
| 9850 | |
| 9851 | num = get_number (&p); |
| 9852 | if (num == 0) |
| 9853 | error (_("bad breakpoint number: '%s'"), args); |
| 9854 | if (*p == 0) |
| 9855 | error (_("Second argument (specified ignore-count) is missing.")); |
| 9856 | |
| 9857 | set_ignore_count (num, |
| 9858 | longest_to_int (value_as_long (parse_and_eval (p))), |
| 9859 | from_tty); |
| 9860 | if (from_tty) |
| 9861 | printf_filtered ("\n"); |
| 9862 | } |
| 9863 | \f |
| 9864 | /* Call FUNCTION on each of the breakpoints |
| 9865 | whose numbers are given in ARGS. */ |
| 9866 | |
| 9867 | static void |
| 9868 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
| 9869 | void *), |
| 9870 | void *data) |
| 9871 | { |
| 9872 | char *p = args; |
| 9873 | char *p1; |
| 9874 | int num; |
| 9875 | struct breakpoint *b, *tmp; |
| 9876 | int match; |
| 9877 | |
| 9878 | if (p == 0) |
| 9879 | error_no_arg (_("one or more breakpoint numbers")); |
| 9880 | |
| 9881 | while (*p) |
| 9882 | { |
| 9883 | match = 0; |
| 9884 | p1 = p; |
| 9885 | |
| 9886 | num = get_number_or_range (&p1); |
| 9887 | if (num == 0) |
| 9888 | { |
| 9889 | warning (_("bad breakpoint number at or near '%s'"), p); |
| 9890 | } |
| 9891 | else |
| 9892 | { |
| 9893 | ALL_BREAKPOINTS_SAFE (b, tmp) |
| 9894 | if (b->number == num) |
| 9895 | { |
| 9896 | struct breakpoint *related_breakpoint = b->related_breakpoint; |
| 9897 | match = 1; |
| 9898 | function (b, data); |
| 9899 | if (related_breakpoint) |
| 9900 | function (related_breakpoint, data); |
| 9901 | break; |
| 9902 | } |
| 9903 | if (match == 0) |
| 9904 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
| 9905 | } |
| 9906 | p = p1; |
| 9907 | } |
| 9908 | } |
| 9909 | |
| 9910 | static struct bp_location * |
| 9911 | find_location_by_number (char *number) |
| 9912 | { |
| 9913 | char *dot = strchr (number, '.'); |
| 9914 | char *p1; |
| 9915 | int bp_num; |
| 9916 | int loc_num; |
| 9917 | struct breakpoint *b; |
| 9918 | struct bp_location *loc; |
| 9919 | |
| 9920 | *dot = '\0'; |
| 9921 | |
| 9922 | p1 = number; |
| 9923 | bp_num = get_number_or_range (&p1); |
| 9924 | if (bp_num == 0) |
| 9925 | error (_("Bad breakpoint number '%s'"), number); |
| 9926 | |
| 9927 | ALL_BREAKPOINTS (b) |
| 9928 | if (b->number == bp_num) |
| 9929 | { |
| 9930 | break; |
| 9931 | } |
| 9932 | |
| 9933 | if (!b || b->number != bp_num) |
| 9934 | error (_("Bad breakpoint number '%s'"), number); |
| 9935 | |
| 9936 | p1 = dot+1; |
| 9937 | loc_num = get_number_or_range (&p1); |
| 9938 | if (loc_num == 0) |
| 9939 | error (_("Bad breakpoint location number '%s'"), number); |
| 9940 | |
| 9941 | --loc_num; |
| 9942 | loc = b->loc; |
| 9943 | for (;loc_num && loc; --loc_num, loc = loc->next) |
| 9944 | ; |
| 9945 | if (!loc) |
| 9946 | error (_("Bad breakpoint location number '%s'"), dot+1); |
| 9947 | |
| 9948 | return loc; |
| 9949 | } |
| 9950 | |
| 9951 | |
| 9952 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 9953 | If from_tty is nonzero, it prints a message to that effect, |
| 9954 | which ends with a period (no newline). */ |
| 9955 | |
| 9956 | void |
| 9957 | disable_breakpoint (struct breakpoint *bpt) |
| 9958 | { |
| 9959 | /* Never disable a watchpoint scope breakpoint; we want to |
| 9960 | hit them when we leave scope so we can delete both the |
| 9961 | watchpoint and its scope breakpoint at that time. */ |
| 9962 | if (bpt->type == bp_watchpoint_scope) |
| 9963 | return; |
| 9964 | |
| 9965 | /* You can't disable permanent breakpoints. */ |
| 9966 | if (bpt->enable_state == bp_permanent) |
| 9967 | return; |
| 9968 | |
| 9969 | bpt->enable_state = bp_disabled; |
| 9970 | |
| 9971 | update_global_location_list (0); |
| 9972 | |
| 9973 | observer_notify_breakpoint_modified (bpt->number); |
| 9974 | } |
| 9975 | |
| 9976 | /* A callback for map_breakpoint_numbers that calls |
| 9977 | disable_breakpoint. */ |
| 9978 | |
| 9979 | static void |
| 9980 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) |
| 9981 | { |
| 9982 | disable_breakpoint (b); |
| 9983 | } |
| 9984 | |
| 9985 | static void |
| 9986 | disable_command (char *args, int from_tty) |
| 9987 | { |
| 9988 | struct breakpoint *bpt; |
| 9989 | if (args == 0) |
| 9990 | ALL_BREAKPOINTS (bpt) |
| 9991 | switch (bpt->type) |
| 9992 | { |
| 9993 | case bp_none: |
| 9994 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
| 9995 | bpt->number); |
| 9996 | continue; |
| 9997 | case bp_breakpoint: |
| 9998 | case bp_tracepoint: |
| 9999 | case bp_fast_tracepoint: |
| 10000 | case bp_catchpoint: |
| 10001 | case bp_hardware_breakpoint: |
| 10002 | case bp_watchpoint: |
| 10003 | case bp_hardware_watchpoint: |
| 10004 | case bp_read_watchpoint: |
| 10005 | case bp_access_watchpoint: |
| 10006 | disable_breakpoint (bpt); |
| 10007 | default: |
| 10008 | continue; |
| 10009 | } |
| 10010 | else if (strchr (args, '.')) |
| 10011 | { |
| 10012 | struct bp_location *loc = find_location_by_number (args); |
| 10013 | if (loc) |
| 10014 | loc->enabled = 0; |
| 10015 | update_global_location_list (0); |
| 10016 | } |
| 10017 | else |
| 10018 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
| 10019 | } |
| 10020 | |
| 10021 | static void |
| 10022 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
| 10023 | { |
| 10024 | int target_resources_ok, other_type_used; |
| 10025 | struct value *mark; |
| 10026 | |
| 10027 | if (bpt->type == bp_hardware_breakpoint) |
| 10028 | { |
| 10029 | int i; |
| 10030 | i = hw_breakpoint_used_count (); |
| 10031 | target_resources_ok = |
| 10032 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 10033 | i + 1, 0); |
| 10034 | if (target_resources_ok == 0) |
| 10035 | error (_("No hardware breakpoint support in the target.")); |
| 10036 | else if (target_resources_ok < 0) |
| 10037 | error (_("Hardware breakpoints used exceeds limit.")); |
| 10038 | } |
| 10039 | |
| 10040 | if (is_watchpoint (bpt)) |
| 10041 | { |
| 10042 | struct gdb_exception e; |
| 10043 | |
| 10044 | TRY_CATCH (e, RETURN_MASK_ALL) |
| 10045 | { |
| 10046 | update_watchpoint (bpt, 1 /* reparse */); |
| 10047 | } |
| 10048 | if (e.reason < 0) |
| 10049 | { |
| 10050 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
| 10051 | bpt->number); |
| 10052 | return; |
| 10053 | } |
| 10054 | } |
| 10055 | |
| 10056 | if (bpt->enable_state != bp_permanent) |
| 10057 | bpt->enable_state = bp_enabled; |
| 10058 | bpt->disposition = disposition; |
| 10059 | update_global_location_list (1); |
| 10060 | breakpoints_changed (); |
| 10061 | |
| 10062 | observer_notify_breakpoint_modified (bpt->number); |
| 10063 | } |
| 10064 | |
| 10065 | |
| 10066 | void |
| 10067 | enable_breakpoint (struct breakpoint *bpt) |
| 10068 | { |
| 10069 | do_enable_breakpoint (bpt, bpt->disposition); |
| 10070 | } |
| 10071 | |
| 10072 | /* A callback for map_breakpoint_numbers that calls |
| 10073 | enable_breakpoint. */ |
| 10074 | |
| 10075 | static void |
| 10076 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) |
| 10077 | { |
| 10078 | enable_breakpoint (b); |
| 10079 | } |
| 10080 | |
| 10081 | /* The enable command enables the specified breakpoints (or all defined |
| 10082 | breakpoints) so they once again become (or continue to be) effective |
| 10083 | in stopping the inferior. */ |
| 10084 | |
| 10085 | static void |
| 10086 | enable_command (char *args, int from_tty) |
| 10087 | { |
| 10088 | struct breakpoint *bpt; |
| 10089 | if (args == 0) |
| 10090 | ALL_BREAKPOINTS (bpt) |
| 10091 | switch (bpt->type) |
| 10092 | { |
| 10093 | case bp_none: |
| 10094 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
| 10095 | bpt->number); |
| 10096 | continue; |
| 10097 | case bp_breakpoint: |
| 10098 | case bp_tracepoint: |
| 10099 | case bp_fast_tracepoint: |
| 10100 | case bp_catchpoint: |
| 10101 | case bp_hardware_breakpoint: |
| 10102 | case bp_watchpoint: |
| 10103 | case bp_hardware_watchpoint: |
| 10104 | case bp_read_watchpoint: |
| 10105 | case bp_access_watchpoint: |
| 10106 | enable_breakpoint (bpt); |
| 10107 | default: |
| 10108 | continue; |
| 10109 | } |
| 10110 | else if (strchr (args, '.')) |
| 10111 | { |
| 10112 | struct bp_location *loc = find_location_by_number (args); |
| 10113 | if (loc) |
| 10114 | loc->enabled = 1; |
| 10115 | update_global_location_list (1); |
| 10116 | } |
| 10117 | else |
| 10118 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
| 10119 | } |
| 10120 | |
| 10121 | static void |
| 10122 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
| 10123 | { |
| 10124 | do_enable_breakpoint (bpt, disp_disable); |
| 10125 | } |
| 10126 | |
| 10127 | static void |
| 10128 | enable_once_command (char *args, int from_tty) |
| 10129 | { |
| 10130 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
| 10131 | } |
| 10132 | |
| 10133 | static void |
| 10134 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
| 10135 | { |
| 10136 | do_enable_breakpoint (bpt, disp_del); |
| 10137 | } |
| 10138 | |
| 10139 | static void |
| 10140 | enable_delete_command (char *args, int from_tty) |
| 10141 | { |
| 10142 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
| 10143 | } |
| 10144 | \f |
| 10145 | static void |
| 10146 | set_breakpoint_cmd (char *args, int from_tty) |
| 10147 | { |
| 10148 | } |
| 10149 | |
| 10150 | static void |
| 10151 | show_breakpoint_cmd (char *args, int from_tty) |
| 10152 | { |
| 10153 | } |
| 10154 | |
| 10155 | /* Invalidate last known value of any hardware watchpoint if |
| 10156 | the memory which that value represents has been written to by |
| 10157 | GDB itself. */ |
| 10158 | |
| 10159 | static void |
| 10160 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, |
| 10161 | const bfd_byte *data) |
| 10162 | { |
| 10163 | struct breakpoint *bp; |
| 10164 | |
| 10165 | ALL_BREAKPOINTS (bp) |
| 10166 | if (bp->enable_state == bp_enabled |
| 10167 | && bp->type == bp_hardware_watchpoint |
| 10168 | && bp->val_valid && bp->val) |
| 10169 | { |
| 10170 | struct bp_location *loc; |
| 10171 | |
| 10172 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
| 10173 | if (loc->loc_type == bp_loc_hardware_watchpoint |
| 10174 | && loc->address + loc->length > addr |
| 10175 | && addr + len > loc->address) |
| 10176 | { |
| 10177 | value_free (bp->val); |
| 10178 | bp->val = NULL; |
| 10179 | bp->val_valid = 0; |
| 10180 | } |
| 10181 | } |
| 10182 | } |
| 10183 | |
| 10184 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
| 10185 | |
| 10186 | struct symtabs_and_lines |
| 10187 | decode_line_spec_1 (char *string, int funfirstline) |
| 10188 | { |
| 10189 | struct symtabs_and_lines sals; |
| 10190 | if (string == 0) |
| 10191 | error (_("Empty line specification.")); |
| 10192 | if (default_breakpoint_valid) |
| 10193 | sals = decode_line_1 (&string, funfirstline, |
| 10194 | default_breakpoint_symtab, |
| 10195 | default_breakpoint_line, |
| 10196 | (char ***) NULL, NULL); |
| 10197 | else |
| 10198 | sals = decode_line_1 (&string, funfirstline, |
| 10199 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
| 10200 | if (*string) |
| 10201 | error (_("Junk at end of line specification: %s"), string); |
| 10202 | return sals; |
| 10203 | } |
| 10204 | |
| 10205 | /* Create and insert a raw software breakpoint at PC. Return an |
| 10206 | identifier, which should be used to remove the breakpoint later. |
| 10207 | In general, places which call this should be using something on the |
| 10208 | breakpoint chain instead; this function should be eliminated |
| 10209 | someday. */ |
| 10210 | |
| 10211 | void * |
| 10212 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
| 10213 | struct address_space *aspace, CORE_ADDR pc) |
| 10214 | { |
| 10215 | struct bp_target_info *bp_tgt; |
| 10216 | |
| 10217 | bp_tgt = XZALLOC (struct bp_target_info); |
| 10218 | |
| 10219 | bp_tgt->placed_address_space = aspace; |
| 10220 | bp_tgt->placed_address = pc; |
| 10221 | |
| 10222 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
| 10223 | { |
| 10224 | /* Could not insert the breakpoint. */ |
| 10225 | xfree (bp_tgt); |
| 10226 | return NULL; |
| 10227 | } |
| 10228 | |
| 10229 | return bp_tgt; |
| 10230 | } |
| 10231 | |
| 10232 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ |
| 10233 | |
| 10234 | int |
| 10235 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
| 10236 | { |
| 10237 | struct bp_target_info *bp_tgt = bp; |
| 10238 | int ret; |
| 10239 | |
| 10240 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
| 10241 | xfree (bp_tgt); |
| 10242 | |
| 10243 | return ret; |
| 10244 | } |
| 10245 | |
| 10246 | /* One (or perhaps two) breakpoints used for software single stepping. */ |
| 10247 | |
| 10248 | static void *single_step_breakpoints[2]; |
| 10249 | static struct gdbarch *single_step_gdbarch[2]; |
| 10250 | |
| 10251 | /* Create and insert a breakpoint for software single step. */ |
| 10252 | |
| 10253 | void |
| 10254 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
| 10255 | struct address_space *aspace, CORE_ADDR next_pc) |
| 10256 | { |
| 10257 | void **bpt_p; |
| 10258 | |
| 10259 | if (single_step_breakpoints[0] == NULL) |
| 10260 | { |
| 10261 | bpt_p = &single_step_breakpoints[0]; |
| 10262 | single_step_gdbarch[0] = gdbarch; |
| 10263 | } |
| 10264 | else |
| 10265 | { |
| 10266 | gdb_assert (single_step_breakpoints[1] == NULL); |
| 10267 | bpt_p = &single_step_breakpoints[1]; |
| 10268 | single_step_gdbarch[1] = gdbarch; |
| 10269 | } |
| 10270 | |
| 10271 | /* NOTE drow/2006-04-11: A future improvement to this function would be |
| 10272 | to only create the breakpoints once, and actually put them on the |
| 10273 | breakpoint chain. That would let us use set_raw_breakpoint. We could |
| 10274 | adjust the addresses each time they were needed. Doing this requires |
| 10275 | corresponding changes elsewhere where single step breakpoints are |
| 10276 | handled, however. So, for now, we use this. */ |
| 10277 | |
| 10278 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
| 10279 | if (*bpt_p == NULL) |
| 10280 | error (_("Could not insert single-step breakpoint at %s"), |
| 10281 | paddress (gdbarch, next_pc)); |
| 10282 | } |
| 10283 | |
| 10284 | /* Remove and delete any breakpoints used for software single step. */ |
| 10285 | |
| 10286 | void |
| 10287 | remove_single_step_breakpoints (void) |
| 10288 | { |
| 10289 | gdb_assert (single_step_breakpoints[0] != NULL); |
| 10290 | |
| 10291 | /* See insert_single_step_breakpoint for more about this deprecated |
| 10292 | call. */ |
| 10293 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
| 10294 | single_step_breakpoints[0]); |
| 10295 | single_step_gdbarch[0] = NULL; |
| 10296 | single_step_breakpoints[0] = NULL; |
| 10297 | |
| 10298 | if (single_step_breakpoints[1] != NULL) |
| 10299 | { |
| 10300 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
| 10301 | single_step_breakpoints[1]); |
| 10302 | single_step_gdbarch[1] = NULL; |
| 10303 | single_step_breakpoints[1] = NULL; |
| 10304 | } |
| 10305 | } |
| 10306 | |
| 10307 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
| 10308 | |
| 10309 | static int |
| 10310 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 10311 | { |
| 10312 | int i; |
| 10313 | |
| 10314 | for (i = 0; i < 2; i++) |
| 10315 | { |
| 10316 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; |
| 10317 | if (bp_tgt |
| 10318 | && breakpoint_address_match (bp_tgt->placed_address_space, |
| 10319 | bp_tgt->placed_address, |
| 10320 | aspace, pc)) |
| 10321 | return 1; |
| 10322 | } |
| 10323 | |
| 10324 | return 0; |
| 10325 | } |
| 10326 | |
| 10327 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
| 10328 | non-zero otherwise. */ |
| 10329 | static int |
| 10330 | is_syscall_catchpoint_enabled (struct breakpoint *bp) |
| 10331 | { |
| 10332 | if (syscall_catchpoint_p (bp) |
| 10333 | && bp->enable_state != bp_disabled |
| 10334 | && bp->enable_state != bp_call_disabled) |
| 10335 | return 1; |
| 10336 | else |
| 10337 | return 0; |
| 10338 | } |
| 10339 | |
| 10340 | int |
| 10341 | catch_syscall_enabled (void) |
| 10342 | { |
| 10343 | struct inferior *inf = current_inferior (); |
| 10344 | |
| 10345 | return inf->total_syscalls_count != 0; |
| 10346 | } |
| 10347 | |
| 10348 | int |
| 10349 | catching_syscall_number (int syscall_number) |
| 10350 | { |
| 10351 | struct breakpoint *bp; |
| 10352 | |
| 10353 | ALL_BREAKPOINTS (bp) |
| 10354 | if (is_syscall_catchpoint_enabled (bp)) |
| 10355 | { |
| 10356 | if (bp->syscalls_to_be_caught) |
| 10357 | { |
| 10358 | int i, iter; |
| 10359 | for (i = 0; |
| 10360 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); |
| 10361 | i++) |
| 10362 | if (syscall_number == iter) |
| 10363 | return 1; |
| 10364 | } |
| 10365 | else |
| 10366 | return 1; |
| 10367 | } |
| 10368 | |
| 10369 | return 0; |
| 10370 | } |
| 10371 | |
| 10372 | /* Complete syscall names. Used by "catch syscall". */ |
| 10373 | static char ** |
| 10374 | catch_syscall_completer (struct cmd_list_element *cmd, |
| 10375 | char *text, char *word) |
| 10376 | { |
| 10377 | const char **list = get_syscall_names (); |
| 10378 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); |
| 10379 | } |
| 10380 | |
| 10381 | /* Tracepoint-specific operations. */ |
| 10382 | |
| 10383 | /* Set tracepoint count to NUM. */ |
| 10384 | static void |
| 10385 | set_tracepoint_count (int num) |
| 10386 | { |
| 10387 | tracepoint_count = num; |
| 10388 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
| 10389 | } |
| 10390 | |
| 10391 | void |
| 10392 | trace_command (char *arg, int from_tty) |
| 10393 | { |
| 10394 | if (create_breakpoint (get_current_arch (), |
| 10395 | arg, |
| 10396 | NULL, 0, 1 /* parse arg */, |
| 10397 | 0 /* tempflag */, 0 /* hardwareflag */, |
| 10398 | 1 /* traceflag */, |
| 10399 | 0 /* Ignore count */, |
| 10400 | pending_break_support, |
| 10401 | NULL, |
| 10402 | from_tty, |
| 10403 | 1 /* enabled */)) |
| 10404 | set_tracepoint_count (breakpoint_count); |
| 10405 | } |
| 10406 | |
| 10407 | void |
| 10408 | ftrace_command (char *arg, int from_tty) |
| 10409 | { |
| 10410 | if (create_breakpoint (get_current_arch (), |
| 10411 | arg, |
| 10412 | NULL, 0, 1 /* parse arg */, |
| 10413 | 0 /* tempflag */, 1 /* hardwareflag */, |
| 10414 | 1 /* traceflag */, |
| 10415 | 0 /* Ignore count */, |
| 10416 | pending_break_support, |
| 10417 | NULL, |
| 10418 | from_tty, |
| 10419 | 1 /* enabled */)) |
| 10420 | set_tracepoint_count (breakpoint_count); |
| 10421 | } |
| 10422 | |
| 10423 | /* Set up a fake reader function that gets command lines from a linked |
| 10424 | list that was acquired during tracepoint uploading. */ |
| 10425 | |
| 10426 | static struct uploaded_tp *this_utp; |
| 10427 | static int next_cmd; |
| 10428 | |
| 10429 | static char * |
| 10430 | read_uploaded_action (void) |
| 10431 | { |
| 10432 | char *rslt; |
| 10433 | |
| 10434 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
| 10435 | |
| 10436 | next_cmd++; |
| 10437 | |
| 10438 | return rslt; |
| 10439 | } |
| 10440 | |
| 10441 | /* Given information about a tracepoint as recorded on a target (which |
| 10442 | can be either a live system or a trace file), attempt to create an |
| 10443 | equivalent GDB tracepoint. This is not a reliable process, since |
| 10444 | the target does not necessarily have all the information used when |
| 10445 | the tracepoint was originally defined. */ |
| 10446 | |
| 10447 | struct breakpoint * |
| 10448 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
| 10449 | { |
| 10450 | char *addr_str, small_buf[100]; |
| 10451 | struct breakpoint *tp; |
| 10452 | |
| 10453 | if (utp->at_string) |
| 10454 | addr_str = utp->at_string; |
| 10455 | else |
| 10456 | { |
| 10457 | /* In the absence of a source location, fall back to raw |
| 10458 | address. Since there is no way to confirm that the address |
| 10459 | means the same thing as when the trace was started, warn the |
| 10460 | user. */ |
| 10461 | warning (_("Uploaded tracepoint %d has no source location, using raw address"), |
| 10462 | utp->number); |
| 10463 | sprintf (small_buf, "*%s", hex_string (utp->addr)); |
| 10464 | addr_str = small_buf; |
| 10465 | } |
| 10466 | |
| 10467 | /* There's not much we can do with a sequence of bytecodes. */ |
| 10468 | if (utp->cond && !utp->cond_string) |
| 10469 | warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"), |
| 10470 | utp->number); |
| 10471 | |
| 10472 | if (!create_breakpoint (get_current_arch (), |
| 10473 | addr_str, |
| 10474 | utp->cond_string, -1, 0 /* parse cond/thread */, |
| 10475 | 0 /* tempflag */, |
| 10476 | (utp->type == bp_fast_tracepoint) /* hardwareflag */, |
| 10477 | 1 /* traceflag */, |
| 10478 | 0 /* Ignore count */, |
| 10479 | pending_break_support, |
| 10480 | NULL, |
| 10481 | 0 /* from_tty */, |
| 10482 | utp->enabled /* enabled */)) |
| 10483 | return NULL; |
| 10484 | |
| 10485 | set_tracepoint_count (breakpoint_count); |
| 10486 | |
| 10487 | /* Get the tracepoint we just created. */ |
| 10488 | tp = get_tracepoint (tracepoint_count); |
| 10489 | gdb_assert (tp != NULL); |
| 10490 | |
| 10491 | if (utp->pass > 0) |
| 10492 | { |
| 10493 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
| 10494 | |
| 10495 | trace_pass_command (small_buf, 0); |
| 10496 | } |
| 10497 | |
| 10498 | /* If we have uploaded versions of the original commands, set up a |
| 10499 | special-purpose "reader" function and call the usual command line |
| 10500 | reader, then pass the result to the breakpoint command-setting |
| 10501 | function. */ |
| 10502 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
| 10503 | { |
| 10504 | struct command_line *cmd_list; |
| 10505 | |
| 10506 | this_utp = utp; |
| 10507 | next_cmd = 0; |
| 10508 | |
| 10509 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
| 10510 | |
| 10511 | breakpoint_set_commands (tp, cmd_list); |
| 10512 | } |
| 10513 | else if (!VEC_empty (char_ptr, utp->actions) |
| 10514 | || !VEC_empty (char_ptr, utp->step_actions)) |
| 10515 | warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"), |
| 10516 | utp->number); |
| 10517 | |
| 10518 | return tp; |
| 10519 | } |
| 10520 | |
| 10521 | /* Print information on tracepoint number TPNUM_EXP, or all if |
| 10522 | omitted. */ |
| 10523 | |
| 10524 | static void |
| 10525 | tracepoints_info (char *tpnum_exp, int from_tty) |
| 10526 | { |
| 10527 | int tpnum = -1, num_printed; |
| 10528 | |
| 10529 | if (tpnum_exp) |
| 10530 | tpnum = parse_and_eval_long (tpnum_exp); |
| 10531 | |
| 10532 | num_printed = breakpoint_1 (tpnum, 0, is_tracepoint); |
| 10533 | |
| 10534 | if (num_printed == 0) |
| 10535 | { |
| 10536 | if (tpnum == -1) |
| 10537 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
| 10538 | else |
| 10539 | ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum); |
| 10540 | } |
| 10541 | |
| 10542 | default_collect_info (); |
| 10543 | } |
| 10544 | |
| 10545 | /* The 'enable trace' command enables tracepoints. |
| 10546 | Not supported by all targets. */ |
| 10547 | static void |
| 10548 | enable_trace_command (char *args, int from_tty) |
| 10549 | { |
| 10550 | enable_command (args, from_tty); |
| 10551 | } |
| 10552 | |
| 10553 | /* The 'disable trace' command disables tracepoints. |
| 10554 | Not supported by all targets. */ |
| 10555 | static void |
| 10556 | disable_trace_command (char *args, int from_tty) |
| 10557 | { |
| 10558 | disable_command (args, from_tty); |
| 10559 | } |
| 10560 | |
| 10561 | /* Remove a tracepoint (or all if no argument) */ |
| 10562 | static void |
| 10563 | delete_trace_command (char *arg, int from_tty) |
| 10564 | { |
| 10565 | struct breakpoint *b, *temp; |
| 10566 | |
| 10567 | dont_repeat (); |
| 10568 | |
| 10569 | if (arg == 0) |
| 10570 | { |
| 10571 | int breaks_to_delete = 0; |
| 10572 | |
| 10573 | /* Delete all breakpoints if no argument. |
| 10574 | Do not delete internal or call-dummy breakpoints, these |
| 10575 | have to be deleted with an explicit breakpoint number argument. */ |
| 10576 | ALL_TRACEPOINTS (b) |
| 10577 | { |
| 10578 | if (b->number >= 0) |
| 10579 | { |
| 10580 | breaks_to_delete = 1; |
| 10581 | break; |
| 10582 | } |
| 10583 | } |
| 10584 | |
| 10585 | /* Ask user only if there are some breakpoints to delete. */ |
| 10586 | if (!from_tty |
| 10587 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) |
| 10588 | { |
| 10589 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 10590 | { |
| 10591 | if (is_tracepoint (b) |
| 10592 | && b->number >= 0) |
| 10593 | delete_breakpoint (b); |
| 10594 | } |
| 10595 | } |
| 10596 | } |
| 10597 | else |
| 10598 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
| 10599 | } |
| 10600 | |
| 10601 | /* Set passcount for tracepoint. |
| 10602 | |
| 10603 | First command argument is passcount, second is tracepoint number. |
| 10604 | If tracepoint number omitted, apply to most recently defined. |
| 10605 | Also accepts special argument "all". */ |
| 10606 | |
| 10607 | static void |
| 10608 | trace_pass_command (char *args, int from_tty) |
| 10609 | { |
| 10610 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; |
| 10611 | unsigned int count; |
| 10612 | int all = 0; |
| 10613 | |
| 10614 | if (args == 0 || *args == 0) |
| 10615 | error (_("passcount command requires an argument (count + optional TP num)")); |
| 10616 | |
| 10617 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
| 10618 | |
| 10619 | while (*args && isspace ((int) *args)) |
| 10620 | args++; |
| 10621 | |
| 10622 | if (*args && strncasecmp (args, "all", 3) == 0) |
| 10623 | { |
| 10624 | args += 3; /* Skip special argument "all". */ |
| 10625 | all = 1; |
| 10626 | if (*args) |
| 10627 | error (_("Junk at end of arguments.")); |
| 10628 | } |
| 10629 | else |
| 10630 | t1 = get_tracepoint_by_number (&args, 1, 1); |
| 10631 | |
| 10632 | do |
| 10633 | { |
| 10634 | if (t1) |
| 10635 | { |
| 10636 | ALL_TRACEPOINTS (t2) |
| 10637 | if (t1 == (struct breakpoint *) -1 || t1 == t2) |
| 10638 | { |
| 10639 | t2->pass_count = count; |
| 10640 | observer_notify_tracepoint_modified (t2->number); |
| 10641 | if (from_tty) |
| 10642 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), |
| 10643 | t2->number, count); |
| 10644 | } |
| 10645 | if (! all && *args) |
| 10646 | t1 = get_tracepoint_by_number (&args, 1, 0); |
| 10647 | } |
| 10648 | } |
| 10649 | while (*args); |
| 10650 | } |
| 10651 | |
| 10652 | struct breakpoint * |
| 10653 | get_tracepoint (int num) |
| 10654 | { |
| 10655 | struct breakpoint *t; |
| 10656 | |
| 10657 | ALL_TRACEPOINTS (t) |
| 10658 | if (t->number == num) |
| 10659 | return t; |
| 10660 | |
| 10661 | return NULL; |
| 10662 | } |
| 10663 | |
| 10664 | /* Find the tracepoint with the given target-side number (which may be |
| 10665 | different from the tracepoint number after disconnecting and |
| 10666 | reconnecting). */ |
| 10667 | |
| 10668 | struct breakpoint * |
| 10669 | get_tracepoint_by_number_on_target (int num) |
| 10670 | { |
| 10671 | struct breakpoint *t; |
| 10672 | |
| 10673 | ALL_TRACEPOINTS (t) |
| 10674 | if (t->number_on_target == num) |
| 10675 | return t; |
| 10676 | |
| 10677 | return NULL; |
| 10678 | } |
| 10679 | |
| 10680 | /* Utility: parse a tracepoint number and look it up in the list. |
| 10681 | If MULTI_P is true, there might be a range of tracepoints in ARG. |
| 10682 | if OPTIONAL_P is true, then if the argument is missing, the most |
| 10683 | recent tracepoint (tracepoint_count) is returned. */ |
| 10684 | struct breakpoint * |
| 10685 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) |
| 10686 | { |
| 10687 | extern int tracepoint_count; |
| 10688 | struct breakpoint *t; |
| 10689 | int tpnum; |
| 10690 | char *instring = arg == NULL ? NULL : *arg; |
| 10691 | |
| 10692 | if (arg == NULL || *arg == NULL || ! **arg) |
| 10693 | { |
| 10694 | if (optional_p) |
| 10695 | tpnum = tracepoint_count; |
| 10696 | else |
| 10697 | error_no_arg (_("tracepoint number")); |
| 10698 | } |
| 10699 | else |
| 10700 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); |
| 10701 | |
| 10702 | if (tpnum <= 0) |
| 10703 | { |
| 10704 | if (instring && *instring) |
| 10705 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), |
| 10706 | instring); |
| 10707 | else |
| 10708 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); |
| 10709 | return NULL; |
| 10710 | } |
| 10711 | |
| 10712 | ALL_TRACEPOINTS (t) |
| 10713 | if (t->number == tpnum) |
| 10714 | { |
| 10715 | return t; |
| 10716 | } |
| 10717 | |
| 10718 | /* FIXME: if we are in the middle of a range we don't want to give |
| 10719 | a message. The current interface to get_number_or_range doesn't |
| 10720 | allow us to discover this. */ |
| 10721 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
| 10722 | return NULL; |
| 10723 | } |
| 10724 | |
| 10725 | /* Save information on user settable breakpoints (watchpoints, etc) to |
| 10726 | a new script file named FILENAME. If FILTER is non-NULL, call it |
| 10727 | on each breakpoint and only include the ones for which it returns |
| 10728 | non-zero. */ |
| 10729 | |
| 10730 | static void |
| 10731 | save_breakpoints (char *filename, int from_tty, |
| 10732 | int (*filter) (const struct breakpoint *)) |
| 10733 | { |
| 10734 | struct breakpoint *tp; |
| 10735 | int any = 0; |
| 10736 | char *pathname; |
| 10737 | struct cleanup *cleanup; |
| 10738 | struct ui_file *fp; |
| 10739 | int extra_trace_bits = 0; |
| 10740 | |
| 10741 | if (filename == 0 || *filename == 0) |
| 10742 | error (_("Argument required (file name in which to save)")); |
| 10743 | |
| 10744 | /* See if we have anything to save. */ |
| 10745 | ALL_BREAKPOINTS (tp) |
| 10746 | { |
| 10747 | /* Skip internal and momentary breakpoints. */ |
| 10748 | if (!user_settable_breakpoint (tp)) |
| 10749 | continue; |
| 10750 | |
| 10751 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 10752 | if (filter && !filter (tp)) |
| 10753 | continue; |
| 10754 | |
| 10755 | any = 1; |
| 10756 | |
| 10757 | if (is_tracepoint (tp)) |
| 10758 | { |
| 10759 | extra_trace_bits = 1; |
| 10760 | |
| 10761 | /* We can stop searching. */ |
| 10762 | break; |
| 10763 | } |
| 10764 | } |
| 10765 | |
| 10766 | if (!any) |
| 10767 | { |
| 10768 | warning (_("Nothing to save.")); |
| 10769 | return; |
| 10770 | } |
| 10771 | |
| 10772 | pathname = tilde_expand (filename); |
| 10773 | cleanup = make_cleanup (xfree, pathname); |
| 10774 | fp = gdb_fopen (pathname, "w"); |
| 10775 | if (!fp) |
| 10776 | error (_("Unable to open file '%s' for saving (%s)"), |
| 10777 | filename, safe_strerror (errno)); |
| 10778 | make_cleanup_ui_file_delete (fp); |
| 10779 | |
| 10780 | if (extra_trace_bits) |
| 10781 | save_trace_state_variables (fp); |
| 10782 | |
| 10783 | ALL_BREAKPOINTS (tp) |
| 10784 | { |
| 10785 | /* Skip internal and momentary breakpoints. */ |
| 10786 | if (!user_settable_breakpoint (tp)) |
| 10787 | continue; |
| 10788 | |
| 10789 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 10790 | if (filter && !filter (tp)) |
| 10791 | continue; |
| 10792 | |
| 10793 | if (tp->ops != NULL) |
| 10794 | (tp->ops->print_recreate) (tp, fp); |
| 10795 | else |
| 10796 | { |
| 10797 | if (tp->type == bp_fast_tracepoint) |
| 10798 | fprintf_unfiltered (fp, "ftrace"); |
| 10799 | else if (tp->type == bp_tracepoint) |
| 10800 | fprintf_unfiltered (fp, "trace"); |
| 10801 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) |
| 10802 | fprintf_unfiltered (fp, "tbreak"); |
| 10803 | else if (tp->type == bp_breakpoint) |
| 10804 | fprintf_unfiltered (fp, "break"); |
| 10805 | else if (tp->type == bp_hardware_breakpoint |
| 10806 | && tp->disposition == disp_del) |
| 10807 | fprintf_unfiltered (fp, "thbreak"); |
| 10808 | else if (tp->type == bp_hardware_breakpoint) |
| 10809 | fprintf_unfiltered (fp, "hbreak"); |
| 10810 | else if (tp->type == bp_watchpoint) |
| 10811 | fprintf_unfiltered (fp, "watch"); |
| 10812 | else if (tp->type == bp_hardware_watchpoint) |
| 10813 | fprintf_unfiltered (fp, "watch"); |
| 10814 | else if (tp->type == bp_read_watchpoint) |
| 10815 | fprintf_unfiltered (fp, "rwatch"); |
| 10816 | else if (tp->type == bp_access_watchpoint) |
| 10817 | fprintf_unfiltered (fp, "awatch"); |
| 10818 | else |
| 10819 | internal_error (__FILE__, __LINE__, |
| 10820 | _("unhandled breakpoint type %d"), (int) tp->type); |
| 10821 | |
| 10822 | if (tp->exp_string) |
| 10823 | fprintf_unfiltered (fp, " %s", tp->exp_string); |
| 10824 | else if (tp->addr_string) |
| 10825 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
| 10826 | else |
| 10827 | { |
| 10828 | char tmp[40]; |
| 10829 | |
| 10830 | sprintf_vma (tmp, tp->loc->address); |
| 10831 | fprintf_unfiltered (fp, " *0x%s", tmp); |
| 10832 | } |
| 10833 | } |
| 10834 | |
| 10835 | if (tp->thread != -1) |
| 10836 | fprintf_unfiltered (fp, " thread %d", tp->thread); |
| 10837 | |
| 10838 | if (tp->task != 0) |
| 10839 | fprintf_unfiltered (fp, " task %d", tp->task); |
| 10840 | |
| 10841 | fprintf_unfiltered (fp, "\n"); |
| 10842 | |
| 10843 | /* Note, we can't rely on tp->number for anything, as we can't |
| 10844 | assume the recreated breakpoint numbers will match. Use $bpnum |
| 10845 | instead. */ |
| 10846 | |
| 10847 | if (tp->cond_string) |
| 10848 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); |
| 10849 | |
| 10850 | if (tp->ignore_count) |
| 10851 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); |
| 10852 | |
| 10853 | if (tp->pass_count) |
| 10854 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
| 10855 | |
| 10856 | if (tp->commands) |
| 10857 | { |
| 10858 | volatile struct gdb_exception ex; |
| 10859 | |
| 10860 | fprintf_unfiltered (fp, " commands\n"); |
| 10861 | |
| 10862 | ui_out_redirect (uiout, fp); |
| 10863 | TRY_CATCH (ex, RETURN_MASK_ERROR) |
| 10864 | { |
| 10865 | print_command_lines (uiout, tp->commands->commands, 2); |
| 10866 | } |
| 10867 | ui_out_redirect (uiout, NULL); |
| 10868 | |
| 10869 | if (ex.reason < 0) |
| 10870 | throw_exception (ex); |
| 10871 | |
| 10872 | fprintf_unfiltered (fp, " end\n"); |
| 10873 | } |
| 10874 | |
| 10875 | if (tp->enable_state == bp_disabled) |
| 10876 | fprintf_unfiltered (fp, "disable\n"); |
| 10877 | |
| 10878 | /* If this is a multi-location breakpoint, check if the locations |
| 10879 | should be individually disabled. Watchpoint locations are |
| 10880 | special, and not user visible. */ |
| 10881 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) |
| 10882 | { |
| 10883 | struct bp_location *loc; |
| 10884 | int n = 1; |
| 10885 | |
| 10886 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) |
| 10887 | if (!loc->enabled) |
| 10888 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); |
| 10889 | } |
| 10890 | } |
| 10891 | |
| 10892 | if (extra_trace_bits && *default_collect) |
| 10893 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
| 10894 | |
| 10895 | do_cleanups (cleanup); |
| 10896 | if (from_tty) |
| 10897 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
| 10898 | } |
| 10899 | |
| 10900 | /* The `save breakpoints' command. */ |
| 10901 | |
| 10902 | static void |
| 10903 | save_breakpoints_command (char *args, int from_tty) |
| 10904 | { |
| 10905 | save_breakpoints (args, from_tty, NULL); |
| 10906 | } |
| 10907 | |
| 10908 | /* The `save tracepoints' command. */ |
| 10909 | |
| 10910 | static void |
| 10911 | save_tracepoints_command (char *args, int from_tty) |
| 10912 | { |
| 10913 | save_breakpoints (args, from_tty, is_tracepoint); |
| 10914 | } |
| 10915 | |
| 10916 | /* Create a vector of all tracepoints. */ |
| 10917 | |
| 10918 | VEC(breakpoint_p) * |
| 10919 | all_tracepoints () |
| 10920 | { |
| 10921 | VEC(breakpoint_p) *tp_vec = 0; |
| 10922 | struct breakpoint *tp; |
| 10923 | |
| 10924 | ALL_TRACEPOINTS (tp) |
| 10925 | { |
| 10926 | VEC_safe_push (breakpoint_p, tp_vec, tp); |
| 10927 | } |
| 10928 | |
| 10929 | return tp_vec; |
| 10930 | } |
| 10931 | |
| 10932 | \f |
| 10933 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
| 10934 | It is defined as a macro to prevent duplication. |
| 10935 | COMMAND should be a string constant containing the name of the command. */ |
| 10936 | #define BREAK_ARGS_HELP(command) \ |
| 10937 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
| 10938 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
| 10939 | If a line number is specified, break at start of code for that line.\n\ |
| 10940 | If a function is specified, break at start of code for that function.\n\ |
| 10941 | If an address is specified, break at that exact address.\n\ |
| 10942 | With no LOCATION, uses current execution address of selected stack frame.\n\ |
| 10943 | This is useful for breaking on return to a stack frame.\n\ |
| 10944 | \n\ |
| 10945 | THREADNUM is the number from \"info threads\".\n\ |
| 10946 | CONDITION is a boolean expression.\n\ |
| 10947 | \n\ |
| 10948 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ |
| 10949 | \n\ |
| 10950 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." |
| 10951 | |
| 10952 | /* List of subcommands for "catch". */ |
| 10953 | static struct cmd_list_element *catch_cmdlist; |
| 10954 | |
| 10955 | /* List of subcommands for "tcatch". */ |
| 10956 | static struct cmd_list_element *tcatch_cmdlist; |
| 10957 | |
| 10958 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" |
| 10959 | lists, and pass some additional user data to the command function. */ |
| 10960 | static void |
| 10961 | add_catch_command (char *name, char *docstring, |
| 10962 | void (*sfunc) (char *args, int from_tty, |
| 10963 | struct cmd_list_element *command), |
| 10964 | char **(*completer) (struct cmd_list_element *cmd, |
| 10965 | char *text, char *word), |
| 10966 | void *user_data_catch, |
| 10967 | void *user_data_tcatch) |
| 10968 | { |
| 10969 | struct cmd_list_element *command; |
| 10970 | |
| 10971 | command = add_cmd (name, class_breakpoint, NULL, docstring, |
| 10972 | &catch_cmdlist); |
| 10973 | set_cmd_sfunc (command, sfunc); |
| 10974 | set_cmd_context (command, user_data_catch); |
| 10975 | set_cmd_completer (command, completer); |
| 10976 | |
| 10977 | command = add_cmd (name, class_breakpoint, NULL, docstring, |
| 10978 | &tcatch_cmdlist); |
| 10979 | set_cmd_sfunc (command, sfunc); |
| 10980 | set_cmd_context (command, user_data_tcatch); |
| 10981 | set_cmd_completer (command, completer); |
| 10982 | } |
| 10983 | |
| 10984 | static void |
| 10985 | clear_syscall_counts (struct inferior *inf) |
| 10986 | { |
| 10987 | inf->total_syscalls_count = 0; |
| 10988 | inf->any_syscall_count = 0; |
| 10989 | VEC_free (int, inf->syscalls_counts); |
| 10990 | } |
| 10991 | |
| 10992 | static void |
| 10993 | save_command (char *arg, int from_tty) |
| 10994 | { |
| 10995 | printf_unfiltered (_("\ |
| 10996 | \"save\" must be followed by the name of a save subcommand.\n")); |
| 10997 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
| 10998 | } |
| 10999 | |
| 11000 | void |
| 11001 | _initialize_breakpoint (void) |
| 11002 | { |
| 11003 | struct cmd_list_element *c; |
| 11004 | |
| 11005 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
| 11006 | observer_attach_inferior_exit (clear_syscall_counts); |
| 11007 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
| 11008 | |
| 11009 | breakpoint_chain = 0; |
| 11010 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful |
| 11011 | before a breakpoint is set. */ |
| 11012 | breakpoint_count = 0; |
| 11013 | |
| 11014 | tracepoint_count = 0; |
| 11015 | |
| 11016 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
| 11017 | Set ignore-count of breakpoint number N to COUNT.\n\ |
| 11018 | Usage is `ignore N COUNT'.")); |
| 11019 | if (xdb_commands) |
| 11020 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
| 11021 | |
| 11022 | add_com ("commands", class_breakpoint, commands_command, _("\ |
| 11023 | Set commands to be executed when a breakpoint is hit.\n\ |
| 11024 | Give breakpoint number as argument after \"commands\".\n\ |
| 11025 | With no argument, the targeted breakpoint is the last one set.\n\ |
| 11026 | The commands themselves follow starting on the next line.\n\ |
| 11027 | Type a line containing \"end\" to indicate the end of them.\n\ |
| 11028 | Give \"silent\" as the first line to make the breakpoint silent;\n\ |
| 11029 | then no output is printed when it is hit, except what the commands print.")); |
| 11030 | |
| 11031 | add_com ("condition", class_breakpoint, condition_command, _("\ |
| 11032 | Specify breakpoint number N to break only if COND is true.\n\ |
| 11033 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
| 11034 | expression to be evaluated whenever breakpoint N is reached.")); |
| 11035 | |
| 11036 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
| 11037 | Set a temporary breakpoint.\n\ |
| 11038 | Like \"break\" except the breakpoint is only temporary,\n\ |
| 11039 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ |
| 11040 | by using \"enable delete\" on the breakpoint number.\n\ |
| 11041 | \n" |
| 11042 | BREAK_ARGS_HELP ("tbreak"))); |
| 11043 | set_cmd_completer (c, location_completer); |
| 11044 | |
| 11045 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
| 11046 | Set a hardware assisted breakpoint.\n\ |
| 11047 | Like \"break\" except the breakpoint requires hardware support,\n\ |
| 11048 | some target hardware may not have this support.\n\ |
| 11049 | \n" |
| 11050 | BREAK_ARGS_HELP ("hbreak"))); |
| 11051 | set_cmd_completer (c, location_completer); |
| 11052 | |
| 11053 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
| 11054 | Set a temporary hardware assisted breakpoint.\n\ |
| 11055 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
| 11056 | so it will be deleted when hit.\n\ |
| 11057 | \n" |
| 11058 | BREAK_ARGS_HELP ("thbreak"))); |
| 11059 | set_cmd_completer (c, location_completer); |
| 11060 | |
| 11061 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
| 11062 | Enable some breakpoints.\n\ |
| 11063 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 11064 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 11065 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 11066 | With a subcommand you can enable temporarily."), |
| 11067 | &enablelist, "enable ", 1, &cmdlist); |
| 11068 | if (xdb_commands) |
| 11069 | add_com ("ab", class_breakpoint, enable_command, _("\ |
| 11070 | Enable some breakpoints.\n\ |
| 11071 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 11072 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 11073 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 11074 | With a subcommand you can enable temporarily.")); |
| 11075 | |
| 11076 | add_com_alias ("en", "enable", class_breakpoint, 1); |
| 11077 | |
| 11078 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
| 11079 | Enable some breakpoints.\n\ |
| 11080 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 11081 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 11082 | May be abbreviated to simply \"enable\".\n"), |
| 11083 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
| 11084 | |
| 11085 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 11086 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 11087 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 11088 | &enablebreaklist); |
| 11089 | |
| 11090 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 11091 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 11092 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 11093 | &enablebreaklist); |
| 11094 | |
| 11095 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 11096 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 11097 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 11098 | &enablelist); |
| 11099 | |
| 11100 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 11101 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 11102 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 11103 | &enablelist); |
| 11104 | |
| 11105 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
| 11106 | Disable some breakpoints.\n\ |
| 11107 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 11108 | To disable all breakpoints, give no argument.\n\ |
| 11109 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
| 11110 | &disablelist, "disable ", 1, &cmdlist); |
| 11111 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
| 11112 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
| 11113 | if (xdb_commands) |
| 11114 | add_com ("sb", class_breakpoint, disable_command, _("\ |
| 11115 | Disable some breakpoints.\n\ |
| 11116 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 11117 | To disable all breakpoints, give no argument.\n\ |
| 11118 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
| 11119 | |
| 11120 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
| 11121 | Disable some breakpoints.\n\ |
| 11122 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 11123 | To disable all breakpoints, give no argument.\n\ |
| 11124 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ |
| 11125 | This command may be abbreviated \"disable\"."), |
| 11126 | &disablelist); |
| 11127 | |
| 11128 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
| 11129 | Delete some breakpoints or auto-display expressions.\n\ |
| 11130 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 11131 | To delete all breakpoints, give no argument.\n\ |
| 11132 | \n\ |
| 11133 | Also a prefix command for deletion of other GDB objects.\n\ |
| 11134 | The \"unset\" command is also an alias for \"delete\"."), |
| 11135 | &deletelist, "delete ", 1, &cmdlist); |
| 11136 | add_com_alias ("d", "delete", class_breakpoint, 1); |
| 11137 | add_com_alias ("del", "delete", class_breakpoint, 1); |
| 11138 | if (xdb_commands) |
| 11139 | add_com ("db", class_breakpoint, delete_command, _("\ |
| 11140 | Delete some breakpoints.\n\ |
| 11141 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 11142 | To delete all breakpoints, give no argument.\n")); |
| 11143 | |
| 11144 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
| 11145 | Delete some breakpoints or auto-display expressions.\n\ |
| 11146 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 11147 | To delete all breakpoints, give no argument.\n\ |
| 11148 | This command may be abbreviated \"delete\"."), |
| 11149 | &deletelist); |
| 11150 | |
| 11151 | add_com ("clear", class_breakpoint, clear_command, _("\ |
| 11152 | Clear breakpoint at specified line or function.\n\ |
| 11153 | Argument may be line number, function name, or \"*\" and an address.\n\ |
| 11154 | If line number is specified, all breakpoints in that line are cleared.\n\ |
| 11155 | If function is specified, breakpoints at beginning of function are cleared.\n\ |
| 11156 | If an address is specified, breakpoints at that address are cleared.\n\ |
| 11157 | \n\ |
| 11158 | With no argument, clears all breakpoints in the line that the selected frame\n\ |
| 11159 | is executing in.\n\ |
| 11160 | \n\ |
| 11161 | See also the \"delete\" command which clears breakpoints by number.")); |
| 11162 | |
| 11163 | c = add_com ("break", class_breakpoint, break_command, _("\ |
| 11164 | Set breakpoint at specified line or function.\n" |
| 11165 | BREAK_ARGS_HELP ("break"))); |
| 11166 | set_cmd_completer (c, location_completer); |
| 11167 | |
| 11168 | add_com_alias ("b", "break", class_run, 1); |
| 11169 | add_com_alias ("br", "break", class_run, 1); |
| 11170 | add_com_alias ("bre", "break", class_run, 1); |
| 11171 | add_com_alias ("brea", "break", class_run, 1); |
| 11172 | |
| 11173 | if (xdb_commands) |
| 11174 | add_com_alias ("ba", "break", class_breakpoint, 1); |
| 11175 | |
| 11176 | if (dbx_commands) |
| 11177 | { |
| 11178 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
| 11179 | Break in function/address or break at a line in the current file."), |
| 11180 | &stoplist, "stop ", 1, &cmdlist); |
| 11181 | add_cmd ("in", class_breakpoint, stopin_command, |
| 11182 | _("Break in function or address."), &stoplist); |
| 11183 | add_cmd ("at", class_breakpoint, stopat_command, |
| 11184 | _("Break at a line in the current file."), &stoplist); |
| 11185 | add_com ("status", class_info, breakpoints_info, _("\ |
| 11186 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 11187 | The \"Type\" column indicates one of:\n\ |
| 11188 | \tbreakpoint - normal breakpoint\n\ |
| 11189 | \twatchpoint - watchpoint\n\ |
| 11190 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 11191 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 11192 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 11193 | address and file/line number respectively.\n\ |
| 11194 | \n\ |
| 11195 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 11196 | are set to the address of the last breakpoint listed unless the command\n\ |
| 11197 | is prefixed with \"server \".\n\n\ |
| 11198 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 11199 | breakpoint set.")); |
| 11200 | } |
| 11201 | |
| 11202 | add_info ("breakpoints", breakpoints_info, _("\ |
| 11203 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 11204 | The \"Type\" column indicates one of:\n\ |
| 11205 | \tbreakpoint - normal breakpoint\n\ |
| 11206 | \twatchpoint - watchpoint\n\ |
| 11207 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 11208 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 11209 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 11210 | address and file/line number respectively.\n\ |
| 11211 | \n\ |
| 11212 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 11213 | are set to the address of the last breakpoint listed unless the command\n\ |
| 11214 | is prefixed with \"server \".\n\n\ |
| 11215 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 11216 | breakpoint set.")); |
| 11217 | |
| 11218 | add_info_alias ("b", "breakpoints", 1); |
| 11219 | |
| 11220 | if (xdb_commands) |
| 11221 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
| 11222 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 11223 | The \"Type\" column indicates one of:\n\ |
| 11224 | \tbreakpoint - normal breakpoint\n\ |
| 11225 | \twatchpoint - watchpoint\n\ |
| 11226 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 11227 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 11228 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 11229 | address and file/line number respectively.\n\ |
| 11230 | \n\ |
| 11231 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 11232 | are set to the address of the last breakpoint listed unless the command\n\ |
| 11233 | is prefixed with \"server \".\n\n\ |
| 11234 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 11235 | breakpoint set.")); |
| 11236 | |
| 11237 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
| 11238 | Status of all breakpoints, or breakpoint number NUMBER.\n\ |
| 11239 | The \"Type\" column indicates one of:\n\ |
| 11240 | \tbreakpoint - normal breakpoint\n\ |
| 11241 | \twatchpoint - watchpoint\n\ |
| 11242 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ |
| 11243 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ |
| 11244 | \tuntil - internal breakpoint used by the \"until\" command\n\ |
| 11245 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
| 11246 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 11247 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 11248 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 11249 | address and file/line number respectively.\n\ |
| 11250 | \n\ |
| 11251 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 11252 | are set to the address of the last breakpoint listed unless the command\n\ |
| 11253 | is prefixed with \"server \".\n\n\ |
| 11254 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 11255 | breakpoint set."), |
| 11256 | &maintenanceinfolist); |
| 11257 | |
| 11258 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
| 11259 | Set catchpoints to catch events."), |
| 11260 | &catch_cmdlist, "catch ", |
| 11261 | 0/*allow-unknown*/, &cmdlist); |
| 11262 | |
| 11263 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ |
| 11264 | Set temporary catchpoints to catch events."), |
| 11265 | &tcatch_cmdlist, "tcatch ", |
| 11266 | 0/*allow-unknown*/, &cmdlist); |
| 11267 | |
| 11268 | /* Add catch and tcatch sub-commands. */ |
| 11269 | add_catch_command ("catch", _("\ |
| 11270 | Catch an exception, when caught.\n\ |
| 11271 | With an argument, catch only exceptions with the given name."), |
| 11272 | catch_catch_command, |
| 11273 | NULL, |
| 11274 | CATCH_PERMANENT, |
| 11275 | CATCH_TEMPORARY); |
| 11276 | add_catch_command ("throw", _("\ |
| 11277 | Catch an exception, when thrown.\n\ |
| 11278 | With an argument, catch only exceptions with the given name."), |
| 11279 | catch_throw_command, |
| 11280 | NULL, |
| 11281 | CATCH_PERMANENT, |
| 11282 | CATCH_TEMPORARY); |
| 11283 | add_catch_command ("fork", _("Catch calls to fork."), |
| 11284 | catch_fork_command_1, |
| 11285 | NULL, |
| 11286 | (void *) (uintptr_t) catch_fork_permanent, |
| 11287 | (void *) (uintptr_t) catch_fork_temporary); |
| 11288 | add_catch_command ("vfork", _("Catch calls to vfork."), |
| 11289 | catch_fork_command_1, |
| 11290 | NULL, |
| 11291 | (void *) (uintptr_t) catch_vfork_permanent, |
| 11292 | (void *) (uintptr_t) catch_vfork_temporary); |
| 11293 | add_catch_command ("exec", _("Catch calls to exec."), |
| 11294 | catch_exec_command_1, |
| 11295 | NULL, |
| 11296 | CATCH_PERMANENT, |
| 11297 | CATCH_TEMPORARY); |
| 11298 | add_catch_command ("syscall", _("\ |
| 11299 | Catch system calls by their names and/or numbers.\n\ |
| 11300 | Arguments say which system calls to catch. If no arguments\n\ |
| 11301 | are given, every system call will be caught.\n\ |
| 11302 | Arguments, if given, should be one or more system call names\n\ |
| 11303 | (if your system supports that), or system call numbers."), |
| 11304 | catch_syscall_command_1, |
| 11305 | catch_syscall_completer, |
| 11306 | CATCH_PERMANENT, |
| 11307 | CATCH_TEMPORARY); |
| 11308 | add_catch_command ("exception", _("\ |
| 11309 | Catch Ada exceptions, when raised.\n\ |
| 11310 | With an argument, catch only exceptions with the given name."), |
| 11311 | catch_ada_exception_command, |
| 11312 | NULL, |
| 11313 | CATCH_PERMANENT, |
| 11314 | CATCH_TEMPORARY); |
| 11315 | add_catch_command ("assert", _("\ |
| 11316 | Catch failed Ada assertions, when raised.\n\ |
| 11317 | With an argument, catch only exceptions with the given name."), |
| 11318 | catch_assert_command, |
| 11319 | NULL, |
| 11320 | CATCH_PERMANENT, |
| 11321 | CATCH_TEMPORARY); |
| 11322 | |
| 11323 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
| 11324 | Set a watchpoint for an expression.\n\ |
| 11325 | A watchpoint stops execution of your program whenever the value of\n\ |
| 11326 | an expression changes.")); |
| 11327 | set_cmd_completer (c, expression_completer); |
| 11328 | |
| 11329 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
| 11330 | Set a read watchpoint for an expression.\n\ |
| 11331 | A watchpoint stops execution of your program whenever the value of\n\ |
| 11332 | an expression is read.")); |
| 11333 | set_cmd_completer (c, expression_completer); |
| 11334 | |
| 11335 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
| 11336 | Set a watchpoint for an expression.\n\ |
| 11337 | A watchpoint stops execution of your program whenever the value of\n\ |
| 11338 | an expression is either read or written.")); |
| 11339 | set_cmd_completer (c, expression_completer); |
| 11340 | |
| 11341 | add_info ("watchpoints", watchpoints_info, _("\ |
| 11342 | Status of watchpoints, or watchpoint number NUMBER.")); |
| 11343 | |
| 11344 | |
| 11345 | |
| 11346 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
| 11347 | respond to changes - contrary to the description. */ |
| 11348 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
| 11349 | &can_use_hw_watchpoints, _("\ |
| 11350 | Set debugger's willingness to use watchpoint hardware."), _("\ |
| 11351 | Show debugger's willingness to use watchpoint hardware."), _("\ |
| 11352 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
| 11353 | such is available. (However, any hardware watchpoints that were\n\ |
| 11354 | created before setting this to nonzero, will continue to use watchpoint\n\ |
| 11355 | hardware.)"), |
| 11356 | NULL, |
| 11357 | show_can_use_hw_watchpoints, |
| 11358 | &setlist, &showlist); |
| 11359 | |
| 11360 | can_use_hw_watchpoints = 1; |
| 11361 | |
| 11362 | /* Tracepoint manipulation commands. */ |
| 11363 | |
| 11364 | c = add_com ("trace", class_breakpoint, trace_command, _("\ |
| 11365 | Set a tracepoint at specified line or function.\n\ |
| 11366 | \n" |
| 11367 | BREAK_ARGS_HELP ("trace") "\n\ |
| 11368 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 11369 | set_cmd_completer (c, location_completer); |
| 11370 | |
| 11371 | add_com_alias ("tp", "trace", class_alias, 0); |
| 11372 | add_com_alias ("tr", "trace", class_alias, 1); |
| 11373 | add_com_alias ("tra", "trace", class_alias, 1); |
| 11374 | add_com_alias ("trac", "trace", class_alias, 1); |
| 11375 | |
| 11376 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
| 11377 | Set a fast tracepoint at specified line or function.\n\ |
| 11378 | \n" |
| 11379 | BREAK_ARGS_HELP ("ftrace") "\n\ |
| 11380 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 11381 | set_cmd_completer (c, location_completer); |
| 11382 | |
| 11383 | add_info ("tracepoints", tracepoints_info, _("\ |
| 11384 | Status of tracepoints, or tracepoint number NUMBER.\n\ |
| 11385 | Convenience variable \"$tpnum\" contains the number of the\n\ |
| 11386 | last tracepoint set.")); |
| 11387 | |
| 11388 | add_info_alias ("tp", "tracepoints", 1); |
| 11389 | |
| 11390 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ |
| 11391 | Delete specified tracepoints.\n\ |
| 11392 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 11393 | No argument means delete all tracepoints."), |
| 11394 | &deletelist); |
| 11395 | |
| 11396 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ |
| 11397 | Disable specified tracepoints.\n\ |
| 11398 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 11399 | No argument means disable all tracepoints."), |
| 11400 | &disablelist); |
| 11401 | deprecate_cmd (c, "disable"); |
| 11402 | |
| 11403 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ |
| 11404 | Enable specified tracepoints.\n\ |
| 11405 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 11406 | No argument means enable all tracepoints."), |
| 11407 | &enablelist); |
| 11408 | deprecate_cmd (c, "enable"); |
| 11409 | |
| 11410 | add_com ("passcount", class_trace, trace_pass_command, _("\ |
| 11411 | Set the passcount for a tracepoint.\n\ |
| 11412 | The trace will end when the tracepoint has been passed 'count' times.\n\ |
| 11413 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ |
| 11414 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); |
| 11415 | |
| 11416 | add_prefix_cmd ("save", class_breakpoint, save_command, |
| 11417 | _("Save breakpoint definitions as a script."), |
| 11418 | &save_cmdlist, "save ", |
| 11419 | 0/*allow-unknown*/, &cmdlist); |
| 11420 | |
| 11421 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ |
| 11422 | Save current breakpoint definitions as a script.\n\ |
| 11423 | This includes all types of breakpoints (breakpoints, watchpoints, \n\ |
| 11424 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
| 11425 | session to restore them."), |
| 11426 | &save_cmdlist); |
| 11427 | set_cmd_completer (c, filename_completer); |
| 11428 | |
| 11429 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ |
| 11430 | Save current tracepoint definitions as a script.\n\ |
| 11431 | Use the 'source' command in another debug session to restore them."), |
| 11432 | &save_cmdlist); |
| 11433 | set_cmd_completer (c, filename_completer); |
| 11434 | |
| 11435 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
| 11436 | deprecate_cmd (c, "save tracepoints"); |
| 11437 | |
| 11438 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
| 11439 | Breakpoint specific settings\n\ |
| 11440 | Configure various breakpoint-specific variables such as\n\ |
| 11441 | pending breakpoint behavior"), |
| 11442 | &breakpoint_set_cmdlist, "set breakpoint ", |
| 11443 | 0/*allow-unknown*/, &setlist); |
| 11444 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
| 11445 | Breakpoint specific settings\n\ |
| 11446 | Configure various breakpoint-specific variables such as\n\ |
| 11447 | pending breakpoint behavior"), |
| 11448 | &breakpoint_show_cmdlist, "show breakpoint ", |
| 11449 | 0/*allow-unknown*/, &showlist); |
| 11450 | |
| 11451 | add_setshow_auto_boolean_cmd ("pending", no_class, |
| 11452 | &pending_break_support, _("\ |
| 11453 | Set debugger's behavior regarding pending breakpoints."), _("\ |
| 11454 | Show debugger's behavior regarding pending breakpoints."), _("\ |
| 11455 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
| 11456 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ |
| 11457 | an error. If auto, an unrecognized breakpoint location results in a\n\ |
| 11458 | user-query to see if a pending breakpoint should be created."), |
| 11459 | NULL, |
| 11460 | show_pending_break_support, |
| 11461 | &breakpoint_set_cmdlist, |
| 11462 | &breakpoint_show_cmdlist); |
| 11463 | |
| 11464 | pending_break_support = AUTO_BOOLEAN_AUTO; |
| 11465 | |
| 11466 | add_setshow_boolean_cmd ("auto-hw", no_class, |
| 11467 | &automatic_hardware_breakpoints, _("\ |
| 11468 | Set automatic usage of hardware breakpoints."), _("\ |
| 11469 | Show automatic usage of hardware breakpoints."), _("\ |
| 11470 | If set, the debugger will automatically use hardware breakpoints for\n\ |
| 11471 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ |
| 11472 | a warning will be emitted for such breakpoints."), |
| 11473 | NULL, |
| 11474 | show_automatic_hardware_breakpoints, |
| 11475 | &breakpoint_set_cmdlist, |
| 11476 | &breakpoint_show_cmdlist); |
| 11477 | |
| 11478 | add_setshow_enum_cmd ("always-inserted", class_support, |
| 11479 | always_inserted_enums, &always_inserted_mode, _("\ |
| 11480 | Set mode for inserting breakpoints."), _("\ |
| 11481 | Show mode for inserting breakpoints."), _("\ |
| 11482 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
| 11483 | resumed, and removed when execution stops. When this mode is on,\n\ |
| 11484 | breakpoints are inserted immediately and removed only when the user\n\ |
| 11485 | deletes the breakpoint. When this mode is auto (which is the default),\n\ |
| 11486 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ |
| 11487 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ |
| 11488 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ |
| 11489 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), |
| 11490 | NULL, |
| 11491 | &show_always_inserted_mode, |
| 11492 | &breakpoint_set_cmdlist, |
| 11493 | &breakpoint_show_cmdlist); |
| 11494 | |
| 11495 | automatic_hardware_breakpoints = 1; |
| 11496 | |
| 11497 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); |
| 11498 | } |