1 /* Everything about breakpoints, for GDB. 2 3 Copyright (C) 1986-2012 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 20 #include "defs.h" 21 #include "arch-utils.h" 22 #include <ctype.h> 23 #include "hashtab.h" 24 #include "symtab.h" 25 #include "frame.h" 26 #include "breakpoint.h" 27 #include "tracepoint.h" 28 #include "gdbtypes.h" 29 #include "expression.h" 30 #include "gdbcore.h" 31 #include "gdbcmd.h" 32 #include "value.h" 33 #include "command.h" 34 #include "inferior.h" 35 #include "gdbthread.h" 36 #include "target.h" 37 #include "language.h" 38 #include "gdb_string.h" 39 #include "gdb-demangle.h" 40 #include "filenames.h" 41 #include "annotate.h" 42 #include "symfile.h" 43 #include "objfiles.h" 44 #include "source.h" 45 #include "linespec.h" 46 #include "completer.h" 47 #include "gdb.h" 48 #include "ui-out.h" 49 #include "cli/cli-script.h" 50 #include "gdb_assert.h" 51 #include "block.h" 52 #include "solib.h" 53 #include "solist.h" 54 #include "observer.h" 55 #include "exceptions.h" 56 #include "memattr.h" 57 #include "ada-lang.h" 58 #include "top.h" 59 #include "wrapper.h" 60 #include "valprint.h" 61 #include "jit.h" 62 #include "xml-syscall.h" 63 #include "parser-defs.h" 64 #include "cli/cli-utils.h" 65 #include "continuations.h" 66 #include "stack.h" 67 #include "skip.h" 68 #include "record.h" 69 70 /* readline include files */ 71 #include "readline/readline.h" 72 #include "readline/history.h" 73 74 /* readline defines this. */ 75 #undef savestring 76 77 #include "mi/mi-common.h" 78 #include "python/python.h" 79 80 /* Prototypes for local functions. */ 81 82 static void enable_delete_command (char *, int); 83 84 static void enable_once_command (char *, int); 85 86 static void disable_command (char *, int); 87 88 static void enable_command (char *, int); 89 90 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, 91 void *), 92 void *); 93 94 static void ignore_command (char *, int); 95 96 static int breakpoint_re_set_one (void *); 97 98 static void breakpoint_re_set_default (struct breakpoint *); 99 100 static void clear_command (char *, int); 101 102 static void catch_command (char *, int); 103 104 static int can_use_hardware_watchpoint (struct value *); 105 106 static void break_command_1 (char *, int, int); 107 108 static void mention (struct breakpoint *); 109 110 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, 111 enum bptype, 112 const struct breakpoint_ops *); 113 static struct bp_location *add_location_to_breakpoint (struct breakpoint *, 114 const struct symtab_and_line *); 115 116 /* This function is used in gdbtk sources and thus can not be made 117 static. */ 118 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, 119 struct symtab_and_line, 120 enum bptype, 121 const struct breakpoint_ops *); 122 123 static struct breakpoint * 124 momentary_breakpoint_from_master (struct breakpoint *orig, 125 enum bptype type, 126 const struct breakpoint_ops *ops); 127 128 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); 129 130 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, 131 CORE_ADDR bpaddr, 132 enum bptype bptype); 133 134 static void describe_other_breakpoints (struct gdbarch *, 135 struct program_space *, CORE_ADDR, 136 struct obj_section *, int); 137 138 static int breakpoint_address_match (struct address_space *aspace1, 139 CORE_ADDR addr1, 140 struct address_space *aspace2, 141 CORE_ADDR addr2); 142 143 static int watchpoint_locations_match (struct bp_location *loc1, 144 struct bp_location *loc2); 145 146 static int breakpoint_location_address_match (struct bp_location *bl, 147 struct address_space *aspace, 148 CORE_ADDR addr); 149 150 static void breakpoints_info (char *, int); 151 152 static void watchpoints_info (char *, int); 153 154 static int breakpoint_1 (char *, int, 155 int (*) (const struct breakpoint *)); 156 157 static int breakpoint_cond_eval (void *); 158 159 static void cleanup_executing_breakpoints (void *); 160 161 static void commands_command (char *, int); 162 163 static void condition_command (char *, int); 164 165 typedef enum 166 { 167 mark_inserted, 168 mark_uninserted 169 } 170 insertion_state_t; 171 172 static int remove_breakpoint (struct bp_location *, insertion_state_t); 173 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); 174 175 static enum print_stop_action print_bp_stop_message (bpstat bs); 176 177 static int watchpoint_check (void *); 178 179 static void maintenance_info_breakpoints (char *, int); 180 181 static int hw_breakpoint_used_count (void); 182 183 static int hw_watchpoint_use_count (struct breakpoint *); 184 185 static int hw_watchpoint_used_count_others (struct breakpoint *except, 186 enum bptype type, 187 int *other_type_used); 188 189 static void hbreak_command (char *, int); 190 191 static void thbreak_command (char *, int); 192 193 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp); 194 195 static void stop_command (char *arg, int from_tty); 196 197 static void stopin_command (char *arg, int from_tty); 198 199 static void stopat_command (char *arg, int from_tty); 200 201 static char *ep_parse_optional_if_clause (char **arg); 202 203 static void catch_exception_command_1 (enum exception_event_kind ex_event, 204 char *arg, int tempflag, int from_tty); 205 206 static void tcatch_command (char *arg, int from_tty); 207 208 static void detach_single_step_breakpoints (void); 209 210 static int single_step_breakpoint_inserted_here_p (struct address_space *, 211 CORE_ADDR pc); 212 213 static void free_bp_location (struct bp_location *loc); 214 static void incref_bp_location (struct bp_location *loc); 215 static void decref_bp_location (struct bp_location **loc); 216 217 static struct bp_location *allocate_bp_location (struct breakpoint *bpt); 218 219 static void update_global_location_list (int); 220 221 static void update_global_location_list_nothrow (int); 222 223 static int is_hardware_watchpoint (const struct breakpoint *bpt); 224 225 static void insert_breakpoint_locations (void); 226 227 static int syscall_catchpoint_p (struct breakpoint *b); 228 229 static void tracepoints_info (char *, int); 230 231 static void delete_trace_command (char *, int); 232 233 static void enable_trace_command (char *, int); 234 235 static void disable_trace_command (char *, int); 236 237 static void trace_pass_command (char *, int); 238 239 static int is_masked_watchpoint (const struct breakpoint *b); 240 241 /* Assuming we're creating a static tracepoint, does S look like a 242 static tracepoint marker spec ("-m MARKER_ID")? */ 243 #define is_marker_spec(s) \ 244 (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) 245 246 /* The abstract base class all breakpoint_ops structures inherit 247 from. */ 248 static struct breakpoint_ops base_breakpoint_ops; 249 250 /* The breakpoint_ops structure to be inherited by all breakpoint_ops 251 that are implemented on top of software or hardware breakpoints 252 (user breakpoints, internal and momentary breakpoints, etc.). */ 253 static struct breakpoint_ops bkpt_base_breakpoint_ops; 254 255 /* Internal breakpoints class type. */ 256 static struct breakpoint_ops internal_breakpoint_ops; 257 258 /* Momentary breakpoints class type. */ 259 static struct breakpoint_ops momentary_breakpoint_ops; 260 261 /* The breakpoint_ops structure to be used in regular user created 262 breakpoints. */ 263 struct breakpoint_ops bkpt_breakpoint_ops; 264 265 /* A reference-counted struct command_line. This lets multiple 266 breakpoints share a single command list. */ 267 struct counted_command_line 268 { 269 /* The reference count. */ 270 int refc; 271 272 /* The command list. */ 273 struct command_line *commands; 274 }; 275 276 struct command_line * 277 breakpoint_commands (struct breakpoint *b) 278 { 279 return b->commands ? b->commands->commands : NULL; 280 } 281 282 /* Flag indicating that a command has proceeded the inferior past the 283 current breakpoint. */ 284 285 static int breakpoint_proceeded; 286 287 const char * 288 bpdisp_text (enum bpdisp disp) 289 { 290 /* NOTE: the following values are a part of MI protocol and 291 represent values of 'disp' field returned when inferior stops at 292 a breakpoint. */ 293 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; 294 295 return bpdisps[(int) disp]; 296 } 297 298 /* Prototypes for exported functions. */ 299 /* If FALSE, gdb will not use hardware support for watchpoints, even 300 if such is available. */ 301 static int can_use_hw_watchpoints; 302 303 static void 304 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, 305 struct cmd_list_element *c, 306 const char *value) 307 { 308 fprintf_filtered (file, 309 _("Debugger's willingness to use " 310 "watchpoint hardware is %s.\n"), 311 value); 312 } 313 314 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. 315 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints 316 for unrecognized breakpoint locations. 317 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ 318 static enum auto_boolean pending_break_support; 319 static void 320 show_pending_break_support (struct ui_file *file, int from_tty, 321 struct cmd_list_element *c, 322 const char *value) 323 { 324 fprintf_filtered (file, 325 _("Debugger's behavior regarding " 326 "pending breakpoints is %s.\n"), 327 value); 328 } 329 330 /* If 1, gdb will automatically use hardware breakpoints for breakpoints 331 set with "break" but falling in read-only memory. 332 If 0, gdb will warn about such breakpoints, but won't automatically 333 use hardware breakpoints. */ 334 static int automatic_hardware_breakpoints; 335 static void 336 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, 337 struct cmd_list_element *c, 338 const char *value) 339 { 340 fprintf_filtered (file, 341 _("Automatic usage of hardware breakpoints is %s.\n"), 342 value); 343 } 344 345 /* If on, gdb will keep breakpoints inserted even as inferior is 346 stopped, and immediately insert any new breakpoints. If off, gdb 347 will insert breakpoints into inferior only when resuming it, and 348 will remove breakpoints upon stop. If auto, GDB will behave as ON 349 if in non-stop mode, and as OFF if all-stop mode.*/ 350 351 static const char always_inserted_auto[] = "auto"; 352 static const char always_inserted_on[] = "on"; 353 static const char always_inserted_off[] = "off"; 354 static const char *always_inserted_enums[] = { 355 always_inserted_auto, 356 always_inserted_off, 357 always_inserted_on, 358 NULL 359 }; 360 static const char *always_inserted_mode = always_inserted_auto; 361 static void 362 show_always_inserted_mode (struct ui_file *file, int from_tty, 363 struct cmd_list_element *c, const char *value) 364 { 365 if (always_inserted_mode == always_inserted_auto) 366 fprintf_filtered (file, 367 _("Always inserted breakpoint " 368 "mode is %s (currently %s).\n"), 369 value, 370 breakpoints_always_inserted_mode () ? "on" : "off"); 371 else 372 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), 373 value); 374 } 375 376 int 377 breakpoints_always_inserted_mode (void) 378 { 379 return ((always_inserted_mode == always_inserted_on 380 || (always_inserted_mode == always_inserted_auto && non_stop)) 381 && !RECORD_IS_USED); 382 } 383 384 void _initialize_breakpoint (void); 385 386 /* Are we executing breakpoint commands? */ 387 static int executing_breakpoint_commands; 388 389 /* Are overlay event breakpoints enabled? */ 390 static int overlay_events_enabled; 391 392 /* See description in breakpoint.h. */ 393 int target_exact_watchpoints = 0; 394 395 /* Walk the following statement or block through all breakpoints. 396 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the 397 current breakpoint. */ 398 399 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) 400 401 #define ALL_BREAKPOINTS_SAFE(B,TMP) \ 402 for (B = breakpoint_chain; \ 403 B ? (TMP=B->next, 1): 0; \ 404 B = TMP) 405 406 /* Similar iterator for the low-level breakpoints. SAFE variant is 407 not provided so update_global_location_list must not be called 408 while executing the block of ALL_BP_LOCATIONS. */ 409 410 #define ALL_BP_LOCATIONS(B,BP_TMP) \ 411 for (BP_TMP = bp_location; \ 412 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ 413 BP_TMP++) 414 415 /* Iterator for tracepoints only. */ 416 417 #define ALL_TRACEPOINTS(B) \ 418 for (B = breakpoint_chain; B; B = B->next) \ 419 if (is_tracepoint (B)) 420 421 /* Chains of all breakpoints defined. */ 422 423 struct breakpoint *breakpoint_chain; 424 425 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ 426 427 static struct bp_location **bp_location; 428 429 /* Number of elements of BP_LOCATION. */ 430 431 static unsigned bp_location_count; 432 433 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and 434 ADDRESS for the current elements of BP_LOCATION which get a valid 435 result from bp_location_has_shadow. You can use it for roughly 436 limiting the subrange of BP_LOCATION to scan for shadow bytes for 437 an address you need to read. */ 438 439 static CORE_ADDR bp_location_placed_address_before_address_max; 440 441 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS 442 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of 443 BP_LOCATION which get a valid result from bp_location_has_shadow. 444 You can use it for roughly limiting the subrange of BP_LOCATION to 445 scan for shadow bytes for an address you need to read. */ 446 447 static CORE_ADDR bp_location_shadow_len_after_address_max; 448 449 /* The locations that no longer correspond to any breakpoint, unlinked 450 from bp_location array, but for which a hit may still be reported 451 by a target. */ 452 VEC(bp_location_p) *moribund_locations = NULL; 453 454 /* Number of last breakpoint made. */ 455 456 static int breakpoint_count; 457 458 /* The value of `breakpoint_count' before the last command that 459 created breakpoints. If the last (break-like) command created more 460 than one breakpoint, then the difference between BREAKPOINT_COUNT 461 and PREV_BREAKPOINT_COUNT is more than one. */ 462 static int prev_breakpoint_count; 463 464 /* Number of last tracepoint made. */ 465 466 static int tracepoint_count; 467 468 static struct cmd_list_element *breakpoint_set_cmdlist; 469 static struct cmd_list_element *breakpoint_show_cmdlist; 470 struct cmd_list_element *save_cmdlist; 471 472 /* Return whether a breakpoint is an active enabled breakpoint. */ 473 static int 474 breakpoint_enabled (struct breakpoint *b) 475 { 476 return (b->enable_state == bp_enabled); 477 } 478 479 /* Set breakpoint count to NUM. */ 480 481 static void 482 set_breakpoint_count (int num) 483 { 484 prev_breakpoint_count = breakpoint_count; 485 breakpoint_count = num; 486 set_internalvar_integer (lookup_internalvar ("bpnum"), num); 487 } 488 489 /* Used by `start_rbreak_breakpoints' below, to record the current 490 breakpoint count before "rbreak" creates any breakpoint. */ 491 static int rbreak_start_breakpoint_count; 492 493 /* Called at the start an "rbreak" command to record the first 494 breakpoint made. */ 495 496 void 497 start_rbreak_breakpoints (void) 498 { 499 rbreak_start_breakpoint_count = breakpoint_count; 500 } 501 502 /* Called at the end of an "rbreak" command to record the last 503 breakpoint made. */ 504 505 void 506 end_rbreak_breakpoints (void) 507 { 508 prev_breakpoint_count = rbreak_start_breakpoint_count; 509 } 510 511 /* Used in run_command to zero the hit count when a new run starts. */ 512 513 void 514 clear_breakpoint_hit_counts (void) 515 { 516 struct breakpoint *b; 517 518 ALL_BREAKPOINTS (b) 519 b->hit_count = 0; 520 } 521 522 /* Allocate a new counted_command_line with reference count of 1. 523 The new structure owns COMMANDS. */ 524 525 static struct counted_command_line * 526 alloc_counted_command_line (struct command_line *commands) 527 { 528 struct counted_command_line *result 529 = xmalloc (sizeof (struct counted_command_line)); 530 531 result->refc = 1; 532 result->commands = commands; 533 return result; 534 } 535 536 /* Increment reference count. This does nothing if CMD is NULL. */ 537 538 static void 539 incref_counted_command_line (struct counted_command_line *cmd) 540 { 541 if (cmd) 542 ++cmd->refc; 543 } 544 545 /* Decrement reference count. If the reference count reaches 0, 546 destroy the counted_command_line. Sets *CMDP to NULL. This does 547 nothing if *CMDP is NULL. */ 548 549 static void 550 decref_counted_command_line (struct counted_command_line **cmdp) 551 { 552 if (*cmdp) 553 { 554 if (--(*cmdp)->refc == 0) 555 { 556 free_command_lines (&(*cmdp)->commands); 557 xfree (*cmdp); 558 } 559 *cmdp = NULL; 560 } 561 } 562 563 /* A cleanup function that calls decref_counted_command_line. */ 564 565 static void 566 do_cleanup_counted_command_line (void *arg) 567 { 568 decref_counted_command_line (arg); 569 } 570 571 /* Create a cleanup that calls decref_counted_command_line on the 572 argument. */ 573 574 static struct cleanup * 575 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) 576 { 577 return make_cleanup (do_cleanup_counted_command_line, cmdp); 578 } 579 580 581 /* Return the breakpoint with the specified number, or NULL 582 if the number does not refer to an existing breakpoint. */ 583 584 struct breakpoint * 585 get_breakpoint (int num) 586 { 587 struct breakpoint *b; 588 589 ALL_BREAKPOINTS (b) 590 if (b->number == num) 591 return b; 592 593 return NULL; 594 } 595 596 597 598 void 599 set_breakpoint_condition (struct breakpoint *b, char *exp, 600 int from_tty) 601 { 602 xfree (b->cond_string); 603 b->cond_string = NULL; 604 605 if (is_watchpoint (b)) 606 { 607 struct watchpoint *w = (struct watchpoint *) b; 608 609 xfree (w->cond_exp); 610 w->cond_exp = NULL; 611 } 612 else 613 { 614 struct bp_location *loc; 615 616 for (loc = b->loc; loc; loc = loc->next) 617 { 618 xfree (loc->cond); 619 loc->cond = NULL; 620 } 621 } 622 623 if (*exp == 0) 624 { 625 if (from_tty) 626 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); 627 } 628 else 629 { 630 char *arg = exp; 631 632 /* I don't know if it matters whether this is the string the user 633 typed in or the decompiled expression. */ 634 b->cond_string = xstrdup (arg); 635 b->condition_not_parsed = 0; 636 637 if (is_watchpoint (b)) 638 { 639 struct watchpoint *w = (struct watchpoint *) b; 640 641 innermost_block = NULL; 642 arg = exp; 643 w->cond_exp = parse_exp_1 (&arg, 0, 0); 644 if (*arg) 645 error (_("Junk at end of expression")); 646 w->cond_exp_valid_block = innermost_block; 647 } 648 else 649 { 650 struct bp_location *loc; 651 652 for (loc = b->loc; loc; loc = loc->next) 653 { 654 arg = exp; 655 loc->cond = 656 parse_exp_1 (&arg, block_for_pc (loc->address), 0); 657 if (*arg) 658 error (_("Junk at end of expression")); 659 } 660 } 661 } 662 breakpoints_changed (); 663 observer_notify_breakpoint_modified (b); 664 } 665 666 /* condition N EXP -- set break condition of breakpoint N to EXP. */ 667 668 static void 669 condition_command (char *arg, int from_tty) 670 { 671 struct breakpoint *b; 672 char *p; 673 int bnum; 674 675 if (arg == 0) 676 error_no_arg (_("breakpoint number")); 677 678 p = arg; 679 bnum = get_number (&p); 680 if (bnum == 0) 681 error (_("Bad breakpoint argument: '%s'"), arg); 682 683 ALL_BREAKPOINTS (b) 684 if (b->number == bnum) 685 { 686 /* Check if this breakpoint has a Python object assigned to 687 it, and if it has a definition of the "stop" 688 method. This method and conditions entered into GDB from 689 the CLI are mutually exclusive. */ 690 if (b->py_bp_object 691 && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) 692 error (_("Cannot set a condition where a Python 'stop' " 693 "method has been defined in the breakpoint.")); 694 set_breakpoint_condition (b, p, from_tty); 695 return; 696 } 697 698 error (_("No breakpoint number %d."), bnum); 699 } 700 701 /* Check that COMMAND do not contain commands that are suitable 702 only for tracepoints and not suitable for ordinary breakpoints. 703 Throw if any such commands is found. */ 704 705 static void 706 check_no_tracepoint_commands (struct command_line *commands) 707 { 708 struct command_line *c; 709 710 for (c = commands; c; c = c->next) 711 { 712 int i; 713 714 if (c->control_type == while_stepping_control) 715 error (_("The 'while-stepping' command can " 716 "only be used for tracepoints")); 717 718 for (i = 0; i < c->body_count; ++i) 719 check_no_tracepoint_commands ((c->body_list)[i]); 720 721 /* Not that command parsing removes leading whitespace and comment 722 lines and also empty lines. So, we only need to check for 723 command directly. */ 724 if (strstr (c->line, "collect ") == c->line) 725 error (_("The 'collect' command can only be used for tracepoints")); 726 727 if (strstr (c->line, "teval ") == c->line) 728 error (_("The 'teval' command can only be used for tracepoints")); 729 } 730 } 731 732 /* Encapsulate tests for different types of tracepoints. */ 733 734 static int 735 is_tracepoint_type (enum bptype type) 736 { 737 return (type == bp_tracepoint 738 || type == bp_fast_tracepoint 739 || type == bp_static_tracepoint); 740 } 741 742 int 743 is_tracepoint (const struct breakpoint *b) 744 { 745 return is_tracepoint_type (b->type); 746 } 747 748 /* A helper function that validates that COMMANDS are valid for a 749 breakpoint. This function will throw an exception if a problem is 750 found. */ 751 752 static void 753 validate_commands_for_breakpoint (struct breakpoint *b, 754 struct command_line *commands) 755 { 756 if (is_tracepoint (b)) 757 { 758 /* We need to verify that each top-level element of commands is 759 valid for tracepoints, that there's at most one 760 while-stepping element, and that while-stepping's body has 761 valid tracing commands excluding nested while-stepping. */ 762 struct command_line *c; 763 struct command_line *while_stepping = 0; 764 for (c = commands; c; c = c->next) 765 { 766 if (c->control_type == while_stepping_control) 767 { 768 if (b->type == bp_fast_tracepoint) 769 error (_("The 'while-stepping' command " 770 "cannot be used for fast tracepoint")); 771 else if (b->type == bp_static_tracepoint) 772 error (_("The 'while-stepping' command " 773 "cannot be used for static tracepoint")); 774 775 if (while_stepping) 776 error (_("The 'while-stepping' command " 777 "can be used only once")); 778 else 779 while_stepping = c; 780 } 781 } 782 if (while_stepping) 783 { 784 struct command_line *c2; 785 786 gdb_assert (while_stepping->body_count == 1); 787 c2 = while_stepping->body_list[0]; 788 for (; c2; c2 = c2->next) 789 { 790 if (c2->control_type == while_stepping_control) 791 error (_("The 'while-stepping' command cannot be nested")); 792 } 793 } 794 } 795 else 796 { 797 check_no_tracepoint_commands (commands); 798 } 799 } 800 801 /* Return a vector of all the static tracepoints set at ADDR. The 802 caller is responsible for releasing the vector. */ 803 804 VEC(breakpoint_p) * 805 static_tracepoints_here (CORE_ADDR addr) 806 { 807 struct breakpoint *b; 808 VEC(breakpoint_p) *found = 0; 809 struct bp_location *loc; 810 811 ALL_BREAKPOINTS (b) 812 if (b->type == bp_static_tracepoint) 813 { 814 for (loc = b->loc; loc; loc = loc->next) 815 if (loc->address == addr) 816 VEC_safe_push(breakpoint_p, found, b); 817 } 818 819 return found; 820 } 821 822 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, 823 validate that only allowed commands are included. */ 824 825 void 826 breakpoint_set_commands (struct breakpoint *b, 827 struct command_line *commands) 828 { 829 validate_commands_for_breakpoint (b, commands); 830 831 decref_counted_command_line (&b->commands); 832 b->commands = alloc_counted_command_line (commands); 833 breakpoints_changed (); 834 observer_notify_breakpoint_modified (b); 835 } 836 837 /* Set the internal `silent' flag on the breakpoint. Note that this 838 is not the same as the "silent" that may appear in the breakpoint's 839 commands. */ 840 841 void 842 breakpoint_set_silent (struct breakpoint *b, int silent) 843 { 844 int old_silent = b->silent; 845 846 b->silent = silent; 847 if (old_silent != silent) 848 observer_notify_breakpoint_modified (b); 849 } 850 851 /* Set the thread for this breakpoint. If THREAD is -1, make the 852 breakpoint work for any thread. */ 853 854 void 855 breakpoint_set_thread (struct breakpoint *b, int thread) 856 { 857 int old_thread = b->thread; 858 859 b->thread = thread; 860 if (old_thread != thread) 861 observer_notify_breakpoint_modified (b); 862 } 863 864 /* Set the task for this breakpoint. If TASK is 0, make the 865 breakpoint work for any task. */ 866 867 void 868 breakpoint_set_task (struct breakpoint *b, int task) 869 { 870 int old_task = b->task; 871 872 b->task = task; 873 if (old_task != task) 874 observer_notify_breakpoint_modified (b); 875 } 876 877 void 878 check_tracepoint_command (char *line, void *closure) 879 { 880 struct breakpoint *b = closure; 881 882 validate_actionline (&line, b); 883 } 884 885 /* A structure used to pass information through 886 map_breakpoint_numbers. */ 887 888 struct commands_info 889 { 890 /* True if the command was typed at a tty. */ 891 int from_tty; 892 893 /* The breakpoint range spec. */ 894 char *arg; 895 896 /* Non-NULL if the body of the commands are being read from this 897 already-parsed command. */ 898 struct command_line *control; 899 900 /* The command lines read from the user, or NULL if they have not 901 yet been read. */ 902 struct counted_command_line *cmd; 903 }; 904 905 /* A callback for map_breakpoint_numbers that sets the commands for 906 commands_command. */ 907 908 static void 909 do_map_commands_command (struct breakpoint *b, void *data) 910 { 911 struct commands_info *info = data; 912 913 if (info->cmd == NULL) 914 { 915 struct command_line *l; 916 917 if (info->control != NULL) 918 l = copy_command_lines (info->control->body_list[0]); 919 else 920 { 921 struct cleanup *old_chain; 922 char *str; 923 924 str = xstrprintf (_("Type commands for breakpoint(s) " 925 "%s, one per line."), 926 info->arg); 927 928 old_chain = make_cleanup (xfree, str); 929 930 l = read_command_lines (str, 931 info->from_tty, 1, 932 (is_tracepoint (b) 933 ? check_tracepoint_command : 0), 934 b); 935 936 do_cleanups (old_chain); 937 } 938 939 info->cmd = alloc_counted_command_line (l); 940 } 941 942 /* If a breakpoint was on the list more than once, we don't need to 943 do anything. */ 944 if (b->commands != info->cmd) 945 { 946 validate_commands_for_breakpoint (b, info->cmd->commands); 947 incref_counted_command_line (info->cmd); 948 decref_counted_command_line (&b->commands); 949 b->commands = info->cmd; 950 breakpoints_changed (); 951 observer_notify_breakpoint_modified (b); 952 } 953 } 954 955 static void 956 commands_command_1 (char *arg, int from_tty, 957 struct command_line *control) 958 { 959 struct cleanup *cleanups; 960 struct commands_info info; 961 962 info.from_tty = from_tty; 963 info.control = control; 964 info.cmd = NULL; 965 /* If we read command lines from the user, then `info' will hold an 966 extra reference to the commands that we must clean up. */ 967 cleanups = make_cleanup_decref_counted_command_line (&info.cmd); 968 969 if (arg == NULL || !*arg) 970 { 971 if (breakpoint_count - prev_breakpoint_count > 1) 972 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, 973 breakpoint_count); 974 else if (breakpoint_count > 0) 975 arg = xstrprintf ("%d", breakpoint_count); 976 else 977 { 978 /* So that we don't try to free the incoming non-NULL 979 argument in the cleanup below. Mapping breakpoint 980 numbers will fail in this case. */ 981 arg = NULL; 982 } 983 } 984 else 985 /* The command loop has some static state, so we need to preserve 986 our argument. */ 987 arg = xstrdup (arg); 988 989 if (arg != NULL) 990 make_cleanup (xfree, arg); 991 992 info.arg = arg; 993 994 map_breakpoint_numbers (arg, do_map_commands_command, &info); 995 996 if (info.cmd == NULL) 997 error (_("No breakpoints specified.")); 998 999 do_cleanups (cleanups); 1000 } 1001 1002 static void 1003 commands_command (char *arg, int from_tty) 1004 { 1005 commands_command_1 (arg, from_tty, NULL); 1006 } 1007 1008 /* Like commands_command, but instead of reading the commands from 1009 input stream, takes them from an already parsed command structure. 1010 1011 This is used by cli-script.c to DTRT with breakpoint commands 1012 that are part of if and while bodies. */ 1013 enum command_control_type 1014 commands_from_control_command (char *arg, struct command_line *cmd) 1015 { 1016 commands_command_1 (arg, 0, cmd); 1017 return simple_control; 1018 } 1019 1020 /* Return non-zero if BL->TARGET_INFO contains valid information. */ 1021 1022 static int 1023 bp_location_has_shadow (struct bp_location *bl) 1024 { 1025 if (bl->loc_type != bp_loc_software_breakpoint) 1026 return 0; 1027 if (!bl->inserted) 1028 return 0; 1029 if (bl->target_info.shadow_len == 0) 1030 /* BL isn't valid, or doesn't shadow memory. */ 1031 return 0; 1032 return 1; 1033 } 1034 1035 /* Update BUF, which is LEN bytes read from the target address MEMADDR, 1036 by replacing any memory breakpoints with their shadowed contents. 1037 1038 The range of shadowed area by each bp_location is: 1039 bl->address - bp_location_placed_address_before_address_max 1040 up to bl->address + bp_location_shadow_len_after_address_max 1041 The range we were requested to resolve shadows for is: 1042 memaddr ... memaddr + len 1043 Thus the safe cutoff boundaries for performance optimization are 1044 memaddr + len <= (bl->address 1045 - bp_location_placed_address_before_address_max) 1046 and: 1047 bl->address + bp_location_shadow_len_after_address_max <= memaddr */ 1048 1049 void 1050 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, 1051 const gdb_byte *writebuf_org, 1052 ULONGEST memaddr, LONGEST len) 1053 { 1054 /* Left boundary, right boundary and median element of our binary 1055 search. */ 1056 unsigned bc_l, bc_r, bc; 1057 1058 /* Find BC_L which is a leftmost element which may affect BUF 1059 content. It is safe to report lower value but a failure to 1060 report higher one. */ 1061 1062 bc_l = 0; 1063 bc_r = bp_location_count; 1064 while (bc_l + 1 < bc_r) 1065 { 1066 struct bp_location *bl; 1067 1068 bc = (bc_l + bc_r) / 2; 1069 bl = bp_location[bc]; 1070 1071 /* Check first BL->ADDRESS will not overflow due to the added 1072 constant. Then advance the left boundary only if we are sure 1073 the BC element can in no way affect the BUF content (MEMADDR 1074 to MEMADDR + LEN range). 1075 1076 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety 1077 offset so that we cannot miss a breakpoint with its shadow 1078 range tail still reaching MEMADDR. */ 1079 1080 if ((bl->address + bp_location_shadow_len_after_address_max 1081 >= bl->address) 1082 && (bl->address + bp_location_shadow_len_after_address_max 1083 <= memaddr)) 1084 bc_l = bc; 1085 else 1086 bc_r = bc; 1087 } 1088 1089 /* Due to the binary search above, we need to make sure we pick the 1090 first location that's at BC_L's address. E.g., if there are 1091 multiple locations at the same address, BC_L may end up pointing 1092 at a duplicate location, and miss the "master"/"inserted" 1093 location. Say, given locations L1, L2 and L3 at addresses A and 1094 B: 1095 1096 L1@A, L2@A, L3@B, ... 1097 1098 BC_L could end up pointing at location L2, while the "master" 1099 location could be L1. Since the `loc->inserted' flag is only set 1100 on "master" locations, we'd forget to restore the shadow of L1 1101 and L2. */ 1102 while (bc_l > 0 1103 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) 1104 bc_l--; 1105 1106 /* Now do full processing of the found relevant range of elements. */ 1107 1108 for (bc = bc_l; bc < bp_location_count; bc++) 1109 { 1110 struct bp_location *bl = bp_location[bc]; 1111 CORE_ADDR bp_addr = 0; 1112 int bp_size = 0; 1113 int bptoffset = 0; 1114 1115 /* bp_location array has BL->OWNER always non-NULL. */ 1116 if (bl->owner->type == bp_none) 1117 warning (_("reading through apparently deleted breakpoint #%d?"), 1118 bl->owner->number); 1119 1120 /* Performance optimization: any further element can no longer affect BUF 1121 content. */ 1122 1123 if (bl->address >= bp_location_placed_address_before_address_max 1124 && memaddr + len <= (bl->address 1125 - bp_location_placed_address_before_address_max)) 1126 break; 1127 1128 if (!bp_location_has_shadow (bl)) 1129 continue; 1130 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, 1131 current_program_space->aspace, 0)) 1132 continue; 1133 1134 /* Addresses and length of the part of the breakpoint that 1135 we need to copy. */ 1136 bp_addr = bl->target_info.placed_address; 1137 bp_size = bl->target_info.shadow_len; 1138 1139 if (bp_addr + bp_size <= memaddr) 1140 /* The breakpoint is entirely before the chunk of memory we 1141 are reading. */ 1142 continue; 1143 1144 if (bp_addr >= memaddr + len) 1145 /* The breakpoint is entirely after the chunk of memory we are 1146 reading. */ 1147 continue; 1148 1149 /* Offset within shadow_contents. */ 1150 if (bp_addr < memaddr) 1151 { 1152 /* Only copy the second part of the breakpoint. */ 1153 bp_size -= memaddr - bp_addr; 1154 bptoffset = memaddr - bp_addr; 1155 bp_addr = memaddr; 1156 } 1157 1158 if (bp_addr + bp_size > memaddr + len) 1159 { 1160 /* Only copy the first part of the breakpoint. */ 1161 bp_size -= (bp_addr + bp_size) - (memaddr + len); 1162 } 1163 1164 if (readbuf != NULL) 1165 { 1166 /* Update the read buffer with this inserted breakpoint's 1167 shadow. */ 1168 memcpy (readbuf + bp_addr - memaddr, 1169 bl->target_info.shadow_contents + bptoffset, bp_size); 1170 } 1171 else 1172 { 1173 struct gdbarch *gdbarch = bl->gdbarch; 1174 const unsigned char *bp; 1175 CORE_ADDR placed_address = bl->target_info.placed_address; 1176 unsigned placed_size = bl->target_info.placed_size; 1177 1178 /* Update the shadow with what we want to write to memory. */ 1179 memcpy (bl->target_info.shadow_contents + bptoffset, 1180 writebuf_org + bp_addr - memaddr, bp_size); 1181 1182 /* Determine appropriate breakpoint contents and size for this 1183 address. */ 1184 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); 1185 1186 /* Update the final write buffer with this inserted 1187 breakpoint's INSN. */ 1188 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); 1189 } 1190 } 1191 } 1192 1193 1194 /* Return true if BPT is of any hardware watchpoint kind. */ 1195 1196 static int 1197 is_hardware_watchpoint (const struct breakpoint *bpt) 1198 { 1199 return (bpt->type == bp_hardware_watchpoint 1200 || bpt->type == bp_read_watchpoint 1201 || bpt->type == bp_access_watchpoint); 1202 } 1203 1204 /* Return true if BPT is of any watchpoint kind, hardware or 1205 software. */ 1206 1207 int 1208 is_watchpoint (const struct breakpoint *bpt) 1209 { 1210 return (is_hardware_watchpoint (bpt) 1211 || bpt->type == bp_watchpoint); 1212 } 1213 1214 /* Returns true if the current thread and its running state are safe 1215 to evaluate or update watchpoint B. Watchpoints on local 1216 expressions need to be evaluated in the context of the thread that 1217 was current when the watchpoint was created, and, that thread needs 1218 to be stopped to be able to select the correct frame context. 1219 Watchpoints on global expressions can be evaluated on any thread, 1220 and in any state. It is presently left to the target allowing 1221 memory accesses when threads are running. */ 1222 1223 static int 1224 watchpoint_in_thread_scope (struct watchpoint *b) 1225 { 1226 return (ptid_equal (b->watchpoint_thread, null_ptid) 1227 || (ptid_equal (inferior_ptid, b->watchpoint_thread) 1228 && !is_executing (inferior_ptid))); 1229 } 1230 1231 /* Set watchpoint B to disp_del_at_next_stop, even including its possible 1232 associated bp_watchpoint_scope breakpoint. */ 1233 1234 static void 1235 watchpoint_del_at_next_stop (struct watchpoint *w) 1236 { 1237 struct breakpoint *b = &w->base; 1238 1239 if (b->related_breakpoint != b) 1240 { 1241 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); 1242 gdb_assert (b->related_breakpoint->related_breakpoint == b); 1243 b->related_breakpoint->disposition = disp_del_at_next_stop; 1244 b->related_breakpoint->related_breakpoint = b->related_breakpoint; 1245 b->related_breakpoint = b; 1246 } 1247 b->disposition = disp_del_at_next_stop; 1248 } 1249 1250 /* Assuming that B is a watchpoint: 1251 - Reparse watchpoint expression, if REPARSE is non-zero 1252 - Evaluate expression and store the result in B->val 1253 - Evaluate the condition if there is one, and store the result 1254 in b->loc->cond. 1255 - Update the list of values that must be watched in B->loc. 1256 1257 If the watchpoint disposition is disp_del_at_next_stop, then do 1258 nothing. If this is local watchpoint that is out of scope, delete 1259 it. 1260 1261 Even with `set breakpoint always-inserted on' the watchpoints are 1262 removed + inserted on each stop here. Normal breakpoints must 1263 never be removed because they might be missed by a running thread 1264 when debugging in non-stop mode. On the other hand, hardware 1265 watchpoints (is_hardware_watchpoint; processed here) are specific 1266 to each LWP since they are stored in each LWP's hardware debug 1267 registers. Therefore, such LWP must be stopped first in order to 1268 be able to modify its hardware watchpoints. 1269 1270 Hardware watchpoints must be reset exactly once after being 1271 presented to the user. It cannot be done sooner, because it would 1272 reset the data used to present the watchpoint hit to the user. And 1273 it must not be done later because it could display the same single 1274 watchpoint hit during multiple GDB stops. Note that the latter is 1275 relevant only to the hardware watchpoint types bp_read_watchpoint 1276 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is 1277 not user-visible - its hit is suppressed if the memory content has 1278 not changed. 1279 1280 The following constraints influence the location where we can reset 1281 hardware watchpoints: 1282 1283 * target_stopped_by_watchpoint and target_stopped_data_address are 1284 called several times when GDB stops. 1285 1286 [linux] 1287 * Multiple hardware watchpoints can be hit at the same time, 1288 causing GDB to stop. GDB only presents one hardware watchpoint 1289 hit at a time as the reason for stopping, and all the other hits 1290 are presented later, one after the other, each time the user 1291 requests the execution to be resumed. Execution is not resumed 1292 for the threads still having pending hit event stored in 1293 LWP_INFO->STATUS. While the watchpoint is already removed from 1294 the inferior on the first stop the thread hit event is kept being 1295 reported from its cached value by linux_nat_stopped_data_address 1296 until the real thread resume happens after the watchpoint gets 1297 presented and thus its LWP_INFO->STATUS gets reset. 1298 1299 Therefore the hardware watchpoint hit can get safely reset on the 1300 watchpoint removal from inferior. */ 1301 1302 static void 1303 update_watchpoint (struct watchpoint *b, int reparse) 1304 { 1305 int within_current_scope; 1306 struct frame_id saved_frame_id; 1307 int frame_saved; 1308 1309 /* If this is a local watchpoint, we only want to check if the 1310 watchpoint frame is in scope if the current thread is the thread 1311 that was used to create the watchpoint. */ 1312 if (!watchpoint_in_thread_scope (b)) 1313 return; 1314 1315 if (b->base.disposition == disp_del_at_next_stop) 1316 return; 1317 1318 frame_saved = 0; 1319 1320 /* Determine if the watchpoint is within scope. */ 1321 if (b->exp_valid_block == NULL) 1322 within_current_scope = 1; 1323 else 1324 { 1325 struct frame_info *fi = get_current_frame (); 1326 struct gdbarch *frame_arch = get_frame_arch (fi); 1327 CORE_ADDR frame_pc = get_frame_pc (fi); 1328 1329 /* If we're in a function epilogue, unwinding may not work 1330 properly, so do not attempt to recreate locations at this 1331 point. See similar comments in watchpoint_check. */ 1332 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) 1333 return; 1334 1335 /* Save the current frame's ID so we can restore it after 1336 evaluating the watchpoint expression on its own frame. */ 1337 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression 1338 took a frame parameter, so that we didn't have to change the 1339 selected frame. */ 1340 frame_saved = 1; 1341 saved_frame_id = get_frame_id (get_selected_frame (NULL)); 1342 1343 fi = frame_find_by_id (b->watchpoint_frame); 1344 within_current_scope = (fi != NULL); 1345 if (within_current_scope) 1346 select_frame (fi); 1347 } 1348 1349 /* We don't free locations. They are stored in the bp_location array 1350 and update_global_location_list will eventually delete them and 1351 remove breakpoints if needed. */ 1352 b->base.loc = NULL; 1353 1354 if (within_current_scope && reparse) 1355 { 1356 char *s; 1357 1358 if (b->exp) 1359 { 1360 xfree (b->exp); 1361 b->exp = NULL; 1362 } 1363 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; 1364 b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); 1365 /* If the meaning of expression itself changed, the old value is 1366 no longer relevant. We don't want to report a watchpoint hit 1367 to the user when the old value and the new value may actually 1368 be completely different objects. */ 1369 value_free (b->val); 1370 b->val = NULL; 1371 b->val_valid = 0; 1372 1373 /* Note that unlike with breakpoints, the watchpoint's condition 1374 expression is stored in the breakpoint object, not in the 1375 locations (re)created below. */ 1376 if (b->base.cond_string != NULL) 1377 { 1378 if (b->cond_exp != NULL) 1379 { 1380 xfree (b->cond_exp); 1381 b->cond_exp = NULL; 1382 } 1383 1384 s = b->base.cond_string; 1385 b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); 1386 } 1387 } 1388 1389 /* If we failed to parse the expression, for example because 1390 it refers to a global variable in a not-yet-loaded shared library, 1391 don't try to insert watchpoint. We don't automatically delete 1392 such watchpoint, though, since failure to parse expression 1393 is different from out-of-scope watchpoint. */ 1394 if ( !target_has_execution) 1395 { 1396 /* Without execution, memory can't change. No use to try and 1397 set watchpoint locations. The watchpoint will be reset when 1398 the target gains execution, through breakpoint_re_set. */ 1399 } 1400 else if (within_current_scope && b->exp) 1401 { 1402 int pc = 0; 1403 struct value *val_chain, *v, *result, *next; 1404 struct program_space *frame_pspace; 1405 1406 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); 1407 1408 /* Avoid setting b->val if it's already set. The meaning of 1409 b->val is 'the last value' user saw, and we should update 1410 it only if we reported that last value to user. As it 1411 happens, the code that reports it updates b->val directly. 1412 We don't keep track of the memory value for masked 1413 watchpoints. */ 1414 if (!b->val_valid && !is_masked_watchpoint (&b->base)) 1415 { 1416 b->val = v; 1417 b->val_valid = 1; 1418 } 1419 1420 frame_pspace = get_frame_program_space (get_selected_frame (NULL)); 1421 1422 /* Look at each value on the value chain. */ 1423 for (v = val_chain; v; v = value_next (v)) 1424 { 1425 /* If it's a memory location, and GDB actually needed 1426 its contents to evaluate the expression, then we 1427 must watch it. If the first value returned is 1428 still lazy, that means an error occurred reading it; 1429 watch it anyway in case it becomes readable. */ 1430 if (VALUE_LVAL (v) == lval_memory 1431 && (v == val_chain || ! value_lazy (v))) 1432 { 1433 struct type *vtype = check_typedef (value_type (v)); 1434 1435 /* We only watch structs and arrays if user asked 1436 for it explicitly, never if they just happen to 1437 appear in the middle of some value chain. */ 1438 if (v == result 1439 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT 1440 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) 1441 { 1442 CORE_ADDR addr; 1443 int len, type; 1444 struct bp_location *loc, **tmp; 1445 1446 addr = value_address (v); 1447 len = TYPE_LENGTH (value_type (v)); 1448 type = hw_write; 1449 if (b->base.type == bp_read_watchpoint) 1450 type = hw_read; 1451 else if (b->base.type == bp_access_watchpoint) 1452 type = hw_access; 1453 1454 loc = allocate_bp_location (&b->base); 1455 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) 1456 ; 1457 *tmp = loc; 1458 loc->gdbarch = get_type_arch (value_type (v)); 1459 1460 loc->pspace = frame_pspace; 1461 loc->address = addr; 1462 loc->length = len; 1463 loc->watchpoint_type = type; 1464 } 1465 } 1466 } 1467 1468 /* Change the type of breakpoint between hardware assisted or 1469 an ordinary watchpoint depending on the hardware support 1470 and free hardware slots. REPARSE is set when the inferior 1471 is started. */ 1472 if (reparse) 1473 { 1474 int reg_cnt; 1475 enum bp_loc_type loc_type; 1476 struct bp_location *bl; 1477 1478 reg_cnt = can_use_hardware_watchpoint (val_chain); 1479 1480 if (reg_cnt) 1481 { 1482 int i, target_resources_ok, other_type_used; 1483 enum bptype type; 1484 1485 /* Use an exact watchpoint when there's only one memory region to be 1486 watched, and only one debug register is needed to watch it. */ 1487 b->exact = target_exact_watchpoints && reg_cnt == 1; 1488 1489 /* We need to determine how many resources are already 1490 used for all other hardware watchpoints plus this one 1491 to see if we still have enough resources to also fit 1492 this watchpoint in as well. */ 1493 1494 /* If this is a software watchpoint, we try to turn it 1495 to a hardware one -- count resources as if B was of 1496 hardware watchpoint type. */ 1497 type = b->base.type; 1498 if (type == bp_watchpoint) 1499 type = bp_hardware_watchpoint; 1500 1501 /* This watchpoint may or may not have been placed on 1502 the list yet at this point (it won't be in the list 1503 if we're trying to create it for the first time, 1504 through watch_command), so always account for it 1505 manually. */ 1506 1507 /* Count resources used by all watchpoints except B. */ 1508 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); 1509 1510 /* Add in the resources needed for B. */ 1511 i += hw_watchpoint_use_count (&b->base); 1512 1513 target_resources_ok 1514 = target_can_use_hardware_watchpoint (type, i, other_type_used); 1515 if (target_resources_ok <= 0) 1516 { 1517 int sw_mode = b->base.ops->works_in_software_mode (&b->base); 1518 1519 if (target_resources_ok == 0 && !sw_mode) 1520 error (_("Target does not support this type of " 1521 "hardware watchpoint.")); 1522 else if (target_resources_ok < 0 && !sw_mode) 1523 error (_("There are not enough available hardware " 1524 "resources for this watchpoint.")); 1525 1526 /* Downgrade to software watchpoint. */ 1527 b->base.type = bp_watchpoint; 1528 } 1529 else 1530 { 1531 /* If this was a software watchpoint, we've just 1532 found we have enough resources to turn it to a 1533 hardware watchpoint. Otherwise, this is a 1534 nop. */ 1535 b->base.type = type; 1536 } 1537 } 1538 else if (!b->base.ops->works_in_software_mode (&b->base)) 1539 error (_("Expression cannot be implemented with " 1540 "read/access watchpoint.")); 1541 else 1542 b->base.type = bp_watchpoint; 1543 1544 loc_type = (b->base.type == bp_watchpoint? bp_loc_other 1545 : bp_loc_hardware_watchpoint); 1546 for (bl = b->base.loc; bl; bl = bl->next) 1547 bl->loc_type = loc_type; 1548 } 1549 1550 for (v = val_chain; v; v = next) 1551 { 1552 next = value_next (v); 1553 if (v != b->val) 1554 value_free (v); 1555 } 1556 1557 /* If a software watchpoint is not watching any memory, then the 1558 above left it without any location set up. But, 1559 bpstat_stop_status requires a location to be able to report 1560 stops, so make sure there's at least a dummy one. */ 1561 if (b->base.type == bp_watchpoint && b->base.loc == NULL) 1562 { 1563 struct breakpoint *base = &b->base; 1564 base->loc = allocate_bp_location (base); 1565 base->loc->pspace = frame_pspace; 1566 base->loc->address = -1; 1567 base->loc->length = -1; 1568 base->loc->watchpoint_type = -1; 1569 } 1570 } 1571 else if (!within_current_scope) 1572 { 1573 printf_filtered (_("\ 1574 Watchpoint %d deleted because the program has left the block\n\ 1575 in which its expression is valid.\n"), 1576 b->base.number); 1577 watchpoint_del_at_next_stop (b); 1578 } 1579 1580 /* Restore the selected frame. */ 1581 if (frame_saved) 1582 select_frame (frame_find_by_id (saved_frame_id)); 1583 } 1584 1585 1586 /* Returns 1 iff breakpoint location should be 1587 inserted in the inferior. We don't differentiate the type of BL's owner 1588 (breakpoint vs. tracepoint), although insert_location in tracepoint's 1589 breakpoint_ops is not defined, because in insert_bp_location, 1590 tracepoint's insert_location will not be called. */ 1591 static int 1592 should_be_inserted (struct bp_location *bl) 1593 { 1594 if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) 1595 return 0; 1596 1597 if (bl->owner->disposition == disp_del_at_next_stop) 1598 return 0; 1599 1600 if (!bl->enabled || bl->shlib_disabled || bl->duplicate) 1601 return 0; 1602 1603 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) 1604 return 0; 1605 1606 /* This is set for example, when we're attached to the parent of a 1607 vfork, and have detached from the child. The child is running 1608 free, and we expect it to do an exec or exit, at which point the 1609 OS makes the parent schedulable again (and the target reports 1610 that the vfork is done). Until the child is done with the shared 1611 memory region, do not insert breakpoints in the parent, otherwise 1612 the child could still trip on the parent's breakpoints. Since 1613 the parent is blocked anyway, it won't miss any breakpoint. */ 1614 if (bl->pspace->breakpoints_not_allowed) 1615 return 0; 1616 1617 return 1; 1618 } 1619 1620 /* Same as should_be_inserted but does the check assuming 1621 that the location is not duplicated. */ 1622 1623 static int 1624 unduplicated_should_be_inserted (struct bp_location *bl) 1625 { 1626 int result; 1627 const int save_duplicate = bl->duplicate; 1628 1629 bl->duplicate = 0; 1630 result = should_be_inserted (bl); 1631 bl->duplicate = save_duplicate; 1632 return result; 1633 } 1634 1635 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint 1636 location. Any error messages are printed to TMP_ERROR_STREAM; and 1637 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. 1638 Returns 0 for success, 1 if the bp_location type is not supported or 1639 -1 for failure. 1640 1641 NOTE drow/2003-09-09: This routine could be broken down to an 1642 object-style method for each breakpoint or catchpoint type. */ 1643 static int 1644 insert_bp_location (struct bp_location *bl, 1645 struct ui_file *tmp_error_stream, 1646 int *disabled_breaks, 1647 int *hw_breakpoint_error) 1648 { 1649 int val = 0; 1650 1651 if (!should_be_inserted (bl) || bl->inserted) 1652 return 0; 1653 1654 /* Initialize the target-specific information. */ 1655 memset (&bl->target_info, 0, sizeof (bl->target_info)); 1656 bl->target_info.placed_address = bl->address; 1657 bl->target_info.placed_address_space = bl->pspace->aspace; 1658 bl->target_info.length = bl->length; 1659 1660 if (bl->loc_type == bp_loc_software_breakpoint 1661 || bl->loc_type == bp_loc_hardware_breakpoint) 1662 { 1663 if (bl->owner->type != bp_hardware_breakpoint) 1664 { 1665 /* If the explicitly specified breakpoint type 1666 is not hardware breakpoint, check the memory map to see 1667 if the breakpoint address is in read only memory or not. 1668 1669 Two important cases are: 1670 - location type is not hardware breakpoint, memory 1671 is readonly. We change the type of the location to 1672 hardware breakpoint. 1673 - location type is hardware breakpoint, memory is 1674 read-write. This means we've previously made the 1675 location hardware one, but then the memory map changed, 1676 so we undo. 1677 1678 When breakpoints are removed, remove_breakpoints will use 1679 location types we've just set here, the only possible 1680 problem is that memory map has changed during running 1681 program, but it's not going to work anyway with current 1682 gdb. */ 1683 struct mem_region *mr 1684 = lookup_mem_region (bl->target_info.placed_address); 1685 1686 if (mr) 1687 { 1688 if (automatic_hardware_breakpoints) 1689 { 1690 enum bp_loc_type new_type; 1691 1692 if (mr->attrib.mode != MEM_RW) 1693 new_type = bp_loc_hardware_breakpoint; 1694 else 1695 new_type = bp_loc_software_breakpoint; 1696 1697 if (new_type != bl->loc_type) 1698 { 1699 static int said = 0; 1700 1701 bl->loc_type = new_type; 1702 if (!said) 1703 { 1704 fprintf_filtered (gdb_stdout, 1705 _("Note: automatically using " 1706 "hardware breakpoints for " 1707 "read-only addresses.\n")); 1708 said = 1; 1709 } 1710 } 1711 } 1712 else if (bl->loc_type == bp_loc_software_breakpoint 1713 && mr->attrib.mode != MEM_RW) 1714 warning (_("cannot set software breakpoint " 1715 "at readonly address %s"), 1716 paddress (bl->gdbarch, bl->address)); 1717 } 1718 } 1719 1720 /* First check to see if we have to handle an overlay. */ 1721 if (overlay_debugging == ovly_off 1722 || bl->section == NULL 1723 || !(section_is_overlay (bl->section))) 1724 { 1725 /* No overlay handling: just set the breakpoint. */ 1726 1727 val = bl->owner->ops->insert_location (bl); 1728 } 1729 else 1730 { 1731 /* This breakpoint is in an overlay section. 1732 Shall we set a breakpoint at the LMA? */ 1733 if (!overlay_events_enabled) 1734 { 1735 /* Yes -- overlay event support is not active, 1736 so we must try to set a breakpoint at the LMA. 1737 This will not work for a hardware breakpoint. */ 1738 if (bl->loc_type == bp_loc_hardware_breakpoint) 1739 warning (_("hardware breakpoint %d not supported in overlay!"), 1740 bl->owner->number); 1741 else 1742 { 1743 CORE_ADDR addr = overlay_unmapped_address (bl->address, 1744 bl->section); 1745 /* Set a software (trap) breakpoint at the LMA. */ 1746 bl->overlay_target_info = bl->target_info; 1747 bl->overlay_target_info.placed_address = addr; 1748 val = target_insert_breakpoint (bl->gdbarch, 1749 &bl->overlay_target_info); 1750 if (val != 0) 1751 fprintf_unfiltered (tmp_error_stream, 1752 "Overlay breakpoint %d " 1753 "failed: in ROM?\n", 1754 bl->owner->number); 1755 } 1756 } 1757 /* Shall we set a breakpoint at the VMA? */ 1758 if (section_is_mapped (bl->section)) 1759 { 1760 /* Yes. This overlay section is mapped into memory. */ 1761 val = bl->owner->ops->insert_location (bl); 1762 } 1763 else 1764 { 1765 /* No. This breakpoint will not be inserted. 1766 No error, but do not mark the bp as 'inserted'. */ 1767 return 0; 1768 } 1769 } 1770 1771 if (val) 1772 { 1773 /* Can't set the breakpoint. */ 1774 if (solib_name_from_address (bl->pspace, bl->address)) 1775 { 1776 /* See also: disable_breakpoints_in_shlibs. */ 1777 val = 0; 1778 bl->shlib_disabled = 1; 1779 observer_notify_breakpoint_modified (bl->owner); 1780 if (!*disabled_breaks) 1781 { 1782 fprintf_unfiltered (tmp_error_stream, 1783 "Cannot insert breakpoint %d.\n", 1784 bl->owner->number); 1785 fprintf_unfiltered (tmp_error_stream, 1786 "Temporarily disabling shared " 1787 "library breakpoints:\n"); 1788 } 1789 *disabled_breaks = 1; 1790 fprintf_unfiltered (tmp_error_stream, 1791 "breakpoint #%d\n", bl->owner->number); 1792 } 1793 else 1794 { 1795 if (bl->loc_type == bp_loc_hardware_breakpoint) 1796 { 1797 *hw_breakpoint_error = 1; 1798 fprintf_unfiltered (tmp_error_stream, 1799 "Cannot insert hardware " 1800 "breakpoint %d.\n", 1801 bl->owner->number); 1802 } 1803 else 1804 { 1805 fprintf_unfiltered (tmp_error_stream, 1806 "Cannot insert breakpoint %d.\n", 1807 bl->owner->number); 1808 fprintf_filtered (tmp_error_stream, 1809 "Error accessing memory address "); 1810 fputs_filtered (paddress (bl->gdbarch, bl->address), 1811 tmp_error_stream); 1812 fprintf_filtered (tmp_error_stream, ": %s.\n", 1813 safe_strerror (val)); 1814 } 1815 1816 } 1817 } 1818 else 1819 bl->inserted = 1; 1820 1821 return val; 1822 } 1823 1824 else if (bl->loc_type == bp_loc_hardware_watchpoint 1825 /* NOTE drow/2003-09-08: This state only exists for removing 1826 watchpoints. It's not clear that it's necessary... */ 1827 && bl->owner->disposition != disp_del_at_next_stop) 1828 { 1829 gdb_assert (bl->owner->ops != NULL 1830 && bl->owner->ops->insert_location != NULL); 1831 1832 val = bl->owner->ops->insert_location (bl); 1833 1834 /* If trying to set a read-watchpoint, and it turns out it's not 1835 supported, try emulating one with an access watchpoint. */ 1836 if (val == 1 && bl->watchpoint_type == hw_read) 1837 { 1838 struct bp_location *loc, **loc_temp; 1839 1840 /* But don't try to insert it, if there's already another 1841 hw_access location that would be considered a duplicate 1842 of this one. */ 1843 ALL_BP_LOCATIONS (loc, loc_temp) 1844 if (loc != bl 1845 && loc->watchpoint_type == hw_access 1846 && watchpoint_locations_match (bl, loc)) 1847 { 1848 bl->duplicate = 1; 1849 bl->inserted = 1; 1850 bl->target_info = loc->target_info; 1851 bl->watchpoint_type = hw_access; 1852 val = 0; 1853 break; 1854 } 1855 1856 if (val == 1) 1857 { 1858 bl->watchpoint_type = hw_access; 1859 val = bl->owner->ops->insert_location (bl); 1860 1861 if (val) 1862 /* Back to the original value. */ 1863 bl->watchpoint_type = hw_read; 1864 } 1865 } 1866 1867 bl->inserted = (val == 0); 1868 } 1869 1870 else if (bl->owner->type == bp_catchpoint) 1871 { 1872 gdb_assert (bl->owner->ops != NULL 1873 && bl->owner->ops->insert_location != NULL); 1874 1875 val = bl->owner->ops->insert_location (bl); 1876 if (val) 1877 { 1878 bl->owner->enable_state = bp_disabled; 1879 1880 if (val == 1) 1881 warning (_("\ 1882 Error inserting catchpoint %d: Your system does not support this type\n\ 1883 of catchpoint."), bl->owner->number); 1884 else 1885 warning (_("Error inserting catchpoint %d."), bl->owner->number); 1886 } 1887 1888 bl->inserted = (val == 0); 1889 1890 /* We've already printed an error message if there was a problem 1891 inserting this catchpoint, and we've disabled the catchpoint, 1892 so just return success. */ 1893 return 0; 1894 } 1895 1896 return 0; 1897 } 1898 1899 /* This function is called when program space PSPACE is about to be 1900 deleted. It takes care of updating breakpoints to not reference 1901 PSPACE anymore. */ 1902 1903 void 1904 breakpoint_program_space_exit (struct program_space *pspace) 1905 { 1906 struct breakpoint *b, *b_temp; 1907 struct bp_location *loc, **loc_temp; 1908 1909 /* Remove any breakpoint that was set through this program space. */ 1910 ALL_BREAKPOINTS_SAFE (b, b_temp) 1911 { 1912 if (b->pspace == pspace) 1913 delete_breakpoint (b); 1914 } 1915 1916 /* Breakpoints set through other program spaces could have locations 1917 bound to PSPACE as well. Remove those. */ 1918 ALL_BP_LOCATIONS (loc, loc_temp) 1919 { 1920 struct bp_location *tmp; 1921 1922 if (loc->pspace == pspace) 1923 { 1924 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ 1925 if (loc->owner->loc == loc) 1926 loc->owner->loc = loc->next; 1927 else 1928 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) 1929 if (tmp->next == loc) 1930 { 1931 tmp->next = loc->next; 1932 break; 1933 } 1934 } 1935 } 1936 1937 /* Now update the global location list to permanently delete the 1938 removed locations above. */ 1939 update_global_location_list (0); 1940 } 1941 1942 /* Make sure all breakpoints are inserted in inferior. 1943 Throws exception on any error. 1944 A breakpoint that is already inserted won't be inserted 1945 again, so calling this function twice is safe. */ 1946 void 1947 insert_breakpoints (void) 1948 { 1949 struct breakpoint *bpt; 1950 1951 ALL_BREAKPOINTS (bpt) 1952 if (is_hardware_watchpoint (bpt)) 1953 { 1954 struct watchpoint *w = (struct watchpoint *) bpt; 1955 1956 update_watchpoint (w, 0 /* don't reparse. */); 1957 } 1958 1959 update_global_location_list (1); 1960 1961 /* update_global_location_list does not insert breakpoints when 1962 always_inserted_mode is not enabled. Explicitly insert them 1963 now. */ 1964 if (!breakpoints_always_inserted_mode ()) 1965 insert_breakpoint_locations (); 1966 } 1967 1968 /* Used when starting or continuing the program. */ 1969 1970 static void 1971 insert_breakpoint_locations (void) 1972 { 1973 struct breakpoint *bpt; 1974 struct bp_location *bl, **blp_tmp; 1975 int error_flag = 0; 1976 int val = 0; 1977 int disabled_breaks = 0; 1978 int hw_breakpoint_error = 0; 1979 1980 struct ui_file *tmp_error_stream = mem_fileopen (); 1981 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); 1982 1983 /* Explicitly mark the warning -- this will only be printed if 1984 there was an error. */ 1985 fprintf_unfiltered (tmp_error_stream, "Warning:\n"); 1986 1987 save_current_space_and_thread (); 1988 1989 ALL_BP_LOCATIONS (bl, blp_tmp) 1990 { 1991 if (!should_be_inserted (bl) || bl->inserted) 1992 continue; 1993 1994 /* There is no point inserting thread-specific breakpoints if 1995 the thread no longer exists. ALL_BP_LOCATIONS bp_location 1996 has BL->OWNER always non-NULL. */ 1997 if (bl->owner->thread != -1 1998 && !valid_thread_id (bl->owner->thread)) 1999 continue; 2000 2001 switch_to_program_space_and_thread (bl->pspace); 2002 2003 /* For targets that support global breakpoints, there's no need 2004 to select an inferior to insert breakpoint to. In fact, even 2005 if we aren't attached to any process yet, we should still 2006 insert breakpoints. */ 2007 if (!gdbarch_has_global_breakpoints (target_gdbarch) 2008 && ptid_equal (inferior_ptid, null_ptid)) 2009 continue; 2010 2011 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, 2012 &hw_breakpoint_error); 2013 if (val) 2014 error_flag = val; 2015 } 2016 2017 /* If we failed to insert all locations of a watchpoint, remove 2018 them, as half-inserted watchpoint is of limited use. */ 2019 ALL_BREAKPOINTS (bpt) 2020 { 2021 int some_failed = 0; 2022 struct bp_location *loc; 2023 2024 if (!is_hardware_watchpoint (bpt)) 2025 continue; 2026 2027 if (!breakpoint_enabled (bpt)) 2028 continue; 2029 2030 if (bpt->disposition == disp_del_at_next_stop) 2031 continue; 2032 2033 for (loc = bpt->loc; loc; loc = loc->next) 2034 if (!loc->inserted && should_be_inserted (loc)) 2035 { 2036 some_failed = 1; 2037 break; 2038 } 2039 if (some_failed) 2040 { 2041 for (loc = bpt->loc; loc; loc = loc->next) 2042 if (loc->inserted) 2043 remove_breakpoint (loc, mark_uninserted); 2044 2045 hw_breakpoint_error = 1; 2046 fprintf_unfiltered (tmp_error_stream, 2047 "Could not insert hardware watchpoint %d.\n", 2048 bpt->number); 2049 error_flag = -1; 2050 } 2051 } 2052 2053 if (error_flag) 2054 { 2055 /* If a hardware breakpoint or watchpoint was inserted, add a 2056 message about possibly exhausted resources. */ 2057 if (hw_breakpoint_error) 2058 { 2059 fprintf_unfiltered (tmp_error_stream, 2060 "Could not insert hardware breakpoints:\n\ 2061 You may have requested too many hardware breakpoints/watchpoints.\n"); 2062 } 2063 target_terminal_ours_for_output (); 2064 error_stream (tmp_error_stream); 2065 } 2066 2067 do_cleanups (cleanups); 2068 } 2069 2070 /* Used when the program stops. 2071 Returns zero if successful, or non-zero if there was a problem 2072 removing a breakpoint location. */ 2073 2074 int 2075 remove_breakpoints (void) 2076 { 2077 struct bp_location *bl, **blp_tmp; 2078 int val = 0; 2079 2080 ALL_BP_LOCATIONS (bl, blp_tmp) 2081 { 2082 if (bl->inserted && !is_tracepoint (bl->owner)) 2083 val |= remove_breakpoint (bl, mark_uninserted); 2084 } 2085 return val; 2086 } 2087 2088 /* Remove breakpoints of process PID. */ 2089 2090 int 2091 remove_breakpoints_pid (int pid) 2092 { 2093 struct bp_location *bl, **blp_tmp; 2094 int val; 2095 struct inferior *inf = find_inferior_pid (pid); 2096 2097 ALL_BP_LOCATIONS (bl, blp_tmp) 2098 { 2099 if (bl->pspace != inf->pspace) 2100 continue; 2101 2102 if (bl->inserted) 2103 { 2104 val = remove_breakpoint (bl, mark_uninserted); 2105 if (val != 0) 2106 return val; 2107 } 2108 } 2109 return 0; 2110 } 2111 2112 int 2113 reattach_breakpoints (int pid) 2114 { 2115 struct cleanup *old_chain; 2116 struct bp_location *bl, **blp_tmp; 2117 int val; 2118 struct ui_file *tmp_error_stream; 2119 int dummy1 = 0, dummy2 = 0; 2120 struct inferior *inf; 2121 struct thread_info *tp; 2122 2123 tp = any_live_thread_of_process (pid); 2124 if (tp == NULL) 2125 return 1; 2126 2127 inf = find_inferior_pid (pid); 2128 old_chain = save_inferior_ptid (); 2129 2130 inferior_ptid = tp->ptid; 2131 2132 tmp_error_stream = mem_fileopen (); 2133 make_cleanup_ui_file_delete (tmp_error_stream); 2134 2135 ALL_BP_LOCATIONS (bl, blp_tmp) 2136 { 2137 if (bl->pspace != inf->pspace) 2138 continue; 2139 2140 if (bl->inserted) 2141 { 2142 bl->inserted = 0; 2143 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); 2144 if (val != 0) 2145 { 2146 do_cleanups (old_chain); 2147 return val; 2148 } 2149 } 2150 } 2151 do_cleanups (old_chain); 2152 return 0; 2153 } 2154 2155 static int internal_breakpoint_number = -1; 2156 2157 /* Set the breakpoint number of B, depending on the value of INTERNAL. 2158 If INTERNAL is non-zero, the breakpoint number will be populated 2159 from internal_breakpoint_number and that variable decremented. 2160 Otherwise the breakpoint number will be populated from 2161 breakpoint_count and that value incremented. Internal breakpoints 2162 do not set the internal var bpnum. */ 2163 static void 2164 set_breakpoint_number (int internal, struct breakpoint *b) 2165 { 2166 if (internal) 2167 b->number = internal_breakpoint_number--; 2168 else 2169 { 2170 set_breakpoint_count (breakpoint_count + 1); 2171 b->number = breakpoint_count; 2172 } 2173 } 2174 2175 static struct breakpoint * 2176 create_internal_breakpoint (struct gdbarch *gdbarch, 2177 CORE_ADDR address, enum bptype type, 2178 const struct breakpoint_ops *ops) 2179 { 2180 struct symtab_and_line sal; 2181 struct breakpoint *b; 2182 2183 init_sal (&sal); /* Initialize to zeroes. */ 2184 2185 sal.pc = address; 2186 sal.section = find_pc_overlay (sal.pc); 2187 sal.pspace = current_program_space; 2188 2189 b = set_raw_breakpoint (gdbarch, sal, type, ops); 2190 b->number = internal_breakpoint_number--; 2191 b->disposition = disp_donttouch; 2192 2193 return b; 2194 } 2195 2196 static const char *const longjmp_names[] = 2197 { 2198 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" 2199 }; 2200 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) 2201 2202 /* Per-objfile data private to breakpoint.c. */ 2203 struct breakpoint_objfile_data 2204 { 2205 /* Minimal symbol for "_ovly_debug_event" (if any). */ 2206 struct minimal_symbol *overlay_msym; 2207 2208 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ 2209 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; 2210 2211 /* Minimal symbol for "std::terminate()" (if any). */ 2212 struct minimal_symbol *terminate_msym; 2213 2214 /* Minimal symbol for "_Unwind_DebugHook" (if any). */ 2215 struct minimal_symbol *exception_msym; 2216 }; 2217 2218 static const struct objfile_data *breakpoint_objfile_key; 2219 2220 /* Minimal symbol not found sentinel. */ 2221 static struct minimal_symbol msym_not_found; 2222 2223 /* Returns TRUE if MSYM point to the "not found" sentinel. */ 2224 2225 static int 2226 msym_not_found_p (const struct minimal_symbol *msym) 2227 { 2228 return msym == &msym_not_found; 2229 } 2230 2231 /* Return per-objfile data needed by breakpoint.c. 2232 Allocate the data if necessary. */ 2233 2234 static struct breakpoint_objfile_data * 2235 get_breakpoint_objfile_data (struct objfile *objfile) 2236 { 2237 struct breakpoint_objfile_data *bp_objfile_data; 2238 2239 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); 2240 if (bp_objfile_data == NULL) 2241 { 2242 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, 2243 sizeof (*bp_objfile_data)); 2244 2245 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); 2246 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); 2247 } 2248 return bp_objfile_data; 2249 } 2250 2251 static void 2252 create_overlay_event_breakpoint (void) 2253 { 2254 struct objfile *objfile; 2255 const char *const func_name = "_ovly_debug_event"; 2256 2257 ALL_OBJFILES (objfile) 2258 { 2259 struct breakpoint *b; 2260 struct breakpoint_objfile_data *bp_objfile_data; 2261 CORE_ADDR addr; 2262 2263 bp_objfile_data = get_breakpoint_objfile_data (objfile); 2264 2265 if (msym_not_found_p (bp_objfile_data->overlay_msym)) 2266 continue; 2267 2268 if (bp_objfile_data->overlay_msym == NULL) 2269 { 2270 struct minimal_symbol *m; 2271 2272 m = lookup_minimal_symbol_text (func_name, objfile); 2273 if (m == NULL) 2274 { 2275 /* Avoid future lookups in this objfile. */ 2276 bp_objfile_data->overlay_msym = &msym_not_found; 2277 continue; 2278 } 2279 bp_objfile_data->overlay_msym = m; 2280 } 2281 2282 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); 2283 b = create_internal_breakpoint (get_objfile_arch (objfile), addr, 2284 bp_overlay_event, 2285 &internal_breakpoint_ops); 2286 b->addr_string = xstrdup (func_name); 2287 2288 if (overlay_debugging == ovly_auto) 2289 { 2290 b->enable_state = bp_enabled; 2291 overlay_events_enabled = 1; 2292 } 2293 else 2294 { 2295 b->enable_state = bp_disabled; 2296 overlay_events_enabled = 0; 2297 } 2298 } 2299 update_global_location_list (1); 2300 } 2301 2302 static void 2303 create_longjmp_master_breakpoint (void) 2304 { 2305 struct program_space *pspace; 2306 struct cleanup *old_chain; 2307 2308 old_chain = save_current_program_space (); 2309 2310 ALL_PSPACES (pspace) 2311 { 2312 struct objfile *objfile; 2313 2314 set_current_program_space (pspace); 2315 2316 ALL_OBJFILES (objfile) 2317 { 2318 int i; 2319 struct gdbarch *gdbarch; 2320 struct breakpoint_objfile_data *bp_objfile_data; 2321 2322 gdbarch = get_objfile_arch (objfile); 2323 if (!gdbarch_get_longjmp_target_p (gdbarch)) 2324 continue; 2325 2326 bp_objfile_data = get_breakpoint_objfile_data (objfile); 2327 2328 for (i = 0; i < NUM_LONGJMP_NAMES; i++) 2329 { 2330 struct breakpoint *b; 2331 const char *func_name; 2332 CORE_ADDR addr; 2333 2334 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) 2335 continue; 2336 2337 func_name = longjmp_names[i]; 2338 if (bp_objfile_data->longjmp_msym[i] == NULL) 2339 { 2340 struct minimal_symbol *m; 2341 2342 m = lookup_minimal_symbol_text (func_name, objfile); 2343 if (m == NULL) 2344 { 2345 /* Prevent future lookups in this objfile. */ 2346 bp_objfile_data->longjmp_msym[i] = &msym_not_found; 2347 continue; 2348 } 2349 bp_objfile_data->longjmp_msym[i] = m; 2350 } 2351 2352 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); 2353 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, 2354 &internal_breakpoint_ops); 2355 b->addr_string = xstrdup (func_name); 2356 b->enable_state = bp_disabled; 2357 } 2358 } 2359 } 2360 update_global_location_list (1); 2361 2362 do_cleanups (old_chain); 2363 } 2364 2365 /* Create a master std::terminate breakpoint. */ 2366 static void 2367 create_std_terminate_master_breakpoint (void) 2368 { 2369 struct program_space *pspace; 2370 struct cleanup *old_chain; 2371 const char *const func_name = "std::terminate()"; 2372 2373 old_chain = save_current_program_space (); 2374 2375 ALL_PSPACES (pspace) 2376 { 2377 struct objfile *objfile; 2378 CORE_ADDR addr; 2379 2380 set_current_program_space (pspace); 2381 2382 ALL_OBJFILES (objfile) 2383 { 2384 struct breakpoint *b; 2385 struct breakpoint_objfile_data *bp_objfile_data; 2386 2387 bp_objfile_data = get_breakpoint_objfile_data (objfile); 2388 2389 if (msym_not_found_p (bp_objfile_data->terminate_msym)) 2390 continue; 2391 2392 if (bp_objfile_data->terminate_msym == NULL) 2393 { 2394 struct minimal_symbol *m; 2395 2396 m = lookup_minimal_symbol (func_name, NULL, objfile); 2397 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text 2398 && MSYMBOL_TYPE (m) != mst_file_text)) 2399 { 2400 /* Prevent future lookups in this objfile. */ 2401 bp_objfile_data->terminate_msym = &msym_not_found; 2402 continue; 2403 } 2404 bp_objfile_data->terminate_msym = m; 2405 } 2406 2407 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); 2408 b = create_internal_breakpoint (get_objfile_arch (objfile), addr, 2409 bp_std_terminate_master, 2410 &internal_breakpoint_ops); 2411 b->addr_string = xstrdup (func_name); 2412 b->enable_state = bp_disabled; 2413 } 2414 } 2415 2416 update_global_location_list (1); 2417 2418 do_cleanups (old_chain); 2419 } 2420 2421 /* Install a master breakpoint on the unwinder's debug hook. */ 2422 2423 void 2424 create_exception_master_breakpoint (void) 2425 { 2426 struct objfile *objfile; 2427 const char *const func_name = "_Unwind_DebugHook"; 2428 2429 ALL_OBJFILES (objfile) 2430 { 2431 struct breakpoint *b; 2432 struct gdbarch *gdbarch; 2433 struct breakpoint_objfile_data *bp_objfile_data; 2434 CORE_ADDR addr; 2435 2436 bp_objfile_data = get_breakpoint_objfile_data (objfile); 2437 2438 if (msym_not_found_p (bp_objfile_data->exception_msym)) 2439 continue; 2440 2441 gdbarch = get_objfile_arch (objfile); 2442 2443 if (bp_objfile_data->exception_msym == NULL) 2444 { 2445 struct minimal_symbol *debug_hook; 2446 2447 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); 2448 if (debug_hook == NULL) 2449 { 2450 bp_objfile_data->exception_msym = &msym_not_found; 2451 continue; 2452 } 2453 2454 bp_objfile_data->exception_msym = debug_hook; 2455 } 2456 2457 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); 2458 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, 2459 ¤t_target); 2460 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, 2461 &internal_breakpoint_ops); 2462 b->addr_string = xstrdup (func_name); 2463 b->enable_state = bp_disabled; 2464 } 2465 2466 update_global_location_list (1); 2467 } 2468 2469 void 2470 update_breakpoints_after_exec (void) 2471 { 2472 struct breakpoint *b, *b_tmp; 2473 struct bp_location *bploc, **bplocp_tmp; 2474 2475 /* We're about to delete breakpoints from GDB's lists. If the 2476 INSERTED flag is true, GDB will try to lift the breakpoints by 2477 writing the breakpoints' "shadow contents" back into memory. The 2478 "shadow contents" are NOT valid after an exec, so GDB should not 2479 do that. Instead, the target is responsible from marking 2480 breakpoints out as soon as it detects an exec. We don't do that 2481 here instead, because there may be other attempts to delete 2482 breakpoints after detecting an exec and before reaching here. */ 2483 ALL_BP_LOCATIONS (bploc, bplocp_tmp) 2484 if (bploc->pspace == current_program_space) 2485 gdb_assert (!bploc->inserted); 2486 2487 ALL_BREAKPOINTS_SAFE (b, b_tmp) 2488 { 2489 if (b->pspace != current_program_space) 2490 continue; 2491 2492 /* Solib breakpoints must be explicitly reset after an exec(). */ 2493 if (b->type == bp_shlib_event) 2494 { 2495 delete_breakpoint (b); 2496 continue; 2497 } 2498 2499 /* JIT breakpoints must be explicitly reset after an exec(). */ 2500 if (b->type == bp_jit_event) 2501 { 2502 delete_breakpoint (b); 2503 continue; 2504 } 2505 2506 /* Thread event breakpoints must be set anew after an exec(), 2507 as must overlay event and longjmp master breakpoints. */ 2508 if (b->type == bp_thread_event || b->type == bp_overlay_event 2509 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master 2510 || b->type == bp_exception_master) 2511 { 2512 delete_breakpoint (b); 2513 continue; 2514 } 2515 2516 /* Step-resume breakpoints are meaningless after an exec(). */ 2517 if (b->type == bp_step_resume || b->type == bp_hp_step_resume) 2518 { 2519 delete_breakpoint (b); 2520 continue; 2521 } 2522 2523 /* Longjmp and longjmp-resume breakpoints are also meaningless 2524 after an exec. */ 2525 if (b->type == bp_longjmp || b->type == bp_longjmp_resume 2526 || b->type == bp_exception || b->type == bp_exception_resume) 2527 { 2528 delete_breakpoint (b); 2529 continue; 2530 } 2531 2532 if (b->type == bp_catchpoint) 2533 { 2534 /* For now, none of the bp_catchpoint breakpoints need to 2535 do anything at this point. In the future, if some of 2536 the catchpoints need to something, we will need to add 2537 a new method, and call this method from here. */ 2538 continue; 2539 } 2540 2541 /* bp_finish is a special case. The only way we ought to be able 2542 to see one of these when an exec() has happened, is if the user 2543 caught a vfork, and then said "finish". Ordinarily a finish just 2544 carries them to the call-site of the current callee, by setting 2545 a temporary bp there and resuming. But in this case, the finish 2546 will carry them entirely through the vfork & exec. 2547 2548 We don't want to allow a bp_finish to remain inserted now. But 2549 we can't safely delete it, 'cause finish_command has a handle to 2550 the bp on a bpstat, and will later want to delete it. There's a 2551 chance (and I've seen it happen) that if we delete the bp_finish 2552 here, that its storage will get reused by the time finish_command 2553 gets 'round to deleting the "use to be a bp_finish" breakpoint. 2554 We really must allow finish_command to delete a bp_finish. 2555 2556 In the absence of a general solution for the "how do we know 2557 it's safe to delete something others may have handles to?" 2558 problem, what we'll do here is just uninsert the bp_finish, and 2559 let finish_command delete it. 2560 2561 (We know the bp_finish is "doomed" in the sense that it's 2562 momentary, and will be deleted as soon as finish_command sees 2563 the inferior stopped. So it doesn't matter that the bp's 2564 address is probably bogus in the new a.out, unlike e.g., the 2565 solib breakpoints.) */ 2566 2567 if (b->type == bp_finish) 2568 { 2569 continue; 2570 } 2571 2572 /* Without a symbolic address, we have little hope of the 2573 pre-exec() address meaning the same thing in the post-exec() 2574 a.out. */ 2575 if (b->addr_string == NULL) 2576 { 2577 delete_breakpoint (b); 2578 continue; 2579 } 2580 } 2581 /* FIXME what about longjmp breakpoints? Re-create them here? */ 2582 create_overlay_event_breakpoint (); 2583 create_longjmp_master_breakpoint (); 2584 create_std_terminate_master_breakpoint (); 2585 create_exception_master_breakpoint (); 2586 } 2587 2588 int 2589 detach_breakpoints (int pid) 2590 { 2591 struct bp_location *bl, **blp_tmp; 2592 int val = 0; 2593 struct cleanup *old_chain = save_inferior_ptid (); 2594 struct inferior *inf = current_inferior (); 2595 2596 if (pid == PIDGET (inferior_ptid)) 2597 error (_("Cannot detach breakpoints of inferior_ptid")); 2598 2599 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ 2600 inferior_ptid = pid_to_ptid (pid); 2601 ALL_BP_LOCATIONS (bl, blp_tmp) 2602 { 2603 if (bl->pspace != inf->pspace) 2604 continue; 2605 2606 if (bl->inserted) 2607 val |= remove_breakpoint_1 (bl, mark_inserted); 2608 } 2609 2610 /* Detach single-step breakpoints as well. */ 2611 detach_single_step_breakpoints (); 2612 2613 do_cleanups (old_chain); 2614 return val; 2615 } 2616 2617 /* Remove the breakpoint location BL from the current address space. 2618 Note that this is used to detach breakpoints from a child fork. 2619 When we get here, the child isn't in the inferior list, and neither 2620 do we have objects to represent its address space --- we should 2621 *not* look at bl->pspace->aspace here. */ 2622 2623 static int 2624 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) 2625 { 2626 int val; 2627 2628 /* BL is never in moribund_locations by our callers. */ 2629 gdb_assert (bl->owner != NULL); 2630 2631 if (bl->owner->enable_state == bp_permanent) 2632 /* Permanent breakpoints cannot be inserted or removed. */ 2633 return 0; 2634 2635 /* The type of none suggests that owner is actually deleted. 2636 This should not ever happen. */ 2637 gdb_assert (bl->owner->type != bp_none); 2638 2639 if (bl->loc_type == bp_loc_software_breakpoint 2640 || bl->loc_type == bp_loc_hardware_breakpoint) 2641 { 2642 /* "Normal" instruction breakpoint: either the standard 2643 trap-instruction bp (bp_breakpoint), or a 2644 bp_hardware_breakpoint. */ 2645 2646 /* First check to see if we have to handle an overlay. */ 2647 if (overlay_debugging == ovly_off 2648 || bl->section == NULL 2649 || !(section_is_overlay (bl->section))) 2650 { 2651 /* No overlay handling: just remove the breakpoint. */ 2652 val = bl->owner->ops->remove_location (bl); 2653 } 2654 else 2655 { 2656 /* This breakpoint is in an overlay section. 2657 Did we set a breakpoint at the LMA? */ 2658 if (!overlay_events_enabled) 2659 { 2660 /* Yes -- overlay event support is not active, so we 2661 should have set a breakpoint at the LMA. Remove it. 2662 */ 2663 /* Ignore any failures: if the LMA is in ROM, we will 2664 have already warned when we failed to insert it. */ 2665 if (bl->loc_type == bp_loc_hardware_breakpoint) 2666 target_remove_hw_breakpoint (bl->gdbarch, 2667 &bl->overlay_target_info); 2668 else 2669 target_remove_breakpoint (bl->gdbarch, 2670 &bl->overlay_target_info); 2671 } 2672 /* Did we set a breakpoint at the VMA? 2673 If so, we will have marked the breakpoint 'inserted'. */ 2674 if (bl->inserted) 2675 { 2676 /* Yes -- remove it. Previously we did not bother to 2677 remove the breakpoint if the section had been 2678 unmapped, but let's not rely on that being safe. We 2679 don't know what the overlay manager might do. */ 2680 2681 /* However, we should remove *software* breakpoints only 2682 if the section is still mapped, or else we overwrite 2683 wrong code with the saved shadow contents. */ 2684 if (bl->loc_type == bp_loc_hardware_breakpoint 2685 || section_is_mapped (bl->section)) 2686 val = bl->owner->ops->remove_location (bl); 2687 else 2688 val = 0; 2689 } 2690 else 2691 { 2692 /* No -- not inserted, so no need to remove. No error. */ 2693 val = 0; 2694 } 2695 } 2696 2697 /* In some cases, we might not be able to remove a breakpoint 2698 in a shared library that has already been removed, but we 2699 have not yet processed the shlib unload event. */ 2700 if (val && solib_name_from_address (bl->pspace, bl->address)) 2701 val = 0; 2702 2703 if (val) 2704 return val; 2705 bl->inserted = (is == mark_inserted); 2706 } 2707 else if (bl->loc_type == bp_loc_hardware_watchpoint) 2708 { 2709 gdb_assert (bl->owner->ops != NULL 2710 && bl->owner->ops->remove_location != NULL); 2711 2712 bl->inserted = (is == mark_inserted); 2713 bl->owner->ops->remove_location (bl); 2714 2715 /* Failure to remove any of the hardware watchpoints comes here. */ 2716 if ((is == mark_uninserted) && (bl->inserted)) 2717 warning (_("Could not remove hardware watchpoint %d."), 2718 bl->owner->number); 2719 } 2720 else if (bl->owner->type == bp_catchpoint 2721 && breakpoint_enabled (bl->owner) 2722 && !bl->duplicate) 2723 { 2724 gdb_assert (bl->owner->ops != NULL 2725 && bl->owner->ops->remove_location != NULL); 2726 2727 val = bl->owner->ops->remove_location (bl); 2728 if (val) 2729 return val; 2730 2731 bl->inserted = (is == mark_inserted); 2732 } 2733 2734 return 0; 2735 } 2736 2737 static int 2738 remove_breakpoint (struct bp_location *bl, insertion_state_t is) 2739 { 2740 int ret; 2741 struct cleanup *old_chain; 2742 2743 /* BL is never in moribund_locations by our callers. */ 2744 gdb_assert (bl->owner != NULL); 2745 2746 if (bl->owner->enable_state == bp_permanent) 2747 /* Permanent breakpoints cannot be inserted or removed. */ 2748 return 0; 2749 2750 /* The type of none suggests that owner is actually deleted. 2751 This should not ever happen. */ 2752 gdb_assert (bl->owner->type != bp_none); 2753 2754 old_chain = save_current_space_and_thread (); 2755 2756 switch_to_program_space_and_thread (bl->pspace); 2757 2758 ret = remove_breakpoint_1 (bl, is); 2759 2760 do_cleanups (old_chain); 2761 return ret; 2762 } 2763 2764 /* Clear the "inserted" flag in all breakpoints. */ 2765 2766 void 2767 mark_breakpoints_out (void) 2768 { 2769 struct bp_location *bl, **blp_tmp; 2770 2771 ALL_BP_LOCATIONS (bl, blp_tmp) 2772 if (bl->pspace == current_program_space) 2773 bl->inserted = 0; 2774 } 2775 2776 /* Clear the "inserted" flag in all breakpoints and delete any 2777 breakpoints which should go away between runs of the program. 2778 2779 Plus other such housekeeping that has to be done for breakpoints 2780 between runs. 2781 2782 Note: this function gets called at the end of a run (by 2783 generic_mourn_inferior) and when a run begins (by 2784 init_wait_for_inferior). */ 2785 2786 2787 2788 void 2789 breakpoint_init_inferior (enum inf_context context) 2790 { 2791 struct breakpoint *b, *b_tmp; 2792 struct bp_location *bl, **blp_tmp; 2793 int ix; 2794 struct program_space *pspace = current_program_space; 2795 2796 /* If breakpoint locations are shared across processes, then there's 2797 nothing to do. */ 2798 if (gdbarch_has_global_breakpoints (target_gdbarch)) 2799 return; 2800 2801 ALL_BP_LOCATIONS (bl, blp_tmp) 2802 { 2803 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ 2804 if (bl->pspace == pspace 2805 && bl->owner->enable_state != bp_permanent) 2806 bl->inserted = 0; 2807 } 2808 2809 ALL_BREAKPOINTS_SAFE (b, b_tmp) 2810 { 2811 if (b->loc && b->loc->pspace != pspace) 2812 continue; 2813 2814 switch (b->type) 2815 { 2816 case bp_call_dummy: 2817 2818 /* If the call dummy breakpoint is at the entry point it will 2819 cause problems when the inferior is rerun, so we better get 2820 rid of it. */ 2821 2822 case bp_watchpoint_scope: 2823 2824 /* Also get rid of scope breakpoints. */ 2825 2826 case bp_shlib_event: 2827 2828 /* Also remove solib event breakpoints. Their addresses may 2829 have changed since the last time we ran the program. 2830 Actually we may now be debugging against different target; 2831 and so the solib backend that installed this breakpoint may 2832 not be used in by the target. E.g., 2833 2834 (gdb) file prog-linux 2835 (gdb) run # native linux target 2836 ... 2837 (gdb) kill 2838 (gdb) file prog-win.exe 2839 (gdb) tar rem :9999 # remote Windows gdbserver. 2840 */ 2841 2842 delete_breakpoint (b); 2843 break; 2844 2845 case bp_watchpoint: 2846 case bp_hardware_watchpoint: 2847 case bp_read_watchpoint: 2848 case bp_access_watchpoint: 2849 { 2850 struct watchpoint *w = (struct watchpoint *) b; 2851 2852 /* Likewise for watchpoints on local expressions. */ 2853 if (w->exp_valid_block != NULL) 2854 delete_breakpoint (b); 2855 else if (context == inf_starting) 2856 { 2857 /* Reset val field to force reread of starting value in 2858 insert_breakpoints. */ 2859 if (w->val) 2860 value_free (w->val); 2861 w->val = NULL; 2862 w->val_valid = 0; 2863 } 2864 } 2865 break; 2866 default: 2867 break; 2868 } 2869 } 2870 2871 /* Get rid of the moribund locations. */ 2872 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) 2873 decref_bp_location (&bl); 2874 VEC_free (bp_location_p, moribund_locations); 2875 } 2876 2877 /* These functions concern about actual breakpoints inserted in the 2878 target --- to e.g. check if we need to do decr_pc adjustment or if 2879 we need to hop over the bkpt --- so we check for address space 2880 match, not program space. */ 2881 2882 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint 2883 exists at PC. It returns ordinary_breakpoint_here if it's an 2884 ordinary breakpoint, or permanent_breakpoint_here if it's a 2885 permanent breakpoint. 2886 - When continuing from a location with an ordinary breakpoint, we 2887 actually single step once before calling insert_breakpoints. 2888 - When continuing from a location with a permanent breakpoint, we 2889 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by 2890 the target, to advance the PC past the breakpoint. */ 2891 2892 enum breakpoint_here 2893 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) 2894 { 2895 struct bp_location *bl, **blp_tmp; 2896 int any_breakpoint_here = 0; 2897 2898 ALL_BP_LOCATIONS (bl, blp_tmp) 2899 { 2900 if (bl->loc_type != bp_loc_software_breakpoint 2901 && bl->loc_type != bp_loc_hardware_breakpoint) 2902 continue; 2903 2904 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ 2905 if ((breakpoint_enabled (bl->owner) 2906 || bl->owner->enable_state == bp_permanent) 2907 && breakpoint_location_address_match (bl, aspace, pc)) 2908 { 2909 if (overlay_debugging 2910 && section_is_overlay (bl->section) 2911 && !section_is_mapped (bl->section)) 2912 continue; /* unmapped overlay -- can't be a match */ 2913 else if (bl->owner->enable_state == bp_permanent) 2914 return permanent_breakpoint_here; 2915 else 2916 any_breakpoint_here = 1; 2917 } 2918 } 2919 2920 return any_breakpoint_here ? ordinary_breakpoint_here : 0; 2921 } 2922 2923 /* Return true if there's a moribund breakpoint at PC. */ 2924 2925 int 2926 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) 2927 { 2928 struct bp_location *loc; 2929 int ix; 2930 2931 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) 2932 if (breakpoint_location_address_match (loc, aspace, pc)) 2933 return 1; 2934 2935 return 0; 2936 } 2937 2938 /* Returns non-zero if there's a breakpoint inserted at PC, which is 2939 inserted using regular breakpoint_chain / bp_location array 2940 mechanism. This does not check for single-step breakpoints, which 2941 are inserted and removed using direct target manipulation. */ 2942 2943 int 2944 regular_breakpoint_inserted_here_p (struct address_space *aspace, 2945 CORE_ADDR pc) 2946 { 2947 struct bp_location *bl, **blp_tmp; 2948 2949 ALL_BP_LOCATIONS (bl, blp_tmp) 2950 { 2951 if (bl->loc_type != bp_loc_software_breakpoint 2952 && bl->loc_type != bp_loc_hardware_breakpoint) 2953 continue; 2954 2955 if (bl->inserted 2956 && breakpoint_location_address_match (bl, aspace, pc)) 2957 { 2958 if (overlay_debugging 2959 && section_is_overlay (bl->section) 2960 && !section_is_mapped (bl->section)) 2961 continue; /* unmapped overlay -- can't be a match */ 2962 else 2963 return 1; 2964 } 2965 } 2966 return 0; 2967 } 2968 2969 /* Returns non-zero iff there's either regular breakpoint 2970 or a single step breakpoint inserted at PC. */ 2971 2972 int 2973 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) 2974 { 2975 if (regular_breakpoint_inserted_here_p (aspace, pc)) 2976 return 1; 2977 2978 if (single_step_breakpoint_inserted_here_p (aspace, pc)) 2979 return 1; 2980 2981 return 0; 2982 } 2983 2984 /* This function returns non-zero iff there is a software breakpoint 2985 inserted at PC. */ 2986 2987 int 2988 software_breakpoint_inserted_here_p (struct address_space *aspace, 2989 CORE_ADDR pc) 2990 { 2991 struct bp_location *bl, **blp_tmp; 2992 2993 ALL_BP_LOCATIONS (bl, blp_tmp) 2994 { 2995 if (bl->loc_type != bp_loc_software_breakpoint) 2996 continue; 2997 2998 if (bl->inserted 2999 && breakpoint_address_match (bl->pspace->aspace, bl->address, 3000 aspace, pc)) 3001 { 3002 if (overlay_debugging 3003 && section_is_overlay (bl->section) 3004 && !section_is_mapped (bl->section)) 3005 continue; /* unmapped overlay -- can't be a match */ 3006 else 3007 return 1; 3008 } 3009 } 3010 3011 /* Also check for software single-step breakpoints. */ 3012 if (single_step_breakpoint_inserted_here_p (aspace, pc)) 3013 return 1; 3014 3015 return 0; 3016 } 3017 3018 int 3019 hardware_watchpoint_inserted_in_range (struct address_space *aspace, 3020 CORE_ADDR addr, ULONGEST len) 3021 { 3022 struct breakpoint *bpt; 3023 3024 ALL_BREAKPOINTS (bpt) 3025 { 3026 struct bp_location *loc; 3027 3028 if (bpt->type != bp_hardware_watchpoint 3029 && bpt->type != bp_access_watchpoint) 3030 continue; 3031 3032 if (!breakpoint_enabled (bpt)) 3033 continue; 3034 3035 for (loc = bpt->loc; loc; loc = loc->next) 3036 if (loc->pspace->aspace == aspace && loc->inserted) 3037 { 3038 CORE_ADDR l, h; 3039 3040 /* Check for intersection. */ 3041 l = max (loc->address, addr); 3042 h = min (loc->address + loc->length, addr + len); 3043 if (l < h) 3044 return 1; 3045 } 3046 } 3047 return 0; 3048 } 3049 3050 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at 3051 PC is valid for process/thread PTID. */ 3052 3053 int 3054 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, 3055 ptid_t ptid) 3056 { 3057 struct bp_location *bl, **blp_tmp; 3058 /* The thread and task IDs associated to PTID, computed lazily. */ 3059 int thread = -1; 3060 int task = 0; 3061 3062 ALL_BP_LOCATIONS (bl, blp_tmp) 3063 { 3064 if (bl->loc_type != bp_loc_software_breakpoint 3065 && bl->loc_type != bp_loc_hardware_breakpoint) 3066 continue; 3067 3068 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ 3069 if (!breakpoint_enabled (bl->owner) 3070 && bl->owner->enable_state != bp_permanent) 3071 continue; 3072 3073 if (!breakpoint_location_address_match (bl, aspace, pc)) 3074 continue; 3075 3076 if (bl->owner->thread != -1) 3077 { 3078 /* This is a thread-specific breakpoint. Check that ptid 3079 matches that thread. If thread hasn't been computed yet, 3080 it is now time to do so. */ 3081 if (thread == -1) 3082 thread = pid_to_thread_id (ptid); 3083 if (bl->owner->thread != thread) 3084 continue; 3085 } 3086 3087 if (bl->owner->task != 0) 3088 { 3089 /* This is a task-specific breakpoint. Check that ptid 3090 matches that task. If task hasn't been computed yet, 3091 it is now time to do so. */ 3092 if (task == 0) 3093 task = ada_get_task_number (ptid); 3094 if (bl->owner->task != task) 3095 continue; 3096 } 3097 3098 if (overlay_debugging 3099 && section_is_overlay (bl->section) 3100 && !section_is_mapped (bl->section)) 3101 continue; /* unmapped overlay -- can't be a match */ 3102 3103 return 1; 3104 } 3105 3106 return 0; 3107 } 3108 3109 3110 /* bpstat stuff. External routines' interfaces are documented 3111 in breakpoint.h. */ 3112 3113 int 3114 ep_is_catchpoint (struct breakpoint *ep) 3115 { 3116 return (ep->type == bp_catchpoint); 3117 } 3118 3119 /* Frees any storage that is part of a bpstat. Does not walk the 3120 'next' chain. */ 3121 3122 static void 3123 bpstat_free (bpstat bs) 3124 { 3125 if (bs->old_val != NULL) 3126 value_free (bs->old_val); 3127 decref_counted_command_line (&bs->commands); 3128 decref_bp_location (&bs->bp_location_at); 3129 xfree (bs); 3130 } 3131 3132 /* Clear a bpstat so that it says we are not at any breakpoint. 3133 Also free any storage that is part of a bpstat. */ 3134 3135 void 3136 bpstat_clear (bpstat *bsp) 3137 { 3138 bpstat p; 3139 bpstat q; 3140 3141 if (bsp == 0) 3142 return; 3143 p = *bsp; 3144 while (p != NULL) 3145 { 3146 q = p->next; 3147 bpstat_free (p); 3148 p = q; 3149 } 3150 *bsp = NULL; 3151 } 3152 3153 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that 3154 is part of the bpstat is copied as well. */ 3155 3156 bpstat 3157 bpstat_copy (bpstat bs) 3158 { 3159 bpstat p = NULL; 3160 bpstat tmp; 3161 bpstat retval = NULL; 3162 3163 if (bs == NULL) 3164 return bs; 3165 3166 for (; bs != NULL; bs = bs->next) 3167 { 3168 tmp = (bpstat) xmalloc (sizeof (*tmp)); 3169 memcpy (tmp, bs, sizeof (*tmp)); 3170 incref_counted_command_line (tmp->commands); 3171 incref_bp_location (tmp->bp_location_at); 3172 if (bs->old_val != NULL) 3173 { 3174 tmp->old_val = value_copy (bs->old_val); 3175 release_value (tmp->old_val); 3176 } 3177 3178 if (p == NULL) 3179 /* This is the first thing in the chain. */ 3180 retval = tmp; 3181 else 3182 p->next = tmp; 3183 p = tmp; 3184 } 3185 p->next = NULL; 3186 return retval; 3187 } 3188 3189 /* Find the bpstat associated with this breakpoint. */ 3190 3191 bpstat 3192 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) 3193 { 3194 if (bsp == NULL) 3195 return NULL; 3196 3197 for (; bsp != NULL; bsp = bsp->next) 3198 { 3199 if (bsp->breakpoint_at == breakpoint) 3200 return bsp; 3201 } 3202 return NULL; 3203 } 3204 3205 /* Put in *NUM the breakpoint number of the first breakpoint we are 3206 stopped at. *BSP upon return is a bpstat which points to the 3207 remaining breakpoints stopped at (but which is not guaranteed to be 3208 good for anything but further calls to bpstat_num). 3209 3210 Return 0 if passed a bpstat which does not indicate any breakpoints. 3211 Return -1 if stopped at a breakpoint that has been deleted since 3212 we set it. 3213 Return 1 otherwise. */ 3214 3215 int 3216 bpstat_num (bpstat *bsp, int *num) 3217 { 3218 struct breakpoint *b; 3219 3220 if ((*bsp) == NULL) 3221 return 0; /* No more breakpoint values */ 3222 3223 /* We assume we'll never have several bpstats that correspond to a 3224 single breakpoint -- otherwise, this function might return the 3225 same number more than once and this will look ugly. */ 3226 b = (*bsp)->breakpoint_at; 3227 *bsp = (*bsp)->next; 3228 if (b == NULL) 3229 return -1; /* breakpoint that's been deleted since */ 3230 3231 *num = b->number; /* We have its number */ 3232 return 1; 3233 } 3234 3235 /* See breakpoint.h. */ 3236 3237 void 3238 bpstat_clear_actions (void) 3239 { 3240 struct thread_info *tp; 3241 bpstat bs; 3242 3243 if (ptid_equal (inferior_ptid, null_ptid)) 3244 return; 3245 3246 tp = find_thread_ptid (inferior_ptid); 3247 if (tp == NULL) 3248 return; 3249 3250 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) 3251 { 3252 decref_counted_command_line (&bs->commands); 3253 3254 if (bs->old_val != NULL) 3255 { 3256 value_free (bs->old_val); 3257 bs->old_val = NULL; 3258 } 3259 } 3260 } 3261 3262 /* Called when a command is about to proceed the inferior. */ 3263 3264 static void 3265 breakpoint_about_to_proceed (void) 3266 { 3267 if (!ptid_equal (inferior_ptid, null_ptid)) 3268 { 3269 struct thread_info *tp = inferior_thread (); 3270 3271 /* Allow inferior function calls in breakpoint commands to not 3272 interrupt the command list. When the call finishes 3273 successfully, the inferior will be standing at the same 3274 breakpoint as if nothing happened. */ 3275 if (tp->control.in_infcall) 3276 return; 3277 } 3278 3279 breakpoint_proceeded = 1; 3280 } 3281 3282 /* Stub for cleaning up our state if we error-out of a breakpoint 3283 command. */ 3284 static void 3285 cleanup_executing_breakpoints (void *ignore) 3286 { 3287 executing_breakpoint_commands = 0; 3288 } 3289 3290 /* Return non-zero iff CMD as the first line of a command sequence is `silent' 3291 or its equivalent. */ 3292 3293 static int 3294 command_line_is_silent (struct command_line *cmd) 3295 { 3296 return cmd && (strcmp ("silent", cmd->line) == 0 3297 || (xdb_commands && strcmp ("Q", cmd->line) == 0)); 3298 } 3299 3300 /* Execute all the commands associated with all the breakpoints at 3301 this location. Any of these commands could cause the process to 3302 proceed beyond this point, etc. We look out for such changes by 3303 checking the global "breakpoint_proceeded" after each command. 3304 3305 Returns true if a breakpoint command resumed the inferior. In that 3306 case, it is the caller's responsibility to recall it again with the 3307 bpstat of the current thread. */ 3308 3309 static int 3310 bpstat_do_actions_1 (bpstat *bsp) 3311 { 3312 bpstat bs; 3313 struct cleanup *old_chain; 3314 int again = 0; 3315 3316 /* Avoid endless recursion if a `source' command is contained 3317 in bs->commands. */ 3318 if (executing_breakpoint_commands) 3319 return 0; 3320 3321 executing_breakpoint_commands = 1; 3322 old_chain = make_cleanup (cleanup_executing_breakpoints, 0); 3323 3324 prevent_dont_repeat (); 3325 3326 /* This pointer will iterate over the list of bpstat's. */ 3327 bs = *bsp; 3328 3329 breakpoint_proceeded = 0; 3330 for (; bs != NULL; bs = bs->next) 3331 { 3332 struct counted_command_line *ccmd; 3333 struct command_line *cmd; 3334 struct cleanup *this_cmd_tree_chain; 3335 3336 /* Take ownership of the BSP's command tree, if it has one. 3337 3338 The command tree could legitimately contain commands like 3339 'step' and 'next', which call clear_proceed_status, which 3340 frees stop_bpstat's command tree. To make sure this doesn't 3341 free the tree we're executing out from under us, we need to 3342 take ownership of the tree ourselves. Since a given bpstat's 3343 commands are only executed once, we don't need to copy it; we 3344 can clear the pointer in the bpstat, and make sure we free 3345 the tree when we're done. */ 3346 ccmd = bs->commands; 3347 bs->commands = NULL; 3348 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); 3349 cmd = ccmd ? ccmd->commands : NULL; 3350 if (command_line_is_silent (cmd)) 3351 { 3352 /* The action has been already done by bpstat_stop_status. */ 3353 cmd = cmd->next; 3354 } 3355 3356 while (cmd != NULL) 3357 { 3358 execute_control_command (cmd); 3359 3360 if (breakpoint_proceeded) 3361 break; 3362 else 3363 cmd = cmd->next; 3364 } 3365 3366 /* We can free this command tree now. */ 3367 do_cleanups (this_cmd_tree_chain); 3368 3369 if (breakpoint_proceeded) 3370 { 3371 if (target_can_async_p ()) 3372 /* If we are in async mode, then the target might be still 3373 running, not stopped at any breakpoint, so nothing for 3374 us to do here -- just return to the event loop. */ 3375 ; 3376 else 3377 /* In sync mode, when execute_control_command returns 3378 we're already standing on the next breakpoint. 3379 Breakpoint commands for that stop were not run, since 3380 execute_command does not run breakpoint commands -- 3381 only command_line_handler does, but that one is not 3382 involved in execution of breakpoint commands. So, we 3383 can now execute breakpoint commands. It should be 3384 noted that making execute_command do bpstat actions is 3385 not an option -- in this case we'll have recursive 3386 invocation of bpstat for each breakpoint with a 3387 command, and can easily blow up GDB stack. Instead, we 3388 return true, which will trigger the caller to recall us 3389 with the new stop_bpstat. */ 3390 again = 1; 3391 break; 3392 } 3393 } 3394 do_cleanups (old_chain); 3395 return again; 3396 } 3397 3398 void 3399 bpstat_do_actions (void) 3400 { 3401 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); 3402 3403 /* Do any commands attached to breakpoint we are stopped at. */ 3404 while (!ptid_equal (inferior_ptid, null_ptid) 3405 && target_has_execution 3406 && !is_exited (inferior_ptid) 3407 && !is_executing (inferior_ptid)) 3408 /* Since in sync mode, bpstat_do_actions may resume the inferior, 3409 and only return when it is stopped at the next breakpoint, we 3410 keep doing breakpoint actions until it returns false to 3411 indicate the inferior was not resumed. */ 3412 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) 3413 break; 3414 3415 discard_cleanups (cleanup_if_error); 3416 } 3417 3418 /* Print out the (old or new) value associated with a watchpoint. */ 3419 3420 static void 3421 watchpoint_value_print (struct value *val, struct ui_file *stream) 3422 { 3423 if (val == NULL) 3424 fprintf_unfiltered (stream, _("<unreadable>")); 3425 else 3426 { 3427 struct value_print_options opts; 3428 get_user_print_options (&opts); 3429 value_print (val, stream, &opts); 3430 } 3431 } 3432 3433 /* Generic routine for printing messages indicating why we 3434 stopped. The behavior of this function depends on the value 3435 'print_it' in the bpstat structure. Under some circumstances we 3436 may decide not to print anything here and delegate the task to 3437 normal_stop(). */ 3438 3439 static enum print_stop_action 3440 print_bp_stop_message (bpstat bs) 3441 { 3442 switch (bs->print_it) 3443 { 3444 case print_it_noop: 3445 /* Nothing should be printed for this bpstat entry. */ 3446 return PRINT_UNKNOWN; 3447 break; 3448 3449 case print_it_done: 3450 /* We still want to print the frame, but we already printed the 3451 relevant messages. */ 3452 return PRINT_SRC_AND_LOC; 3453 break; 3454 3455 case print_it_normal: 3456 { 3457 struct breakpoint *b = bs->breakpoint_at; 3458 3459 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint 3460 which has since been deleted. */ 3461 if (b == NULL) 3462 return PRINT_UNKNOWN; 3463 3464 /* Normal case. Call the breakpoint's print_it method. */ 3465 return b->ops->print_it (bs); 3466 } 3467 break; 3468 3469 default: 3470 internal_error (__FILE__, __LINE__, 3471 _("print_bp_stop_message: unrecognized enum value")); 3472 break; 3473 } 3474 } 3475 3476 /* Print a message indicating what happened. This is called from 3477 normal_stop(). The input to this routine is the head of the bpstat 3478 list - a list of the eventpoints that caused this stop. KIND is 3479 the target_waitkind for the stopping event. This 3480 routine calls the generic print routine for printing a message 3481 about reasons for stopping. This will print (for example) the 3482 "Breakpoint n," part of the output. The return value of this 3483 routine is one of: 3484 3485 PRINT_UNKNOWN: Means we printed nothing. 3486 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent 3487 code to print the location. An example is 3488 "Breakpoint 1, " which should be followed by 3489 the location. 3490 PRINT_SRC_ONLY: Means we printed something, but there is no need 3491 to also print the location part of the message. 3492 An example is the catch/throw messages, which 3493 don't require a location appended to the end. 3494 PRINT_NOTHING: We have done some printing and we don't need any 3495 further info to be printed. */ 3496 3497 enum print_stop_action 3498 bpstat_print (bpstat bs, int kind) 3499 { 3500 int val; 3501 3502 /* Maybe another breakpoint in the chain caused us to stop. 3503 (Currently all watchpoints go on the bpstat whether hit or not. 3504 That probably could (should) be changed, provided care is taken 3505 with respect to bpstat_explains_signal). */ 3506 for (; bs; bs = bs->next) 3507 { 3508 val = print_bp_stop_message (bs); 3509 if (val == PRINT_SRC_ONLY 3510 || val == PRINT_SRC_AND_LOC 3511 || val == PRINT_NOTHING) 3512 return val; 3513 } 3514 3515 /* If we had hit a shared library event breakpoint, 3516 print_bp_stop_message would print out this message. If we hit an 3517 OS-level shared library event, do the same thing. */ 3518 if (kind == TARGET_WAITKIND_LOADED) 3519 { 3520 ui_out_text (current_uiout, _("Stopped due to shared library event\n")); 3521 if (ui_out_is_mi_like_p (current_uiout)) 3522 ui_out_field_string (current_uiout, "reason", 3523 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); 3524 return PRINT_NOTHING; 3525 } 3526 3527 /* We reached the end of the chain, or we got a null BS to start 3528 with and nothing was printed. */ 3529 return PRINT_UNKNOWN; 3530 } 3531 3532 /* Evaluate the expression EXP and return 1 if value is zero. This is 3533 used inside a catch_errors to evaluate the breakpoint condition. 3534 The argument is a "struct expression *" that has been cast to a 3535 "char *" to make it pass through catch_errors. */ 3536 3537 static int 3538 breakpoint_cond_eval (void *exp) 3539 { 3540 struct value *mark = value_mark (); 3541 int i = !value_true (evaluate_expression ((struct expression *) exp)); 3542 3543 value_free_to_mark (mark); 3544 return i; 3545 } 3546 3547 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ 3548 3549 static bpstat 3550 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) 3551 { 3552 bpstat bs; 3553 3554 bs = (bpstat) xmalloc (sizeof (*bs)); 3555 bs->next = NULL; 3556 **bs_link_pointer = bs; 3557 *bs_link_pointer = &bs->next; 3558 bs->breakpoint_at = bl->owner; 3559 bs->bp_location_at = bl; 3560 incref_bp_location (bl); 3561 /* If the condition is false, etc., don't do the commands. */ 3562 bs->commands = NULL; 3563 bs->old_val = NULL; 3564 bs->print_it = print_it_normal; 3565 return bs; 3566 } 3567 3568 /* The target has stopped with waitstatus WS. Check if any hardware 3569 watchpoints have triggered, according to the target. */ 3570 3571 int 3572 watchpoints_triggered (struct target_waitstatus *ws) 3573 { 3574 int stopped_by_watchpoint = target_stopped_by_watchpoint (); 3575 CORE_ADDR addr; 3576 struct breakpoint *b; 3577 3578 if (!stopped_by_watchpoint) 3579 { 3580 /* We were not stopped by a watchpoint. Mark all watchpoints 3581 as not triggered. */ 3582 ALL_BREAKPOINTS (b) 3583 if (is_hardware_watchpoint (b)) 3584 { 3585 struct watchpoint *w = (struct watchpoint *) b; 3586 3587 w->watchpoint_triggered = watch_triggered_no; 3588 } 3589 3590 return 0; 3591 } 3592 3593 if (!target_stopped_data_address (¤t_target, &addr)) 3594 { 3595 /* We were stopped by a watchpoint, but we don't know where. 3596 Mark all watchpoints as unknown. */ 3597 ALL_BREAKPOINTS (b) 3598 if (is_hardware_watchpoint (b)) 3599 { 3600 struct watchpoint *w = (struct watchpoint *) b; 3601 3602 w->watchpoint_triggered = watch_triggered_unknown; 3603 } 3604 3605 return stopped_by_watchpoint; 3606 } 3607 3608 /* The target could report the data address. Mark watchpoints 3609 affected by this data address as triggered, and all others as not 3610 triggered. */ 3611 3612 ALL_BREAKPOINTS (b) 3613 if (is_hardware_watchpoint (b)) 3614 { 3615 struct watchpoint *w = (struct watchpoint *) b; 3616 struct bp_location *loc; 3617 3618 w->watchpoint_triggered = watch_triggered_no; 3619 for (loc = b->loc; loc; loc = loc->next) 3620 { 3621 if (is_masked_watchpoint (b)) 3622 { 3623 CORE_ADDR newaddr = addr & w->hw_wp_mask; 3624 CORE_ADDR start = loc->address & w->hw_wp_mask; 3625 3626 if (newaddr == start) 3627 { 3628 w->watchpoint_triggered = watch_triggered_yes; 3629 break; 3630 } 3631 } 3632 /* Exact match not required. Within range is sufficient. */ 3633 else if (target_watchpoint_addr_within_range (¤t_target, 3634 addr, loc->address, 3635 loc->length)) 3636 { 3637 w->watchpoint_triggered = watch_triggered_yes; 3638 break; 3639 } 3640 } 3641 } 3642 3643 return 1; 3644 } 3645 3646 /* Possible return values for watchpoint_check (this can't be an enum 3647 because of check_errors). */ 3648 /* The watchpoint has been deleted. */ 3649 #define WP_DELETED 1 3650 /* The value has changed. */ 3651 #define WP_VALUE_CHANGED 2 3652 /* The value has not changed. */ 3653 #define WP_VALUE_NOT_CHANGED 3 3654 /* Ignore this watchpoint, no matter if the value changed or not. */ 3655 #define WP_IGNORE 4 3656 3657 #define BP_TEMPFLAG 1 3658 #define BP_HARDWAREFLAG 2 3659 3660 /* Evaluate watchpoint condition expression and check if its value 3661 changed. 3662 3663 P should be a pointer to struct bpstat, but is defined as a void * 3664 in order for this function to be usable with catch_errors. */ 3665 3666 static int 3667 watchpoint_check (void *p) 3668 { 3669 bpstat bs = (bpstat) p; 3670 struct watchpoint *b; 3671 struct frame_info *fr; 3672 int within_current_scope; 3673 3674 /* BS is built from an existing struct breakpoint. */ 3675 gdb_assert (bs->breakpoint_at != NULL); 3676 b = (struct watchpoint *) bs->breakpoint_at; 3677 3678 /* If this is a local watchpoint, we only want to check if the 3679 watchpoint frame is in scope if the current thread is the thread 3680 that was used to create the watchpoint. */ 3681 if (!watchpoint_in_thread_scope (b)) 3682 return WP_IGNORE; 3683 3684 if (b->exp_valid_block == NULL) 3685 within_current_scope = 1; 3686 else 3687 { 3688 struct frame_info *frame = get_current_frame (); 3689 struct gdbarch *frame_arch = get_frame_arch (frame); 3690 CORE_ADDR frame_pc = get_frame_pc (frame); 3691 3692 /* in_function_epilogue_p() returns a non-zero value if we're 3693 still in the function but the stack frame has already been 3694 invalidated. Since we can't rely on the values of local 3695 variables after the stack has been destroyed, we are treating 3696 the watchpoint in that state as `not changed' without further 3697 checking. Don't mark watchpoints as changed if the current 3698 frame is in an epilogue - even if they are in some other 3699 frame, our view of the stack is likely to be wrong and 3700 frame_find_by_id could error out. */ 3701 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) 3702 return WP_IGNORE; 3703 3704 fr = frame_find_by_id (b->watchpoint_frame); 3705 within_current_scope = (fr != NULL); 3706 3707 /* If we've gotten confused in the unwinder, we might have 3708 returned a frame that can't describe this variable. */ 3709 if (within_current_scope) 3710 { 3711 struct symbol *function; 3712 3713 function = get_frame_function (fr); 3714 if (function == NULL 3715 || !contained_in (b->exp_valid_block, 3716 SYMBOL_BLOCK_VALUE (function))) 3717 within_current_scope = 0; 3718 } 3719 3720 if (within_current_scope) 3721 /* If we end up stopping, the current frame will get selected 3722 in normal_stop. So this call to select_frame won't affect 3723 the user. */ 3724 select_frame (fr); 3725 } 3726 3727 if (within_current_scope) 3728 { 3729 /* We use value_{,free_to_}mark because it could be a *long* 3730 time before we return to the command level and call 3731 free_all_values. We can't call free_all_values because we 3732 might be in the middle of evaluating a function call. */ 3733 3734 int pc = 0; 3735 struct value *mark; 3736 struct value *new_val; 3737 3738 if (is_masked_watchpoint (&b->base)) 3739 /* Since we don't know the exact trigger address (from 3740 stopped_data_address), just tell the user we've triggered 3741 a mask watchpoint. */ 3742 return WP_VALUE_CHANGED; 3743 3744 mark = value_mark (); 3745 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); 3746 3747 /* We use value_equal_contents instead of value_equal because 3748 the latter coerces an array to a pointer, thus comparing just 3749 the address of the array instead of its contents. This is 3750 not what we want. */ 3751 if ((b->val != NULL) != (new_val != NULL) 3752 || (b->val != NULL && !value_equal_contents (b->val, new_val))) 3753 { 3754 if (new_val != NULL) 3755 { 3756 release_value (new_val); 3757 value_free_to_mark (mark); 3758 } 3759 bs->old_val = b->val; 3760 b->val = new_val; 3761 b->val_valid = 1; 3762 return WP_VALUE_CHANGED; 3763 } 3764 else 3765 { 3766 /* Nothing changed. */ 3767 value_free_to_mark (mark); 3768 return WP_VALUE_NOT_CHANGED; 3769 } 3770 } 3771 else 3772 { 3773 struct ui_out *uiout = current_uiout; 3774 3775 /* This seems like the only logical thing to do because 3776 if we temporarily ignored the watchpoint, then when 3777 we reenter the block in which it is valid it contains 3778 garbage (in the case of a function, it may have two 3779 garbage values, one before and one after the prologue). 3780 So we can't even detect the first assignment to it and 3781 watch after that (since the garbage may or may not equal 3782 the first value assigned). */ 3783 /* We print all the stop information in 3784 breakpoint_ops->print_it, but in this case, by the time we 3785 call breakpoint_ops->print_it this bp will be deleted 3786 already. So we have no choice but print the information 3787 here. */ 3788 if (ui_out_is_mi_like_p (uiout)) 3789 ui_out_field_string 3790 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); 3791 ui_out_text (uiout, "\nWatchpoint "); 3792 ui_out_field_int (uiout, "wpnum", b->base.number); 3793 ui_out_text (uiout, 3794 " deleted because the program has left the block in\n\ 3795 which its expression is valid.\n"); 3796 3797 /* Make sure the watchpoint's commands aren't executed. */ 3798 decref_counted_command_line (&b->base.commands); 3799 watchpoint_del_at_next_stop (b); 3800 3801 return WP_DELETED; 3802 } 3803 } 3804 3805 /* Return true if it looks like target has stopped due to hitting 3806 breakpoint location BL. This function does not check if we should 3807 stop, only if BL explains the stop. */ 3808 3809 static int 3810 bpstat_check_location (const struct bp_location *bl, 3811 struct address_space *aspace, CORE_ADDR bp_addr) 3812 { 3813 struct breakpoint *b = bl->owner; 3814 3815 /* BL is from an existing breakpoint. */ 3816 gdb_assert (b != NULL); 3817 3818 return b->ops->breakpoint_hit (bl, aspace, bp_addr); 3819 } 3820 3821 /* Determine if the watched values have actually changed, and we 3822 should stop. If not, set BS->stop to 0. */ 3823 3824 static void 3825 bpstat_check_watchpoint (bpstat bs) 3826 { 3827 const struct bp_location *bl; 3828 struct watchpoint *b; 3829 3830 /* BS is built for existing struct breakpoint. */ 3831 bl = bs->bp_location_at; 3832 gdb_assert (bl != NULL); 3833 b = (struct watchpoint *) bs->breakpoint_at; 3834 gdb_assert (b != NULL); 3835 3836 { 3837 int must_check_value = 0; 3838 3839 if (b->base.type == bp_watchpoint) 3840 /* For a software watchpoint, we must always check the 3841 watched value. */ 3842 must_check_value = 1; 3843 else if (b->watchpoint_triggered == watch_triggered_yes) 3844 /* We have a hardware watchpoint (read, write, or access) 3845 and the target earlier reported an address watched by 3846 this watchpoint. */ 3847 must_check_value = 1; 3848 else if (b->watchpoint_triggered == watch_triggered_unknown 3849 && b->base.type == bp_hardware_watchpoint) 3850 /* We were stopped by a hardware watchpoint, but the target could 3851 not report the data address. We must check the watchpoint's 3852 value. Access and read watchpoints are out of luck; without 3853 a data address, we can't figure it out. */ 3854 must_check_value = 1; 3855 3856 if (must_check_value) 3857 { 3858 char *message 3859 = xstrprintf ("Error evaluating expression for watchpoint %d\n", 3860 b->base.number); 3861 struct cleanup *cleanups = make_cleanup (xfree, message); 3862 int e = catch_errors (watchpoint_check, bs, message, 3863 RETURN_MASK_ALL); 3864 do_cleanups (cleanups); 3865 switch (e) 3866 { 3867 case WP_DELETED: 3868 /* We've already printed what needs to be printed. */ 3869 bs->print_it = print_it_done; 3870 /* Stop. */ 3871 break; 3872 case WP_IGNORE: 3873 bs->print_it = print_it_noop; 3874 bs->stop = 0; 3875 break; 3876 case WP_VALUE_CHANGED: 3877 if (b->base.type == bp_read_watchpoint) 3878 { 3879 /* There are two cases to consider here: 3880 3881 1. We're watching the triggered memory for reads. 3882 In that case, trust the target, and always report 3883 the watchpoint hit to the user. Even though 3884 reads don't cause value changes, the value may 3885 have changed since the last time it was read, and 3886 since we're not trapping writes, we will not see 3887 those, and as such we should ignore our notion of 3888 old value. 3889 3890 2. We're watching the triggered memory for both 3891 reads and writes. There are two ways this may 3892 happen: 3893 3894 2.1. This is a target that can't break on data 3895 reads only, but can break on accesses (reads or 3896 writes), such as e.g., x86. We detect this case 3897 at the time we try to insert read watchpoints. 3898 3899 2.2. Otherwise, the target supports read 3900 watchpoints, but, the user set an access or write 3901 watchpoint watching the same memory as this read 3902 watchpoint. 3903 3904 If we're watching memory writes as well as reads, 3905 ignore watchpoint hits when we find that the 3906 value hasn't changed, as reads don't cause 3907 changes. This still gives false positives when 3908 the program writes the same value to memory as 3909 what there was already in memory (we will confuse 3910 it for a read), but it's much better than 3911 nothing. */ 3912 3913 int other_write_watchpoint = 0; 3914 3915 if (bl->watchpoint_type == hw_read) 3916 { 3917 struct breakpoint *other_b; 3918 3919 ALL_BREAKPOINTS (other_b) 3920 if (other_b->type == bp_hardware_watchpoint 3921 || other_b->type == bp_access_watchpoint) 3922 { 3923 struct watchpoint *other_w = 3924 (struct watchpoint *) other_b; 3925 3926 if (other_w->watchpoint_triggered 3927 == watch_triggered_yes) 3928 { 3929 other_write_watchpoint = 1; 3930 break; 3931 } 3932 } 3933 } 3934 3935 if (other_write_watchpoint 3936 || bl->watchpoint_type == hw_access) 3937 { 3938 /* We're watching the same memory for writes, 3939 and the value changed since the last time we 3940 updated it, so this trap must be for a write. 3941 Ignore it. */ 3942 bs->print_it = print_it_noop; 3943 bs->stop = 0; 3944 } 3945 } 3946 break; 3947 case WP_VALUE_NOT_CHANGED: 3948 if (b->base.type == bp_hardware_watchpoint 3949 || b->base.type == bp_watchpoint) 3950 { 3951 /* Don't stop: write watchpoints shouldn't fire if 3952 the value hasn't changed. */ 3953 bs->print_it = print_it_noop; 3954 bs->stop = 0; 3955 } 3956 /* Stop. */ 3957 break; 3958 default: 3959 /* Can't happen. */ 3960 case 0: 3961 /* Error from catch_errors. */ 3962 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); 3963 watchpoint_del_at_next_stop (b); 3964 /* We've already printed what needs to be printed. */ 3965 bs->print_it = print_it_done; 3966 break; 3967 } 3968 } 3969 else /* must_check_value == 0 */ 3970 { 3971 /* This is a case where some watchpoint(s) triggered, but 3972 not at the address of this watchpoint, or else no 3973 watchpoint triggered after all. So don't print 3974 anything for this watchpoint. */ 3975 bs->print_it = print_it_noop; 3976 bs->stop = 0; 3977 } 3978 } 3979 } 3980 3981 3982 /* Check conditions (condition proper, frame, thread and ignore count) 3983 of breakpoint referred to by BS. If we should not stop for this 3984 breakpoint, set BS->stop to 0. */ 3985 3986 static void 3987 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) 3988 { 3989 int thread_id = pid_to_thread_id (ptid); 3990 const struct bp_location *bl; 3991 struct breakpoint *b; 3992 3993 /* BS is built for existing struct breakpoint. */ 3994 bl = bs->bp_location_at; 3995 gdb_assert (bl != NULL); 3996 b = bs->breakpoint_at; 3997 gdb_assert (b != NULL); 3998 3999 if (frame_id_p (b->frame_id) 4000 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) 4001 bs->stop = 0; 4002 else if (bs->stop) 4003 { 4004 int value_is_zero = 0; 4005 struct expression *cond; 4006 4007 /* Evaluate Python breakpoints that have a "stop" 4008 method implemented. */ 4009 if (b->py_bp_object) 4010 bs->stop = gdbpy_should_stop (b->py_bp_object); 4011 4012 if (is_watchpoint (b)) 4013 { 4014 struct watchpoint *w = (struct watchpoint *) b; 4015 4016 cond = w->cond_exp; 4017 } 4018 else 4019 cond = bl->cond; 4020 4021 if (cond && b->disposition != disp_del_at_next_stop) 4022 { 4023 int within_current_scope = 1; 4024 struct watchpoint * w; 4025 4026 /* We use value_mark and value_free_to_mark because it could 4027 be a long time before we return to the command level and 4028 call free_all_values. We can't call free_all_values 4029 because we might be in the middle of evaluating a 4030 function call. */ 4031 struct value *mark = value_mark (); 4032 4033 if (is_watchpoint (b)) 4034 w = (struct watchpoint *) b; 4035 else 4036 w = NULL; 4037 4038 /* Need to select the frame, with all that implies so that 4039 the conditions will have the right context. Because we 4040 use the frame, we will not see an inlined function's 4041 variables when we arrive at a breakpoint at the start 4042 of the inlined function; the current frame will be the 4043 call site. */ 4044 if (w == NULL || w->cond_exp_valid_block == NULL) 4045 select_frame (get_current_frame ()); 4046 else 4047 { 4048 struct frame_info *frame; 4049 4050 /* For local watchpoint expressions, which particular 4051 instance of a local is being watched matters, so we 4052 keep track of the frame to evaluate the expression 4053 in. To evaluate the condition however, it doesn't 4054 really matter which instantiation of the function 4055 where the condition makes sense triggers the 4056 watchpoint. This allows an expression like "watch 4057 global if q > 10" set in `func', catch writes to 4058 global on all threads that call `func', or catch 4059 writes on all recursive calls of `func' by a single 4060 thread. We simply always evaluate the condition in 4061 the innermost frame that's executing where it makes 4062 sense to evaluate the condition. It seems 4063 intuitive. */ 4064 frame = block_innermost_frame (w->cond_exp_valid_block); 4065 if (frame != NULL) 4066 select_frame (frame); 4067 else 4068 within_current_scope = 0; 4069 } 4070 if (within_current_scope) 4071 value_is_zero 4072 = catch_errors (breakpoint_cond_eval, cond, 4073 "Error in testing breakpoint condition:\n", 4074 RETURN_MASK_ALL); 4075 else 4076 { 4077 warning (_("Watchpoint condition cannot be tested " 4078 "in the current scope")); 4079 /* If we failed to set the right context for this 4080 watchpoint, unconditionally report it. */ 4081 value_is_zero = 0; 4082 } 4083 /* FIXME-someday, should give breakpoint #. */ 4084 value_free_to_mark (mark); 4085 } 4086 4087 if (cond && value_is_zero) 4088 { 4089 bs->stop = 0; 4090 } 4091 else if (b->thread != -1 && b->thread != thread_id) 4092 { 4093 bs->stop = 0; 4094 } 4095 else if (b->ignore_count > 0) 4096 { 4097 b->ignore_count--; 4098 annotate_ignore_count_change (); 4099 bs->stop = 0; 4100 /* Increase the hit count even though we don't stop. */ 4101 ++(b->hit_count); 4102 observer_notify_breakpoint_modified (b); 4103 } 4104 } 4105 } 4106 4107 4108 /* Get a bpstat associated with having just stopped at address 4109 BP_ADDR in thread PTID. 4110 4111 Determine whether we stopped at a breakpoint, etc, or whether we 4112 don't understand this stop. Result is a chain of bpstat's such 4113 that: 4114 4115 if we don't understand the stop, the result is a null pointer. 4116 4117 if we understand why we stopped, the result is not null. 4118 4119 Each element of the chain refers to a particular breakpoint or 4120 watchpoint at which we have stopped. (We may have stopped for 4121 several reasons concurrently.) 4122 4123 Each element of the chain has valid next, breakpoint_at, 4124 commands, FIXME??? fields. */ 4125 4126 bpstat 4127 bpstat_stop_status (struct address_space *aspace, 4128 CORE_ADDR bp_addr, ptid_t ptid) 4129 { 4130 struct breakpoint *b = NULL; 4131 struct bp_location *bl; 4132 struct bp_location *loc; 4133 /* First item of allocated bpstat's. */ 4134 bpstat bs_head = NULL, *bs_link = &bs_head; 4135 /* Pointer to the last thing in the chain currently. */ 4136 bpstat bs; 4137 int ix; 4138 int need_remove_insert; 4139 int removed_any; 4140 4141 /* First, build the bpstat chain with locations that explain a 4142 target stop, while being careful to not set the target running, 4143 as that may invalidate locations (in particular watchpoint 4144 locations are recreated). Resuming will happen here with 4145 breakpoint conditions or watchpoint expressions that include 4146 inferior function calls. */ 4147 4148 ALL_BREAKPOINTS (b) 4149 { 4150 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) 4151 continue; 4152 4153 for (bl = b->loc; bl != NULL; bl = bl->next) 4154 { 4155 /* For hardware watchpoints, we look only at the first 4156 location. The watchpoint_check function will work on the 4157 entire expression, not the individual locations. For 4158 read watchpoints, the watchpoints_triggered function has 4159 checked all locations already. */ 4160 if (b->type == bp_hardware_watchpoint && bl != b->loc) 4161 break; 4162 4163 if (bl->shlib_disabled) 4164 continue; 4165 4166 if (!bpstat_check_location (bl, aspace, bp_addr)) 4167 continue; 4168 4169 /* Come here if it's a watchpoint, or if the break address 4170 matches. */ 4171 4172 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to 4173 explain stop. */ 4174 4175 /* Assume we stop. Should we find a watchpoint that is not 4176 actually triggered, or if the condition of the breakpoint 4177 evaluates as false, we'll reset 'stop' to 0. */ 4178 bs->stop = 1; 4179 bs->print = 1; 4180 4181 /* If this is a scope breakpoint, mark the associated 4182 watchpoint as triggered so that we will handle the 4183 out-of-scope event. We'll get to the watchpoint next 4184 iteration. */ 4185 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) 4186 { 4187 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; 4188 4189 w->watchpoint_triggered = watch_triggered_yes; 4190 } 4191 } 4192 } 4193 4194 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) 4195 { 4196 if (breakpoint_location_address_match (loc, aspace, bp_addr)) 4197 { 4198 bs = bpstat_alloc (loc, &bs_link); 4199 /* For hits of moribund locations, we should just proceed. */ 4200 bs->stop = 0; 4201 bs->print = 0; 4202 bs->print_it = print_it_noop; 4203 } 4204 } 4205 4206 /* Now go through the locations that caused the target to stop, and 4207 check whether we're interested in reporting this stop to higher 4208 layers, or whether we should resume the target transparently. */ 4209 4210 removed_any = 0; 4211 4212 for (bs = bs_head; bs != NULL; bs = bs->next) 4213 { 4214 if (!bs->stop) 4215 continue; 4216 4217 b = bs->breakpoint_at; 4218 b->ops->check_status (bs); 4219 if (bs->stop) 4220 { 4221 bpstat_check_breakpoint_conditions (bs, ptid); 4222 4223 if (bs->stop) 4224 { 4225 ++(b->hit_count); 4226 observer_notify_breakpoint_modified (b); 4227 4228 /* We will stop here. */ 4229 if (b->disposition == disp_disable) 4230 { 4231 if (b->enable_state != bp_permanent) 4232 b->enable_state = bp_disabled; 4233 removed_any = 1; 4234 } 4235 if (b->silent) 4236 bs->print = 0; 4237 bs->commands = b->commands; 4238 incref_counted_command_line (bs->commands); 4239 if (command_line_is_silent (bs->commands 4240 ? bs->commands->commands : NULL)) 4241 bs->print = 0; 4242 } 4243 4244 /* Print nothing for this entry if we don't stop or don't print. */ 4245 if (bs->stop == 0 || bs->print == 0) 4246 bs->print_it = print_it_noop; 4247 } 4248 } 4249 4250 /* If we aren't stopping, the value of some hardware watchpoint may 4251 not have changed, but the intermediate memory locations we are 4252 watching may have. Don't bother if we're stopping; this will get 4253 done later. */ 4254 need_remove_insert = 0; 4255 if (! bpstat_causes_stop (bs_head)) 4256 for (bs = bs_head; bs != NULL; bs = bs->next) 4257 if (!bs->stop 4258 && bs->breakpoint_at 4259 && is_hardware_watchpoint (bs->breakpoint_at)) 4260 { 4261 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; 4262 4263 update_watchpoint (w, 0 /* don't reparse. */); 4264 need_remove_insert = 1; 4265 } 4266 4267 if (need_remove_insert) 4268 update_global_location_list (1); 4269 else if (removed_any) 4270 update_global_location_list (0); 4271 4272 return bs_head; 4273 } 4274 4275 static void 4276 handle_jit_event (void) 4277 { 4278 struct frame_info *frame; 4279 struct gdbarch *gdbarch; 4280 4281 /* Switch terminal for any messages produced by 4282 breakpoint_re_set. */ 4283 target_terminal_ours_for_output (); 4284 4285 frame = get_current_frame (); 4286 gdbarch = get_frame_arch (frame); 4287 4288 jit_event_handler (gdbarch); 4289 4290 target_terminal_inferior (); 4291 } 4292 4293 /* Prepare WHAT final decision for infrun. */ 4294 4295 /* Decide what infrun needs to do with this bpstat. */ 4296 4297 struct bpstat_what 4298 bpstat_what (bpstat bs_head) 4299 { 4300 struct bpstat_what retval; 4301 /* We need to defer calling `solib_add', as adding new symbols 4302 resets breakpoints, which in turn deletes breakpoint locations, 4303 and hence may clear unprocessed entries in the BS chain. */ 4304 int shlib_event = 0; 4305 int jit_event = 0; 4306 bpstat bs; 4307 4308 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; 4309 retval.call_dummy = STOP_NONE; 4310 retval.is_longjmp = 0; 4311 4312 for (bs = bs_head; bs != NULL; bs = bs->next) 4313 { 4314 /* Extract this BS's action. After processing each BS, we check 4315 if its action overrides all we've seem so far. */ 4316 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; 4317 enum bptype bptype; 4318 4319 if (bs->breakpoint_at == NULL) 4320 { 4321 /* I suspect this can happen if it was a momentary 4322 breakpoint which has since been deleted. */ 4323 bptype = bp_none; 4324 } 4325 else 4326 bptype = bs->breakpoint_at->type; 4327 4328 switch (bptype) 4329 { 4330 case bp_none: 4331 break; 4332 case bp_breakpoint: 4333 case bp_hardware_breakpoint: 4334 case bp_until: 4335 case bp_finish: 4336 if (bs->stop) 4337 { 4338 if (bs->print) 4339 this_action = BPSTAT_WHAT_STOP_NOISY; 4340 else 4341 this_action = BPSTAT_WHAT_STOP_SILENT; 4342 } 4343 else 4344 this_action = BPSTAT_WHAT_SINGLE; 4345 break; 4346 case bp_watchpoint: 4347 case bp_hardware_watchpoint: 4348 case bp_read_watchpoint: 4349 case bp_access_watchpoint: 4350 if (bs->stop) 4351 { 4352 if (bs->print) 4353 this_action = BPSTAT_WHAT_STOP_NOISY; 4354 else 4355 this_action = BPSTAT_WHAT_STOP_SILENT; 4356 } 4357 else 4358 { 4359 /* There was a watchpoint, but we're not stopping. 4360 This requires no further action. */ 4361 } 4362 break; 4363 case bp_longjmp: 4364 case bp_exception: 4365 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; 4366 retval.is_longjmp = bptype == bp_longjmp; 4367 break; 4368 case bp_longjmp_resume: 4369 case bp_exception_resume: 4370 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; 4371 retval.is_longjmp = bptype == bp_longjmp_resume; 4372 break; 4373 case bp_step_resume: 4374 if (bs->stop) 4375 this_action = BPSTAT_WHAT_STEP_RESUME; 4376 else 4377 { 4378 /* It is for the wrong frame. */ 4379 this_action = BPSTAT_WHAT_SINGLE; 4380 } 4381 break; 4382 case bp_hp_step_resume: 4383 if (bs->stop) 4384 this_action = BPSTAT_WHAT_HP_STEP_RESUME; 4385 else 4386 { 4387 /* It is for the wrong frame. */ 4388 this_action = BPSTAT_WHAT_SINGLE; 4389 } 4390 break; 4391 case bp_watchpoint_scope: 4392 case bp_thread_event: 4393 case bp_overlay_event: 4394 case bp_longjmp_master: 4395 case bp_std_terminate_master: 4396 case bp_exception_master: 4397 this_action = BPSTAT_WHAT_SINGLE; 4398 break; 4399 case bp_catchpoint: 4400 if (bs->stop) 4401 { 4402 if (bs->print) 4403 this_action = BPSTAT_WHAT_STOP_NOISY; 4404 else 4405 this_action = BPSTAT_WHAT_STOP_SILENT; 4406 } 4407 else 4408 { 4409 /* There was a catchpoint, but we're not stopping. 4410 This requires no further action. */ 4411 } 4412 break; 4413 case bp_shlib_event: 4414 shlib_event = 1; 4415 4416 /* If requested, stop when the dynamic linker notifies GDB 4417 of events. This allows the user to get control and place 4418 breakpoints in initializer routines for dynamically 4419 loaded objects (among other things). */ 4420 if (stop_on_solib_events) 4421 this_action = BPSTAT_WHAT_STOP_NOISY; 4422 else 4423 this_action = BPSTAT_WHAT_SINGLE; 4424 break; 4425 case bp_jit_event: 4426 jit_event = 1; 4427 this_action = BPSTAT_WHAT_SINGLE; 4428 break; 4429 case bp_call_dummy: 4430 /* Make sure the action is stop (silent or noisy), 4431 so infrun.c pops the dummy frame. */ 4432 retval.call_dummy = STOP_STACK_DUMMY; 4433 this_action = BPSTAT_WHAT_STOP_SILENT; 4434 break; 4435 case bp_std_terminate: 4436 /* Make sure the action is stop (silent or noisy), 4437 so infrun.c pops the dummy frame. */ 4438 retval.call_dummy = STOP_STD_TERMINATE; 4439 this_action = BPSTAT_WHAT_STOP_SILENT; 4440 break; 4441 case bp_tracepoint: 4442 case bp_fast_tracepoint: 4443 case bp_static_tracepoint: 4444 /* Tracepoint hits should not be reported back to GDB, and 4445 if one got through somehow, it should have been filtered 4446 out already. */ 4447 internal_error (__FILE__, __LINE__, 4448 _("bpstat_what: tracepoint encountered")); 4449 break; 4450 case bp_gnu_ifunc_resolver: 4451 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ 4452 this_action = BPSTAT_WHAT_SINGLE; 4453 break; 4454 case bp_gnu_ifunc_resolver_return: 4455 /* The breakpoint will be removed, execution will restart from the 4456 PC of the former breakpoint. */ 4457 this_action = BPSTAT_WHAT_KEEP_CHECKING; 4458 break; 4459 default: 4460 internal_error (__FILE__, __LINE__, 4461 _("bpstat_what: unhandled bptype %d"), (int) bptype); 4462 } 4463 4464 retval.main_action = max (retval.main_action, this_action); 4465 } 4466 4467 /* These operations may affect the bs->breakpoint_at state so they are 4468 delayed after MAIN_ACTION is decided above. */ 4469 4470 if (shlib_event) 4471 { 4472 if (debug_infrun) 4473 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); 4474 4475 /* Check for any newly added shared libraries if we're supposed 4476 to be adding them automatically. */ 4477 4478 /* Switch terminal for any messages produced by 4479 breakpoint_re_set. */ 4480 target_terminal_ours_for_output (); 4481 4482 #ifdef SOLIB_ADD 4483 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); 4484 #else 4485 solib_add (NULL, 0, ¤t_target, auto_solib_add); 4486 #endif 4487 4488 target_terminal_inferior (); 4489 } 4490 4491 if (jit_event) 4492 { 4493 if (debug_infrun) 4494 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); 4495 4496 handle_jit_event (); 4497 } 4498 4499 for (bs = bs_head; bs != NULL; bs = bs->next) 4500 { 4501 struct breakpoint *b = bs->breakpoint_at; 4502 4503 if (b == NULL) 4504 continue; 4505 switch (b->type) 4506 { 4507 case bp_gnu_ifunc_resolver: 4508 gnu_ifunc_resolver_stop (b); 4509 break; 4510 case bp_gnu_ifunc_resolver_return: 4511 gnu_ifunc_resolver_return_stop (b); 4512 break; 4513 } 4514 } 4515 4516 return retval; 4517 } 4518 4519 /* Nonzero if we should step constantly (e.g. watchpoints on machines 4520 without hardware support). This isn't related to a specific bpstat, 4521 just to things like whether watchpoints are set. */ 4522 4523 int 4524 bpstat_should_step (void) 4525 { 4526 struct breakpoint *b; 4527 4528 ALL_BREAKPOINTS (b) 4529 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) 4530 return 1; 4531 return 0; 4532 } 4533 4534 int 4535 bpstat_causes_stop (bpstat bs) 4536 { 4537 for (; bs != NULL; bs = bs->next) 4538 if (bs->stop) 4539 return 1; 4540 4541 return 0; 4542 } 4543 4544 4545 4546 /* Compute a string of spaces suitable to indent the next line 4547 so it starts at the position corresponding to the table column 4548 named COL_NAME in the currently active table of UIOUT. */ 4549 4550 static char * 4551 wrap_indent_at_field (struct ui_out *uiout, const char *col_name) 4552 { 4553 static char wrap_indent[80]; 4554 int i, total_width, width, align; 4555 char *text; 4556 4557 total_width = 0; 4558 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) 4559 { 4560 if (strcmp (text, col_name) == 0) 4561 { 4562 gdb_assert (total_width < sizeof wrap_indent); 4563 memset (wrap_indent, ' ', total_width); 4564 wrap_indent[total_width] = 0; 4565 4566 return wrap_indent; 4567 } 4568 4569 total_width += width + 1; 4570 } 4571 4572 return NULL; 4573 } 4574 4575 /* Print the LOC location out of the list of B->LOC locations. */ 4576 4577 static void 4578 print_breakpoint_location (struct breakpoint *b, 4579 struct bp_location *loc) 4580 { 4581 struct ui_out *uiout = current_uiout; 4582 struct cleanup *old_chain = save_current_program_space (); 4583 4584 if (loc != NULL && loc->shlib_disabled) 4585 loc = NULL; 4586 4587 if (loc != NULL) 4588 set_current_program_space (loc->pspace); 4589 4590 if (b->display_canonical) 4591 ui_out_field_string (uiout, "what", b->addr_string); 4592 else if (loc && loc->source_file) 4593 { 4594 struct symbol *sym 4595 = find_pc_sect_function (loc->address, loc->section); 4596 if (sym) 4597 { 4598 ui_out_text (uiout, "in "); 4599 ui_out_field_string (uiout, "func", 4600 SYMBOL_PRINT_NAME (sym)); 4601 ui_out_text (uiout, " "); 4602 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); 4603 ui_out_text (uiout, "at "); 4604 } 4605 ui_out_field_string (uiout, "file", loc->source_file); 4606 ui_out_text (uiout, ":"); 4607 4608 if (ui_out_is_mi_like_p (uiout)) 4609 { 4610 struct symtab_and_line sal = find_pc_line (loc->address, 0); 4611 char *fullname = symtab_to_fullname (sal.symtab); 4612 4613 if (fullname) 4614 ui_out_field_string (uiout, "fullname", fullname); 4615 } 4616 4617 ui_out_field_int (uiout, "line", loc->line_number); 4618 } 4619 else if (loc) 4620 { 4621 struct ui_stream *stb = ui_out_stream_new (uiout); 4622 struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); 4623 4624 print_address_symbolic (loc->gdbarch, loc->address, stb->stream, 4625 demangle, ""); 4626 ui_out_field_stream (uiout, "at", stb); 4627 4628 do_cleanups (stb_chain); 4629 } 4630 else 4631 ui_out_field_string (uiout, "pending", b->addr_string); 4632 4633 do_cleanups (old_chain); 4634 } 4635 4636 static const char * 4637 bptype_string (enum bptype type) 4638 { 4639 struct ep_type_description 4640 { 4641 enum bptype type; 4642 char *description; 4643 }; 4644 static struct ep_type_description bptypes[] = 4645 { 4646 {bp_none, "?deleted?"}, 4647 {bp_breakpoint, "breakpoint"}, 4648 {bp_hardware_breakpoint, "hw breakpoint"}, 4649 {bp_until, "until"}, 4650 {bp_finish, "finish"}, 4651 {bp_watchpoint, "watchpoint"}, 4652 {bp_hardware_watchpoint, "hw watchpoint"}, 4653 {bp_read_watchpoint, "read watchpoint"}, 4654 {bp_access_watchpoint, "acc watchpoint"}, 4655 {bp_longjmp, "longjmp"}, 4656 {bp_longjmp_resume, "longjmp resume"}, 4657 {bp_exception, "exception"}, 4658 {bp_exception_resume, "exception resume"}, 4659 {bp_step_resume, "step resume"}, 4660 {bp_hp_step_resume, "high-priority step resume"}, 4661 {bp_watchpoint_scope, "watchpoint scope"}, 4662 {bp_call_dummy, "call dummy"}, 4663 {bp_std_terminate, "std::terminate"}, 4664 {bp_shlib_event, "shlib events"}, 4665 {bp_thread_event, "thread events"}, 4666 {bp_overlay_event, "overlay events"}, 4667 {bp_longjmp_master, "longjmp master"}, 4668 {bp_std_terminate_master, "std::terminate master"}, 4669 {bp_exception_master, "exception master"}, 4670 {bp_catchpoint, "catchpoint"}, 4671 {bp_tracepoint, "tracepoint"}, 4672 {bp_fast_tracepoint, "fast tracepoint"}, 4673 {bp_static_tracepoint, "static tracepoint"}, 4674 {bp_jit_event, "jit events"}, 4675 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, 4676 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, 4677 }; 4678 4679 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) 4680 || ((int) type != bptypes[(int) type].type)) 4681 internal_error (__FILE__, __LINE__, 4682 _("bptypes table does not describe type #%d."), 4683 (int) type); 4684 4685 return bptypes[(int) type].description; 4686 } 4687 4688 /* Print B to gdb_stdout. */ 4689 4690 static void 4691 print_one_breakpoint_location (struct breakpoint *b, 4692 struct bp_location *loc, 4693 int loc_number, 4694 struct bp_location **last_loc, 4695 int allflag) 4696 { 4697 struct command_line *l; 4698 static char bpenables[] = "nynny"; 4699 4700 struct ui_out *uiout = current_uiout; 4701 int header_of_multiple = 0; 4702 int part_of_multiple = (loc != NULL); 4703 struct value_print_options opts; 4704 4705 get_user_print_options (&opts); 4706 4707 gdb_assert (!loc || loc_number != 0); 4708 /* See comment in print_one_breakpoint concerning treatment of 4709 breakpoints with single disabled location. */ 4710 if (loc == NULL 4711 && (b->loc != NULL 4712 && (b->loc->next != NULL || !b->loc->enabled))) 4713 header_of_multiple = 1; 4714 if (loc == NULL) 4715 loc = b->loc; 4716 4717 annotate_record (); 4718 4719 /* 1 */ 4720 annotate_field (0); 4721 if (part_of_multiple) 4722 { 4723 char *formatted; 4724 formatted = xstrprintf ("%d.%d", b->number, loc_number); 4725 ui_out_field_string (uiout, "number", formatted); 4726 xfree (formatted); 4727 } 4728 else 4729 { 4730 ui_out_field_int (uiout, "number", b->number); 4731 } 4732 4733 /* 2 */ 4734 annotate_field (1); 4735 if (part_of_multiple) 4736 ui_out_field_skip (uiout, "type"); 4737 else 4738 ui_out_field_string (uiout, "type", bptype_string (b->type)); 4739 4740 /* 3 */ 4741 annotate_field (2); 4742 if (part_of_multiple) 4743 ui_out_field_skip (uiout, "disp"); 4744 else 4745 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 4746 4747 4748 /* 4 */ 4749 annotate_field (3); 4750 if (part_of_multiple) 4751 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); 4752 else 4753 ui_out_field_fmt (uiout, "enabled", "%c", 4754 bpenables[(int) b->enable_state]); 4755 ui_out_spaces (uiout, 2); 4756 4757 4758 /* 5 and 6 */ 4759 if (b->ops != NULL && b->ops->print_one != NULL) 4760 { 4761 /* Although the print_one can possibly print all locations, 4762 calling it here is not likely to get any nice result. So, 4763 make sure there's just one location. */ 4764 gdb_assert (b->loc == NULL || b->loc->next == NULL); 4765 b->ops->print_one (b, last_loc); 4766 } 4767 else 4768 switch (b->type) 4769 { 4770 case bp_none: 4771 internal_error (__FILE__, __LINE__, 4772 _("print_one_breakpoint: bp_none encountered\n")); 4773 break; 4774 4775 case bp_watchpoint: 4776 case bp_hardware_watchpoint: 4777 case bp_read_watchpoint: 4778 case bp_access_watchpoint: 4779 { 4780 struct watchpoint *w = (struct watchpoint *) b; 4781 4782 /* Field 4, the address, is omitted (which makes the columns 4783 not line up too nicely with the headers, but the effect 4784 is relatively readable). */ 4785 if (opts.addressprint) 4786 ui_out_field_skip (uiout, "addr"); 4787 annotate_field (5); 4788 ui_out_field_string (uiout, "what", w->exp_string); 4789 } 4790 break; 4791 4792 case bp_breakpoint: 4793 case bp_hardware_breakpoint: 4794 case bp_until: 4795 case bp_finish: 4796 case bp_longjmp: 4797 case bp_longjmp_resume: 4798 case bp_exception: 4799 case bp_exception_resume: 4800 case bp_step_resume: 4801 case bp_hp_step_resume: 4802 case bp_watchpoint_scope: 4803 case bp_call_dummy: 4804 case bp_std_terminate: 4805 case bp_shlib_event: 4806 case bp_thread_event: 4807 case bp_overlay_event: 4808 case bp_longjmp_master: 4809 case bp_std_terminate_master: 4810 case bp_exception_master: 4811 case bp_tracepoint: 4812 case bp_fast_tracepoint: 4813 case bp_static_tracepoint: 4814 case bp_jit_event: 4815 case bp_gnu_ifunc_resolver: 4816 case bp_gnu_ifunc_resolver_return: 4817 if (opts.addressprint) 4818 { 4819 annotate_field (4); 4820 if (header_of_multiple) 4821 ui_out_field_string (uiout, "addr", "<MULTIPLE>"); 4822 else if (b->loc == NULL || loc->shlib_disabled) 4823 ui_out_field_string (uiout, "addr", "<PENDING>"); 4824 else 4825 ui_out_field_core_addr (uiout, "addr", 4826 loc->gdbarch, loc->address); 4827 } 4828 annotate_field (5); 4829 if (!header_of_multiple) 4830 print_breakpoint_location (b, loc); 4831 if (b->loc) 4832 *last_loc = b->loc; 4833 break; 4834 } 4835 4836 4837 /* For backward compatibility, don't display inferiors unless there 4838 are several. */ 4839 if (loc != NULL 4840 && !header_of_multiple 4841 && (allflag 4842 || (!gdbarch_has_global_breakpoints (target_gdbarch) 4843 && (number_of_program_spaces () > 1 4844 || number_of_inferiors () > 1) 4845 /* LOC is for existing B, it cannot be in 4846 moribund_locations and thus having NULL OWNER. */ 4847 && loc->owner->type != bp_catchpoint))) 4848 { 4849 struct inferior *inf; 4850 int first = 1; 4851 4852 for (inf = inferior_list; inf != NULL; inf = inf->next) 4853 { 4854 if (inf->pspace == loc->pspace) 4855 { 4856 if (first) 4857 { 4858 first = 0; 4859 ui_out_text (uiout, " inf "); 4860 } 4861 else 4862 ui_out_text (uiout, ", "); 4863 ui_out_text (uiout, plongest (inf->num)); 4864 } 4865 } 4866 } 4867 4868 if (!part_of_multiple) 4869 { 4870 if (b->thread != -1) 4871 { 4872 /* FIXME: This seems to be redundant and lost here; see the 4873 "stop only in" line a little further down. */ 4874 ui_out_text (uiout, " thread "); 4875 ui_out_field_int (uiout, "thread", b->thread); 4876 } 4877 else if (b->task != 0) 4878 { 4879 ui_out_text (uiout, " task "); 4880 ui_out_field_int (uiout, "task", b->task); 4881 } 4882 } 4883 4884 ui_out_text (uiout, "\n"); 4885 4886 if (!part_of_multiple) 4887 b->ops->print_one_detail (b, uiout); 4888 4889 if (part_of_multiple && frame_id_p (b->frame_id)) 4890 { 4891 annotate_field (6); 4892 ui_out_text (uiout, "\tstop only in stack frame at "); 4893 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside 4894 the frame ID. */ 4895 ui_out_field_core_addr (uiout, "frame", 4896 b->gdbarch, b->frame_id.stack_addr); 4897 ui_out_text (uiout, "\n"); 4898 } 4899 4900 if (!part_of_multiple && b->cond_string) 4901 { 4902 annotate_field (7); 4903 if (is_tracepoint (b)) 4904 ui_out_text (uiout, "\ttrace only if "); 4905 else 4906 ui_out_text (uiout, "\tstop only if "); 4907 ui_out_field_string (uiout, "cond", b->cond_string); 4908 ui_out_text (uiout, "\n"); 4909 } 4910 4911 if (!part_of_multiple && b->thread != -1) 4912 { 4913 /* FIXME should make an annotation for this. */ 4914 ui_out_text (uiout, "\tstop only in thread "); 4915 ui_out_field_int (uiout, "thread", b->thread); 4916 ui_out_text (uiout, "\n"); 4917 } 4918 4919 if (!part_of_multiple && b->hit_count) 4920 { 4921 /* FIXME should make an annotation for this. */ 4922 if (ep_is_catchpoint (b)) 4923 ui_out_text (uiout, "\tcatchpoint"); 4924 else if (is_tracepoint (b)) 4925 ui_out_text (uiout, "\ttracepoint"); 4926 else 4927 ui_out_text (uiout, "\tbreakpoint"); 4928 ui_out_text (uiout, " already hit "); 4929 ui_out_field_int (uiout, "times", b->hit_count); 4930 if (b->hit_count == 1) 4931 ui_out_text (uiout, " time\n"); 4932 else 4933 ui_out_text (uiout, " times\n"); 4934 } 4935 4936 /* Output the count also if it is zero, but only if this is mi. 4937 FIXME: Should have a better test for this. */ 4938 if (ui_out_is_mi_like_p (uiout)) 4939 if (!part_of_multiple && b->hit_count == 0) 4940 ui_out_field_int (uiout, "times", b->hit_count); 4941 4942 if (!part_of_multiple && b->ignore_count) 4943 { 4944 annotate_field (8); 4945 ui_out_text (uiout, "\tignore next "); 4946 ui_out_field_int (uiout, "ignore", b->ignore_count); 4947 ui_out_text (uiout, " hits\n"); 4948 } 4949 4950 if (!part_of_multiple && is_tracepoint (b)) 4951 { 4952 struct tracepoint *tp = (struct tracepoint *) b; 4953 4954 if (tp->traceframe_usage) 4955 { 4956 ui_out_text (uiout, "\ttrace buffer usage "); 4957 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); 4958 ui_out_text (uiout, " bytes\n"); 4959 } 4960 } 4961 4962 l = b->commands ? b->commands->commands : NULL; 4963 if (!part_of_multiple && l) 4964 { 4965 struct cleanup *script_chain; 4966 4967 annotate_field (9); 4968 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); 4969 print_command_lines (uiout, l, 4); 4970 do_cleanups (script_chain); 4971 } 4972 4973 if (is_tracepoint (b)) 4974 { 4975 struct tracepoint *t = (struct tracepoint *) b; 4976 4977 if (!part_of_multiple && t->pass_count) 4978 { 4979 annotate_field (10); 4980 ui_out_text (uiout, "\tpass count "); 4981 ui_out_field_int (uiout, "pass", t->pass_count); 4982 ui_out_text (uiout, " \n"); 4983 } 4984 } 4985 4986 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) 4987 { 4988 if (is_watchpoint (b)) 4989 { 4990 struct watchpoint *w = (struct watchpoint *) b; 4991 4992 ui_out_field_string (uiout, "original-location", w->exp_string); 4993 } 4994 else if (b->addr_string) 4995 ui_out_field_string (uiout, "original-location", b->addr_string); 4996 } 4997 } 4998 4999 static void 5000 print_one_breakpoint (struct breakpoint *b, 5001 struct bp_location **last_loc, 5002 int allflag) 5003 { 5004 struct cleanup *bkpt_chain; 5005 struct ui_out *uiout = current_uiout; 5006 5007 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); 5008 5009 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); 5010 do_cleanups (bkpt_chain); 5011 5012 /* If this breakpoint has custom print function, 5013 it's already printed. Otherwise, print individual 5014 locations, if any. */ 5015 if (b->ops == NULL || b->ops->print_one == NULL) 5016 { 5017 /* If breakpoint has a single location that is disabled, we 5018 print it as if it had several locations, since otherwise it's 5019 hard to represent "breakpoint enabled, location disabled" 5020 situation. 5021 5022 Note that while hardware watchpoints have several locations 5023 internally, that's not a property exposed to user. */ 5024 if (b->loc 5025 && !is_hardware_watchpoint (b) 5026 && (b->loc->next || !b->loc->enabled)) 5027 { 5028 struct bp_location *loc; 5029 int n = 1; 5030 5031 for (loc = b->loc; loc; loc = loc->next, ++n) 5032 { 5033 struct cleanup *inner2 = 5034 make_cleanup_ui_out_tuple_begin_end (uiout, NULL); 5035 print_one_breakpoint_location (b, loc, n, last_loc, allflag); 5036 do_cleanups (inner2); 5037 } 5038 } 5039 } 5040 } 5041 5042 static int 5043 breakpoint_address_bits (struct breakpoint *b) 5044 { 5045 int print_address_bits = 0; 5046 struct bp_location *loc; 5047 5048 for (loc = b->loc; loc; loc = loc->next) 5049 { 5050 int addr_bit; 5051 5052 /* Software watchpoints that aren't watching memory don't have 5053 an address to print. */ 5054 if (b->type == bp_watchpoint && loc->watchpoint_type == -1) 5055 continue; 5056 5057 addr_bit = gdbarch_addr_bit (loc->gdbarch); 5058 if (addr_bit > print_address_bits) 5059 print_address_bits = addr_bit; 5060 } 5061 5062 return print_address_bits; 5063 } 5064 5065 struct captured_breakpoint_query_args 5066 { 5067 int bnum; 5068 }; 5069 5070 static int 5071 do_captured_breakpoint_query (struct ui_out *uiout, void *data) 5072 { 5073 struct captured_breakpoint_query_args *args = data; 5074 struct breakpoint *b; 5075 struct bp_location *dummy_loc = NULL; 5076 5077 ALL_BREAKPOINTS (b) 5078 { 5079 if (args->bnum == b->number) 5080 { 5081 print_one_breakpoint (b, &dummy_loc, 0); 5082 return GDB_RC_OK; 5083 } 5084 } 5085 return GDB_RC_NONE; 5086 } 5087 5088 enum gdb_rc 5089 gdb_breakpoint_query (struct ui_out *uiout, int bnum, 5090 char **error_message) 5091 { 5092 struct captured_breakpoint_query_args args; 5093 5094 args.bnum = bnum; 5095 /* For the moment we don't trust print_one_breakpoint() to not throw 5096 an error. */ 5097 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, 5098 error_message, RETURN_MASK_ALL) < 0) 5099 return GDB_RC_FAIL; 5100 else 5101 return GDB_RC_OK; 5102 } 5103 5104 /* Return true if this breakpoint was set by the user, false if it is 5105 internal or momentary. */ 5106 5107 int 5108 user_breakpoint_p (struct breakpoint *b) 5109 { 5110 return b->number > 0; 5111 } 5112 5113 /* Print information on user settable breakpoint (watchpoint, etc) 5114 number BNUM. If BNUM is -1 print all user-settable breakpoints. 5115 If ALLFLAG is non-zero, include non-user-settable breakpoints. If 5116 FILTER is non-NULL, call it on each breakpoint and only include the 5117 ones for which it returns non-zero. Return the total number of 5118 breakpoints listed. */ 5119 5120 static int 5121 breakpoint_1 (char *args, int allflag, 5122 int (*filter) (const struct breakpoint *)) 5123 { 5124 struct breakpoint *b; 5125 struct bp_location *last_loc = NULL; 5126 int nr_printable_breakpoints; 5127 struct cleanup *bkpttbl_chain; 5128 struct value_print_options opts; 5129 int print_address_bits = 0; 5130 int print_type_col_width = 14; 5131 struct ui_out *uiout = current_uiout; 5132 5133 get_user_print_options (&opts); 5134 5135 /* Compute the number of rows in the table, as well as the size 5136 required for address fields. */ 5137 nr_printable_breakpoints = 0; 5138 ALL_BREAKPOINTS (b) 5139 { 5140 /* If we have a filter, only list the breakpoints it accepts. */ 5141 if (filter && !filter (b)) 5142 continue; 5143 5144 /* If we have an "args" string, it is a list of breakpoints to 5145 accept. Skip the others. */ 5146 if (args != NULL && *args != '\0') 5147 { 5148 if (allflag && parse_and_eval_long (args) != b->number) 5149 continue; 5150 if (!allflag && !number_is_in_list (args, b->number)) 5151 continue; 5152 } 5153 5154 if (allflag || user_breakpoint_p (b)) 5155 { 5156 int addr_bit, type_len; 5157 5158 addr_bit = breakpoint_address_bits (b); 5159 if (addr_bit > print_address_bits) 5160 print_address_bits = addr_bit; 5161 5162 type_len = strlen (bptype_string (b->type)); 5163 if (type_len > print_type_col_width) 5164 print_type_col_width = type_len; 5165 5166 nr_printable_breakpoints++; 5167 } 5168 } 5169 5170 if (opts.addressprint) 5171 bkpttbl_chain 5172 = make_cleanup_ui_out_table_begin_end (uiout, 6, 5173 nr_printable_breakpoints, 5174 "BreakpointTable"); 5175 else 5176 bkpttbl_chain 5177 = make_cleanup_ui_out_table_begin_end (uiout, 5, 5178 nr_printable_breakpoints, 5179 "BreakpointTable"); 5180 5181 if (nr_printable_breakpoints > 0) 5182 annotate_breakpoints_headers (); 5183 if (nr_printable_breakpoints > 0) 5184 annotate_field (0); 5185 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ 5186 if (nr_printable_breakpoints > 0) 5187 annotate_field (1); 5188 ui_out_table_header (uiout, print_type_col_width, ui_left, 5189 "type", "Type"); /* 2 */ 5190 if (nr_printable_breakpoints > 0) 5191 annotate_field (2); 5192 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ 5193 if (nr_printable_breakpoints > 0) 5194 annotate_field (3); 5195 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ 5196 if (opts.addressprint) 5197 { 5198 if (nr_printable_breakpoints > 0) 5199 annotate_field (4); 5200 if (print_address_bits <= 32) 5201 ui_out_table_header (uiout, 10, ui_left, 5202 "addr", "Address"); /* 5 */ 5203 else 5204 ui_out_table_header (uiout, 18, ui_left, 5205 "addr", "Address"); /* 5 */ 5206 } 5207 if (nr_printable_breakpoints > 0) 5208 annotate_field (5); 5209 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ 5210 ui_out_table_body (uiout); 5211 if (nr_printable_breakpoints > 0) 5212 annotate_breakpoints_table (); 5213 5214 ALL_BREAKPOINTS (b) 5215 { 5216 QUIT; 5217 /* If we have a filter, only list the breakpoints it accepts. */ 5218 if (filter && !filter (b)) 5219 continue; 5220 5221 /* If we have an "args" string, it is a list of breakpoints to 5222 accept. Skip the others. */ 5223 5224 if (args != NULL && *args != '\0') 5225 { 5226 if (allflag) /* maintenance info breakpoint */ 5227 { 5228 if (parse_and_eval_long (args) != b->number) 5229 continue; 5230 } 5231 else /* all others */ 5232 { 5233 if (!number_is_in_list (args, b->number)) 5234 continue; 5235 } 5236 } 5237 /* We only print out user settable breakpoints unless the 5238 allflag is set. */ 5239 if (allflag || user_breakpoint_p (b)) 5240 print_one_breakpoint (b, &last_loc, allflag); 5241 } 5242 5243 do_cleanups (bkpttbl_chain); 5244 5245 if (nr_printable_breakpoints == 0) 5246 { 5247 /* If there's a filter, let the caller decide how to report 5248 empty list. */ 5249 if (!filter) 5250 { 5251 if (args == NULL || *args == '\0') 5252 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); 5253 else 5254 ui_out_message (uiout, 0, 5255 "No breakpoint or watchpoint matching '%s'.\n", 5256 args); 5257 } 5258 } 5259 else 5260 { 5261 if (last_loc && !server_command) 5262 set_next_address (last_loc->gdbarch, last_loc->address); 5263 } 5264 5265 /* FIXME? Should this be moved up so that it is only called when 5266 there have been breakpoints? */ 5267 annotate_breakpoints_table_end (); 5268 5269 return nr_printable_breakpoints; 5270 } 5271 5272 /* Display the value of default-collect in a way that is generally 5273 compatible with the breakpoint list. */ 5274 5275 static void 5276 default_collect_info (void) 5277 { 5278 struct ui_out *uiout = current_uiout; 5279 5280 /* If it has no value (which is frequently the case), say nothing; a 5281 message like "No default-collect." gets in user's face when it's 5282 not wanted. */ 5283 if (!*default_collect) 5284 return; 5285 5286 /* The following phrase lines up nicely with per-tracepoint collect 5287 actions. */ 5288 ui_out_text (uiout, "default collect "); 5289 ui_out_field_string (uiout, "default-collect", default_collect); 5290 ui_out_text (uiout, " \n"); 5291 } 5292 5293 static void 5294 breakpoints_info (char *args, int from_tty) 5295 { 5296 breakpoint_1 (args, 0, NULL); 5297 5298 default_collect_info (); 5299 } 5300 5301 static void 5302 watchpoints_info (char *args, int from_tty) 5303 { 5304 int num_printed = breakpoint_1 (args, 0, is_watchpoint); 5305 struct ui_out *uiout = current_uiout; 5306 5307 if (num_printed == 0) 5308 { 5309 if (args == NULL || *args == '\0') 5310 ui_out_message (uiout, 0, "No watchpoints.\n"); 5311 else 5312 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); 5313 } 5314 } 5315 5316 static void 5317 maintenance_info_breakpoints (char *args, int from_tty) 5318 { 5319 breakpoint_1 (args, 1, NULL); 5320 5321 default_collect_info (); 5322 } 5323 5324 static int 5325 breakpoint_has_pc (struct breakpoint *b, 5326 struct program_space *pspace, 5327 CORE_ADDR pc, struct obj_section *section) 5328 { 5329 struct bp_location *bl = b->loc; 5330 5331 for (; bl; bl = bl->next) 5332 { 5333 if (bl->pspace == pspace 5334 && bl->address == pc 5335 && (!overlay_debugging || bl->section == section)) 5336 return 1; 5337 } 5338 return 0; 5339 } 5340 5341 /* Print a message describing any user-breakpoints set at PC. This 5342 concerns with logical breakpoints, so we match program spaces, not 5343 address spaces. */ 5344 5345 static void 5346 describe_other_breakpoints (struct gdbarch *gdbarch, 5347 struct program_space *pspace, CORE_ADDR pc, 5348 struct obj_section *section, int thread) 5349 { 5350 int others = 0; 5351 struct breakpoint *b; 5352 5353 ALL_BREAKPOINTS (b) 5354 others += (user_breakpoint_p (b) 5355 && breakpoint_has_pc (b, pspace, pc, section)); 5356 if (others > 0) 5357 { 5358 if (others == 1) 5359 printf_filtered (_("Note: breakpoint ")); 5360 else /* if (others == ???) */ 5361 printf_filtered (_("Note: breakpoints ")); 5362 ALL_BREAKPOINTS (b) 5363 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) 5364 { 5365 others--; 5366 printf_filtered ("%d", b->number); 5367 if (b->thread == -1 && thread != -1) 5368 printf_filtered (" (all threads)"); 5369 else if (b->thread != -1) 5370 printf_filtered (" (thread %d)", b->thread); 5371 printf_filtered ("%s%s ", 5372 ((b->enable_state == bp_disabled 5373 || b->enable_state == bp_call_disabled) 5374 ? " (disabled)" 5375 : b->enable_state == bp_permanent 5376 ? " (permanent)" 5377 : ""), 5378 (others > 1) ? "," 5379 : ((others == 1) ? " and" : "")); 5380 } 5381 printf_filtered (_("also set at pc ")); 5382 fputs_filtered (paddress (gdbarch, pc), gdb_stdout); 5383 printf_filtered (".\n"); 5384 } 5385 } 5386 5387 5388 /* Return true iff it is meaningful to use the address member of 5389 BPT. For some breakpoint types, the address member is irrelevant 5390 and it makes no sense to attempt to compare it to other addresses 5391 (or use it for any other purpose either). 5392 5393 More specifically, each of the following breakpoint types will 5394 always have a zero valued address and we don't want to mark 5395 breakpoints of any of these types to be a duplicate of an actual 5396 breakpoint at address zero: 5397 5398 bp_watchpoint 5399 bp_catchpoint 5400 5401 */ 5402 5403 static int 5404 breakpoint_address_is_meaningful (struct breakpoint *bpt) 5405 { 5406 enum bptype type = bpt->type; 5407 5408 return (type != bp_watchpoint && type != bp_catchpoint); 5409 } 5410 5411 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns 5412 true if LOC1 and LOC2 represent the same watchpoint location. */ 5413 5414 static int 5415 watchpoint_locations_match (struct bp_location *loc1, 5416 struct bp_location *loc2) 5417 { 5418 struct watchpoint *w1 = (struct watchpoint *) loc1->owner; 5419 struct watchpoint *w2 = (struct watchpoint *) loc2->owner; 5420 5421 /* Both of them must exist. */ 5422 gdb_assert (w1 != NULL); 5423 gdb_assert (w2 != NULL); 5424 5425 /* If the target can evaluate the condition expression in hardware, 5426 then we we need to insert both watchpoints even if they are at 5427 the same place. Otherwise the watchpoint will only trigger when 5428 the condition of whichever watchpoint was inserted evaluates to 5429 true, not giving a chance for GDB to check the condition of the 5430 other watchpoint. */ 5431 if ((w1->cond_exp 5432 && target_can_accel_watchpoint_condition (loc1->address, 5433 loc1->length, 5434 loc1->watchpoint_type, 5435 w1->cond_exp)) 5436 || (w2->cond_exp 5437 && target_can_accel_watchpoint_condition (loc2->address, 5438 loc2->length, 5439 loc2->watchpoint_type, 5440 w2->cond_exp))) 5441 return 0; 5442 5443 /* Note that this checks the owner's type, not the location's. In 5444 case the target does not support read watchpoints, but does 5445 support access watchpoints, we'll have bp_read_watchpoint 5446 watchpoints with hw_access locations. Those should be considered 5447 duplicates of hw_read locations. The hw_read locations will 5448 become hw_access locations later. */ 5449 return (loc1->owner->type == loc2->owner->type 5450 && loc1->pspace->aspace == loc2->pspace->aspace 5451 && loc1->address == loc2->address 5452 && loc1->length == loc2->length); 5453 } 5454 5455 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the 5456 same breakpoint location. In most targets, this can only be true 5457 if ASPACE1 matches ASPACE2. On targets that have global 5458 breakpoints, the address space doesn't really matter. */ 5459 5460 static int 5461 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, 5462 struct address_space *aspace2, CORE_ADDR addr2) 5463 { 5464 return ((gdbarch_has_global_breakpoints (target_gdbarch) 5465 || aspace1 == aspace2) 5466 && addr1 == addr2); 5467 } 5468 5469 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by 5470 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 5471 matches ASPACE2. On targets that have global breakpoints, the address 5472 space doesn't really matter. */ 5473 5474 static int 5475 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, 5476 int len1, struct address_space *aspace2, 5477 CORE_ADDR addr2) 5478 { 5479 return ((gdbarch_has_global_breakpoints (target_gdbarch) 5480 || aspace1 == aspace2) 5481 && addr2 >= addr1 && addr2 < addr1 + len1); 5482 } 5483 5484 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be 5485 a ranged breakpoint. In most targets, a match happens only if ASPACE 5486 matches the breakpoint's address space. On targets that have global 5487 breakpoints, the address space doesn't really matter. */ 5488 5489 static int 5490 breakpoint_location_address_match (struct bp_location *bl, 5491 struct address_space *aspace, 5492 CORE_ADDR addr) 5493 { 5494 return (breakpoint_address_match (bl->pspace->aspace, bl->address, 5495 aspace, addr) 5496 || (bl->length 5497 && breakpoint_address_match_range (bl->pspace->aspace, 5498 bl->address, bl->length, 5499 aspace, addr))); 5500 } 5501 5502 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. 5503 Then, if LOC1 and LOC2 represent the same tracepoint location, returns 5504 true, otherwise returns false. */ 5505 5506 static int 5507 tracepoint_locations_match (struct bp_location *loc1, 5508 struct bp_location *loc2) 5509 { 5510 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) 5511 /* Since tracepoint locations are never duplicated with others', tracepoint 5512 locations at the same address of different tracepoints are regarded as 5513 different locations. */ 5514 return (loc1->address == loc2->address && loc1->owner == loc2->owner); 5515 else 5516 return 0; 5517 } 5518 5519 /* Assuming LOC1 and LOC2's types' have meaningful target addresses 5520 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 5521 represent the same location. */ 5522 5523 static int 5524 breakpoint_locations_match (struct bp_location *loc1, 5525 struct bp_location *loc2) 5526 { 5527 int hw_point1, hw_point2; 5528 5529 /* Both of them must not be in moribund_locations. */ 5530 gdb_assert (loc1->owner != NULL); 5531 gdb_assert (loc2->owner != NULL); 5532 5533 hw_point1 = is_hardware_watchpoint (loc1->owner); 5534 hw_point2 = is_hardware_watchpoint (loc2->owner); 5535 5536 if (hw_point1 != hw_point2) 5537 return 0; 5538 else if (hw_point1) 5539 return watchpoint_locations_match (loc1, loc2); 5540 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) 5541 return tracepoint_locations_match (loc1, loc2); 5542 else 5543 /* We compare bp_location.length in order to cover ranged breakpoints. */ 5544 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, 5545 loc2->pspace->aspace, loc2->address) 5546 && loc1->length == loc2->length); 5547 } 5548 5549 static void 5550 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, 5551 int bnum, int have_bnum) 5552 { 5553 /* The longest string possibly returned by hex_string_custom 5554 is 50 chars. These must be at least that big for safety. */ 5555 char astr1[64]; 5556 char astr2[64]; 5557 5558 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); 5559 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); 5560 if (have_bnum) 5561 warning (_("Breakpoint %d address previously adjusted from %s to %s."), 5562 bnum, astr1, astr2); 5563 else 5564 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); 5565 } 5566 5567 /* Adjust a breakpoint's address to account for architectural 5568 constraints on breakpoint placement. Return the adjusted address. 5569 Note: Very few targets require this kind of adjustment. For most 5570 targets, this function is simply the identity function. */ 5571 5572 static CORE_ADDR 5573 adjust_breakpoint_address (struct gdbarch *gdbarch, 5574 CORE_ADDR bpaddr, enum bptype bptype) 5575 { 5576 if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) 5577 { 5578 /* Very few targets need any kind of breakpoint adjustment. */ 5579 return bpaddr; 5580 } 5581 else if (bptype == bp_watchpoint 5582 || bptype == bp_hardware_watchpoint 5583 || bptype == bp_read_watchpoint 5584 || bptype == bp_access_watchpoint 5585 || bptype == bp_catchpoint) 5586 { 5587 /* Watchpoints and the various bp_catch_* eventpoints should not 5588 have their addresses modified. */ 5589 return bpaddr; 5590 } 5591 else 5592 { 5593 CORE_ADDR adjusted_bpaddr; 5594 5595 /* Some targets have architectural constraints on the placement 5596 of breakpoint instructions. Obtain the adjusted address. */ 5597 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); 5598 5599 /* An adjusted breakpoint address can significantly alter 5600 a user's expectations. Print a warning if an adjustment 5601 is required. */ 5602 if (adjusted_bpaddr != bpaddr) 5603 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); 5604 5605 return adjusted_bpaddr; 5606 } 5607 } 5608 5609 void 5610 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, 5611 struct breakpoint *owner) 5612 { 5613 memset (loc, 0, sizeof (*loc)); 5614 5615 gdb_assert (ops != NULL); 5616 5617 loc->ops = ops; 5618 loc->owner = owner; 5619 loc->cond = NULL; 5620 loc->shlib_disabled = 0; 5621 loc->enabled = 1; 5622 5623 switch (owner->type) 5624 { 5625 case bp_breakpoint: 5626 case bp_until: 5627 case bp_finish: 5628 case bp_longjmp: 5629 case bp_longjmp_resume: 5630 case bp_exception: 5631 case bp_exception_resume: 5632 case bp_step_resume: 5633 case bp_hp_step_resume: 5634 case bp_watchpoint_scope: 5635 case bp_call_dummy: 5636 case bp_std_terminate: 5637 case bp_shlib_event: 5638 case bp_thread_event: 5639 case bp_overlay_event: 5640 case bp_jit_event: 5641 case bp_longjmp_master: 5642 case bp_std_terminate_master: 5643 case bp_exception_master: 5644 case bp_gnu_ifunc_resolver: 5645 case bp_gnu_ifunc_resolver_return: 5646 loc->loc_type = bp_loc_software_breakpoint; 5647 break; 5648 case bp_hardware_breakpoint: 5649 loc->loc_type = bp_loc_hardware_breakpoint; 5650 break; 5651 case bp_hardware_watchpoint: 5652 case bp_read_watchpoint: 5653 case bp_access_watchpoint: 5654 loc->loc_type = bp_loc_hardware_watchpoint; 5655 break; 5656 case bp_watchpoint: 5657 case bp_catchpoint: 5658 case bp_tracepoint: 5659 case bp_fast_tracepoint: 5660 case bp_static_tracepoint: 5661 loc->loc_type = bp_loc_other; 5662 break; 5663 default: 5664 internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); 5665 } 5666 5667 loc->refc = 1; 5668 } 5669 5670 /* Allocate a struct bp_location. */ 5671 5672 static struct bp_location * 5673 allocate_bp_location (struct breakpoint *bpt) 5674 { 5675 return bpt->ops->allocate_location (bpt); 5676 } 5677 5678 static void 5679 free_bp_location (struct bp_location *loc) 5680 { 5681 loc->ops->dtor (loc); 5682 xfree (loc); 5683 } 5684 5685 /* Increment reference count. */ 5686 5687 static void 5688 incref_bp_location (struct bp_location *bl) 5689 { 5690 ++bl->refc; 5691 } 5692 5693 /* Decrement reference count. If the reference count reaches 0, 5694 destroy the bp_location. Sets *BLP to NULL. */ 5695 5696 static void 5697 decref_bp_location (struct bp_location **blp) 5698 { 5699 gdb_assert ((*blp)->refc > 0); 5700 5701 if (--(*blp)->refc == 0) 5702 free_bp_location (*blp); 5703 *blp = NULL; 5704 } 5705 5706 /* Add breakpoint B at the end of the global breakpoint chain. */ 5707 5708 static void 5709 add_to_breakpoint_chain (struct breakpoint *b) 5710 { 5711 struct breakpoint *b1; 5712 5713 /* Add this breakpoint to the end of the chain so that a list of 5714 breakpoints will come out in order of increasing numbers. */ 5715 5716 b1 = breakpoint_chain; 5717 if (b1 == 0) 5718 breakpoint_chain = b; 5719 else 5720 { 5721 while (b1->next) 5722 b1 = b1->next; 5723 b1->next = b; 5724 } 5725 } 5726 5727 /* Initializes breakpoint B with type BPTYPE and no locations yet. */ 5728 5729 static void 5730 init_raw_breakpoint_without_location (struct breakpoint *b, 5731 struct gdbarch *gdbarch, 5732 enum bptype bptype, 5733 const struct breakpoint_ops *ops) 5734 { 5735 memset (b, 0, sizeof (*b)); 5736 5737 gdb_assert (ops != NULL); 5738 5739 b->ops = ops; 5740 b->type = bptype; 5741 b->gdbarch = gdbarch; 5742 b->language = current_language->la_language; 5743 b->input_radix = input_radix; 5744 b->thread = -1; 5745 b->enable_state = bp_enabled; 5746 b->next = 0; 5747 b->silent = 0; 5748 b->ignore_count = 0; 5749 b->commands = NULL; 5750 b->frame_id = null_frame_id; 5751 b->condition_not_parsed = 0; 5752 b->py_bp_object = NULL; 5753 b->related_breakpoint = b; 5754 } 5755 5756 /* Helper to set_raw_breakpoint below. Creates a breakpoint 5757 that has type BPTYPE and has no locations as yet. */ 5758 5759 static struct breakpoint * 5760 set_raw_breakpoint_without_location (struct gdbarch *gdbarch, 5761 enum bptype bptype, 5762 const struct breakpoint_ops *ops) 5763 { 5764 struct breakpoint *b = XNEW (struct breakpoint); 5765 5766 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); 5767 add_to_breakpoint_chain (b); 5768 return b; 5769 } 5770 5771 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function 5772 resolutions should be made as the user specified the location explicitly 5773 enough. */ 5774 5775 static void 5776 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) 5777 { 5778 gdb_assert (loc->owner != NULL); 5779 5780 if (loc->owner->type == bp_breakpoint 5781 || loc->owner->type == bp_hardware_breakpoint 5782 || is_tracepoint (loc->owner)) 5783 { 5784 int is_gnu_ifunc; 5785 5786 find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, 5787 NULL, NULL, &is_gnu_ifunc); 5788 5789 if (is_gnu_ifunc && !explicit_loc) 5790 { 5791 struct breakpoint *b = loc->owner; 5792 5793 gdb_assert (loc->pspace == current_program_space); 5794 if (gnu_ifunc_resolve_name (loc->function_name, 5795 &loc->requested_address)) 5796 { 5797 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ 5798 loc->address = adjust_breakpoint_address (loc->gdbarch, 5799 loc->requested_address, 5800 b->type); 5801 } 5802 else if (b->type == bp_breakpoint && b->loc == loc 5803 && loc->next == NULL && b->related_breakpoint == b) 5804 { 5805 /* Create only the whole new breakpoint of this type but do not 5806 mess more complicated breakpoints with multiple locations. */ 5807 b->type = bp_gnu_ifunc_resolver; 5808 } 5809 } 5810 5811 if (loc->function_name) 5812 loc->function_name = xstrdup (loc->function_name); 5813 } 5814 } 5815 5816 /* Attempt to determine architecture of location identified by SAL. */ 5817 struct gdbarch * 5818 get_sal_arch (struct symtab_and_line sal) 5819 { 5820 if (sal.section) 5821 return get_objfile_arch (sal.section->objfile); 5822 if (sal.symtab) 5823 return get_objfile_arch (sal.symtab->objfile); 5824 5825 return NULL; 5826 } 5827 5828 /* Low level routine for partially initializing a breakpoint of type 5829 BPTYPE. The newly created breakpoint's address, section, source 5830 file name, and line number are provided by SAL. 5831 5832 It is expected that the caller will complete the initialization of 5833 the newly created breakpoint struct as well as output any status 5834 information regarding the creation of a new breakpoint. */ 5835 5836 static void 5837 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, 5838 struct symtab_and_line sal, enum bptype bptype, 5839 const struct breakpoint_ops *ops) 5840 { 5841 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); 5842 5843 add_location_to_breakpoint (b, &sal); 5844 5845 if (bptype != bp_catchpoint) 5846 gdb_assert (sal.pspace != NULL); 5847 5848 /* Store the program space that was used to set the breakpoint, 5849 except for ordinary breakpoints, which are independent of the 5850 program space. */ 5851 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) 5852 b->pspace = sal.pspace; 5853 5854 breakpoints_changed (); 5855 } 5856 5857 /* set_raw_breakpoint is a low level routine for allocating and 5858 partially initializing a breakpoint of type BPTYPE. The newly 5859 created breakpoint's address, section, source file name, and line 5860 number are provided by SAL. The newly created and partially 5861 initialized breakpoint is added to the breakpoint chain and 5862 is also returned as the value of this function. 5863 5864 It is expected that the caller will complete the initialization of 5865 the newly created breakpoint struct as well as output any status 5866 information regarding the creation of a new breakpoint. In 5867 particular, set_raw_breakpoint does NOT set the breakpoint 5868 number! Care should be taken to not allow an error to occur 5869 prior to completing the initialization of the breakpoint. If this 5870 should happen, a bogus breakpoint will be left on the chain. */ 5871 5872 struct breakpoint * 5873 set_raw_breakpoint (struct gdbarch *gdbarch, 5874 struct symtab_and_line sal, enum bptype bptype, 5875 const struct breakpoint_ops *ops) 5876 { 5877 struct breakpoint *b = XNEW (struct breakpoint); 5878 5879 init_raw_breakpoint (b, gdbarch, sal, bptype, ops); 5880 add_to_breakpoint_chain (b); 5881 return b; 5882 } 5883 5884 5885 /* Note that the breakpoint object B describes a permanent breakpoint 5886 instruction, hard-wired into the inferior's code. */ 5887 void 5888 make_breakpoint_permanent (struct breakpoint *b) 5889 { 5890 struct bp_location *bl; 5891 5892 b->enable_state = bp_permanent; 5893 5894 /* By definition, permanent breakpoints are already present in the 5895 code. Mark all locations as inserted. For now, 5896 make_breakpoint_permanent is called in just one place, so it's 5897 hard to say if it's reasonable to have permanent breakpoint with 5898 multiple locations or not, but it's easy to implement. */ 5899 for (bl = b->loc; bl; bl = bl->next) 5900 bl->inserted = 1; 5901 } 5902 5903 /* Call this routine when stepping and nexting to enable a breakpoint 5904 if we do a longjmp() or 'throw' in TP. FRAME is the frame which 5905 initiated the operation. */ 5906 5907 void 5908 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) 5909 { 5910 struct breakpoint *b, *b_tmp; 5911 int thread = tp->num; 5912 5913 /* To avoid having to rescan all objfile symbols at every step, 5914 we maintain a list of continually-inserted but always disabled 5915 longjmp "master" breakpoints. Here, we simply create momentary 5916 clones of those and enable them for the requested thread. */ 5917 ALL_BREAKPOINTS_SAFE (b, b_tmp) 5918 if (b->pspace == current_program_space 5919 && (b->type == bp_longjmp_master 5920 || b->type == bp_exception_master)) 5921 { 5922 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; 5923 struct breakpoint *clone; 5924 5925 clone = momentary_breakpoint_from_master (b, type, 5926 &momentary_breakpoint_ops); 5927 clone->thread = thread; 5928 } 5929 5930 tp->initiating_frame = frame; 5931 } 5932 5933 /* Delete all longjmp breakpoints from THREAD. */ 5934 void 5935 delete_longjmp_breakpoint (int thread) 5936 { 5937 struct breakpoint *b, *b_tmp; 5938 5939 ALL_BREAKPOINTS_SAFE (b, b_tmp) 5940 if (b->type == bp_longjmp || b->type == bp_exception) 5941 { 5942 if (b->thread == thread) 5943 delete_breakpoint (b); 5944 } 5945 } 5946 5947 void 5948 enable_overlay_breakpoints (void) 5949 { 5950 struct breakpoint *b; 5951 5952 ALL_BREAKPOINTS (b) 5953 if (b->type == bp_overlay_event) 5954 { 5955 b->enable_state = bp_enabled; 5956 update_global_location_list (1); 5957 overlay_events_enabled = 1; 5958 } 5959 } 5960 5961 void 5962 disable_overlay_breakpoints (void) 5963 { 5964 struct breakpoint *b; 5965 5966 ALL_BREAKPOINTS (b) 5967 if (b->type == bp_overlay_event) 5968 { 5969 b->enable_state = bp_disabled; 5970 update_global_location_list (0); 5971 overlay_events_enabled = 0; 5972 } 5973 } 5974 5975 /* Set an active std::terminate breakpoint for each std::terminate 5976 master breakpoint. */ 5977 void 5978 set_std_terminate_breakpoint (void) 5979 { 5980 struct breakpoint *b, *b_tmp; 5981 5982 ALL_BREAKPOINTS_SAFE (b, b_tmp) 5983 if (b->pspace == current_program_space 5984 && b->type == bp_std_terminate_master) 5985 { 5986 momentary_breakpoint_from_master (b, bp_std_terminate, 5987 &momentary_breakpoint_ops); 5988 } 5989 } 5990 5991 /* Delete all the std::terminate breakpoints. */ 5992 void 5993 delete_std_terminate_breakpoint (void) 5994 { 5995 struct breakpoint *b, *b_tmp; 5996 5997 ALL_BREAKPOINTS_SAFE (b, b_tmp) 5998 if (b->type == bp_std_terminate) 5999 delete_breakpoint (b); 6000 } 6001 6002 struct breakpoint * 6003 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) 6004 { 6005 struct breakpoint *b; 6006 6007 b = create_internal_breakpoint (gdbarch, address, bp_thread_event, 6008 &internal_breakpoint_ops); 6009 6010 b->enable_state = bp_enabled; 6011 /* addr_string has to be used or breakpoint_re_set will delete me. */ 6012 b->addr_string 6013 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); 6014 6015 update_global_location_list_nothrow (1); 6016 6017 return b; 6018 } 6019 6020 void 6021 remove_thread_event_breakpoints (void) 6022 { 6023 struct breakpoint *b, *b_tmp; 6024 6025 ALL_BREAKPOINTS_SAFE (b, b_tmp) 6026 if (b->type == bp_thread_event 6027 && b->loc->pspace == current_program_space) 6028 delete_breakpoint (b); 6029 } 6030 6031 struct lang_and_radix 6032 { 6033 enum language lang; 6034 int radix; 6035 }; 6036 6037 /* Create a breakpoint for JIT code registration and unregistration. */ 6038 6039 struct breakpoint * 6040 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) 6041 { 6042 struct breakpoint *b; 6043 6044 b = create_internal_breakpoint (gdbarch, address, bp_jit_event, 6045 &internal_breakpoint_ops); 6046 update_global_location_list_nothrow (1); 6047 return b; 6048 } 6049 6050 /* Remove JIT code registration and unregistration breakpoint(s). */ 6051 6052 void 6053 remove_jit_event_breakpoints (void) 6054 { 6055 struct breakpoint *b, *b_tmp; 6056 6057 ALL_BREAKPOINTS_SAFE (b, b_tmp) 6058 if (b->type == bp_jit_event 6059 && b->loc->pspace == current_program_space) 6060 delete_breakpoint (b); 6061 } 6062 6063 void 6064 remove_solib_event_breakpoints (void) 6065 { 6066 struct breakpoint *b, *b_tmp; 6067 6068 ALL_BREAKPOINTS_SAFE (b, b_tmp) 6069 if (b->type == bp_shlib_event 6070 && b->loc->pspace == current_program_space) 6071 delete_breakpoint (b); 6072 } 6073 6074 struct breakpoint * 6075 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) 6076 { 6077 struct breakpoint *b; 6078 6079 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, 6080 &internal_breakpoint_ops); 6081 update_global_location_list_nothrow (1); 6082 return b; 6083 } 6084 6085 /* Disable any breakpoints that are on code in shared libraries. Only 6086 apply to enabled breakpoints, disabled ones can just stay disabled. */ 6087 6088 void 6089 disable_breakpoints_in_shlibs (void) 6090 { 6091 struct bp_location *loc, **locp_tmp; 6092 6093 ALL_BP_LOCATIONS (loc, locp_tmp) 6094 { 6095 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ 6096 struct breakpoint *b = loc->owner; 6097 6098 /* We apply the check to all breakpoints, including disabled for 6099 those with loc->duplicate set. This is so that when breakpoint 6100 becomes enabled, or the duplicate is removed, gdb will try to 6101 insert all breakpoints. If we don't set shlib_disabled here, 6102 we'll try to insert those breakpoints and fail. */ 6103 if (((b->type == bp_breakpoint) 6104 || (b->type == bp_jit_event) 6105 || (b->type == bp_hardware_breakpoint) 6106 || (is_tracepoint (b))) 6107 && loc->pspace == current_program_space 6108 && !loc->shlib_disabled 6109 #ifdef PC_SOLIB 6110 && PC_SOLIB (loc->address) 6111 #else 6112 && solib_name_from_address (loc->pspace, loc->address) 6113 #endif 6114 ) 6115 { 6116 loc->shlib_disabled = 1; 6117 } 6118 } 6119 } 6120 6121 /* Disable any breakpoints and tracepoints that are in an unloaded shared 6122 library. Only apply to enabled breakpoints, disabled ones can just stay 6123 disabled. */ 6124 6125 static void 6126 disable_breakpoints_in_unloaded_shlib (struct so_list *solib) 6127 { 6128 struct bp_location *loc, **locp_tmp; 6129 int disabled_shlib_breaks = 0; 6130 6131 /* SunOS a.out shared libraries are always mapped, so do not 6132 disable breakpoints; they will only be reported as unloaded 6133 through clear_solib when GDB discards its shared library 6134 list. See clear_solib for more information. */ 6135 if (exec_bfd != NULL 6136 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) 6137 return; 6138 6139 ALL_BP_LOCATIONS (loc, locp_tmp) 6140 { 6141 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ 6142 struct breakpoint *b = loc->owner; 6143 6144 if (solib->pspace == loc->pspace 6145 && !loc->shlib_disabled 6146 && (((b->type == bp_breakpoint 6147 || b->type == bp_jit_event 6148 || b->type == bp_hardware_breakpoint) 6149 && (loc->loc_type == bp_loc_hardware_breakpoint 6150 || loc->loc_type == bp_loc_software_breakpoint)) 6151 || is_tracepoint (b)) 6152 && solib_contains_address_p (solib, loc->address)) 6153 { 6154 loc->shlib_disabled = 1; 6155 /* At this point, we cannot rely on remove_breakpoint 6156 succeeding so we must mark the breakpoint as not inserted 6157 to prevent future errors occurring in remove_breakpoints. */ 6158 loc->inserted = 0; 6159 6160 /* This may cause duplicate notifications for the same breakpoint. */ 6161 observer_notify_breakpoint_modified (b); 6162 6163 if (!disabled_shlib_breaks) 6164 { 6165 target_terminal_ours_for_output (); 6166 warning (_("Temporarily disabling breakpoints " 6167 "for unloaded shared library \"%s\""), 6168 solib->so_name); 6169 } 6170 disabled_shlib_breaks = 1; 6171 } 6172 } 6173 } 6174 6175 /* FORK & VFORK catchpoints. */ 6176 6177 /* An instance of this type is used to represent a fork or vfork 6178 catchpoint. It includes a "struct breakpoint" as a kind of base 6179 class; users downcast to "struct breakpoint *" when needed. A 6180 breakpoint is really of this type iff its ops pointer points to 6181 CATCH_FORK_BREAKPOINT_OPS. */ 6182 6183 struct fork_catchpoint 6184 { 6185 /* The base class. */ 6186 struct breakpoint base; 6187 6188 /* Process id of a child process whose forking triggered this 6189 catchpoint. This field is only valid immediately after this 6190 catchpoint has triggered. */ 6191 ptid_t forked_inferior_pid; 6192 }; 6193 6194 /* Implement the "insert" breakpoint_ops method for fork 6195 catchpoints. */ 6196 6197 static int 6198 insert_catch_fork (struct bp_location *bl) 6199 { 6200 return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); 6201 } 6202 6203 /* Implement the "remove" breakpoint_ops method for fork 6204 catchpoints. */ 6205 6206 static int 6207 remove_catch_fork (struct bp_location *bl) 6208 { 6209 return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); 6210 } 6211 6212 /* Implement the "breakpoint_hit" breakpoint_ops method for fork 6213 catchpoints. */ 6214 6215 static int 6216 breakpoint_hit_catch_fork (const struct bp_location *bl, 6217 struct address_space *aspace, CORE_ADDR bp_addr) 6218 { 6219 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; 6220 6221 return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid); 6222 } 6223 6224 /* Implement the "print_it" breakpoint_ops method for fork 6225 catchpoints. */ 6226 6227 static enum print_stop_action 6228 print_it_catch_fork (bpstat bs) 6229 { 6230 struct ui_out *uiout = current_uiout; 6231 struct breakpoint *b = bs->breakpoint_at; 6232 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; 6233 6234 annotate_catchpoint (b->number); 6235 if (b->disposition == disp_del) 6236 ui_out_text (uiout, "\nTemporary catchpoint "); 6237 else 6238 ui_out_text (uiout, "\nCatchpoint "); 6239 if (ui_out_is_mi_like_p (uiout)) 6240 { 6241 ui_out_field_string (uiout, "reason", 6242 async_reason_lookup (EXEC_ASYNC_FORK)); 6243 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 6244 } 6245 ui_out_field_int (uiout, "bkptno", b->number); 6246 ui_out_text (uiout, " (forked process "); 6247 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); 6248 ui_out_text (uiout, "), "); 6249 return PRINT_SRC_AND_LOC; 6250 } 6251 6252 /* Implement the "print_one" breakpoint_ops method for fork 6253 catchpoints. */ 6254 6255 static void 6256 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) 6257 { 6258 struct fork_catchpoint *c = (struct fork_catchpoint *) b; 6259 struct value_print_options opts; 6260 struct ui_out *uiout = current_uiout; 6261 6262 get_user_print_options (&opts); 6263 6264 /* Field 4, the address, is omitted (which makes the columns not 6265 line up too nicely with the headers, but the effect is relatively 6266 readable). */ 6267 if (opts.addressprint) 6268 ui_out_field_skip (uiout, "addr"); 6269 annotate_field (5); 6270 ui_out_text (uiout, "fork"); 6271 if (!ptid_equal (c->forked_inferior_pid, null_ptid)) 6272 { 6273 ui_out_text (uiout, ", process "); 6274 ui_out_field_int (uiout, "what", 6275 ptid_get_pid (c->forked_inferior_pid)); 6276 ui_out_spaces (uiout, 1); 6277 } 6278 } 6279 6280 /* Implement the "print_mention" breakpoint_ops method for fork 6281 catchpoints. */ 6282 6283 static void 6284 print_mention_catch_fork (struct breakpoint *b) 6285 { 6286 printf_filtered (_("Catchpoint %d (fork)"), b->number); 6287 } 6288 6289 /* Implement the "print_recreate" breakpoint_ops method for fork 6290 catchpoints. */ 6291 6292 static void 6293 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) 6294 { 6295 fprintf_unfiltered (fp, "catch fork"); 6296 print_recreate_thread (b, fp); 6297 } 6298 6299 /* The breakpoint_ops structure to be used in fork catchpoints. */ 6300 6301 static struct breakpoint_ops catch_fork_breakpoint_ops; 6302 6303 /* Implement the "insert" breakpoint_ops method for vfork 6304 catchpoints. */ 6305 6306 static int 6307 insert_catch_vfork (struct bp_location *bl) 6308 { 6309 return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); 6310 } 6311 6312 /* Implement the "remove" breakpoint_ops method for vfork 6313 catchpoints. */ 6314 6315 static int 6316 remove_catch_vfork (struct bp_location *bl) 6317 { 6318 return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); 6319 } 6320 6321 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork 6322 catchpoints. */ 6323 6324 static int 6325 breakpoint_hit_catch_vfork (const struct bp_location *bl, 6326 struct address_space *aspace, CORE_ADDR bp_addr) 6327 { 6328 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; 6329 6330 return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid); 6331 } 6332 6333 /* Implement the "print_it" breakpoint_ops method for vfork 6334 catchpoints. */ 6335 6336 static enum print_stop_action 6337 print_it_catch_vfork (bpstat bs) 6338 { 6339 struct ui_out *uiout = current_uiout; 6340 struct breakpoint *b = bs->breakpoint_at; 6341 struct fork_catchpoint *c = (struct fork_catchpoint *) b; 6342 6343 annotate_catchpoint (b->number); 6344 if (b->disposition == disp_del) 6345 ui_out_text (uiout, "\nTemporary catchpoint "); 6346 else 6347 ui_out_text (uiout, "\nCatchpoint "); 6348 if (ui_out_is_mi_like_p (uiout)) 6349 { 6350 ui_out_field_string (uiout, "reason", 6351 async_reason_lookup (EXEC_ASYNC_VFORK)); 6352 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 6353 } 6354 ui_out_field_int (uiout, "bkptno", b->number); 6355 ui_out_text (uiout, " (vforked process "); 6356 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); 6357 ui_out_text (uiout, "), "); 6358 return PRINT_SRC_AND_LOC; 6359 } 6360 6361 /* Implement the "print_one" breakpoint_ops method for vfork 6362 catchpoints. */ 6363 6364 static void 6365 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) 6366 { 6367 struct fork_catchpoint *c = (struct fork_catchpoint *) b; 6368 struct value_print_options opts; 6369 struct ui_out *uiout = current_uiout; 6370 6371 get_user_print_options (&opts); 6372 /* Field 4, the address, is omitted (which makes the columns not 6373 line up too nicely with the headers, but the effect is relatively 6374 readable). */ 6375 if (opts.addressprint) 6376 ui_out_field_skip (uiout, "addr"); 6377 annotate_field (5); 6378 ui_out_text (uiout, "vfork"); 6379 if (!ptid_equal (c->forked_inferior_pid, null_ptid)) 6380 { 6381 ui_out_text (uiout, ", process "); 6382 ui_out_field_int (uiout, "what", 6383 ptid_get_pid (c->forked_inferior_pid)); 6384 ui_out_spaces (uiout, 1); 6385 } 6386 } 6387 6388 /* Implement the "print_mention" breakpoint_ops method for vfork 6389 catchpoints. */ 6390 6391 static void 6392 print_mention_catch_vfork (struct breakpoint *b) 6393 { 6394 printf_filtered (_("Catchpoint %d (vfork)"), b->number); 6395 } 6396 6397 /* Implement the "print_recreate" breakpoint_ops method for vfork 6398 catchpoints. */ 6399 6400 static void 6401 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) 6402 { 6403 fprintf_unfiltered (fp, "catch vfork"); 6404 print_recreate_thread (b, fp); 6405 } 6406 6407 /* The breakpoint_ops structure to be used in vfork catchpoints. */ 6408 6409 static struct breakpoint_ops catch_vfork_breakpoint_ops; 6410 6411 /* An instance of this type is used to represent a syscall catchpoint. 6412 It includes a "struct breakpoint" as a kind of base class; users 6413 downcast to "struct breakpoint *" when needed. A breakpoint is 6414 really of this type iff its ops pointer points to 6415 CATCH_SYSCALL_BREAKPOINT_OPS. */ 6416 6417 struct syscall_catchpoint 6418 { 6419 /* The base class. */ 6420 struct breakpoint base; 6421 6422 /* Syscall numbers used for the 'catch syscall' feature. If no 6423 syscall has been specified for filtering, its value is NULL. 6424 Otherwise, it holds a list of all syscalls to be caught. The 6425 list elements are allocated with xmalloc. */ 6426 VEC(int) *syscalls_to_be_caught; 6427 }; 6428 6429 /* Implement the "dtor" breakpoint_ops method for syscall 6430 catchpoints. */ 6431 6432 static void 6433 dtor_catch_syscall (struct breakpoint *b) 6434 { 6435 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; 6436 6437 VEC_free (int, c->syscalls_to_be_caught); 6438 6439 base_breakpoint_ops.dtor (b); 6440 } 6441 6442 /* Implement the "insert" breakpoint_ops method for syscall 6443 catchpoints. */ 6444 6445 static int 6446 insert_catch_syscall (struct bp_location *bl) 6447 { 6448 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; 6449 struct inferior *inf = current_inferior (); 6450 6451 ++inf->total_syscalls_count; 6452 if (!c->syscalls_to_be_caught) 6453 ++inf->any_syscall_count; 6454 else 6455 { 6456 int i, iter; 6457 6458 for (i = 0; 6459 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 6460 i++) 6461 { 6462 int elem; 6463 6464 if (iter >= VEC_length (int, inf->syscalls_counts)) 6465 { 6466 int old_size = VEC_length (int, inf->syscalls_counts); 6467 uintptr_t vec_addr_offset 6468 = old_size * ((uintptr_t) sizeof (int)); 6469 uintptr_t vec_addr; 6470 VEC_safe_grow (int, inf->syscalls_counts, iter + 1); 6471 vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + 6472 vec_addr_offset; 6473 memset ((void *) vec_addr, 0, 6474 (iter + 1 - old_size) * sizeof (int)); 6475 } 6476 elem = VEC_index (int, inf->syscalls_counts, iter); 6477 VEC_replace (int, inf->syscalls_counts, iter, ++elem); 6478 } 6479 } 6480 6481 return target_set_syscall_catchpoint (PIDGET (inferior_ptid), 6482 inf->total_syscalls_count != 0, 6483 inf->any_syscall_count, 6484 VEC_length (int, inf->syscalls_counts), 6485 VEC_address (int, inf->syscalls_counts)); 6486 } 6487 6488 /* Implement the "remove" breakpoint_ops method for syscall 6489 catchpoints. */ 6490 6491 static int 6492 remove_catch_syscall (struct bp_location *bl) 6493 { 6494 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; 6495 struct inferior *inf = current_inferior (); 6496 6497 --inf->total_syscalls_count; 6498 if (!c->syscalls_to_be_caught) 6499 --inf->any_syscall_count; 6500 else 6501 { 6502 int i, iter; 6503 6504 for (i = 0; 6505 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 6506 i++) 6507 { 6508 int elem; 6509 if (iter >= VEC_length (int, inf->syscalls_counts)) 6510 /* Shouldn't happen. */ 6511 continue; 6512 elem = VEC_index (int, inf->syscalls_counts, iter); 6513 VEC_replace (int, inf->syscalls_counts, iter, --elem); 6514 } 6515 } 6516 6517 return target_set_syscall_catchpoint (PIDGET (inferior_ptid), 6518 inf->total_syscalls_count != 0, 6519 inf->any_syscall_count, 6520 VEC_length (int, inf->syscalls_counts), 6521 VEC_address (int, 6522 inf->syscalls_counts)); 6523 } 6524 6525 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall 6526 catchpoints. */ 6527 6528 static int 6529 breakpoint_hit_catch_syscall (const struct bp_location *bl, 6530 struct address_space *aspace, CORE_ADDR bp_addr) 6531 { 6532 /* We must check if we are catching specific syscalls in this 6533 breakpoint. If we are, then we must guarantee that the called 6534 syscall is the same syscall we are catching. */ 6535 int syscall_number = 0; 6536 const struct syscall_catchpoint *c 6537 = (const struct syscall_catchpoint *) bl->owner; 6538 6539 if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) 6540 return 0; 6541 6542 /* Now, checking if the syscall is the same. */ 6543 if (c->syscalls_to_be_caught) 6544 { 6545 int i, iter; 6546 6547 for (i = 0; 6548 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 6549 i++) 6550 if (syscall_number == iter) 6551 break; 6552 /* Not the same. */ 6553 if (!iter) 6554 return 0; 6555 } 6556 6557 return 1; 6558 } 6559 6560 /* Implement the "print_it" breakpoint_ops method for syscall 6561 catchpoints. */ 6562 6563 static enum print_stop_action 6564 print_it_catch_syscall (bpstat bs) 6565 { 6566 struct ui_out *uiout = current_uiout; 6567 struct breakpoint *b = bs->breakpoint_at; 6568 /* These are needed because we want to know in which state a 6569 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY 6570 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we 6571 must print "called syscall" or "returned from syscall". */ 6572 ptid_t ptid; 6573 struct target_waitstatus last; 6574 struct syscall s; 6575 char *syscall_id; 6576 6577 get_last_target_status (&ptid, &last); 6578 6579 get_syscall_by_number (last.value.syscall_number, &s); 6580 6581 annotate_catchpoint (b->number); 6582 6583 if (b->disposition == disp_del) 6584 ui_out_text (uiout, "\nTemporary catchpoint "); 6585 else 6586 ui_out_text (uiout, "\nCatchpoint "); 6587 if (ui_out_is_mi_like_p (uiout)) 6588 { 6589 ui_out_field_string (uiout, "reason", 6590 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY 6591 ? EXEC_ASYNC_SYSCALL_ENTRY 6592 : EXEC_ASYNC_SYSCALL_RETURN)); 6593 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 6594 } 6595 ui_out_field_int (uiout, "bkptno", b->number); 6596 6597 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) 6598 ui_out_text (uiout, " (call to syscall "); 6599 else 6600 ui_out_text (uiout, " (returned from syscall "); 6601 6602 if (s.name == NULL || ui_out_is_mi_like_p (uiout)) 6603 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); 6604 if (s.name != NULL) 6605 ui_out_field_string (uiout, "syscall-name", s.name); 6606 6607 ui_out_text (uiout, "), "); 6608 6609 return PRINT_SRC_AND_LOC; 6610 } 6611 6612 /* Implement the "print_one" breakpoint_ops method for syscall 6613 catchpoints. */ 6614 6615 static void 6616 print_one_catch_syscall (struct breakpoint *b, 6617 struct bp_location **last_loc) 6618 { 6619 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; 6620 struct value_print_options opts; 6621 struct ui_out *uiout = current_uiout; 6622 6623 get_user_print_options (&opts); 6624 /* Field 4, the address, is omitted (which makes the columns not 6625 line up too nicely with the headers, but the effect is relatively 6626 readable). */ 6627 if (opts.addressprint) 6628 ui_out_field_skip (uiout, "addr"); 6629 annotate_field (5); 6630 6631 if (c->syscalls_to_be_caught 6632 && VEC_length (int, c->syscalls_to_be_caught) > 1) 6633 ui_out_text (uiout, "syscalls \""); 6634 else 6635 ui_out_text (uiout, "syscall \""); 6636 6637 if (c->syscalls_to_be_caught) 6638 { 6639 int i, iter; 6640 char *text = xstrprintf ("%s", ""); 6641 6642 for (i = 0; 6643 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 6644 i++) 6645 { 6646 char *x = text; 6647 struct syscall s; 6648 get_syscall_by_number (iter, &s); 6649 6650 if (s.name != NULL) 6651 text = xstrprintf ("%s%s, ", text, s.name); 6652 else 6653 text = xstrprintf ("%s%d, ", text, iter); 6654 6655 /* We have to xfree the last 'text' (now stored at 'x') 6656 because xstrprintf dynamically allocates new space for it 6657 on every call. */ 6658 xfree (x); 6659 } 6660 /* Remove the last comma. */ 6661 text[strlen (text) - 2] = '\0'; 6662 ui_out_field_string (uiout, "what", text); 6663 } 6664 else 6665 ui_out_field_string (uiout, "what", "<any syscall>"); 6666 ui_out_text (uiout, "\" "); 6667 } 6668 6669 /* Implement the "print_mention" breakpoint_ops method for syscall 6670 catchpoints. */ 6671 6672 static void 6673 print_mention_catch_syscall (struct breakpoint *b) 6674 { 6675 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; 6676 6677 if (c->syscalls_to_be_caught) 6678 { 6679 int i, iter; 6680 6681 if (VEC_length (int, c->syscalls_to_be_caught) > 1) 6682 printf_filtered (_("Catchpoint %d (syscalls"), b->number); 6683 else 6684 printf_filtered (_("Catchpoint %d (syscall"), b->number); 6685 6686 for (i = 0; 6687 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 6688 i++) 6689 { 6690 struct syscall s; 6691 get_syscall_by_number (iter, &s); 6692 6693 if (s.name) 6694 printf_filtered (" '%s' [%d]", s.name, s.number); 6695 else 6696 printf_filtered (" %d", s.number); 6697 } 6698 printf_filtered (")"); 6699 } 6700 else 6701 printf_filtered (_("Catchpoint %d (any syscall)"), 6702 b->number); 6703 } 6704 6705 /* Implement the "print_recreate" breakpoint_ops method for syscall 6706 catchpoints. */ 6707 6708 static void 6709 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) 6710 { 6711 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; 6712 6713 fprintf_unfiltered (fp, "catch syscall"); 6714 6715 if (c->syscalls_to_be_caught) 6716 { 6717 int i, iter; 6718 6719 for (i = 0; 6720 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 6721 i++) 6722 { 6723 struct syscall s; 6724 6725 get_syscall_by_number (iter, &s); 6726 if (s.name) 6727 fprintf_unfiltered (fp, " %s", s.name); 6728 else 6729 fprintf_unfiltered (fp, " %d", s.number); 6730 } 6731 } 6732 print_recreate_thread (b, fp); 6733 } 6734 6735 /* The breakpoint_ops structure to be used in syscall catchpoints. */ 6736 6737 static struct breakpoint_ops catch_syscall_breakpoint_ops; 6738 6739 /* Returns non-zero if 'b' is a syscall catchpoint. */ 6740 6741 static int 6742 syscall_catchpoint_p (struct breakpoint *b) 6743 { 6744 return (b->ops == &catch_syscall_breakpoint_ops); 6745 } 6746 6747 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG 6748 is non-zero, then make the breakpoint temporary. If COND_STRING is 6749 not NULL, then store it in the breakpoint. OPS, if not NULL, is 6750 the breakpoint_ops structure associated to the catchpoint. */ 6751 6752 static void 6753 init_catchpoint (struct breakpoint *b, 6754 struct gdbarch *gdbarch, int tempflag, 6755 char *cond_string, 6756 const struct breakpoint_ops *ops) 6757 { 6758 struct symtab_and_line sal; 6759 6760 init_sal (&sal); 6761 sal.pspace = current_program_space; 6762 6763 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); 6764 6765 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); 6766 b->disposition = tempflag ? disp_del : disp_donttouch; 6767 } 6768 6769 void 6770 install_breakpoint (int internal, struct breakpoint *b, int update_gll) 6771 { 6772 add_to_breakpoint_chain (b); 6773 set_breakpoint_number (internal, b); 6774 if (!internal) 6775 mention (b); 6776 observer_notify_breakpoint_created (b); 6777 6778 if (update_gll) 6779 update_global_location_list (1); 6780 } 6781 6782 static void 6783 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, 6784 int tempflag, char *cond_string, 6785 const struct breakpoint_ops *ops) 6786 { 6787 struct fork_catchpoint *c = XNEW (struct fork_catchpoint); 6788 6789 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); 6790 6791 c->forked_inferior_pid = null_ptid; 6792 6793 install_breakpoint (0, &c->base, 1); 6794 } 6795 6796 /* Exec catchpoints. */ 6797 6798 /* An instance of this type is used to represent an exec catchpoint. 6799 It includes a "struct breakpoint" as a kind of base class; users 6800 downcast to "struct breakpoint *" when needed. A breakpoint is 6801 really of this type iff its ops pointer points to 6802 CATCH_EXEC_BREAKPOINT_OPS. */ 6803 6804 struct exec_catchpoint 6805 { 6806 /* The base class. */ 6807 struct breakpoint base; 6808 6809 /* Filename of a program whose exec triggered this catchpoint. 6810 This field is only valid immediately after this catchpoint has 6811 triggered. */ 6812 char *exec_pathname; 6813 }; 6814 6815 /* Implement the "dtor" breakpoint_ops method for exec 6816 catchpoints. */ 6817 6818 static void 6819 dtor_catch_exec (struct breakpoint *b) 6820 { 6821 struct exec_catchpoint *c = (struct exec_catchpoint *) b; 6822 6823 xfree (c->exec_pathname); 6824 6825 base_breakpoint_ops.dtor (b); 6826 } 6827 6828 static int 6829 insert_catch_exec (struct bp_location *bl) 6830 { 6831 return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); 6832 } 6833 6834 static int 6835 remove_catch_exec (struct bp_location *bl) 6836 { 6837 return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); 6838 } 6839 6840 static int 6841 breakpoint_hit_catch_exec (const struct bp_location *bl, 6842 struct address_space *aspace, CORE_ADDR bp_addr) 6843 { 6844 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; 6845 6846 return inferior_has_execd (inferior_ptid, &c->exec_pathname); 6847 } 6848 6849 static enum print_stop_action 6850 print_it_catch_exec (bpstat bs) 6851 { 6852 struct ui_out *uiout = current_uiout; 6853 struct breakpoint *b = bs->breakpoint_at; 6854 struct exec_catchpoint *c = (struct exec_catchpoint *) b; 6855 6856 annotate_catchpoint (b->number); 6857 if (b->disposition == disp_del) 6858 ui_out_text (uiout, "\nTemporary catchpoint "); 6859 else 6860 ui_out_text (uiout, "\nCatchpoint "); 6861 if (ui_out_is_mi_like_p (uiout)) 6862 { 6863 ui_out_field_string (uiout, "reason", 6864 async_reason_lookup (EXEC_ASYNC_EXEC)); 6865 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 6866 } 6867 ui_out_field_int (uiout, "bkptno", b->number); 6868 ui_out_text (uiout, " (exec'd "); 6869 ui_out_field_string (uiout, "new-exec", c->exec_pathname); 6870 ui_out_text (uiout, "), "); 6871 6872 return PRINT_SRC_AND_LOC; 6873 } 6874 6875 static void 6876 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) 6877 { 6878 struct exec_catchpoint *c = (struct exec_catchpoint *) b; 6879 struct value_print_options opts; 6880 struct ui_out *uiout = current_uiout; 6881 6882 get_user_print_options (&opts); 6883 6884 /* Field 4, the address, is omitted (which makes the columns 6885 not line up too nicely with the headers, but the effect 6886 is relatively readable). */ 6887 if (opts.addressprint) 6888 ui_out_field_skip (uiout, "addr"); 6889 annotate_field (5); 6890 ui_out_text (uiout, "exec"); 6891 if (c->exec_pathname != NULL) 6892 { 6893 ui_out_text (uiout, ", program \""); 6894 ui_out_field_string (uiout, "what", c->exec_pathname); 6895 ui_out_text (uiout, "\" "); 6896 } 6897 } 6898 6899 static void 6900 print_mention_catch_exec (struct breakpoint *b) 6901 { 6902 printf_filtered (_("Catchpoint %d (exec)"), b->number); 6903 } 6904 6905 /* Implement the "print_recreate" breakpoint_ops method for exec 6906 catchpoints. */ 6907 6908 static void 6909 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) 6910 { 6911 fprintf_unfiltered (fp, "catch exec"); 6912 print_recreate_thread (b, fp); 6913 } 6914 6915 static struct breakpoint_ops catch_exec_breakpoint_ops; 6916 6917 static void 6918 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, 6919 const struct breakpoint_ops *ops) 6920 { 6921 struct syscall_catchpoint *c; 6922 struct gdbarch *gdbarch = get_current_arch (); 6923 6924 c = XNEW (struct syscall_catchpoint); 6925 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); 6926 c->syscalls_to_be_caught = filter; 6927 6928 install_breakpoint (0, &c->base, 1); 6929 } 6930 6931 static int 6932 hw_breakpoint_used_count (void) 6933 { 6934 int i = 0; 6935 struct breakpoint *b; 6936 struct bp_location *bl; 6937 6938 ALL_BREAKPOINTS (b) 6939 { 6940 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) 6941 for (bl = b->loc; bl; bl = bl->next) 6942 { 6943 /* Special types of hardware breakpoints may use more than 6944 one register. */ 6945 i += b->ops->resources_needed (bl); 6946 } 6947 } 6948 6949 return i; 6950 } 6951 6952 /* Returns the resources B would use if it were a hardware 6953 watchpoint. */ 6954 6955 static int 6956 hw_watchpoint_use_count (struct breakpoint *b) 6957 { 6958 int i = 0; 6959 struct bp_location *bl; 6960 6961 if (!breakpoint_enabled (b)) 6962 return 0; 6963 6964 for (bl = b->loc; bl; bl = bl->next) 6965 { 6966 /* Special types of hardware watchpoints may use more than 6967 one register. */ 6968 i += b->ops->resources_needed (bl); 6969 } 6970 6971 return i; 6972 } 6973 6974 /* Returns the sum the used resources of all hardware watchpoints of 6975 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED 6976 the sum of the used resources of all hardware watchpoints of other 6977 types _not_ TYPE. */ 6978 6979 static int 6980 hw_watchpoint_used_count_others (struct breakpoint *except, 6981 enum bptype type, int *other_type_used) 6982 { 6983 int i = 0; 6984 struct breakpoint *b; 6985 6986 *other_type_used = 0; 6987 ALL_BREAKPOINTS (b) 6988 { 6989 if (b == except) 6990 continue; 6991 if (!breakpoint_enabled (b)) 6992 continue; 6993 6994 if (b->type == type) 6995 i += hw_watchpoint_use_count (b); 6996 else if (is_hardware_watchpoint (b)) 6997 *other_type_used = 1; 6998 } 6999 7000 return i; 7001 } 7002 7003 void 7004 disable_watchpoints_before_interactive_call_start (void) 7005 { 7006 struct breakpoint *b; 7007 7008 ALL_BREAKPOINTS (b) 7009 { 7010 if (is_watchpoint (b) && breakpoint_enabled (b)) 7011 { 7012 b->enable_state = bp_call_disabled; 7013 update_global_location_list (0); 7014 } 7015 } 7016 } 7017 7018 void 7019 enable_watchpoints_after_interactive_call_stop (void) 7020 { 7021 struct breakpoint *b; 7022 7023 ALL_BREAKPOINTS (b) 7024 { 7025 if (is_watchpoint (b) && b->enable_state == bp_call_disabled) 7026 { 7027 b->enable_state = bp_enabled; 7028 update_global_location_list (1); 7029 } 7030 } 7031 } 7032 7033 void 7034 disable_breakpoints_before_startup (void) 7035 { 7036 current_program_space->executing_startup = 1; 7037 update_global_location_list (0); 7038 } 7039 7040 void 7041 enable_breakpoints_after_startup (void) 7042 { 7043 current_program_space->executing_startup = 0; 7044 breakpoint_re_set (); 7045 } 7046 7047 7048 /* Set a breakpoint that will evaporate an end of command 7049 at address specified by SAL. 7050 Restrict it to frame FRAME if FRAME is nonzero. */ 7051 7052 struct breakpoint * 7053 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, 7054 struct frame_id frame_id, enum bptype type) 7055 { 7056 struct breakpoint *b; 7057 7058 /* If FRAME_ID is valid, it should be a real frame, not an inlined 7059 one. */ 7060 gdb_assert (!frame_id_inlined_p (frame_id)); 7061 7062 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); 7063 b->enable_state = bp_enabled; 7064 b->disposition = disp_donttouch; 7065 b->frame_id = frame_id; 7066 7067 /* If we're debugging a multi-threaded program, then we want 7068 momentary breakpoints to be active in only a single thread of 7069 control. */ 7070 if (in_thread_list (inferior_ptid)) 7071 b->thread = pid_to_thread_id (inferior_ptid); 7072 7073 update_global_location_list_nothrow (1); 7074 7075 return b; 7076 } 7077 7078 /* Make a momentary breakpoint based on the master breakpoint ORIG. 7079 The new breakpoint will have type TYPE, and use OPS as it 7080 breakpoint_ops. */ 7081 7082 static struct breakpoint * 7083 momentary_breakpoint_from_master (struct breakpoint *orig, 7084 enum bptype type, 7085 const struct breakpoint_ops *ops) 7086 { 7087 struct breakpoint *copy; 7088 7089 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); 7090 copy->loc = allocate_bp_location (copy); 7091 set_breakpoint_location_function (copy->loc, 1); 7092 7093 copy->loc->gdbarch = orig->loc->gdbarch; 7094 copy->loc->requested_address = orig->loc->requested_address; 7095 copy->loc->address = orig->loc->address; 7096 copy->loc->section = orig->loc->section; 7097 copy->loc->pspace = orig->loc->pspace; 7098 7099 if (orig->loc->source_file != NULL) 7100 copy->loc->source_file = xstrdup (orig->loc->source_file); 7101 7102 copy->loc->line_number = orig->loc->line_number; 7103 copy->frame_id = orig->frame_id; 7104 copy->thread = orig->thread; 7105 copy->pspace = orig->pspace; 7106 7107 copy->enable_state = bp_enabled; 7108 copy->disposition = disp_donttouch; 7109 copy->number = internal_breakpoint_number--; 7110 7111 update_global_location_list_nothrow (0); 7112 return copy; 7113 } 7114 7115 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if 7116 ORIG is NULL. */ 7117 7118 struct breakpoint * 7119 clone_momentary_breakpoint (struct breakpoint *orig) 7120 { 7121 /* If there's nothing to clone, then return nothing. */ 7122 if (orig == NULL) 7123 return NULL; 7124 7125 return momentary_breakpoint_from_master (orig, orig->type, orig->ops); 7126 } 7127 7128 struct breakpoint * 7129 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, 7130 enum bptype type) 7131 { 7132 struct symtab_and_line sal; 7133 7134 sal = find_pc_line (pc, 0); 7135 sal.pc = pc; 7136 sal.section = find_pc_overlay (pc); 7137 sal.explicit_pc = 1; 7138 7139 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); 7140 } 7141 7142 7143 /* Tell the user we have just set a breakpoint B. */ 7144 7145 static void 7146 mention (struct breakpoint *b) 7147 { 7148 b->ops->print_mention (b); 7149 if (ui_out_is_mi_like_p (current_uiout)) 7150 return; 7151 printf_filtered ("\n"); 7152 } 7153 7154 7155 static struct bp_location * 7156 add_location_to_breakpoint (struct breakpoint *b, 7157 const struct symtab_and_line *sal) 7158 { 7159 struct bp_location *loc, **tmp; 7160 CORE_ADDR adjusted_address; 7161 struct gdbarch *loc_gdbarch = get_sal_arch (*sal); 7162 7163 if (loc_gdbarch == NULL) 7164 loc_gdbarch = b->gdbarch; 7165 7166 /* Adjust the breakpoint's address prior to allocating a location. 7167 Once we call allocate_bp_location(), that mostly uninitialized 7168 location will be placed on the location chain. Adjustment of the 7169 breakpoint may cause target_read_memory() to be called and we do 7170 not want its scan of the location chain to find a breakpoint and 7171 location that's only been partially initialized. */ 7172 adjusted_address = adjust_breakpoint_address (loc_gdbarch, 7173 sal->pc, b->type); 7174 7175 loc = allocate_bp_location (b); 7176 for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) 7177 ; 7178 *tmp = loc; 7179 7180 loc->requested_address = sal->pc; 7181 loc->address = adjusted_address; 7182 loc->pspace = sal->pspace; 7183 gdb_assert (loc->pspace != NULL); 7184 loc->section = sal->section; 7185 loc->gdbarch = loc_gdbarch; 7186 7187 if (sal->symtab != NULL) 7188 loc->source_file = xstrdup (sal->symtab->filename); 7189 loc->line_number = sal->line; 7190 7191 set_breakpoint_location_function (loc, 7192 sal->explicit_pc || sal->explicit_line); 7193 return loc; 7194 } 7195 7196 7197 /* Return 1 if LOC is pointing to a permanent breakpoint, 7198 return 0 otherwise. */ 7199 7200 static int 7201 bp_loc_is_permanent (struct bp_location *loc) 7202 { 7203 int len; 7204 CORE_ADDR addr; 7205 const gdb_byte *bpoint; 7206 gdb_byte *target_mem; 7207 struct cleanup *cleanup; 7208 int retval = 0; 7209 7210 gdb_assert (loc != NULL); 7211 7212 addr = loc->address; 7213 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); 7214 7215 /* Software breakpoints unsupported? */ 7216 if (bpoint == NULL) 7217 return 0; 7218 7219 target_mem = alloca (len); 7220 7221 /* Enable the automatic memory restoration from breakpoints while 7222 we read the memory. Otherwise we could say about our temporary 7223 breakpoints they are permanent. */ 7224 cleanup = save_current_space_and_thread (); 7225 7226 switch_to_program_space_and_thread (loc->pspace); 7227 make_show_memory_breakpoints_cleanup (0); 7228 7229 if (target_read_memory (loc->address, target_mem, len) == 0 7230 && memcmp (target_mem, bpoint, len) == 0) 7231 retval = 1; 7232 7233 do_cleanups (cleanup); 7234 7235 return retval; 7236 } 7237 7238 7239 7240 /* Create a breakpoint with SAL as location. Use ADDR_STRING 7241 as textual description of the location, and COND_STRING 7242 as condition expression. */ 7243 7244 static void 7245 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, 7246 struct symtabs_and_lines sals, char *addr_string, 7247 char *filter, char *cond_string, 7248 enum bptype type, enum bpdisp disposition, 7249 int thread, int task, int ignore_count, 7250 const struct breakpoint_ops *ops, int from_tty, 7251 int enabled, int internal, unsigned flags, 7252 int display_canonical) 7253 { 7254 int i; 7255 7256 if (type == bp_hardware_breakpoint) 7257 { 7258 int target_resources_ok; 7259 7260 i = hw_breakpoint_used_count (); 7261 target_resources_ok = 7262 target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 7263 i + 1, 0); 7264 if (target_resources_ok == 0) 7265 error (_("No hardware breakpoint support in the target.")); 7266 else if (target_resources_ok < 0) 7267 error (_("Hardware breakpoints used exceeds limit.")); 7268 } 7269 7270 gdb_assert (sals.nelts > 0); 7271 7272 for (i = 0; i < sals.nelts; ++i) 7273 { 7274 struct symtab_and_line sal = sals.sals[i]; 7275 struct bp_location *loc; 7276 7277 if (from_tty) 7278 { 7279 struct gdbarch *loc_gdbarch = get_sal_arch (sal); 7280 if (!loc_gdbarch) 7281 loc_gdbarch = gdbarch; 7282 7283 describe_other_breakpoints (loc_gdbarch, 7284 sal.pspace, sal.pc, sal.section, thread); 7285 } 7286 7287 if (i == 0) 7288 { 7289 init_raw_breakpoint (b, gdbarch, sal, type, ops); 7290 b->thread = thread; 7291 b->task = task; 7292 7293 b->cond_string = cond_string; 7294 b->ignore_count = ignore_count; 7295 b->enable_state = enabled ? bp_enabled : bp_disabled; 7296 b->disposition = disposition; 7297 7298 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) 7299 b->loc->inserted = 1; 7300 7301 if (type == bp_static_tracepoint) 7302 { 7303 struct tracepoint *t = (struct tracepoint *) b; 7304 struct static_tracepoint_marker marker; 7305 7306 if (is_marker_spec (addr_string)) 7307 { 7308 /* We already know the marker exists, otherwise, we 7309 wouldn't see a sal for it. */ 7310 char *p = &addr_string[3]; 7311 char *endp; 7312 char *marker_str; 7313 7314 p = skip_spaces (p); 7315 7316 endp = skip_to_space (p); 7317 7318 marker_str = savestring (p, endp - p); 7319 t->static_trace_marker_id = marker_str; 7320 7321 printf_filtered (_("Probed static tracepoint " 7322 "marker \"%s\"\n"), 7323 t->static_trace_marker_id); 7324 } 7325 else if (target_static_tracepoint_marker_at (sal.pc, &marker)) 7326 { 7327 t->static_trace_marker_id = xstrdup (marker.str_id); 7328 release_static_tracepoint_marker (&marker); 7329 7330 printf_filtered (_("Probed static tracepoint " 7331 "marker \"%s\"\n"), 7332 t->static_trace_marker_id); 7333 } 7334 else 7335 warning (_("Couldn't determine the static " 7336 "tracepoint marker to probe")); 7337 } 7338 7339 loc = b->loc; 7340 } 7341 else 7342 { 7343 loc = add_location_to_breakpoint (b, &sal); 7344 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) 7345 loc->inserted = 1; 7346 } 7347 7348 if (bp_loc_is_permanent (loc)) 7349 make_breakpoint_permanent (b); 7350 7351 if (b->cond_string) 7352 { 7353 char *arg = b->cond_string; 7354 loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); 7355 if (*arg) 7356 error (_("Garbage %s follows condition"), arg); 7357 } 7358 } 7359 7360 b->display_canonical = display_canonical; 7361 if (addr_string) 7362 b->addr_string = addr_string; 7363 else 7364 /* addr_string has to be used or breakpoint_re_set will delete 7365 me. */ 7366 b->addr_string 7367 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); 7368 b->filter = filter; 7369 } 7370 7371 static void 7372 create_breakpoint_sal (struct gdbarch *gdbarch, 7373 struct symtabs_and_lines sals, char *addr_string, 7374 char *filter, char *cond_string, 7375 enum bptype type, enum bpdisp disposition, 7376 int thread, int task, int ignore_count, 7377 const struct breakpoint_ops *ops, int from_tty, 7378 int enabled, int internal, unsigned flags, 7379 int display_canonical) 7380 { 7381 struct breakpoint *b; 7382 struct cleanup *old_chain; 7383 7384 if (is_tracepoint_type (type)) 7385 { 7386 struct tracepoint *t; 7387 7388 t = XCNEW (struct tracepoint); 7389 b = &t->base; 7390 } 7391 else 7392 b = XNEW (struct breakpoint); 7393 7394 old_chain = make_cleanup (xfree, b); 7395 7396 init_breakpoint_sal (b, gdbarch, 7397 sals, addr_string, 7398 filter, cond_string, 7399 type, disposition, 7400 thread, task, ignore_count, 7401 ops, from_tty, 7402 enabled, internal, flags, 7403 display_canonical); 7404 discard_cleanups (old_chain); 7405 7406 install_breakpoint (internal, b, 0); 7407 } 7408 7409 /* Add SALS.nelts breakpoints to the breakpoint table. For each 7410 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] 7411 value. COND_STRING, if not NULL, specified the condition to be 7412 used for all breakpoints. Essentially the only case where 7413 SALS.nelts is not 1 is when we set a breakpoint on an overloaded 7414 function. In that case, it's still not possible to specify 7415 separate conditions for different overloaded functions, so 7416 we take just a single condition string. 7417 7418 NOTE: If the function succeeds, the caller is expected to cleanup 7419 the arrays ADDR_STRING, COND_STRING, and SALS (but not the 7420 array contents). If the function fails (error() is called), the 7421 caller is expected to cleanups both the ADDR_STRING, COND_STRING, 7422 COND and SALS arrays and each of those arrays contents. */ 7423 7424 static void 7425 create_breakpoints_sal (struct gdbarch *gdbarch, 7426 struct linespec_result *canonical, 7427 char *cond_string, 7428 enum bptype type, enum bpdisp disposition, 7429 int thread, int task, int ignore_count, 7430 const struct breakpoint_ops *ops, int from_tty, 7431 int enabled, int internal, unsigned flags) 7432 { 7433 int i; 7434 struct linespec_sals *lsal; 7435 7436 if (canonical->pre_expanded) 7437 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); 7438 7439 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) 7440 { 7441 /* Note that 'addr_string' can be NULL in the case of a plain 7442 'break', without arguments. */ 7443 char *addr_string = (canonical->addr_string 7444 ? xstrdup (canonical->addr_string) 7445 : NULL); 7446 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; 7447 struct cleanup *inner = make_cleanup (xfree, addr_string); 7448 7449 make_cleanup (xfree, filter_string); 7450 create_breakpoint_sal (gdbarch, lsal->sals, 7451 addr_string, 7452 filter_string, 7453 cond_string, type, disposition, 7454 thread, task, ignore_count, ops, 7455 from_tty, enabled, internal, flags, 7456 canonical->special_display); 7457 discard_cleanups (inner); 7458 } 7459 } 7460 7461 /* Parse ADDRESS which is assumed to be a SAL specification possibly 7462 followed by conditionals. On return, SALS contains an array of SAL 7463 addresses found. ADDR_STRING contains a vector of (canonical) 7464 address strings. ADDRESS points to the end of the SAL. 7465 7466 The array and the line spec strings are allocated on the heap, it is 7467 the caller's responsibility to free them. */ 7468 7469 static void 7470 parse_breakpoint_sals (char **address, 7471 struct linespec_result *canonical) 7472 { 7473 char *addr_start = *address; 7474 7475 /* If no arg given, or if first arg is 'if ', use the default 7476 breakpoint. */ 7477 if ((*address) == NULL 7478 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) 7479 { 7480 /* The last displayed codepoint, if it's valid, is our default breakpoint 7481 address. */ 7482 if (last_displayed_sal_is_valid ()) 7483 { 7484 struct linespec_sals lsal; 7485 struct symtab_and_line sal; 7486 7487 init_sal (&sal); /* Initialize to zeroes. */ 7488 lsal.sals.sals = (struct symtab_and_line *) 7489 xmalloc (sizeof (struct symtab_and_line)); 7490 7491 /* Set sal's pspace, pc, symtab, and line to the values 7492 corresponding to the last call to print_frame_info. */ 7493 get_last_displayed_sal (&sal); 7494 sal.section = find_pc_overlay (sal.pc); 7495 7496 /* "break" without arguments is equivalent to "break *PC" 7497 where PC is the last displayed codepoint's address. So 7498 make sure to set sal.explicit_pc to prevent GDB from 7499 trying to expand the list of sals to include all other 7500 instances with the same symtab and line. */ 7501 sal.explicit_pc = 1; 7502 7503 lsal.sals.sals[0] = sal; 7504 lsal.sals.nelts = 1; 7505 lsal.canonical = NULL; 7506 7507 VEC_safe_push (linespec_sals, canonical->sals, &lsal); 7508 } 7509 else 7510 error (_("No default breakpoint address now.")); 7511 } 7512 else 7513 { 7514 /* Force almost all breakpoints to be in terms of the 7515 current_source_symtab (which is decode_line_1's default). 7516 This should produce the results we want almost all of the 7517 time while leaving default_breakpoint_* alone. */ 7518 if (last_displayed_sal_is_valid ()) 7519 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, 7520 get_last_displayed_symtab (), 7521 get_last_displayed_line (), 7522 canonical, NULL, NULL); 7523 else 7524 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, 7525 (struct symtab *) NULL, 0, 7526 canonical, NULL, NULL); 7527 } 7528 } 7529 7530 7531 /* Convert each SAL into a real PC. Verify that the PC can be 7532 inserted as a breakpoint. If it can't throw an error. */ 7533 7534 static void 7535 breakpoint_sals_to_pc (struct symtabs_and_lines *sals) 7536 { 7537 int i; 7538 7539 for (i = 0; i < sals->nelts; i++) 7540 resolve_sal_pc (&sals->sals[i]); 7541 } 7542 7543 /* Fast tracepoints may have restrictions on valid locations. For 7544 instance, a fast tracepoint using a jump instead of a trap will 7545 likely have to overwrite more bytes than a trap would, and so can 7546 only be placed where the instruction is longer than the jump, or a 7547 multi-instruction sequence does not have a jump into the middle of 7548 it, etc. */ 7549 7550 static void 7551 check_fast_tracepoint_sals (struct gdbarch *gdbarch, 7552 struct symtabs_and_lines *sals) 7553 { 7554 int i, rslt; 7555 struct symtab_and_line *sal; 7556 char *msg; 7557 struct cleanup *old_chain; 7558 7559 for (i = 0; i < sals->nelts; i++) 7560 { 7561 struct gdbarch *sarch; 7562 7563 sal = &sals->sals[i]; 7564 7565 sarch = get_sal_arch (*sal); 7566 /* We fall back to GDBARCH if there is no architecture 7567 associated with SAL. */ 7568 if (sarch == NULL) 7569 sarch = gdbarch; 7570 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, 7571 NULL, &msg); 7572 old_chain = make_cleanup (xfree, msg); 7573 7574 if (!rslt) 7575 error (_("May not have a fast tracepoint at 0x%s%s"), 7576 paddress (sarch, sal->pc), (msg ? msg : "")); 7577 7578 do_cleanups (old_chain); 7579 } 7580 } 7581 7582 /* Given TOK, a string specification of condition and thread, as 7583 accepted by the 'break' command, extract the condition 7584 string and thread number and set *COND_STRING and *THREAD. 7585 PC identifies the context at which the condition should be parsed. 7586 If no condition is found, *COND_STRING is set to NULL. 7587 If no thread is found, *THREAD is set to -1. */ 7588 static void 7589 find_condition_and_thread (char *tok, CORE_ADDR pc, 7590 char **cond_string, int *thread, int *task) 7591 { 7592 *cond_string = NULL; 7593 *thread = -1; 7594 while (tok && *tok) 7595 { 7596 char *end_tok; 7597 int toklen; 7598 char *cond_start = NULL; 7599 char *cond_end = NULL; 7600 7601 tok = skip_spaces (tok); 7602 7603 end_tok = skip_to_space (tok); 7604 7605 toklen = end_tok - tok; 7606 7607 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) 7608 { 7609 struct expression *expr; 7610 7611 tok = cond_start = end_tok + 1; 7612 expr = parse_exp_1 (&tok, block_for_pc (pc), 0); 7613 xfree (expr); 7614 cond_end = tok; 7615 *cond_string = savestring (cond_start, 7616 cond_end - cond_start); 7617 } 7618 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) 7619 { 7620 char *tmptok; 7621 7622 tok = end_tok + 1; 7623 tmptok = tok; 7624 *thread = strtol (tok, &tok, 0); 7625 if (tok == tmptok) 7626 error (_("Junk after thread keyword.")); 7627 if (!valid_thread_id (*thread)) 7628 error (_("Unknown thread %d."), *thread); 7629 } 7630 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) 7631 { 7632 char *tmptok; 7633 7634 tok = end_tok + 1; 7635 tmptok = tok; 7636 *task = strtol (tok, &tok, 0); 7637 if (tok == tmptok) 7638 error (_("Junk after task keyword.")); 7639 if (!valid_task_id (*task)) 7640 error (_("Unknown task %d."), *task); 7641 } 7642 else 7643 error (_("Junk at end of arguments.")); 7644 } 7645 } 7646 7647 /* Decode a static tracepoint marker spec. */ 7648 7649 static struct symtabs_and_lines 7650 decode_static_tracepoint_spec (char **arg_p) 7651 { 7652 VEC(static_tracepoint_marker_p) *markers = NULL; 7653 struct symtabs_and_lines sals; 7654 struct symtab_and_line sal; 7655 struct symbol *sym; 7656 struct cleanup *old_chain; 7657 char *p = &(*arg_p)[3]; 7658 char *endp; 7659 char *marker_str; 7660 int i; 7661 7662 p = skip_spaces (p); 7663 7664 endp = skip_to_space (p); 7665 7666 marker_str = savestring (p, endp - p); 7667 old_chain = make_cleanup (xfree, marker_str); 7668 7669 markers = target_static_tracepoint_markers_by_strid (marker_str); 7670 if (VEC_empty(static_tracepoint_marker_p, markers)) 7671 error (_("No known static tracepoint marker named %s"), marker_str); 7672 7673 sals.nelts = VEC_length(static_tracepoint_marker_p, markers); 7674 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); 7675 7676 for (i = 0; i < sals.nelts; i++) 7677 { 7678 struct static_tracepoint_marker *marker; 7679 7680 marker = VEC_index (static_tracepoint_marker_p, markers, i); 7681 7682 init_sal (&sals.sals[i]); 7683 7684 sals.sals[i] = find_pc_line (marker->address, 0); 7685 sals.sals[i].pc = marker->address; 7686 7687 release_static_tracepoint_marker (marker); 7688 } 7689 7690 do_cleanups (old_chain); 7691 7692 *arg_p = endp; 7693 return sals; 7694 } 7695 7696 /* Set a breakpoint. This function is shared between CLI and MI 7697 functions for setting a breakpoint. This function has two major 7698 modes of operations, selected by the PARSE_CONDITION_AND_THREAD 7699 parameter. If non-zero, the function will parse arg, extracting 7700 breakpoint location, address and thread. Otherwise, ARG is just 7701 the location of breakpoint, with condition and thread specified by 7702 the COND_STRING and THREAD parameters. If INTERNAL is non-zero, 7703 the breakpoint number will be allocated from the internal 7704 breakpoint count. Returns true if any breakpoint was created; 7705 false otherwise. */ 7706 7707 int 7708 create_breakpoint (struct gdbarch *gdbarch, 7709 char *arg, char *cond_string, int thread, 7710 int parse_condition_and_thread, 7711 int tempflag, enum bptype type_wanted, 7712 int ignore_count, 7713 enum auto_boolean pending_break_support, 7714 const struct breakpoint_ops *ops, 7715 int from_tty, int enabled, int internal, 7716 unsigned flags) 7717 { 7718 volatile struct gdb_exception e; 7719 char *copy_arg = NULL; 7720 char *addr_start = arg; 7721 struct linespec_result canonical; 7722 struct cleanup *old_chain; 7723 struct cleanup *bkpt_chain = NULL; 7724 int i; 7725 int pending = 0; 7726 int task = 0; 7727 int prev_bkpt_count = breakpoint_count; 7728 7729 gdb_assert (ops != NULL); 7730 7731 init_linespec_result (&canonical); 7732 7733 if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) 7734 { 7735 int i; 7736 struct linespec_sals lsal; 7737 7738 lsal.sals = decode_static_tracepoint_spec (&arg); 7739 7740 copy_arg = savestring (addr_start, arg - addr_start); 7741 7742 canonical.addr_string = xstrdup (copy_arg); 7743 lsal.canonical = xstrdup (copy_arg); 7744 VEC_safe_push (linespec_sals, canonical.sals, &lsal); 7745 7746 goto done; 7747 } 7748 7749 TRY_CATCH (e, RETURN_MASK_ALL) 7750 { 7751 parse_breakpoint_sals (&arg, &canonical); 7752 } 7753 7754 /* If caller is interested in rc value from parse, set value. */ 7755 switch (e.reason) 7756 { 7757 case RETURN_QUIT: 7758 throw_exception (e); 7759 case RETURN_ERROR: 7760 switch (e.error) 7761 { 7762 case NOT_FOUND_ERROR: 7763 7764 /* If pending breakpoint support is turned off, throw 7765 error. */ 7766 7767 if (pending_break_support == AUTO_BOOLEAN_FALSE) 7768 throw_exception (e); 7769 7770 exception_print (gdb_stderr, e); 7771 7772 /* If pending breakpoint support is auto query and the user 7773 selects no, then simply return the error code. */ 7774 if (pending_break_support == AUTO_BOOLEAN_AUTO 7775 && !nquery (_("Make %s pending on future shared library load? "), 7776 bptype_string (type_wanted))) 7777 return 0; 7778 7779 /* At this point, either the user was queried about setting 7780 a pending breakpoint and selected yes, or pending 7781 breakpoint behavior is on and thus a pending breakpoint 7782 is defaulted on behalf of the user. */ 7783 { 7784 struct linespec_sals lsal; 7785 7786 copy_arg = xstrdup (addr_start); 7787 lsal.canonical = xstrdup (copy_arg); 7788 lsal.sals.nelts = 1; 7789 lsal.sals.sals = XNEW (struct symtab_and_line); 7790 init_sal (&lsal.sals.sals[0]); 7791 pending = 1; 7792 VEC_safe_push (linespec_sals, canonical.sals, &lsal); 7793 } 7794 break; 7795 default: 7796 throw_exception (e); 7797 } 7798 break; 7799 default: 7800 if (VEC_empty (linespec_sals, canonical.sals)) 7801 return 0; 7802 } 7803 7804 done: 7805 7806 /* Create a chain of things that always need to be cleaned up. */ 7807 old_chain = make_cleanup_destroy_linespec_result (&canonical); 7808 7809 /* ----------------------------- SNIP ----------------------------- 7810 Anything added to the cleanup chain beyond this point is assumed 7811 to be part of a breakpoint. If the breakpoint create succeeds 7812 then the memory is not reclaimed. */ 7813 bkpt_chain = make_cleanup (null_cleanup, 0); 7814 7815 /* Resolve all line numbers to PC's and verify that the addresses 7816 are ok for the target. */ 7817 if (!pending) 7818 { 7819 int ix; 7820 struct linespec_sals *iter; 7821 7822 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) 7823 breakpoint_sals_to_pc (&iter->sals); 7824 } 7825 7826 /* Fast tracepoints may have additional restrictions on location. */ 7827 if (!pending && type_wanted == bp_fast_tracepoint) 7828 { 7829 int ix; 7830 struct linespec_sals *iter; 7831 7832 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) 7833 check_fast_tracepoint_sals (gdbarch, &iter->sals); 7834 } 7835 7836 /* Verify that condition can be parsed, before setting any 7837 breakpoints. Allocate a separate condition expression for each 7838 breakpoint. */ 7839 if (!pending) 7840 { 7841 struct linespec_sals *lsal; 7842 7843 lsal = VEC_index (linespec_sals, canonical.sals, 0); 7844 7845 if (parse_condition_and_thread) 7846 { 7847 /* Here we only parse 'arg' to separate condition 7848 from thread number, so parsing in context of first 7849 sal is OK. When setting the breakpoint we'll 7850 re-parse it in context of each sal. */ 7851 cond_string = NULL; 7852 thread = -1; 7853 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, 7854 &thread, &task); 7855 if (cond_string) 7856 make_cleanup (xfree, cond_string); 7857 } 7858 else 7859 { 7860 /* Create a private copy of condition string. */ 7861 if (cond_string) 7862 { 7863 cond_string = xstrdup (cond_string); 7864 make_cleanup (xfree, cond_string); 7865 } 7866 } 7867 7868 /* If the user is creating a static tracepoint by marker id 7869 (strace -m MARKER_ID), then store the sals index, so that 7870 breakpoint_re_set can try to match up which of the newly 7871 found markers corresponds to this one, and, don't try to 7872 expand multiple locations for each sal, given than SALS 7873 already should contain all sals for MARKER_ID. */ 7874 if (type_wanted == bp_static_tracepoint 7875 && is_marker_spec (copy_arg)) 7876 { 7877 int i; 7878 7879 for (i = 0; i < lsal->sals.nelts; ++i) 7880 { 7881 struct symtabs_and_lines expanded; 7882 struct tracepoint *tp; 7883 struct cleanup *old_chain; 7884 char *addr_string; 7885 7886 expanded.nelts = 1; 7887 expanded.sals = &lsal->sals.sals[i]; 7888 7889 addr_string = xstrdup (canonical.addr_string); 7890 old_chain = make_cleanup (xfree, addr_string); 7891 7892 tp = XCNEW (struct tracepoint); 7893 init_breakpoint_sal (&tp->base, gdbarch, expanded, 7894 addr_string, NULL, 7895 cond_string, type_wanted, 7896 tempflag ? disp_del : disp_donttouch, 7897 thread, task, ignore_count, ops, 7898 from_tty, enabled, internal, flags, 7899 canonical.special_display); 7900 /* Given that its possible to have multiple markers with 7901 the same string id, if the user is creating a static 7902 tracepoint by marker id ("strace -m MARKER_ID"), then 7903 store the sals index, so that breakpoint_re_set can 7904 try to match up which of the newly found markers 7905 corresponds to this one */ 7906 tp->static_trace_marker_id_idx = i; 7907 7908 install_breakpoint (internal, &tp->base, 0); 7909 7910 discard_cleanups (old_chain); 7911 } 7912 } 7913 else 7914 create_breakpoints_sal (gdbarch, &canonical, cond_string, 7915 type_wanted, 7916 tempflag ? disp_del : disp_donttouch, 7917 thread, task, ignore_count, ops, from_tty, 7918 enabled, internal, flags); 7919 } 7920 else 7921 { 7922 struct breakpoint *b; 7923 7924 make_cleanup (xfree, copy_arg); 7925 7926 if (is_tracepoint_type (type_wanted)) 7927 { 7928 struct tracepoint *t; 7929 7930 t = XCNEW (struct tracepoint); 7931 b = &t->base; 7932 } 7933 else 7934 b = XNEW (struct breakpoint); 7935 7936 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); 7937 7938 b->addr_string = copy_arg; 7939 b->cond_string = NULL; 7940 b->ignore_count = ignore_count; 7941 b->disposition = tempflag ? disp_del : disp_donttouch; 7942 b->condition_not_parsed = 1; 7943 b->enable_state = enabled ? bp_enabled : bp_disabled; 7944 if ((type_wanted != bp_breakpoint 7945 && type_wanted != bp_hardware_breakpoint) || thread != -1) 7946 b->pspace = current_program_space; 7947 7948 install_breakpoint (internal, b, 0); 7949 } 7950 7951 if (VEC_length (linespec_sals, canonical.sals) > 1) 7952 { 7953 warning (_("Multiple breakpoints were set.\nUse the " 7954 "\"delete\" command to delete unwanted breakpoints.")); 7955 prev_breakpoint_count = prev_bkpt_count; 7956 } 7957 7958 /* That's it. Discard the cleanups for data inserted into the 7959 breakpoint. */ 7960 discard_cleanups (bkpt_chain); 7961 /* But cleanup everything else. */ 7962 do_cleanups (old_chain); 7963 7964 /* error call may happen here - have BKPT_CHAIN already discarded. */ 7965 update_global_location_list (1); 7966 7967 return 1; 7968 } 7969 7970 /* Set a breakpoint. 7971 ARG is a string describing breakpoint address, 7972 condition, and thread. 7973 FLAG specifies if a breakpoint is hardware on, 7974 and if breakpoint is temporary, using BP_HARDWARE_FLAG 7975 and BP_TEMPFLAG. */ 7976 7977 static void 7978 break_command_1 (char *arg, int flag, int from_tty) 7979 { 7980 int tempflag = flag & BP_TEMPFLAG; 7981 enum bptype type_wanted = (flag & BP_HARDWAREFLAG 7982 ? bp_hardware_breakpoint 7983 : bp_breakpoint); 7984 7985 create_breakpoint (get_current_arch (), 7986 arg, 7987 NULL, 0, 1 /* parse arg */, 7988 tempflag, type_wanted, 7989 0 /* Ignore count */, 7990 pending_break_support, 7991 &bkpt_breakpoint_ops, 7992 from_tty, 7993 1 /* enabled */, 7994 0 /* internal */, 7995 0); 7996 } 7997 7998 /* Helper function for break_command_1 and disassemble_command. */ 7999 8000 void 8001 resolve_sal_pc (struct symtab_and_line *sal) 8002 { 8003 CORE_ADDR pc; 8004 8005 if (sal->pc == 0 && sal->symtab != NULL) 8006 { 8007 if (!find_line_pc (sal->symtab, sal->line, &pc)) 8008 error (_("No line %d in file \"%s\"."), 8009 sal->line, sal->symtab->filename); 8010 sal->pc = pc; 8011 8012 /* If this SAL corresponds to a breakpoint inserted using a line 8013 number, then skip the function prologue if necessary. */ 8014 if (sal->explicit_line) 8015 skip_prologue_sal (sal); 8016 } 8017 8018 if (sal->section == 0 && sal->symtab != NULL) 8019 { 8020 struct blockvector *bv; 8021 struct block *b; 8022 struct symbol *sym; 8023 8024 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); 8025 if (bv != NULL) 8026 { 8027 sym = block_linkage_function (b); 8028 if (sym != NULL) 8029 { 8030 fixup_symbol_section (sym, sal->symtab->objfile); 8031 sal->section = SYMBOL_OBJ_SECTION (sym); 8032 } 8033 else 8034 { 8035 /* It really is worthwhile to have the section, so we'll 8036 just have to look harder. This case can be executed 8037 if we have line numbers but no functions (as can 8038 happen in assembly source). */ 8039 8040 struct minimal_symbol *msym; 8041 struct cleanup *old_chain = save_current_space_and_thread (); 8042 8043 switch_to_program_space_and_thread (sal->pspace); 8044 8045 msym = lookup_minimal_symbol_by_pc (sal->pc); 8046 if (msym) 8047 sal->section = SYMBOL_OBJ_SECTION (msym); 8048 8049 do_cleanups (old_chain); 8050 } 8051 } 8052 } 8053 } 8054 8055 void 8056 break_command (char *arg, int from_tty) 8057 { 8058 break_command_1 (arg, 0, from_tty); 8059 } 8060 8061 void 8062 tbreak_command (char *arg, int from_tty) 8063 { 8064 break_command_1 (arg, BP_TEMPFLAG, from_tty); 8065 } 8066 8067 static void 8068 hbreak_command (char *arg, int from_tty) 8069 { 8070 break_command_1 (arg, BP_HARDWAREFLAG, from_tty); 8071 } 8072 8073 static void 8074 thbreak_command (char *arg, int from_tty) 8075 { 8076 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); 8077 } 8078 8079 static void 8080 stop_command (char *arg, int from_tty) 8081 { 8082 printf_filtered (_("Specify the type of breakpoint to set.\n\ 8083 Usage: stop in <function | address>\n\ 8084 stop at <line>\n")); 8085 } 8086 8087 static void 8088 stopin_command (char *arg, int from_tty) 8089 { 8090 int badInput = 0; 8091 8092 if (arg == (char *) NULL) 8093 badInput = 1; 8094 else if (*arg != '*') 8095 { 8096 char *argptr = arg; 8097 int hasColon = 0; 8098 8099 /* Look for a ':'. If this is a line number specification, then 8100 say it is bad, otherwise, it should be an address or 8101 function/method name. */ 8102 while (*argptr && !hasColon) 8103 { 8104 hasColon = (*argptr == ':'); 8105 argptr++; 8106 } 8107 8108 if (hasColon) 8109 badInput = (*argptr != ':'); /* Not a class::method */ 8110 else 8111 badInput = isdigit (*arg); /* a simple line number */ 8112 } 8113 8114 if (badInput) 8115 printf_filtered (_("Usage: stop in <function | address>\n")); 8116 else 8117 break_command_1 (arg, 0, from_tty); 8118 } 8119 8120 static void 8121 stopat_command (char *arg, int from_tty) 8122 { 8123 int badInput = 0; 8124 8125 if (arg == (char *) NULL || *arg == '*') /* no line number */ 8126 badInput = 1; 8127 else 8128 { 8129 char *argptr = arg; 8130 int hasColon = 0; 8131 8132 /* Look for a ':'. If there is a '::' then get out, otherwise 8133 it is probably a line number. */ 8134 while (*argptr && !hasColon) 8135 { 8136 hasColon = (*argptr == ':'); 8137 argptr++; 8138 } 8139 8140 if (hasColon) 8141 badInput = (*argptr == ':'); /* we have class::method */ 8142 else 8143 badInput = !isdigit (*arg); /* not a line number */ 8144 } 8145 8146 if (badInput) 8147 printf_filtered (_("Usage: stop at <line>\n")); 8148 else 8149 break_command_1 (arg, 0, from_tty); 8150 } 8151 8152 /* Implement the "breakpoint_hit" breakpoint_ops method for 8153 ranged breakpoints. */ 8154 8155 static int 8156 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, 8157 struct address_space *aspace, 8158 CORE_ADDR bp_addr) 8159 { 8160 return breakpoint_address_match_range (bl->pspace->aspace, bl->address, 8161 bl->length, aspace, bp_addr); 8162 } 8163 8164 /* Implement the "resources_needed" breakpoint_ops method for 8165 ranged breakpoints. */ 8166 8167 static int 8168 resources_needed_ranged_breakpoint (const struct bp_location *bl) 8169 { 8170 return target_ranged_break_num_registers (); 8171 } 8172 8173 /* Implement the "print_it" breakpoint_ops method for 8174 ranged breakpoints. */ 8175 8176 static enum print_stop_action 8177 print_it_ranged_breakpoint (bpstat bs) 8178 { 8179 struct breakpoint *b = bs->breakpoint_at; 8180 struct bp_location *bl = b->loc; 8181 struct ui_out *uiout = current_uiout; 8182 8183 gdb_assert (b->type == bp_hardware_breakpoint); 8184 8185 /* Ranged breakpoints have only one location. */ 8186 gdb_assert (bl && bl->next == NULL); 8187 8188 annotate_breakpoint (b->number); 8189 if (b->disposition == disp_del) 8190 ui_out_text (uiout, "\nTemporary ranged breakpoint "); 8191 else 8192 ui_out_text (uiout, "\nRanged breakpoint "); 8193 if (ui_out_is_mi_like_p (uiout)) 8194 { 8195 ui_out_field_string (uiout, "reason", 8196 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); 8197 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 8198 } 8199 ui_out_field_int (uiout, "bkptno", b->number); 8200 ui_out_text (uiout, ", "); 8201 8202 return PRINT_SRC_AND_LOC; 8203 } 8204 8205 /* Implement the "print_one" breakpoint_ops method for 8206 ranged breakpoints. */ 8207 8208 static void 8209 print_one_ranged_breakpoint (struct breakpoint *b, 8210 struct bp_location **last_loc) 8211 { 8212 struct bp_location *bl = b->loc; 8213 struct value_print_options opts; 8214 struct ui_out *uiout = current_uiout; 8215 8216 /* Ranged breakpoints have only one location. */ 8217 gdb_assert (bl && bl->next == NULL); 8218 8219 get_user_print_options (&opts); 8220 8221 if (opts.addressprint) 8222 /* We don't print the address range here, it will be printed later 8223 by print_one_detail_ranged_breakpoint. */ 8224 ui_out_field_skip (uiout, "addr"); 8225 annotate_field (5); 8226 print_breakpoint_location (b, bl); 8227 *last_loc = bl; 8228 } 8229 8230 /* Implement the "print_one_detail" breakpoint_ops method for 8231 ranged breakpoints. */ 8232 8233 static void 8234 print_one_detail_ranged_breakpoint (const struct breakpoint *b, 8235 struct ui_out *uiout) 8236 { 8237 CORE_ADDR address_start, address_end; 8238 struct bp_location *bl = b->loc; 8239 struct ui_stream *stb = ui_out_stream_new (uiout); 8240 struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); 8241 8242 gdb_assert (bl); 8243 8244 address_start = bl->address; 8245 address_end = address_start + bl->length - 1; 8246 8247 ui_out_text (uiout, "\taddress range: "); 8248 fprintf_unfiltered (stb->stream, "[%s, %s]", 8249 print_core_address (bl->gdbarch, address_start), 8250 print_core_address (bl->gdbarch, address_end)); 8251 ui_out_field_stream (uiout, "addr", stb); 8252 ui_out_text (uiout, "\n"); 8253 8254 do_cleanups (cleanup); 8255 } 8256 8257 /* Implement the "print_mention" breakpoint_ops method for 8258 ranged breakpoints. */ 8259 8260 static void 8261 print_mention_ranged_breakpoint (struct breakpoint *b) 8262 { 8263 struct bp_location *bl = b->loc; 8264 struct ui_out *uiout = current_uiout; 8265 8266 gdb_assert (bl); 8267 gdb_assert (b->type == bp_hardware_breakpoint); 8268 8269 if (ui_out_is_mi_like_p (uiout)) 8270 return; 8271 8272 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), 8273 b->number, paddress (bl->gdbarch, bl->address), 8274 paddress (bl->gdbarch, bl->address + bl->length - 1)); 8275 } 8276 8277 /* Implement the "print_recreate" breakpoint_ops method for 8278 ranged breakpoints. */ 8279 8280 static void 8281 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) 8282 { 8283 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, 8284 b->addr_string_range_end); 8285 print_recreate_thread (b, fp); 8286 } 8287 8288 /* The breakpoint_ops structure to be used in ranged breakpoints. */ 8289 8290 static struct breakpoint_ops ranged_breakpoint_ops; 8291 8292 /* Find the address where the end of the breakpoint range should be 8293 placed, given the SAL of the end of the range. This is so that if 8294 the user provides a line number, the end of the range is set to the 8295 last instruction of the given line. */ 8296 8297 static CORE_ADDR 8298 find_breakpoint_range_end (struct symtab_and_line sal) 8299 { 8300 CORE_ADDR end; 8301 8302 /* If the user provided a PC value, use it. Otherwise, 8303 find the address of the end of the given location. */ 8304 if (sal.explicit_pc) 8305 end = sal.pc; 8306 else 8307 { 8308 int ret; 8309 CORE_ADDR start; 8310 8311 ret = find_line_pc_range (sal, &start, &end); 8312 if (!ret) 8313 error (_("Could not find location of the end of the range.")); 8314 8315 /* find_line_pc_range returns the start of the next line. */ 8316 end--; 8317 } 8318 8319 return end; 8320 } 8321 8322 /* Implement the "break-range" CLI command. */ 8323 8324 static void 8325 break_range_command (char *arg, int from_tty) 8326 { 8327 char *arg_start, *addr_string_start, *addr_string_end; 8328 struct linespec_result canonical_start, canonical_end; 8329 int bp_count, can_use_bp, length; 8330 CORE_ADDR end; 8331 struct breakpoint *b; 8332 struct symtab_and_line sal_start, sal_end; 8333 struct cleanup *cleanup_bkpt; 8334 struct linespec_sals *lsal_start, *lsal_end; 8335 8336 /* We don't support software ranged breakpoints. */ 8337 if (target_ranged_break_num_registers () < 0) 8338 error (_("This target does not support hardware ranged breakpoints.")); 8339 8340 bp_count = hw_breakpoint_used_count (); 8341 bp_count += target_ranged_break_num_registers (); 8342 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 8343 bp_count, 0); 8344 if (can_use_bp < 0) 8345 error (_("Hardware breakpoints used exceeds limit.")); 8346 8347 arg = skip_spaces (arg); 8348 if (arg == NULL || arg[0] == '\0') 8349 error(_("No address range specified.")); 8350 8351 init_linespec_result (&canonical_start); 8352 8353 arg_start = arg; 8354 parse_breakpoint_sals (&arg, &canonical_start); 8355 8356 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); 8357 8358 if (arg[0] != ',') 8359 error (_("Too few arguments.")); 8360 else if (VEC_empty (linespec_sals, canonical_start.sals)) 8361 error (_("Could not find location of the beginning of the range.")); 8362 8363 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); 8364 8365 if (VEC_length (linespec_sals, canonical_start.sals) > 1 8366 || lsal_start->sals.nelts != 1) 8367 error (_("Cannot create a ranged breakpoint with multiple locations.")); 8368 8369 sal_start = lsal_start->sals.sals[0]; 8370 addr_string_start = savestring (arg_start, arg - arg_start); 8371 make_cleanup (xfree, addr_string_start); 8372 8373 arg++; /* Skip the comma. */ 8374 arg = skip_spaces (arg); 8375 8376 /* Parse the end location. */ 8377 8378 init_linespec_result (&canonical_end); 8379 arg_start = arg; 8380 8381 /* We call decode_line_full directly here instead of using 8382 parse_breakpoint_sals because we need to specify the start location's 8383 symtab and line as the default symtab and line for the end of the 8384 range. This makes it possible to have ranges like "foo.c:27, +14", 8385 where +14 means 14 lines from the start location. */ 8386 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, 8387 sal_start.symtab, sal_start.line, 8388 &canonical_end, NULL, NULL); 8389 8390 make_cleanup_destroy_linespec_result (&canonical_end); 8391 8392 if (VEC_empty (linespec_sals, canonical_end.sals)) 8393 error (_("Could not find location of the end of the range.")); 8394 8395 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); 8396 if (VEC_length (linespec_sals, canonical_end.sals) > 1 8397 || lsal_end->sals.nelts != 1) 8398 error (_("Cannot create a ranged breakpoint with multiple locations.")); 8399 8400 sal_end = lsal_end->sals.sals[0]; 8401 addr_string_end = savestring (arg_start, arg - arg_start); 8402 make_cleanup (xfree, addr_string_end); 8403 8404 end = find_breakpoint_range_end (sal_end); 8405 if (sal_start.pc > end) 8406 error (_("Invalid address range, end precedes start.")); 8407 8408 length = end - sal_start.pc + 1; 8409 if (length < 0) 8410 /* Length overflowed. */ 8411 error (_("Address range too large.")); 8412 else if (length == 1) 8413 { 8414 /* This range is simple enough to be handled by 8415 the `hbreak' command. */ 8416 hbreak_command (addr_string_start, 1); 8417 8418 do_cleanups (cleanup_bkpt); 8419 8420 return; 8421 } 8422 8423 /* Now set up the breakpoint. */ 8424 b = set_raw_breakpoint (get_current_arch (), sal_start, 8425 bp_hardware_breakpoint, &ranged_breakpoint_ops); 8426 set_breakpoint_count (breakpoint_count + 1); 8427 b->number = breakpoint_count; 8428 b->disposition = disp_donttouch; 8429 b->addr_string = xstrdup (addr_string_start); 8430 b->addr_string_range_end = xstrdup (addr_string_end); 8431 b->loc->length = length; 8432 8433 do_cleanups (cleanup_bkpt); 8434 8435 mention (b); 8436 observer_notify_breakpoint_created (b); 8437 update_global_location_list (1); 8438 } 8439 8440 /* Return non-zero if EXP is verified as constant. Returned zero 8441 means EXP is variable. Also the constant detection may fail for 8442 some constant expressions and in such case still falsely return 8443 zero. */ 8444 static int 8445 watchpoint_exp_is_const (const struct expression *exp) 8446 { 8447 int i = exp->nelts; 8448 8449 while (i > 0) 8450 { 8451 int oplenp, argsp; 8452 8453 /* We are only interested in the descriptor of each element. */ 8454 operator_length (exp, i, &oplenp, &argsp); 8455 i -= oplenp; 8456 8457 switch (exp->elts[i].opcode) 8458 { 8459 case BINOP_ADD: 8460 case BINOP_SUB: 8461 case BINOP_MUL: 8462 case BINOP_DIV: 8463 case BINOP_REM: 8464 case BINOP_MOD: 8465 case BINOP_LSH: 8466 case BINOP_RSH: 8467 case BINOP_LOGICAL_AND: 8468 case BINOP_LOGICAL_OR: 8469 case BINOP_BITWISE_AND: 8470 case BINOP_BITWISE_IOR: 8471 case BINOP_BITWISE_XOR: 8472 case BINOP_EQUAL: 8473 case BINOP_NOTEQUAL: 8474 case BINOP_LESS: 8475 case BINOP_GTR: 8476 case BINOP_LEQ: 8477 case BINOP_GEQ: 8478 case BINOP_REPEAT: 8479 case BINOP_COMMA: 8480 case BINOP_EXP: 8481 case BINOP_MIN: 8482 case BINOP_MAX: 8483 case BINOP_INTDIV: 8484 case BINOP_CONCAT: 8485 case BINOP_IN: 8486 case BINOP_RANGE: 8487 case TERNOP_COND: 8488 case TERNOP_SLICE: 8489 case TERNOP_SLICE_COUNT: 8490 8491 case OP_LONG: 8492 case OP_DOUBLE: 8493 case OP_DECFLOAT: 8494 case OP_LAST: 8495 case OP_COMPLEX: 8496 case OP_STRING: 8497 case OP_BITSTRING: 8498 case OP_ARRAY: 8499 case OP_TYPE: 8500 case OP_NAME: 8501 case OP_OBJC_NSSTRING: 8502 8503 case UNOP_NEG: 8504 case UNOP_LOGICAL_NOT: 8505 case UNOP_COMPLEMENT: 8506 case UNOP_ADDR: 8507 case UNOP_HIGH: 8508 /* Unary, binary and ternary operators: We have to check 8509 their operands. If they are constant, then so is the 8510 result of that operation. For instance, if A and B are 8511 determined to be constants, then so is "A + B". 8512 8513 UNOP_IND is one exception to the rule above, because the 8514 value of *ADDR is not necessarily a constant, even when 8515 ADDR is. */ 8516 break; 8517 8518 case OP_VAR_VALUE: 8519 /* Check whether the associated symbol is a constant. 8520 8521 We use SYMBOL_CLASS rather than TYPE_CONST because it's 8522 possible that a buggy compiler could mark a variable as 8523 constant even when it is not, and TYPE_CONST would return 8524 true in this case, while SYMBOL_CLASS wouldn't. 8525 8526 We also have to check for function symbols because they 8527 are always constant. */ 8528 { 8529 struct symbol *s = exp->elts[i + 2].symbol; 8530 8531 if (SYMBOL_CLASS (s) != LOC_BLOCK 8532 && SYMBOL_CLASS (s) != LOC_CONST 8533 && SYMBOL_CLASS (s) != LOC_CONST_BYTES) 8534 return 0; 8535 break; 8536 } 8537 8538 /* The default action is to return 0 because we are using 8539 the optimistic approach here: If we don't know something, 8540 then it is not a constant. */ 8541 default: 8542 return 0; 8543 } 8544 } 8545 8546 return 1; 8547 } 8548 8549 /* Implement the "dtor" breakpoint_ops method for watchpoints. */ 8550 8551 static void 8552 dtor_watchpoint (struct breakpoint *self) 8553 { 8554 struct watchpoint *w = (struct watchpoint *) self; 8555 8556 xfree (w->cond_exp); 8557 xfree (w->exp); 8558 xfree (w->exp_string); 8559 xfree (w->exp_string_reparse); 8560 value_free (w->val); 8561 8562 base_breakpoint_ops.dtor (self); 8563 } 8564 8565 /* Implement the "re_set" breakpoint_ops method for watchpoints. */ 8566 8567 static void 8568 re_set_watchpoint (struct breakpoint *b) 8569 { 8570 struct watchpoint *w = (struct watchpoint *) b; 8571 8572 /* Watchpoint can be either on expression using entirely global 8573 variables, or it can be on local variables. 8574 8575 Watchpoints of the first kind are never auto-deleted, and even 8576 persist across program restarts. Since they can use variables 8577 from shared libraries, we need to reparse expression as libraries 8578 are loaded and unloaded. 8579 8580 Watchpoints on local variables can also change meaning as result 8581 of solib event. For example, if a watchpoint uses both a local 8582 and a global variables in expression, it's a local watchpoint, 8583 but unloading of a shared library will make the expression 8584 invalid. This is not a very common use case, but we still 8585 re-evaluate expression, to avoid surprises to the user. 8586 8587 Note that for local watchpoints, we re-evaluate it only if 8588 watchpoints frame id is still valid. If it's not, it means the 8589 watchpoint is out of scope and will be deleted soon. In fact, 8590 I'm not sure we'll ever be called in this case. 8591 8592 If a local watchpoint's frame id is still valid, then 8593 w->exp_valid_block is likewise valid, and we can safely use it. 8594 8595 Don't do anything about disabled watchpoints, since they will be 8596 reevaluated again when enabled. */ 8597 update_watchpoint (w, 1 /* reparse */); 8598 } 8599 8600 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ 8601 8602 static int 8603 insert_watchpoint (struct bp_location *bl) 8604 { 8605 struct watchpoint *w = (struct watchpoint *) bl->owner; 8606 int length = w->exact ? 1 : bl->length; 8607 8608 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, 8609 w->cond_exp); 8610 } 8611 8612 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ 8613 8614 static int 8615 remove_watchpoint (struct bp_location *bl) 8616 { 8617 struct watchpoint *w = (struct watchpoint *) bl->owner; 8618 int length = w->exact ? 1 : bl->length; 8619 8620 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, 8621 w->cond_exp); 8622 } 8623 8624 static int 8625 breakpoint_hit_watchpoint (const struct bp_location *bl, 8626 struct address_space *aspace, CORE_ADDR bp_addr) 8627 { 8628 struct breakpoint *b = bl->owner; 8629 struct watchpoint *w = (struct watchpoint *) b; 8630 8631 /* Continuable hardware watchpoints are treated as non-existent if the 8632 reason we stopped wasn't a hardware watchpoint (we didn't stop on 8633 some data address). Otherwise gdb won't stop on a break instruction 8634 in the code (not from a breakpoint) when a hardware watchpoint has 8635 been defined. Also skip watchpoints which we know did not trigger 8636 (did not match the data address). */ 8637 if (is_hardware_watchpoint (b) 8638 && w->watchpoint_triggered == watch_triggered_no) 8639 return 0; 8640 8641 return 1; 8642 } 8643 8644 static void 8645 check_status_watchpoint (bpstat bs) 8646 { 8647 gdb_assert (is_watchpoint (bs->breakpoint_at)); 8648 8649 bpstat_check_watchpoint (bs); 8650 } 8651 8652 /* Implement the "resources_needed" breakpoint_ops method for 8653 hardware watchpoints. */ 8654 8655 static int 8656 resources_needed_watchpoint (const struct bp_location *bl) 8657 { 8658 struct watchpoint *w = (struct watchpoint *) bl->owner; 8659 int length = w->exact? 1 : bl->length; 8660 8661 return target_region_ok_for_hw_watchpoint (bl->address, length); 8662 } 8663 8664 /* Implement the "works_in_software_mode" breakpoint_ops method for 8665 hardware watchpoints. */ 8666 8667 static int 8668 works_in_software_mode_watchpoint (const struct breakpoint *b) 8669 { 8670 /* Read and access watchpoints only work with hardware support. */ 8671 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; 8672 } 8673 8674 static enum print_stop_action 8675 print_it_watchpoint (bpstat bs) 8676 { 8677 struct cleanup *old_chain; 8678 struct breakpoint *b; 8679 const struct bp_location *bl; 8680 struct ui_stream *stb; 8681 enum print_stop_action result; 8682 struct watchpoint *w; 8683 struct ui_out *uiout = current_uiout; 8684 8685 gdb_assert (bs->bp_location_at != NULL); 8686 8687 bl = bs->bp_location_at; 8688 b = bs->breakpoint_at; 8689 w = (struct watchpoint *) b; 8690 8691 stb = ui_out_stream_new (uiout); 8692 old_chain = make_cleanup_ui_out_stream_delete (stb); 8693 8694 switch (b->type) 8695 { 8696 case bp_watchpoint: 8697 case bp_hardware_watchpoint: 8698 annotate_watchpoint (b->number); 8699 if (ui_out_is_mi_like_p (uiout)) 8700 ui_out_field_string 8701 (uiout, "reason", 8702 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); 8703 mention (b); 8704 make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 8705 ui_out_text (uiout, "\nOld value = "); 8706 watchpoint_value_print (bs->old_val, stb->stream); 8707 ui_out_field_stream (uiout, "old", stb); 8708 ui_out_text (uiout, "\nNew value = "); 8709 watchpoint_value_print (w->val, stb->stream); 8710 ui_out_field_stream (uiout, "new", stb); 8711 ui_out_text (uiout, "\n"); 8712 /* More than one watchpoint may have been triggered. */ 8713 result = PRINT_UNKNOWN; 8714 break; 8715 8716 case bp_read_watchpoint: 8717 if (ui_out_is_mi_like_p (uiout)) 8718 ui_out_field_string 8719 (uiout, "reason", 8720 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); 8721 mention (b); 8722 make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 8723 ui_out_text (uiout, "\nValue = "); 8724 watchpoint_value_print (w->val, stb->stream); 8725 ui_out_field_stream (uiout, "value", stb); 8726 ui_out_text (uiout, "\n"); 8727 result = PRINT_UNKNOWN; 8728 break; 8729 8730 case bp_access_watchpoint: 8731 if (bs->old_val != NULL) 8732 { 8733 annotate_watchpoint (b->number); 8734 if (ui_out_is_mi_like_p (uiout)) 8735 ui_out_field_string 8736 (uiout, "reason", 8737 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); 8738 mention (b); 8739 make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 8740 ui_out_text (uiout, "\nOld value = "); 8741 watchpoint_value_print (bs->old_val, stb->stream); 8742 ui_out_field_stream (uiout, "old", stb); 8743 ui_out_text (uiout, "\nNew value = "); 8744 } 8745 else 8746 { 8747 mention (b); 8748 if (ui_out_is_mi_like_p (uiout)) 8749 ui_out_field_string 8750 (uiout, "reason", 8751 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); 8752 make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 8753 ui_out_text (uiout, "\nValue = "); 8754 } 8755 watchpoint_value_print (w->val, stb->stream); 8756 ui_out_field_stream (uiout, "new", stb); 8757 ui_out_text (uiout, "\n"); 8758 result = PRINT_UNKNOWN; 8759 break; 8760 default: 8761 result = PRINT_UNKNOWN; 8762 } 8763 8764 do_cleanups (old_chain); 8765 return result; 8766 } 8767 8768 /* Implement the "print_mention" breakpoint_ops method for hardware 8769 watchpoints. */ 8770 8771 static void 8772 print_mention_watchpoint (struct breakpoint *b) 8773 { 8774 struct cleanup *ui_out_chain; 8775 struct watchpoint *w = (struct watchpoint *) b; 8776 struct ui_out *uiout = current_uiout; 8777 8778 switch (b->type) 8779 { 8780 case bp_watchpoint: 8781 ui_out_text (uiout, "Watchpoint "); 8782 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); 8783 break; 8784 case bp_hardware_watchpoint: 8785 ui_out_text (uiout, "Hardware watchpoint "); 8786 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); 8787 break; 8788 case bp_read_watchpoint: 8789 ui_out_text (uiout, "Hardware read watchpoint "); 8790 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); 8791 break; 8792 case bp_access_watchpoint: 8793 ui_out_text (uiout, "Hardware access (read/write) watchpoint "); 8794 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); 8795 break; 8796 default: 8797 internal_error (__FILE__, __LINE__, 8798 _("Invalid hardware watchpoint type.")); 8799 } 8800 8801 ui_out_field_int (uiout, "number", b->number); 8802 ui_out_text (uiout, ": "); 8803 ui_out_field_string (uiout, "exp", w->exp_string); 8804 do_cleanups (ui_out_chain); 8805 } 8806 8807 /* Implement the "print_recreate" breakpoint_ops method for 8808 watchpoints. */ 8809 8810 static void 8811 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) 8812 { 8813 struct watchpoint *w = (struct watchpoint *) b; 8814 8815 switch (b->type) 8816 { 8817 case bp_watchpoint: 8818 case bp_hardware_watchpoint: 8819 fprintf_unfiltered (fp, "watch"); 8820 break; 8821 case bp_read_watchpoint: 8822 fprintf_unfiltered (fp, "rwatch"); 8823 break; 8824 case bp_access_watchpoint: 8825 fprintf_unfiltered (fp, "awatch"); 8826 break; 8827 default: 8828 internal_error (__FILE__, __LINE__, 8829 _("Invalid watchpoint type.")); 8830 } 8831 8832 fprintf_unfiltered (fp, " %s", w->exp_string); 8833 print_recreate_thread (b, fp); 8834 } 8835 8836 /* The breakpoint_ops structure to be used in hardware watchpoints. */ 8837 8838 static struct breakpoint_ops watchpoint_breakpoint_ops; 8839 8840 /* Implement the "insert" breakpoint_ops method for 8841 masked hardware watchpoints. */ 8842 8843 static int 8844 insert_masked_watchpoint (struct bp_location *bl) 8845 { 8846 struct watchpoint *w = (struct watchpoint *) bl->owner; 8847 8848 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, 8849 bl->watchpoint_type); 8850 } 8851 8852 /* Implement the "remove" breakpoint_ops method for 8853 masked hardware watchpoints. */ 8854 8855 static int 8856 remove_masked_watchpoint (struct bp_location *bl) 8857 { 8858 struct watchpoint *w = (struct watchpoint *) bl->owner; 8859 8860 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, 8861 bl->watchpoint_type); 8862 } 8863 8864 /* Implement the "resources_needed" breakpoint_ops method for 8865 masked hardware watchpoints. */ 8866 8867 static int 8868 resources_needed_masked_watchpoint (const struct bp_location *bl) 8869 { 8870 struct watchpoint *w = (struct watchpoint *) bl->owner; 8871 8872 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); 8873 } 8874 8875 /* Implement the "works_in_software_mode" breakpoint_ops method for 8876 masked hardware watchpoints. */ 8877 8878 static int 8879 works_in_software_mode_masked_watchpoint (const struct breakpoint *b) 8880 { 8881 return 0; 8882 } 8883 8884 /* Implement the "print_it" breakpoint_ops method for 8885 masked hardware watchpoints. */ 8886 8887 static enum print_stop_action 8888 print_it_masked_watchpoint (bpstat bs) 8889 { 8890 struct breakpoint *b = bs->breakpoint_at; 8891 struct ui_out *uiout = current_uiout; 8892 8893 /* Masked watchpoints have only one location. */ 8894 gdb_assert (b->loc && b->loc->next == NULL); 8895 8896 switch (b->type) 8897 { 8898 case bp_hardware_watchpoint: 8899 annotate_watchpoint (b->number); 8900 if (ui_out_is_mi_like_p (uiout)) 8901 ui_out_field_string 8902 (uiout, "reason", 8903 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); 8904 break; 8905 8906 case bp_read_watchpoint: 8907 if (ui_out_is_mi_like_p (uiout)) 8908 ui_out_field_string 8909 (uiout, "reason", 8910 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); 8911 break; 8912 8913 case bp_access_watchpoint: 8914 if (ui_out_is_mi_like_p (uiout)) 8915 ui_out_field_string 8916 (uiout, "reason", 8917 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); 8918 break; 8919 default: 8920 internal_error (__FILE__, __LINE__, 8921 _("Invalid hardware watchpoint type.")); 8922 } 8923 8924 mention (b); 8925 ui_out_text (uiout, _("\n\ 8926 Check the underlying instruction at PC for the memory\n\ 8927 address and value which triggered this watchpoint.\n")); 8928 ui_out_text (uiout, "\n"); 8929 8930 /* More than one watchpoint may have been triggered. */ 8931 return PRINT_UNKNOWN; 8932 } 8933 8934 /* Implement the "print_one_detail" breakpoint_ops method for 8935 masked hardware watchpoints. */ 8936 8937 static void 8938 print_one_detail_masked_watchpoint (const struct breakpoint *b, 8939 struct ui_out *uiout) 8940 { 8941 struct watchpoint *w = (struct watchpoint *) b; 8942 8943 /* Masked watchpoints have only one location. */ 8944 gdb_assert (b->loc && b->loc->next == NULL); 8945 8946 ui_out_text (uiout, "\tmask "); 8947 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); 8948 ui_out_text (uiout, "\n"); 8949 } 8950 8951 /* Implement the "print_mention" breakpoint_ops method for 8952 masked hardware watchpoints. */ 8953 8954 static void 8955 print_mention_masked_watchpoint (struct breakpoint *b) 8956 { 8957 struct watchpoint *w = (struct watchpoint *) b; 8958 struct ui_out *uiout = current_uiout; 8959 struct cleanup *ui_out_chain; 8960 8961 switch (b->type) 8962 { 8963 case bp_hardware_watchpoint: 8964 ui_out_text (uiout, "Masked hardware watchpoint "); 8965 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); 8966 break; 8967 case bp_read_watchpoint: 8968 ui_out_text (uiout, "Masked hardware read watchpoint "); 8969 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); 8970 break; 8971 case bp_access_watchpoint: 8972 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); 8973 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); 8974 break; 8975 default: 8976 internal_error (__FILE__, __LINE__, 8977 _("Invalid hardware watchpoint type.")); 8978 } 8979 8980 ui_out_field_int (uiout, "number", b->number); 8981 ui_out_text (uiout, ": "); 8982 ui_out_field_string (uiout, "exp", w->exp_string); 8983 do_cleanups (ui_out_chain); 8984 } 8985 8986 /* Implement the "print_recreate" breakpoint_ops method for 8987 masked hardware watchpoints. */ 8988 8989 static void 8990 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) 8991 { 8992 struct watchpoint *w = (struct watchpoint *) b; 8993 char tmp[40]; 8994 8995 switch (b->type) 8996 { 8997 case bp_hardware_watchpoint: 8998 fprintf_unfiltered (fp, "watch"); 8999 break; 9000 case bp_read_watchpoint: 9001 fprintf_unfiltered (fp, "rwatch"); 9002 break; 9003 case bp_access_watchpoint: 9004 fprintf_unfiltered (fp, "awatch"); 9005 break; 9006 default: 9007 internal_error (__FILE__, __LINE__, 9008 _("Invalid hardware watchpoint type.")); 9009 } 9010 9011 sprintf_vma (tmp, w->hw_wp_mask); 9012 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); 9013 print_recreate_thread (b, fp); 9014 } 9015 9016 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ 9017 9018 static struct breakpoint_ops masked_watchpoint_breakpoint_ops; 9019 9020 /* Tell whether the given watchpoint is a masked hardware watchpoint. */ 9021 9022 static int 9023 is_masked_watchpoint (const struct breakpoint *b) 9024 { 9025 return b->ops == &masked_watchpoint_breakpoint_ops; 9026 } 9027 9028 /* accessflag: hw_write: watch write, 9029 hw_read: watch read, 9030 hw_access: watch access (read or write) */ 9031 static void 9032 watch_command_1 (char *arg, int accessflag, int from_tty, 9033 int just_location, int internal) 9034 { 9035 volatile struct gdb_exception e; 9036 struct breakpoint *b, *scope_breakpoint = NULL; 9037 struct expression *exp; 9038 struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; 9039 struct value *val, *mark, *result; 9040 struct frame_info *frame; 9041 char *exp_start = NULL; 9042 char *exp_end = NULL; 9043 char *tok, *end_tok; 9044 int toklen = -1; 9045 char *cond_start = NULL; 9046 char *cond_end = NULL; 9047 enum bptype bp_type; 9048 int thread = -1; 9049 int pc = 0; 9050 /* Flag to indicate whether we are going to use masks for 9051 the hardware watchpoint. */ 9052 int use_mask = 0; 9053 CORE_ADDR mask = 0; 9054 struct watchpoint *w; 9055 9056 /* Make sure that we actually have parameters to parse. */ 9057 if (arg != NULL && arg[0] != '\0') 9058 { 9059 char *value_start; 9060 9061 /* Look for "parameter value" pairs at the end 9062 of the arguments string. */ 9063 for (tok = arg + strlen (arg) - 1; tok > arg; tok--) 9064 { 9065 /* Skip whitespace at the end of the argument list. */ 9066 while (tok > arg && (*tok == ' ' || *tok == '\t')) 9067 tok--; 9068 9069 /* Find the beginning of the last token. 9070 This is the value of the parameter. */ 9071 while (tok > arg && (*tok != ' ' && *tok != '\t')) 9072 tok--; 9073 value_start = tok + 1; 9074 9075 /* Skip whitespace. */ 9076 while (tok > arg && (*tok == ' ' || *tok == '\t')) 9077 tok--; 9078 9079 end_tok = tok; 9080 9081 /* Find the beginning of the second to last token. 9082 This is the parameter itself. */ 9083 while (tok > arg && (*tok != ' ' && *tok != '\t')) 9084 tok--; 9085 tok++; 9086 toklen = end_tok - tok + 1; 9087 9088 if (toklen == 6 && !strncmp (tok, "thread", 6)) 9089 { 9090 /* At this point we've found a "thread" token, which means 9091 the user is trying to set a watchpoint that triggers 9092 only in a specific thread. */ 9093 char *endp; 9094 9095 if (thread != -1) 9096 error(_("You can specify only one thread.")); 9097 9098 /* Extract the thread ID from the next token. */ 9099 thread = strtol (value_start, &endp, 0); 9100 9101 /* Check if the user provided a valid numeric value for the 9102 thread ID. */ 9103 if (*endp != ' ' && *endp != '\t' && *endp != '\0') 9104 error (_("Invalid thread ID specification %s."), value_start); 9105 9106 /* Check if the thread actually exists. */ 9107 if (!valid_thread_id (thread)) 9108 error (_("Unknown thread %d."), thread); 9109 } 9110 else if (toklen == 4 && !strncmp (tok, "mask", 4)) 9111 { 9112 /* We've found a "mask" token, which means the user wants to 9113 create a hardware watchpoint that is going to have the mask 9114 facility. */ 9115 struct value *mask_value, *mark; 9116 9117 if (use_mask) 9118 error(_("You can specify only one mask.")); 9119 9120 use_mask = just_location = 1; 9121 9122 mark = value_mark (); 9123 mask_value = parse_to_comma_and_eval (&value_start); 9124 mask = value_as_address (mask_value); 9125 value_free_to_mark (mark); 9126 } 9127 else 9128 /* We didn't recognize what we found. We should stop here. */ 9129 break; 9130 9131 /* Truncate the string and get rid of the "parameter value" pair before 9132 the arguments string is parsed by the parse_exp_1 function. */ 9133 *tok = '\0'; 9134 } 9135 } 9136 9137 /* Parse the rest of the arguments. */ 9138 innermost_block = NULL; 9139 exp_start = arg; 9140 exp = parse_exp_1 (&arg, 0, 0); 9141 exp_end = arg; 9142 /* Remove trailing whitespace from the expression before saving it. 9143 This makes the eventual display of the expression string a bit 9144 prettier. */ 9145 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) 9146 --exp_end; 9147 9148 /* Checking if the expression is not constant. */ 9149 if (watchpoint_exp_is_const (exp)) 9150 { 9151 int len; 9152 9153 len = exp_end - exp_start; 9154 while (len > 0 && isspace (exp_start[len - 1])) 9155 len--; 9156 error (_("Cannot watch constant value `%.*s'."), len, exp_start); 9157 } 9158 9159 exp_valid_block = innermost_block; 9160 mark = value_mark (); 9161 fetch_subexp_value (exp, &pc, &val, &result, NULL); 9162 9163 if (just_location) 9164 { 9165 int ret; 9166 9167 exp_valid_block = NULL; 9168 val = value_addr (result); 9169 release_value (val); 9170 value_free_to_mark (mark); 9171 9172 if (use_mask) 9173 { 9174 ret = target_masked_watch_num_registers (value_as_address (val), 9175 mask); 9176 if (ret == -1) 9177 error (_("This target does not support masked watchpoints.")); 9178 else if (ret == -2) 9179 error (_("Invalid mask or memory region.")); 9180 } 9181 } 9182 else if (val != NULL) 9183 release_value (val); 9184 9185 tok = skip_spaces (arg); 9186 end_tok = skip_to_space (tok); 9187 9188 toklen = end_tok - tok; 9189 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) 9190 { 9191 struct expression *cond; 9192 9193 innermost_block = NULL; 9194 tok = cond_start = end_tok + 1; 9195 cond = parse_exp_1 (&tok, 0, 0); 9196 9197 /* The watchpoint expression may not be local, but the condition 9198 may still be. E.g.: `watch global if local > 0'. */ 9199 cond_exp_valid_block = innermost_block; 9200 9201 xfree (cond); 9202 cond_end = tok; 9203 } 9204 if (*tok) 9205 error (_("Junk at end of command.")); 9206 9207 if (accessflag == hw_read) 9208 bp_type = bp_read_watchpoint; 9209 else if (accessflag == hw_access) 9210 bp_type = bp_access_watchpoint; 9211 else 9212 bp_type = bp_hardware_watchpoint; 9213 9214 frame = block_innermost_frame (exp_valid_block); 9215 9216 /* If the expression is "local", then set up a "watchpoint scope" 9217 breakpoint at the point where we've left the scope of the watchpoint 9218 expression. Create the scope breakpoint before the watchpoint, so 9219 that we will encounter it first in bpstat_stop_status. */ 9220 if (exp_valid_block && frame) 9221 { 9222 if (frame_id_p (frame_unwind_caller_id (frame))) 9223 { 9224 scope_breakpoint 9225 = create_internal_breakpoint (frame_unwind_caller_arch (frame), 9226 frame_unwind_caller_pc (frame), 9227 bp_watchpoint_scope, 9228 &momentary_breakpoint_ops); 9229 9230 scope_breakpoint->enable_state = bp_enabled; 9231 9232 /* Automatically delete the breakpoint when it hits. */ 9233 scope_breakpoint->disposition = disp_del; 9234 9235 /* Only break in the proper frame (help with recursion). */ 9236 scope_breakpoint->frame_id = frame_unwind_caller_id (frame); 9237 9238 /* Set the address at which we will stop. */ 9239 scope_breakpoint->loc->gdbarch 9240 = frame_unwind_caller_arch (frame); 9241 scope_breakpoint->loc->requested_address 9242 = frame_unwind_caller_pc (frame); 9243 scope_breakpoint->loc->address 9244 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, 9245 scope_breakpoint->loc->requested_address, 9246 scope_breakpoint->type); 9247 } 9248 } 9249 9250 /* Now set up the breakpoint. */ 9251 9252 w = XCNEW (struct watchpoint); 9253 b = &w->base; 9254 if (use_mask) 9255 init_raw_breakpoint_without_location (b, NULL, bp_type, 9256 &masked_watchpoint_breakpoint_ops); 9257 else 9258 init_raw_breakpoint_without_location (b, NULL, bp_type, 9259 &watchpoint_breakpoint_ops); 9260 b->thread = thread; 9261 b->disposition = disp_donttouch; 9262 b->pspace = current_program_space; 9263 w->exp = exp; 9264 w->exp_valid_block = exp_valid_block; 9265 w->cond_exp_valid_block = cond_exp_valid_block; 9266 if (just_location) 9267 { 9268 struct type *t = value_type (val); 9269 CORE_ADDR addr = value_as_address (val); 9270 char *name; 9271 9272 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); 9273 name = type_to_string (t); 9274 9275 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, 9276 core_addr_to_string (addr)); 9277 xfree (name); 9278 9279 w->exp_string = xstrprintf ("-location %.*s", 9280 (int) (exp_end - exp_start), exp_start); 9281 9282 /* The above expression is in C. */ 9283 b->language = language_c; 9284 } 9285 else 9286 w->exp_string = savestring (exp_start, exp_end - exp_start); 9287 9288 if (use_mask) 9289 { 9290 w->hw_wp_mask = mask; 9291 } 9292 else 9293 { 9294 w->val = val; 9295 w->val_valid = 1; 9296 } 9297 9298 if (cond_start) 9299 b->cond_string = savestring (cond_start, cond_end - cond_start); 9300 else 9301 b->cond_string = 0; 9302 9303 if (frame) 9304 { 9305 w->watchpoint_frame = get_frame_id (frame); 9306 w->watchpoint_thread = inferior_ptid; 9307 } 9308 else 9309 { 9310 w->watchpoint_frame = null_frame_id; 9311 w->watchpoint_thread = null_ptid; 9312 } 9313 9314 if (scope_breakpoint != NULL) 9315 { 9316 /* The scope breakpoint is related to the watchpoint. We will 9317 need to act on them together. */ 9318 b->related_breakpoint = scope_breakpoint; 9319 scope_breakpoint->related_breakpoint = b; 9320 } 9321 9322 if (!just_location) 9323 value_free_to_mark (mark); 9324 9325 TRY_CATCH (e, RETURN_MASK_ALL) 9326 { 9327 /* Finally update the new watchpoint. This creates the locations 9328 that should be inserted. */ 9329 update_watchpoint (w, 1); 9330 } 9331 if (e.reason < 0) 9332 { 9333 delete_breakpoint (b); 9334 throw_exception (e); 9335 } 9336 9337 install_breakpoint (internal, b, 1); 9338 } 9339 9340 /* Return count of debug registers needed to watch the given expression. 9341 If the watchpoint cannot be handled in hardware return zero. */ 9342 9343 static int 9344 can_use_hardware_watchpoint (struct value *v) 9345 { 9346 int found_memory_cnt = 0; 9347 struct value *head = v; 9348 9349 /* Did the user specifically forbid us to use hardware watchpoints? */ 9350 if (!can_use_hw_watchpoints) 9351 return 0; 9352 9353 /* Make sure that the value of the expression depends only upon 9354 memory contents, and values computed from them within GDB. If we 9355 find any register references or function calls, we can't use a 9356 hardware watchpoint. 9357 9358 The idea here is that evaluating an expression generates a series 9359 of values, one holding the value of every subexpression. (The 9360 expression a*b+c has five subexpressions: a, b, a*b, c, and 9361 a*b+c.) GDB's values hold almost enough information to establish 9362 the criteria given above --- they identify memory lvalues, 9363 register lvalues, computed values, etcetera. So we can evaluate 9364 the expression, and then scan the chain of values that leaves 9365 behind to decide whether we can detect any possible change to the 9366 expression's final value using only hardware watchpoints. 9367 9368 However, I don't think that the values returned by inferior 9369 function calls are special in any way. So this function may not 9370 notice that an expression involving an inferior function call 9371 can't be watched with hardware watchpoints. FIXME. */ 9372 for (; v; v = value_next (v)) 9373 { 9374 if (VALUE_LVAL (v) == lval_memory) 9375 { 9376 if (v != head && value_lazy (v)) 9377 /* A lazy memory lvalue in the chain is one that GDB never 9378 needed to fetch; we either just used its address (e.g., 9379 `a' in `a.b') or we never needed it at all (e.g., `a' 9380 in `a,b'). This doesn't apply to HEAD; if that is 9381 lazy then it was not readable, but watch it anyway. */ 9382 ; 9383 else 9384 { 9385 /* Ahh, memory we actually used! Check if we can cover 9386 it with hardware watchpoints. */ 9387 struct type *vtype = check_typedef (value_type (v)); 9388 9389 /* We only watch structs and arrays if user asked for it 9390 explicitly, never if they just happen to appear in a 9391 middle of some value chain. */ 9392 if (v == head 9393 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT 9394 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) 9395 { 9396 CORE_ADDR vaddr = value_address (v); 9397 int len; 9398 int num_regs; 9399 9400 len = (target_exact_watchpoints 9401 && is_scalar_type_recursive (vtype))? 9402 1 : TYPE_LENGTH (value_type (v)); 9403 9404 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); 9405 if (!num_regs) 9406 return 0; 9407 else 9408 found_memory_cnt += num_regs; 9409 } 9410 } 9411 } 9412 else if (VALUE_LVAL (v) != not_lval 9413 && deprecated_value_modifiable (v) == 0) 9414 return 0; /* These are values from the history (e.g., $1). */ 9415 else if (VALUE_LVAL (v) == lval_register) 9416 return 0; /* Cannot watch a register with a HW watchpoint. */ 9417 } 9418 9419 /* The expression itself looks suitable for using a hardware 9420 watchpoint, but give the target machine a chance to reject it. */ 9421 return found_memory_cnt; 9422 } 9423 9424 void 9425 watch_command_wrapper (char *arg, int from_tty, int internal) 9426 { 9427 watch_command_1 (arg, hw_write, from_tty, 0, internal); 9428 } 9429 9430 /* A helper function that looks for an argument at the start of a 9431 string. The argument must also either be at the end of the string, 9432 or be followed by whitespace. Returns 1 if it finds the argument, 9433 0 otherwise. If the argument is found, it updates *STR. */ 9434 9435 static int 9436 check_for_argument (char **str, char *arg, int arg_len) 9437 { 9438 if (strncmp (*str, arg, arg_len) == 0 9439 && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) 9440 { 9441 *str += arg_len; 9442 return 1; 9443 } 9444 return 0; 9445 } 9446 9447 /* A helper function that looks for the "-location" argument and then 9448 calls watch_command_1. */ 9449 9450 static void 9451 watch_maybe_just_location (char *arg, int accessflag, int from_tty) 9452 { 9453 int just_location = 0; 9454 9455 if (arg 9456 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) 9457 || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) 9458 { 9459 arg = skip_spaces (arg); 9460 just_location = 1; 9461 } 9462 9463 watch_command_1 (arg, accessflag, from_tty, just_location, 0); 9464 } 9465 9466 static void 9467 watch_command (char *arg, int from_tty) 9468 { 9469 watch_maybe_just_location (arg, hw_write, from_tty); 9470 } 9471 9472 void 9473 rwatch_command_wrapper (char *arg, int from_tty, int internal) 9474 { 9475 watch_command_1 (arg, hw_read, from_tty, 0, internal); 9476 } 9477 9478 static void 9479 rwatch_command (char *arg, int from_tty) 9480 { 9481 watch_maybe_just_location (arg, hw_read, from_tty); 9482 } 9483 9484 void 9485 awatch_command_wrapper (char *arg, int from_tty, int internal) 9486 { 9487 watch_command_1 (arg, hw_access, from_tty, 0, internal); 9488 } 9489 9490 static void 9491 awatch_command (char *arg, int from_tty) 9492 { 9493 watch_maybe_just_location (arg, hw_access, from_tty); 9494 } 9495 9496 9497 /* Helper routines for the until_command routine in infcmd.c. Here 9498 because it uses the mechanisms of breakpoints. */ 9499 9500 struct until_break_command_continuation_args 9501 { 9502 struct breakpoint *breakpoint; 9503 struct breakpoint *breakpoint2; 9504 int thread_num; 9505 }; 9506 9507 /* This function is called by fetch_inferior_event via the 9508 cmd_continuation pointer, to complete the until command. It takes 9509 care of cleaning up the temporary breakpoints set up by the until 9510 command. */ 9511 static void 9512 until_break_command_continuation (void *arg, int err) 9513 { 9514 struct until_break_command_continuation_args *a = arg; 9515 9516 delete_breakpoint (a->breakpoint); 9517 if (a->breakpoint2) 9518 delete_breakpoint (a->breakpoint2); 9519 delete_longjmp_breakpoint (a->thread_num); 9520 } 9521 9522 void 9523 until_break_command (char *arg, int from_tty, int anywhere) 9524 { 9525 struct symtabs_and_lines sals; 9526 struct symtab_and_line sal; 9527 struct frame_info *frame = get_selected_frame (NULL); 9528 struct breakpoint *breakpoint; 9529 struct breakpoint *breakpoint2 = NULL; 9530 struct cleanup *old_chain; 9531 int thread; 9532 struct thread_info *tp; 9533 9534 clear_proceed_status (); 9535 9536 /* Set a breakpoint where the user wants it and at return from 9537 this function. */ 9538 9539 if (last_displayed_sal_is_valid ()) 9540 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, 9541 get_last_displayed_symtab (), 9542 get_last_displayed_line ()); 9543 else 9544 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, 9545 (struct symtab *) NULL, 0); 9546 9547 if (sals.nelts != 1) 9548 error (_("Couldn't get information on specified line.")); 9549 9550 sal = sals.sals[0]; 9551 xfree (sals.sals); /* malloc'd, so freed. */ 9552 9553 if (*arg) 9554 error (_("Junk at end of arguments.")); 9555 9556 resolve_sal_pc (&sal); 9557 9558 if (anywhere) 9559 /* If the user told us to continue until a specified location, 9560 we don't specify a frame at which we need to stop. */ 9561 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, 9562 null_frame_id, bp_until); 9563 else 9564 /* Otherwise, specify the selected frame, because we want to stop 9565 only at the very same frame. */ 9566 breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, 9567 get_stack_frame_id (frame), 9568 bp_until); 9569 9570 old_chain = make_cleanup_delete_breakpoint (breakpoint); 9571 9572 tp = inferior_thread (); 9573 thread = tp->num; 9574 9575 /* Keep within the current frame, or in frames called by the current 9576 one. */ 9577 9578 if (frame_id_p (frame_unwind_caller_id (frame))) 9579 { 9580 sal = find_pc_line (frame_unwind_caller_pc (frame), 0); 9581 sal.pc = frame_unwind_caller_pc (frame); 9582 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), 9583 sal, 9584 frame_unwind_caller_id (frame), 9585 bp_until); 9586 make_cleanup_delete_breakpoint (breakpoint2); 9587 9588 set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); 9589 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); 9590 } 9591 9592 proceed (-1, TARGET_SIGNAL_DEFAULT, 0); 9593 9594 /* If we are running asynchronously, and proceed call above has 9595 actually managed to start the target, arrange for breakpoints to 9596 be deleted when the target stops. Otherwise, we're already 9597 stopped and delete breakpoints via cleanup chain. */ 9598 9599 if (target_can_async_p () && is_running (inferior_ptid)) 9600 { 9601 struct until_break_command_continuation_args *args; 9602 args = xmalloc (sizeof (*args)); 9603 9604 args->breakpoint = breakpoint; 9605 args->breakpoint2 = breakpoint2; 9606 args->thread_num = thread; 9607 9608 discard_cleanups (old_chain); 9609 add_continuation (inferior_thread (), 9610 until_break_command_continuation, args, 9611 xfree); 9612 } 9613 else 9614 do_cleanups (old_chain); 9615 } 9616 9617 /* This function attempts to parse an optional "if <cond>" clause 9618 from the arg string. If one is not found, it returns NULL. 9619 9620 Else, it returns a pointer to the condition string. (It does not 9621 attempt to evaluate the string against a particular block.) And, 9622 it updates arg to point to the first character following the parsed 9623 if clause in the arg string. */ 9624 9625 static char * 9626 ep_parse_optional_if_clause (char **arg) 9627 { 9628 char *cond_string; 9629 9630 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) 9631 return NULL; 9632 9633 /* Skip the "if" keyword. */ 9634 (*arg) += 2; 9635 9636 /* Skip any extra leading whitespace, and record the start of the 9637 condition string. */ 9638 *arg = skip_spaces (*arg); 9639 cond_string = *arg; 9640 9641 /* Assume that the condition occupies the remainder of the arg 9642 string. */ 9643 (*arg) += strlen (cond_string); 9644 9645 return cond_string; 9646 } 9647 9648 /* Commands to deal with catching events, such as signals, exceptions, 9649 process start/exit, etc. */ 9650 9651 typedef enum 9652 { 9653 catch_fork_temporary, catch_vfork_temporary, 9654 catch_fork_permanent, catch_vfork_permanent 9655 } 9656 catch_fork_kind; 9657 9658 static void 9659 catch_fork_command_1 (char *arg, int from_tty, 9660 struct cmd_list_element *command) 9661 { 9662 struct gdbarch *gdbarch = get_current_arch (); 9663 char *cond_string = NULL; 9664 catch_fork_kind fork_kind; 9665 int tempflag; 9666 9667 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); 9668 tempflag = (fork_kind == catch_fork_temporary 9669 || fork_kind == catch_vfork_temporary); 9670 9671 if (!arg) 9672 arg = ""; 9673 arg = skip_spaces (arg); 9674 9675 /* The allowed syntax is: 9676 catch [v]fork 9677 catch [v]fork if <cond> 9678 9679 First, check if there's an if clause. */ 9680 cond_string = ep_parse_optional_if_clause (&arg); 9681 9682 if ((*arg != '\0') && !isspace (*arg)) 9683 error (_("Junk at end of arguments.")); 9684 9685 /* If this target supports it, create a fork or vfork catchpoint 9686 and enable reporting of such events. */ 9687 switch (fork_kind) 9688 { 9689 case catch_fork_temporary: 9690 case catch_fork_permanent: 9691 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, 9692 &catch_fork_breakpoint_ops); 9693 break; 9694 case catch_vfork_temporary: 9695 case catch_vfork_permanent: 9696 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, 9697 &catch_vfork_breakpoint_ops); 9698 break; 9699 default: 9700 error (_("unsupported or unknown fork kind; cannot catch it")); 9701 break; 9702 } 9703 } 9704 9705 static void 9706 catch_exec_command_1 (char *arg, int from_tty, 9707 struct cmd_list_element *command) 9708 { 9709 struct exec_catchpoint *c; 9710 struct gdbarch *gdbarch = get_current_arch (); 9711 int tempflag; 9712 char *cond_string = NULL; 9713 9714 tempflag = get_cmd_context (command) == CATCH_TEMPORARY; 9715 9716 if (!arg) 9717 arg = ""; 9718 arg = skip_spaces (arg); 9719 9720 /* The allowed syntax is: 9721 catch exec 9722 catch exec if <cond> 9723 9724 First, check if there's an if clause. */ 9725 cond_string = ep_parse_optional_if_clause (&arg); 9726 9727 if ((*arg != '\0') && !isspace (*arg)) 9728 error (_("Junk at end of arguments.")); 9729 9730 c = XNEW (struct exec_catchpoint); 9731 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, 9732 &catch_exec_breakpoint_ops); 9733 c->exec_pathname = NULL; 9734 9735 install_breakpoint (0, &c->base, 1); 9736 } 9737 9738 static enum print_stop_action 9739 print_it_exception_catchpoint (bpstat bs) 9740 { 9741 struct ui_out *uiout = current_uiout; 9742 struct breakpoint *b = bs->breakpoint_at; 9743 int bp_temp, bp_throw; 9744 9745 annotate_catchpoint (b->number); 9746 9747 bp_throw = strstr (b->addr_string, "throw") != NULL; 9748 if (b->loc->address != b->loc->requested_address) 9749 breakpoint_adjustment_warning (b->loc->requested_address, 9750 b->loc->address, 9751 b->number, 1); 9752 bp_temp = b->disposition == disp_del; 9753 ui_out_text (uiout, 9754 bp_temp ? "Temporary catchpoint " 9755 : "Catchpoint "); 9756 if (!ui_out_is_mi_like_p (uiout)) 9757 ui_out_field_int (uiout, "bkptno", b->number); 9758 ui_out_text (uiout, 9759 bp_throw ? " (exception thrown), " 9760 : " (exception caught), "); 9761 if (ui_out_is_mi_like_p (uiout)) 9762 { 9763 ui_out_field_string (uiout, "reason", 9764 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); 9765 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 9766 ui_out_field_int (uiout, "bkptno", b->number); 9767 } 9768 return PRINT_SRC_AND_LOC; 9769 } 9770 9771 static void 9772 print_one_exception_catchpoint (struct breakpoint *b, 9773 struct bp_location **last_loc) 9774 { 9775 struct value_print_options opts; 9776 struct ui_out *uiout = current_uiout; 9777 9778 get_user_print_options (&opts); 9779 if (opts.addressprint) 9780 { 9781 annotate_field (4); 9782 if (b->loc == NULL || b->loc->shlib_disabled) 9783 ui_out_field_string (uiout, "addr", "<PENDING>"); 9784 else 9785 ui_out_field_core_addr (uiout, "addr", 9786 b->loc->gdbarch, b->loc->address); 9787 } 9788 annotate_field (5); 9789 if (b->loc) 9790 *last_loc = b->loc; 9791 if (strstr (b->addr_string, "throw") != NULL) 9792 ui_out_field_string (uiout, "what", "exception throw"); 9793 else 9794 ui_out_field_string (uiout, "what", "exception catch"); 9795 } 9796 9797 static void 9798 print_mention_exception_catchpoint (struct breakpoint *b) 9799 { 9800 struct ui_out *uiout = current_uiout; 9801 int bp_temp; 9802 int bp_throw; 9803 9804 bp_temp = b->disposition == disp_del; 9805 bp_throw = strstr (b->addr_string, "throw") != NULL; 9806 ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") 9807 : _("Catchpoint ")); 9808 ui_out_field_int (uiout, "bkptno", b->number); 9809 ui_out_text (uiout, bp_throw ? _(" (throw)") 9810 : _(" (catch)")); 9811 } 9812 9813 /* Implement the "print_recreate" breakpoint_ops method for throw and 9814 catch catchpoints. */ 9815 9816 static void 9817 print_recreate_exception_catchpoint (struct breakpoint *b, 9818 struct ui_file *fp) 9819 { 9820 int bp_temp; 9821 int bp_throw; 9822 9823 bp_temp = b->disposition == disp_del; 9824 bp_throw = strstr (b->addr_string, "throw") != NULL; 9825 fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); 9826 fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); 9827 print_recreate_thread (b, fp); 9828 } 9829 9830 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; 9831 9832 static int 9833 handle_gnu_v3_exceptions (int tempflag, char *cond_string, 9834 enum exception_event_kind ex_event, int from_tty) 9835 { 9836 char *trigger_func_name; 9837 9838 if (ex_event == EX_EVENT_CATCH) 9839 trigger_func_name = "__cxa_begin_catch"; 9840 else 9841 trigger_func_name = "__cxa_throw"; 9842 9843 create_breakpoint (get_current_arch (), 9844 trigger_func_name, cond_string, -1, 9845 0 /* condition and thread are valid. */, 9846 tempflag, bp_breakpoint, 9847 0, 9848 AUTO_BOOLEAN_TRUE /* pending */, 9849 &gnu_v3_exception_catchpoint_ops, from_tty, 9850 1 /* enabled */, 9851 0 /* internal */, 9852 0); 9853 9854 return 1; 9855 } 9856 9857 /* Deal with "catch catch" and "catch throw" commands. */ 9858 9859 static void 9860 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, 9861 int tempflag, int from_tty) 9862 { 9863 char *cond_string = NULL; 9864 9865 if (!arg) 9866 arg = ""; 9867 arg = skip_spaces (arg); 9868 9869 cond_string = ep_parse_optional_if_clause (&arg); 9870 9871 if ((*arg != '\0') && !isspace (*arg)) 9872 error (_("Junk at end of arguments.")); 9873 9874 if (ex_event != EX_EVENT_THROW 9875 && ex_event != EX_EVENT_CATCH) 9876 error (_("Unsupported or unknown exception event; cannot catch it")); 9877 9878 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) 9879 return; 9880 9881 warning (_("Unsupported with this platform/compiler combination.")); 9882 } 9883 9884 /* Implementation of "catch catch" command. */ 9885 9886 static void 9887 catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) 9888 { 9889 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; 9890 9891 catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); 9892 } 9893 9894 /* Implementation of "catch throw" command. */ 9895 9896 static void 9897 catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) 9898 { 9899 int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; 9900 9901 catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); 9902 } 9903 9904 void 9905 init_ada_exception_breakpoint (struct breakpoint *b, 9906 struct gdbarch *gdbarch, 9907 struct symtab_and_line sal, 9908 char *addr_string, 9909 const struct breakpoint_ops *ops, 9910 int tempflag, 9911 int from_tty) 9912 { 9913 if (from_tty) 9914 { 9915 struct gdbarch *loc_gdbarch = get_sal_arch (sal); 9916 if (!loc_gdbarch) 9917 loc_gdbarch = gdbarch; 9918 9919 describe_other_breakpoints (loc_gdbarch, 9920 sal.pspace, sal.pc, sal.section, -1); 9921 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special 9922 version for exception catchpoints, because two catchpoints 9923 used for different exception names will use the same address. 9924 In this case, a "breakpoint ... also set at..." warning is 9925 unproductive. Besides, the warning phrasing is also a bit 9926 inappropriate, we should use the word catchpoint, and tell 9927 the user what type of catchpoint it is. The above is good 9928 enough for now, though. */ 9929 } 9930 9931 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); 9932 9933 b->enable_state = bp_enabled; 9934 b->disposition = tempflag ? disp_del : disp_donttouch; 9935 b->addr_string = addr_string; 9936 b->language = language_ada; 9937 } 9938 9939 /* Splits the argument using space as delimiter. Returns an xmalloc'd 9940 filter list, or NULL if no filtering is required. */ 9941 static VEC(int) * 9942 catch_syscall_split_args (char *arg) 9943 { 9944 VEC(int) *result = NULL; 9945 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); 9946 9947 while (*arg != '\0') 9948 { 9949 int i, syscall_number; 9950 char *endptr; 9951 char cur_name[128]; 9952 struct syscall s; 9953 9954 /* Skip whitespace. */ 9955 while (isspace (*arg)) 9956 arg++; 9957 9958 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) 9959 cur_name[i] = arg[i]; 9960 cur_name[i] = '\0'; 9961 arg += i; 9962 9963 /* Check if the user provided a syscall name or a number. */ 9964 syscall_number = (int) strtol (cur_name, &endptr, 0); 9965 if (*endptr == '\0') 9966 get_syscall_by_number (syscall_number, &s); 9967 else 9968 { 9969 /* We have a name. Let's check if it's valid and convert it 9970 to a number. */ 9971 get_syscall_by_name (cur_name, &s); 9972 9973 if (s.number == UNKNOWN_SYSCALL) 9974 /* Here we have to issue an error instead of a warning, 9975 because GDB cannot do anything useful if there's no 9976 syscall number to be caught. */ 9977 error (_("Unknown syscall name '%s'."), cur_name); 9978 } 9979 9980 /* Ok, it's valid. */ 9981 VEC_safe_push (int, result, s.number); 9982 } 9983 9984 discard_cleanups (cleanup); 9985 return result; 9986 } 9987 9988 /* Implement the "catch syscall" command. */ 9989 9990 static void 9991 catch_syscall_command_1 (char *arg, int from_tty, 9992 struct cmd_list_element *command) 9993 { 9994 int tempflag; 9995 VEC(int) *filter; 9996 struct syscall s; 9997 struct gdbarch *gdbarch = get_current_arch (); 9998 9999 /* Checking if the feature if supported. */ 10000 if (gdbarch_get_syscall_number_p (gdbarch) == 0) 10001 error (_("The feature 'catch syscall' is not supported on \ 10002 this architecture yet.")); 10003 10004 tempflag = get_cmd_context (command) == CATCH_TEMPORARY; 10005 10006 arg = skip_spaces (arg); 10007 10008 /* We need to do this first "dummy" translation in order 10009 to get the syscall XML file loaded or, most important, 10010 to display a warning to the user if there's no XML file 10011 for his/her architecture. */ 10012 get_syscall_by_number (0, &s); 10013 10014 /* The allowed syntax is: 10015 catch syscall 10016 catch syscall <name | number> [<name | number> ... <name | number>] 10017 10018 Let's check if there's a syscall name. */ 10019 10020 if (arg != NULL) 10021 filter = catch_syscall_split_args (arg); 10022 else 10023 filter = NULL; 10024 10025 create_syscall_event_catchpoint (tempflag, filter, 10026 &catch_syscall_breakpoint_ops); 10027 } 10028 10029 static void 10030 catch_command (char *arg, int from_tty) 10031 { 10032 error (_("Catch requires an event name.")); 10033 } 10034 10035 10036 static void 10037 tcatch_command (char *arg, int from_tty) 10038 { 10039 error (_("Catch requires an event name.")); 10040 } 10041 10042 /* A qsort comparison function that sorts breakpoints in order. */ 10043 10044 static int 10045 compare_breakpoints (const void *a, const void *b) 10046 { 10047 const breakpoint_p *ba = a; 10048 uintptr_t ua = (uintptr_t) *ba; 10049 const breakpoint_p *bb = b; 10050 uintptr_t ub = (uintptr_t) *bb; 10051 10052 if ((*ba)->number < (*bb)->number) 10053 return -1; 10054 else if ((*ba)->number > (*bb)->number) 10055 return 1; 10056 10057 /* Now sort by address, in case we see, e..g, two breakpoints with 10058 the number 0. */ 10059 if (ua < ub) 10060 return -1; 10061 return ub > ub ? 1 : 0; 10062 } 10063 10064 /* Delete breakpoints by address or line. */ 10065 10066 static void 10067 clear_command (char *arg, int from_tty) 10068 { 10069 struct breakpoint *b, *prev; 10070 VEC(breakpoint_p) *found = 0; 10071 int ix; 10072 int default_match; 10073 struct symtabs_and_lines sals; 10074 struct symtab_and_line sal; 10075 int i; 10076 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); 10077 10078 if (arg) 10079 { 10080 sals = decode_line_spec (arg, (DECODE_LINE_FUNFIRSTLINE 10081 | DECODE_LINE_LIST_MODE)); 10082 default_match = 0; 10083 } 10084 else 10085 { 10086 sals.sals = (struct symtab_and_line *) 10087 xmalloc (sizeof (struct symtab_and_line)); 10088 make_cleanup (xfree, sals.sals); 10089 init_sal (&sal); /* Initialize to zeroes. */ 10090 10091 /* Set sal's line, symtab, pc, and pspace to the values 10092 corresponding to the last call to print_frame_info. If the 10093 codepoint is not valid, this will set all the fields to 0. */ 10094 get_last_displayed_sal (&sal); 10095 if (sal.symtab == 0) 10096 error (_("No source file specified.")); 10097 10098 sals.sals[0] = sal; 10099 sals.nelts = 1; 10100 10101 default_match = 1; 10102 } 10103 10104 /* We don't call resolve_sal_pc here. That's not as bad as it 10105 seems, because all existing breakpoints typically have both 10106 file/line and pc set. So, if clear is given file/line, we can 10107 match this to existing breakpoint without obtaining pc at all. 10108 10109 We only support clearing given the address explicitly 10110 present in breakpoint table. Say, we've set breakpoint 10111 at file:line. There were several PC values for that file:line, 10112 due to optimization, all in one block. 10113 10114 We've picked one PC value. If "clear" is issued with another 10115 PC corresponding to the same file:line, the breakpoint won't 10116 be cleared. We probably can still clear the breakpoint, but 10117 since the other PC value is never presented to user, user 10118 can only find it by guessing, and it does not seem important 10119 to support that. */ 10120 10121 /* For each line spec given, delete bps which correspond to it. Do 10122 it in two passes, solely to preserve the current behavior that 10123 from_tty is forced true if we delete more than one 10124 breakpoint. */ 10125 10126 found = NULL; 10127 make_cleanup (VEC_cleanup (breakpoint_p), &found); 10128 for (i = 0; i < sals.nelts; i++) 10129 { 10130 /* If exact pc given, clear bpts at that pc. 10131 If line given (pc == 0), clear all bpts on specified line. 10132 If defaulting, clear all bpts on default line 10133 or at default pc. 10134 10135 defaulting sal.pc != 0 tests to do 10136 10137 0 1 pc 10138 1 1 pc _and_ line 10139 0 0 line 10140 1 0 <can't happen> */ 10141 10142 sal = sals.sals[i]; 10143 10144 /* Find all matching breakpoints and add them to 'found'. */ 10145 ALL_BREAKPOINTS (b) 10146 { 10147 int match = 0; 10148 /* Are we going to delete b? */ 10149 if (b->type != bp_none && !is_watchpoint (b)) 10150 { 10151 struct bp_location *loc = b->loc; 10152 for (; loc; loc = loc->next) 10153 { 10154 /* If the user specified file:line, don't allow a PC 10155 match. This matches historical gdb behavior. */ 10156 int pc_match = (!sal.explicit_line 10157 && sal.pc 10158 && (loc->pspace == sal.pspace) 10159 && (loc->address == sal.pc) 10160 && (!section_is_overlay (loc->section) 10161 || loc->section == sal.section)); 10162 int line_match = ((default_match || sal.explicit_line) 10163 && loc->source_file != NULL 10164 && sal.symtab != NULL 10165 && sal.pspace == loc->pspace 10166 && filename_cmp (loc->source_file, 10167 sal.symtab->filename) == 0 10168 && loc->line_number == sal.line); 10169 if (pc_match || line_match) 10170 { 10171 match = 1; 10172 break; 10173 } 10174 } 10175 } 10176 10177 if (match) 10178 VEC_safe_push(breakpoint_p, found, b); 10179 } 10180 } 10181 10182 /* Now go thru the 'found' chain and delete them. */ 10183 if (VEC_empty(breakpoint_p, found)) 10184 { 10185 if (arg) 10186 error (_("No breakpoint at %s."), arg); 10187 else 10188 error (_("No breakpoint at this line.")); 10189 } 10190 10191 /* Remove duplicates from the vec. */ 10192 qsort (VEC_address (breakpoint_p, found), 10193 VEC_length (breakpoint_p, found), 10194 sizeof (breakpoint_p), 10195 compare_breakpoints); 10196 prev = VEC_index (breakpoint_p, found, 0); 10197 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) 10198 { 10199 if (b == prev) 10200 { 10201 VEC_ordered_remove (breakpoint_p, found, ix); 10202 --ix; 10203 } 10204 } 10205 10206 if (VEC_length(breakpoint_p, found) > 1) 10207 from_tty = 1; /* Always report if deleted more than one. */ 10208 if (from_tty) 10209 { 10210 if (VEC_length(breakpoint_p, found) == 1) 10211 printf_unfiltered (_("Deleted breakpoint ")); 10212 else 10213 printf_unfiltered (_("Deleted breakpoints ")); 10214 } 10215 breakpoints_changed (); 10216 10217 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) 10218 { 10219 if (from_tty) 10220 printf_unfiltered ("%d ", b->number); 10221 delete_breakpoint (b); 10222 } 10223 if (from_tty) 10224 putchar_unfiltered ('\n'); 10225 10226 do_cleanups (cleanups); 10227 } 10228 10229 /* Delete breakpoint in BS if they are `delete' breakpoints and 10230 all breakpoints that are marked for deletion, whether hit or not. 10231 This is called after any breakpoint is hit, or after errors. */ 10232 10233 void 10234 breakpoint_auto_delete (bpstat bs) 10235 { 10236 struct breakpoint *b, *b_tmp; 10237 10238 for (; bs; bs = bs->next) 10239 if (bs->breakpoint_at 10240 && bs->breakpoint_at->disposition == disp_del 10241 && bs->stop) 10242 delete_breakpoint (bs->breakpoint_at); 10243 10244 ALL_BREAKPOINTS_SAFE (b, b_tmp) 10245 { 10246 if (b->disposition == disp_del_at_next_stop) 10247 delete_breakpoint (b); 10248 } 10249 } 10250 10251 /* A comparison function for bp_location AP and BP being interfaced to 10252 qsort. Sort elements primarily by their ADDRESS (no matter what 10253 does breakpoint_address_is_meaningful say for its OWNER), 10254 secondarily by ordering first bp_permanent OWNERed elements and 10255 terciarily just ensuring the array is sorted stable way despite 10256 qsort being an unstable algorithm. */ 10257 10258 static int 10259 bp_location_compare (const void *ap, const void *bp) 10260 { 10261 struct bp_location *a = *(void **) ap; 10262 struct bp_location *b = *(void **) bp; 10263 /* A and B come from existing breakpoints having non-NULL OWNER. */ 10264 int a_perm = a->owner->enable_state == bp_permanent; 10265 int b_perm = b->owner->enable_state == bp_permanent; 10266 10267 if (a->address != b->address) 10268 return (a->address > b->address) - (a->address < b->address); 10269 10270 /* Sort permanent breakpoints first. */ 10271 if (a_perm != b_perm) 10272 return (a_perm < b_perm) - (a_perm > b_perm); 10273 10274 /* Make the user-visible order stable across GDB runs. Locations of 10275 the same breakpoint can be sorted in arbitrary order. */ 10276 10277 if (a->owner->number != b->owner->number) 10278 return (a->owner->number > b->owner->number) 10279 - (a->owner->number < b->owner->number); 10280 10281 return (a > b) - (a < b); 10282 } 10283 10284 /* Set bp_location_placed_address_before_address_max and 10285 bp_location_shadow_len_after_address_max according to the current 10286 content of the bp_location array. */ 10287 10288 static void 10289 bp_location_target_extensions_update (void) 10290 { 10291 struct bp_location *bl, **blp_tmp; 10292 10293 bp_location_placed_address_before_address_max = 0; 10294 bp_location_shadow_len_after_address_max = 0; 10295 10296 ALL_BP_LOCATIONS (bl, blp_tmp) 10297 { 10298 CORE_ADDR start, end, addr; 10299 10300 if (!bp_location_has_shadow (bl)) 10301 continue; 10302 10303 start = bl->target_info.placed_address; 10304 end = start + bl->target_info.shadow_len; 10305 10306 gdb_assert (bl->address >= start); 10307 addr = bl->address - start; 10308 if (addr > bp_location_placed_address_before_address_max) 10309 bp_location_placed_address_before_address_max = addr; 10310 10311 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ 10312 10313 gdb_assert (bl->address < end); 10314 addr = end - bl->address; 10315 if (addr > bp_location_shadow_len_after_address_max) 10316 bp_location_shadow_len_after_address_max = addr; 10317 } 10318 } 10319 10320 /* Download tracepoint locations if they haven't been. */ 10321 10322 static void 10323 download_tracepoint_locations (void) 10324 { 10325 struct bp_location *bl, **blp_tmp; 10326 struct cleanup *old_chain; 10327 10328 if (!target_can_download_tracepoint ()) 10329 return; 10330 10331 old_chain = save_current_space_and_thread (); 10332 10333 ALL_BP_LOCATIONS (bl, blp_tmp) 10334 { 10335 struct tracepoint *t; 10336 10337 if (!is_tracepoint (bl->owner)) 10338 continue; 10339 10340 if ((bl->owner->type == bp_fast_tracepoint 10341 ? !may_insert_fast_tracepoints 10342 : !may_insert_tracepoints)) 10343 continue; 10344 10345 /* In tracepoint, locations are _never_ duplicated, so 10346 should_be_inserted is equivalent to 10347 unduplicated_should_be_inserted. */ 10348 if (!should_be_inserted (bl) || bl->inserted) 10349 continue; 10350 10351 switch_to_program_space_and_thread (bl->pspace); 10352 10353 target_download_tracepoint (bl); 10354 10355 bl->inserted = 1; 10356 t = (struct tracepoint *) bl->owner; 10357 t->number_on_target = bl->owner->number; 10358 } 10359 10360 do_cleanups (old_chain); 10361 } 10362 10363 /* Swap the insertion/duplication state between two locations. */ 10364 10365 static void 10366 swap_insertion (struct bp_location *left, struct bp_location *right) 10367 { 10368 const int left_inserted = left->inserted; 10369 const int left_duplicate = left->duplicate; 10370 const struct bp_target_info left_target_info = left->target_info; 10371 10372 /* Locations of tracepoints can never be duplicated. */ 10373 if (is_tracepoint (left->owner)) 10374 gdb_assert (!left->duplicate); 10375 if (is_tracepoint (right->owner)) 10376 gdb_assert (!right->duplicate); 10377 10378 left->inserted = right->inserted; 10379 left->duplicate = right->duplicate; 10380 left->target_info = right->target_info; 10381 right->inserted = left_inserted; 10382 right->duplicate = left_duplicate; 10383 right->target_info = left_target_info; 10384 } 10385 10386 /* If SHOULD_INSERT is false, do not insert any breakpoint locations 10387 into the inferior, only remove already-inserted locations that no 10388 longer should be inserted. Functions that delete a breakpoint or 10389 breakpoints should pass false, so that deleting a breakpoint 10390 doesn't have the side effect of inserting the locations of other 10391 breakpoints that are marked not-inserted, but should_be_inserted 10392 returns true on them. 10393 10394 This behaviour is useful is situations close to tear-down -- e.g., 10395 after an exec, while the target still has execution, but breakpoint 10396 shadows of the previous executable image should *NOT* be restored 10397 to the new image; or before detaching, where the target still has 10398 execution and wants to delete breakpoints from GDB's lists, and all 10399 breakpoints had already been removed from the inferior. */ 10400 10401 static void 10402 update_global_location_list (int should_insert) 10403 { 10404 struct breakpoint *b; 10405 struct bp_location **locp, *loc; 10406 struct cleanup *cleanups; 10407 10408 /* Used in the duplicates detection below. When iterating over all 10409 bp_locations, points to the first bp_location of a given address. 10410 Breakpoints and watchpoints of different types are never 10411 duplicates of each other. Keep one pointer for each type of 10412 breakpoint/watchpoint, so we only need to loop over all locations 10413 once. */ 10414 struct bp_location *bp_loc_first; /* breakpoint */ 10415 struct bp_location *wp_loc_first; /* hardware watchpoint */ 10416 struct bp_location *awp_loc_first; /* access watchpoint */ 10417 struct bp_location *rwp_loc_first; /* read watchpoint */ 10418 10419 /* Saved former bp_location array which we compare against the newly 10420 built bp_location from the current state of ALL_BREAKPOINTS. */ 10421 struct bp_location **old_location, **old_locp; 10422 unsigned old_location_count; 10423 10424 old_location = bp_location; 10425 old_location_count = bp_location_count; 10426 bp_location = NULL; 10427 bp_location_count = 0; 10428 cleanups = make_cleanup (xfree, old_location); 10429 10430 ALL_BREAKPOINTS (b) 10431 for (loc = b->loc; loc; loc = loc->next) 10432 bp_location_count++; 10433 10434 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); 10435 locp = bp_location; 10436 ALL_BREAKPOINTS (b) 10437 for (loc = b->loc; loc; loc = loc->next) 10438 *locp++ = loc; 10439 qsort (bp_location, bp_location_count, sizeof (*bp_location), 10440 bp_location_compare); 10441 10442 bp_location_target_extensions_update (); 10443 10444 /* Identify bp_location instances that are no longer present in the 10445 new list, and therefore should be freed. Note that it's not 10446 necessary that those locations should be removed from inferior -- 10447 if there's another location at the same address (previously 10448 marked as duplicate), we don't need to remove/insert the 10449 location. 10450 10451 LOCP is kept in sync with OLD_LOCP, each pointing to the current 10452 and former bp_location array state respectively. */ 10453 10454 locp = bp_location; 10455 for (old_locp = old_location; old_locp < old_location + old_location_count; 10456 old_locp++) 10457 { 10458 struct bp_location *old_loc = *old_locp; 10459 struct bp_location **loc2p; 10460 10461 /* Tells if 'old_loc' is found among the new locations. If 10462 not, we have to free it. */ 10463 int found_object = 0; 10464 /* Tells if the location should remain inserted in the target. */ 10465 int keep_in_target = 0; 10466 int removed = 0; 10467 10468 /* Skip LOCP entries which will definitely never be needed. 10469 Stop either at or being the one matching OLD_LOC. */ 10470 while (locp < bp_location + bp_location_count 10471 && (*locp)->address < old_loc->address) 10472 locp++; 10473 10474 for (loc2p = locp; 10475 (loc2p < bp_location + bp_location_count 10476 && (*loc2p)->address == old_loc->address); 10477 loc2p++) 10478 { 10479 if (*loc2p == old_loc) 10480 { 10481 found_object = 1; 10482 break; 10483 } 10484 } 10485 10486 /* If this location is no longer present, and inserted, look if 10487 there's maybe a new location at the same address. If so, 10488 mark that one inserted, and don't remove this one. This is 10489 needed so that we don't have a time window where a breakpoint 10490 at certain location is not inserted. */ 10491 10492 if (old_loc->inserted) 10493 { 10494 /* If the location is inserted now, we might have to remove 10495 it. */ 10496 10497 if (found_object && should_be_inserted (old_loc)) 10498 { 10499 /* The location is still present in the location list, 10500 and still should be inserted. Don't do anything. */ 10501 keep_in_target = 1; 10502 } 10503 else 10504 { 10505 /* The location is either no longer present, or got 10506 disabled. See if there's another location at the 10507 same address, in which case we don't need to remove 10508 this one from the target. */ 10509 10510 /* OLD_LOC comes from existing struct breakpoint. */ 10511 if (breakpoint_address_is_meaningful (old_loc->owner)) 10512 { 10513 for (loc2p = locp; 10514 (loc2p < bp_location + bp_location_count 10515 && (*loc2p)->address == old_loc->address); 10516 loc2p++) 10517 { 10518 struct bp_location *loc2 = *loc2p; 10519 10520 if (breakpoint_locations_match (loc2, old_loc)) 10521 { 10522 /* Read watchpoint locations are switched to 10523 access watchpoints, if the former are not 10524 supported, but the latter are. */ 10525 if (is_hardware_watchpoint (old_loc->owner)) 10526 { 10527 gdb_assert (is_hardware_watchpoint (loc2->owner)); 10528 loc2->watchpoint_type = old_loc->watchpoint_type; 10529 } 10530 10531 /* loc2 is a duplicated location. We need to check 10532 if it should be inserted in case it will be 10533 unduplicated. */ 10534 if (loc2 != old_loc 10535 && unduplicated_should_be_inserted (loc2)) 10536 { 10537 swap_insertion (old_loc, loc2); 10538 keep_in_target = 1; 10539 break; 10540 } 10541 } 10542 } 10543 } 10544 } 10545 10546 if (!keep_in_target) 10547 { 10548 if (remove_breakpoint (old_loc, mark_uninserted)) 10549 { 10550 /* This is just about all we can do. We could keep 10551 this location on the global list, and try to 10552 remove it next time, but there's no particular 10553 reason why we will succeed next time. 10554 10555 Note that at this point, old_loc->owner is still 10556 valid, as delete_breakpoint frees the breakpoint 10557 only after calling us. */ 10558 printf_filtered (_("warning: Error removing " 10559 "breakpoint %d\n"), 10560 old_loc->owner->number); 10561 } 10562 removed = 1; 10563 } 10564 } 10565 10566 if (!found_object) 10567 { 10568 if (removed && non_stop 10569 && breakpoint_address_is_meaningful (old_loc->owner) 10570 && !is_hardware_watchpoint (old_loc->owner)) 10571 { 10572 /* This location was removed from the target. In 10573 non-stop mode, a race condition is possible where 10574 we've removed a breakpoint, but stop events for that 10575 breakpoint are already queued and will arrive later. 10576 We apply an heuristic to be able to distinguish such 10577 SIGTRAPs from other random SIGTRAPs: we keep this 10578 breakpoint location for a bit, and will retire it 10579 after we see some number of events. The theory here 10580 is that reporting of events should, "on the average", 10581 be fair, so after a while we'll see events from all 10582 threads that have anything of interest, and no longer 10583 need to keep this breakpoint location around. We 10584 don't hold locations forever so to reduce chances of 10585 mistaking a non-breakpoint SIGTRAP for a breakpoint 10586 SIGTRAP. 10587 10588 The heuristic failing can be disastrous on 10589 decr_pc_after_break targets. 10590 10591 On decr_pc_after_break targets, like e.g., x86-linux, 10592 if we fail to recognize a late breakpoint SIGTRAP, 10593 because events_till_retirement has reached 0 too 10594 soon, we'll fail to do the PC adjustment, and report 10595 a random SIGTRAP to the user. When the user resumes 10596 the inferior, it will most likely immediately crash 10597 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently 10598 corrupted, because of being resumed e.g., in the 10599 middle of a multi-byte instruction, or skipped a 10600 one-byte instruction. This was actually seen happen 10601 on native x86-linux, and should be less rare on 10602 targets that do not support new thread events, like 10603 remote, due to the heuristic depending on 10604 thread_count. 10605 10606 Mistaking a random SIGTRAP for a breakpoint trap 10607 causes similar symptoms (PC adjustment applied when 10608 it shouldn't), but then again, playing with SIGTRAPs 10609 behind the debugger's back is asking for trouble. 10610 10611 Since hardware watchpoint traps are always 10612 distinguishable from other traps, so we don't need to 10613 apply keep hardware watchpoint moribund locations 10614 around. We simply always ignore hardware watchpoint 10615 traps we can no longer explain. */ 10616 10617 old_loc->events_till_retirement = 3 * (thread_count () + 1); 10618 old_loc->owner = NULL; 10619 10620 VEC_safe_push (bp_location_p, moribund_locations, old_loc); 10621 } 10622 else 10623 { 10624 old_loc->owner = NULL; 10625 decref_bp_location (&old_loc); 10626 } 10627 } 10628 } 10629 10630 /* Rescan breakpoints at the same address and section, marking the 10631 first one as "first" and any others as "duplicates". This is so 10632 that the bpt instruction is only inserted once. If we have a 10633 permanent breakpoint at the same place as BPT, make that one the 10634 official one, and the rest as duplicates. Permanent breakpoints 10635 are sorted first for the same address. 10636 10637 Do the same for hardware watchpoints, but also considering the 10638 watchpoint's type (regular/access/read) and length. */ 10639 10640 bp_loc_first = NULL; 10641 wp_loc_first = NULL; 10642 awp_loc_first = NULL; 10643 rwp_loc_first = NULL; 10644 ALL_BP_LOCATIONS (loc, locp) 10645 { 10646 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always 10647 non-NULL. */ 10648 struct bp_location **loc_first_p; 10649 b = loc->owner; 10650 10651 if (!should_be_inserted (loc) 10652 || !breakpoint_address_is_meaningful (b) 10653 /* Don't detect duplicate for tracepoint locations because they are 10654 never duplicated. See the comments in field `duplicate' of 10655 `struct bp_location'. */ 10656 || is_tracepoint (b)) 10657 continue; 10658 10659 /* Permanent breakpoint should always be inserted. */ 10660 if (b->enable_state == bp_permanent && ! loc->inserted) 10661 internal_error (__FILE__, __LINE__, 10662 _("allegedly permanent breakpoint is not " 10663 "actually inserted")); 10664 10665 if (b->type == bp_hardware_watchpoint) 10666 loc_first_p = &wp_loc_first; 10667 else if (b->type == bp_read_watchpoint) 10668 loc_first_p = &rwp_loc_first; 10669 else if (b->type == bp_access_watchpoint) 10670 loc_first_p = &awp_loc_first; 10671 else 10672 loc_first_p = &bp_loc_first; 10673 10674 if (*loc_first_p == NULL 10675 || (overlay_debugging && loc->section != (*loc_first_p)->section) 10676 || !breakpoint_locations_match (loc, *loc_first_p)) 10677 { 10678 *loc_first_p = loc; 10679 loc->duplicate = 0; 10680 continue; 10681 } 10682 10683 10684 /* This and the above ensure the invariant that the first location 10685 is not duplicated, and is the inserted one. 10686 All following are marked as duplicated, and are not inserted. */ 10687 if (loc->inserted) 10688 swap_insertion (loc, *loc_first_p); 10689 loc->duplicate = 1; 10690 10691 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted 10692 && b->enable_state != bp_permanent) 10693 internal_error (__FILE__, __LINE__, 10694 _("another breakpoint was inserted on top of " 10695 "a permanent breakpoint")); 10696 } 10697 10698 if (breakpoints_always_inserted_mode () && should_insert 10699 && (have_live_inferiors () 10700 || (gdbarch_has_global_breakpoints (target_gdbarch)))) 10701 insert_breakpoint_locations (); 10702 10703 if (should_insert) 10704 download_tracepoint_locations (); 10705 10706 do_cleanups (cleanups); 10707 } 10708 10709 void 10710 breakpoint_retire_moribund (void) 10711 { 10712 struct bp_location *loc; 10713 int ix; 10714 10715 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) 10716 if (--(loc->events_till_retirement) == 0) 10717 { 10718 decref_bp_location (&loc); 10719 VEC_unordered_remove (bp_location_p, moribund_locations, ix); 10720 --ix; 10721 } 10722 } 10723 10724 static void 10725 update_global_location_list_nothrow (int inserting) 10726 { 10727 struct gdb_exception e; 10728 10729 TRY_CATCH (e, RETURN_MASK_ERROR) 10730 update_global_location_list (inserting); 10731 } 10732 10733 /* Clear BKP from a BPS. */ 10734 10735 static void 10736 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) 10737 { 10738 bpstat bs; 10739 10740 for (bs = bps; bs; bs = bs->next) 10741 if (bs->breakpoint_at == bpt) 10742 { 10743 bs->breakpoint_at = NULL; 10744 bs->old_val = NULL; 10745 /* bs->commands will be freed later. */ 10746 } 10747 } 10748 10749 /* Callback for iterate_over_threads. */ 10750 static int 10751 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) 10752 { 10753 struct breakpoint *bpt = data; 10754 10755 bpstat_remove_bp_location (th->control.stop_bpstat, bpt); 10756 return 0; 10757 } 10758 10759 /* Helper for breakpoint and tracepoint breakpoint_ops->mention 10760 callbacks. */ 10761 10762 static void 10763 say_where (struct breakpoint *b) 10764 { 10765 struct ui_out *uiout = current_uiout; 10766 struct value_print_options opts; 10767 10768 get_user_print_options (&opts); 10769 10770 /* i18n: cagney/2005-02-11: Below needs to be merged into a 10771 single string. */ 10772 if (b->loc == NULL) 10773 { 10774 printf_filtered (_(" (%s) pending."), b->addr_string); 10775 } 10776 else 10777 { 10778 if (opts.addressprint || b->loc->source_file == NULL) 10779 { 10780 printf_filtered (" at "); 10781 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), 10782 gdb_stdout); 10783 } 10784 if (b->loc->source_file) 10785 { 10786 /* If there is a single location, we can print the location 10787 more nicely. */ 10788 if (b->loc->next == NULL) 10789 printf_filtered (": file %s, line %d.", 10790 b->loc->source_file, b->loc->line_number); 10791 else 10792 /* This is not ideal, but each location may have a 10793 different file name, and this at least reflects the 10794 real situation somewhat. */ 10795 printf_filtered (": %s.", b->addr_string); 10796 } 10797 10798 if (b->loc->next) 10799 { 10800 struct bp_location *loc = b->loc; 10801 int n = 0; 10802 for (; loc; loc = loc->next) 10803 ++n; 10804 printf_filtered (" (%d locations)", n); 10805 } 10806 } 10807 } 10808 10809 /* Default bp_location_ops methods. */ 10810 10811 static void 10812 bp_location_dtor (struct bp_location *self) 10813 { 10814 xfree (self->cond); 10815 xfree (self->function_name); 10816 xfree (self->source_file); 10817 } 10818 10819 static const struct bp_location_ops bp_location_ops = 10820 { 10821 bp_location_dtor 10822 }; 10823 10824 /* Default breakpoint_ops methods all breakpoint_ops ultimately 10825 inherit from. */ 10826 10827 static void 10828 base_breakpoint_dtor (struct breakpoint *self) 10829 { 10830 decref_counted_command_line (&self->commands); 10831 xfree (self->cond_string); 10832 xfree (self->addr_string); 10833 xfree (self->filter); 10834 xfree (self->addr_string_range_end); 10835 } 10836 10837 static struct bp_location * 10838 base_breakpoint_allocate_location (struct breakpoint *self) 10839 { 10840 struct bp_location *loc; 10841 10842 loc = XNEW (struct bp_location); 10843 init_bp_location (loc, &bp_location_ops, self); 10844 return loc; 10845 } 10846 10847 static void 10848 base_breakpoint_re_set (struct breakpoint *b) 10849 { 10850 /* Nothing to re-set. */ 10851 } 10852 10853 #define internal_error_pure_virtual_called() \ 10854 gdb_assert_not_reached ("pure virtual function called") 10855 10856 static int 10857 base_breakpoint_insert_location (struct bp_location *bl) 10858 { 10859 internal_error_pure_virtual_called (); 10860 } 10861 10862 static int 10863 base_breakpoint_remove_location (struct bp_location *bl) 10864 { 10865 internal_error_pure_virtual_called (); 10866 } 10867 10868 static int 10869 base_breakpoint_breakpoint_hit (const struct bp_location *bl, 10870 struct address_space *aspace, 10871 CORE_ADDR bp_addr) 10872 { 10873 internal_error_pure_virtual_called (); 10874 } 10875 10876 static void 10877 base_breakpoint_check_status (bpstat bs) 10878 { 10879 /* Always stop. */ 10880 } 10881 10882 /* A "works_in_software_mode" breakpoint_ops method that just internal 10883 errors. */ 10884 10885 static int 10886 base_breakpoint_works_in_software_mode (const struct breakpoint *b) 10887 { 10888 internal_error_pure_virtual_called (); 10889 } 10890 10891 /* A "resources_needed" breakpoint_ops method that just internal 10892 errors. */ 10893 10894 static int 10895 base_breakpoint_resources_needed (const struct bp_location *bl) 10896 { 10897 internal_error_pure_virtual_called (); 10898 } 10899 10900 static enum print_stop_action 10901 base_breakpoint_print_it (bpstat bs) 10902 { 10903 internal_error_pure_virtual_called (); 10904 } 10905 10906 static void 10907 base_breakpoint_print_one_detail (const struct breakpoint *self, 10908 struct ui_out *uiout) 10909 { 10910 /* nothing */ 10911 } 10912 10913 static void 10914 base_breakpoint_print_mention (struct breakpoint *b) 10915 { 10916 internal_error_pure_virtual_called (); 10917 } 10918 10919 static void 10920 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) 10921 { 10922 internal_error_pure_virtual_called (); 10923 } 10924 10925 static struct breakpoint_ops base_breakpoint_ops = 10926 { 10927 base_breakpoint_dtor, 10928 base_breakpoint_allocate_location, 10929 base_breakpoint_re_set, 10930 base_breakpoint_insert_location, 10931 base_breakpoint_remove_location, 10932 base_breakpoint_breakpoint_hit, 10933 base_breakpoint_check_status, 10934 base_breakpoint_resources_needed, 10935 base_breakpoint_works_in_software_mode, 10936 base_breakpoint_print_it, 10937 NULL, 10938 base_breakpoint_print_one_detail, 10939 base_breakpoint_print_mention, 10940 base_breakpoint_print_recreate 10941 }; 10942 10943 /* Default breakpoint_ops methods. */ 10944 10945 static void 10946 bkpt_re_set (struct breakpoint *b) 10947 { 10948 /* FIXME: is this still reachable? */ 10949 if (b->addr_string == NULL) 10950 { 10951 /* Anything without a string can't be re-set. */ 10952 delete_breakpoint (b); 10953 return; 10954 } 10955 10956 breakpoint_re_set_default (b); 10957 } 10958 10959 static int 10960 bkpt_insert_location (struct bp_location *bl) 10961 { 10962 if (bl->loc_type == bp_loc_hardware_breakpoint) 10963 return target_insert_hw_breakpoint (bl->gdbarch, 10964 &bl->target_info); 10965 else 10966 return target_insert_breakpoint (bl->gdbarch, 10967 &bl->target_info); 10968 } 10969 10970 static int 10971 bkpt_remove_location (struct bp_location *bl) 10972 { 10973 if (bl->loc_type == bp_loc_hardware_breakpoint) 10974 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); 10975 else 10976 return target_remove_breakpoint (bl->gdbarch, &bl->target_info); 10977 } 10978 10979 static int 10980 bkpt_breakpoint_hit (const struct bp_location *bl, 10981 struct address_space *aspace, CORE_ADDR bp_addr) 10982 { 10983 struct breakpoint *b = bl->owner; 10984 10985 if (!breakpoint_address_match (bl->pspace->aspace, bl->address, 10986 aspace, bp_addr)) 10987 return 0; 10988 10989 if (overlay_debugging /* unmapped overlay section */ 10990 && section_is_overlay (bl->section) 10991 && !section_is_mapped (bl->section)) 10992 return 0; 10993 10994 return 1; 10995 } 10996 10997 static int 10998 bkpt_resources_needed (const struct bp_location *bl) 10999 { 11000 gdb_assert (bl->owner->type == bp_hardware_breakpoint); 11001 11002 return 1; 11003 } 11004 11005 static enum print_stop_action 11006 bkpt_print_it (bpstat bs) 11007 { 11008 struct breakpoint *b; 11009 const struct bp_location *bl; 11010 int bp_temp; 11011 struct ui_out *uiout = current_uiout; 11012 11013 gdb_assert (bs->bp_location_at != NULL); 11014 11015 bl = bs->bp_location_at; 11016 b = bs->breakpoint_at; 11017 11018 bp_temp = b->disposition == disp_del; 11019 if (bl->address != bl->requested_address) 11020 breakpoint_adjustment_warning (bl->requested_address, 11021 bl->address, 11022 b->number, 1); 11023 annotate_breakpoint (b->number); 11024 if (bp_temp) 11025 ui_out_text (uiout, "\nTemporary breakpoint "); 11026 else 11027 ui_out_text (uiout, "\nBreakpoint "); 11028 if (ui_out_is_mi_like_p (uiout)) 11029 { 11030 ui_out_field_string (uiout, "reason", 11031 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); 11032 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 11033 } 11034 ui_out_field_int (uiout, "bkptno", b->number); 11035 ui_out_text (uiout, ", "); 11036 11037 return PRINT_SRC_AND_LOC; 11038 } 11039 11040 static void 11041 bkpt_print_mention (struct breakpoint *b) 11042 { 11043 if (ui_out_is_mi_like_p (current_uiout)) 11044 return; 11045 11046 switch (b->type) 11047 { 11048 case bp_breakpoint: 11049 case bp_gnu_ifunc_resolver: 11050 if (b->disposition == disp_del) 11051 printf_filtered (_("Temporary breakpoint")); 11052 else 11053 printf_filtered (_("Breakpoint")); 11054 printf_filtered (_(" %d"), b->number); 11055 if (b->type == bp_gnu_ifunc_resolver) 11056 printf_filtered (_(" at gnu-indirect-function resolver")); 11057 break; 11058 case bp_hardware_breakpoint: 11059 printf_filtered (_("Hardware assisted breakpoint %d"), b->number); 11060 break; 11061 } 11062 11063 say_where (b); 11064 } 11065 11066 static void 11067 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) 11068 { 11069 if (tp->type == bp_breakpoint && tp->disposition == disp_del) 11070 fprintf_unfiltered (fp, "tbreak"); 11071 else if (tp->type == bp_breakpoint) 11072 fprintf_unfiltered (fp, "break"); 11073 else if (tp->type == bp_hardware_breakpoint 11074 && tp->disposition == disp_del) 11075 fprintf_unfiltered (fp, "thbreak"); 11076 else if (tp->type == bp_hardware_breakpoint) 11077 fprintf_unfiltered (fp, "hbreak"); 11078 else 11079 internal_error (__FILE__, __LINE__, 11080 _("unhandled breakpoint type %d"), (int) tp->type); 11081 11082 fprintf_unfiltered (fp, " %s", tp->addr_string); 11083 print_recreate_thread (tp, fp); 11084 } 11085 11086 /* Virtual table for internal breakpoints. */ 11087 11088 static void 11089 internal_bkpt_re_set (struct breakpoint *b) 11090 { 11091 switch (b->type) 11092 { 11093 /* Delete overlay event and longjmp master breakpoints; they 11094 will be reset later by breakpoint_re_set. */ 11095 case bp_overlay_event: 11096 case bp_longjmp_master: 11097 case bp_std_terminate_master: 11098 case bp_exception_master: 11099 delete_breakpoint (b); 11100 break; 11101 11102 /* This breakpoint is special, it's set up when the inferior 11103 starts and we really don't want to touch it. */ 11104 case bp_shlib_event: 11105 11106 /* Like bp_shlib_event, this breakpoint type is special. Once 11107 it is set up, we do not want to touch it. */ 11108 case bp_thread_event: 11109 break; 11110 } 11111 } 11112 11113 static void 11114 internal_bkpt_check_status (bpstat bs) 11115 { 11116 /* We do not stop for these. */ 11117 bs->stop = 0; 11118 } 11119 11120 static enum print_stop_action 11121 internal_bkpt_print_it (bpstat bs) 11122 { 11123 struct ui_out *uiout = current_uiout; 11124 struct breakpoint *b; 11125 11126 b = bs->breakpoint_at; 11127 11128 switch (b->type) 11129 { 11130 case bp_shlib_event: 11131 /* Did we stop because the user set the stop_on_solib_events 11132 variable? (If so, we report this as a generic, "Stopped due 11133 to shlib event" message.) */ 11134 ui_out_text (uiout, _("Stopped due to shared library event\n")); 11135 if (ui_out_is_mi_like_p (uiout)) 11136 ui_out_field_string (uiout, "reason", 11137 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); 11138 break; 11139 11140 case bp_thread_event: 11141 /* Not sure how we will get here. 11142 GDB should not stop for these breakpoints. */ 11143 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); 11144 break; 11145 11146 case bp_overlay_event: 11147 /* By analogy with the thread event, GDB should not stop for these. */ 11148 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); 11149 break; 11150 11151 case bp_longjmp_master: 11152 /* These should never be enabled. */ 11153 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); 11154 break; 11155 11156 case bp_std_terminate_master: 11157 /* These should never be enabled. */ 11158 printf_filtered (_("std::terminate Master Breakpoint: " 11159 "gdb should not stop!\n")); 11160 break; 11161 11162 case bp_exception_master: 11163 /* These should never be enabled. */ 11164 printf_filtered (_("Exception Master Breakpoint: " 11165 "gdb should not stop!\n")); 11166 break; 11167 } 11168 11169 return PRINT_NOTHING; 11170 } 11171 11172 static void 11173 internal_bkpt_print_mention (struct breakpoint *b) 11174 { 11175 /* Nothing to mention. These breakpoints are internal. */ 11176 } 11177 11178 /* Virtual table for momentary breakpoints */ 11179 11180 static void 11181 momentary_bkpt_re_set (struct breakpoint *b) 11182 { 11183 /* Keep temporary breakpoints, which can be encountered when we step 11184 over a dlopen call and SOLIB_ADD is resetting the breakpoints. 11185 Otherwise these should have been blown away via the cleanup chain 11186 or by breakpoint_init_inferior when we rerun the executable. */ 11187 } 11188 11189 static void 11190 momentary_bkpt_check_status (bpstat bs) 11191 { 11192 /* Nothing. The point of these breakpoints is causing a stop. */ 11193 } 11194 11195 static enum print_stop_action 11196 momentary_bkpt_print_it (bpstat bs) 11197 { 11198 struct ui_out *uiout = current_uiout; 11199 11200 if (ui_out_is_mi_like_p (uiout)) 11201 { 11202 struct breakpoint *b = bs->breakpoint_at; 11203 11204 switch (b->type) 11205 { 11206 case bp_finish: 11207 ui_out_field_string 11208 (uiout, "reason", 11209 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); 11210 break; 11211 11212 case bp_until: 11213 ui_out_field_string 11214 (uiout, "reason", 11215 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); 11216 break; 11217 } 11218 } 11219 11220 return PRINT_UNKNOWN; 11221 } 11222 11223 static void 11224 momentary_bkpt_print_mention (struct breakpoint *b) 11225 { 11226 /* Nothing to mention. These breakpoints are internal. */ 11227 } 11228 11229 /* The breakpoint_ops structure to be used in tracepoints. */ 11230 11231 static void 11232 tracepoint_re_set (struct breakpoint *b) 11233 { 11234 breakpoint_re_set_default (b); 11235 } 11236 11237 static int 11238 tracepoint_breakpoint_hit (const struct bp_location *bl, 11239 struct address_space *aspace, CORE_ADDR bp_addr) 11240 { 11241 /* By definition, the inferior does not report stops at 11242 tracepoints. */ 11243 return 0; 11244 } 11245 11246 static void 11247 tracepoint_print_one_detail (const struct breakpoint *self, 11248 struct ui_out *uiout) 11249 { 11250 struct tracepoint *tp = (struct tracepoint *) self; 11251 if (tp->static_trace_marker_id) 11252 { 11253 gdb_assert (self->type == bp_static_tracepoint); 11254 11255 ui_out_text (uiout, "\tmarker id is "); 11256 ui_out_field_string (uiout, "static-tracepoint-marker-string-id", 11257 tp->static_trace_marker_id); 11258 ui_out_text (uiout, "\n"); 11259 } 11260 } 11261 11262 static void 11263 tracepoint_print_mention (struct breakpoint *b) 11264 { 11265 if (ui_out_is_mi_like_p (current_uiout)) 11266 return; 11267 11268 switch (b->type) 11269 { 11270 case bp_tracepoint: 11271 printf_filtered (_("Tracepoint")); 11272 printf_filtered (_(" %d"), b->number); 11273 break; 11274 case bp_fast_tracepoint: 11275 printf_filtered (_("Fast tracepoint")); 11276 printf_filtered (_(" %d"), b->number); 11277 break; 11278 case bp_static_tracepoint: 11279 printf_filtered (_("Static tracepoint")); 11280 printf_filtered (_(" %d"), b->number); 11281 break; 11282 default: 11283 internal_error (__FILE__, __LINE__, 11284 _("unhandled tracepoint type %d"), (int) b->type); 11285 } 11286 11287 say_where (b); 11288 } 11289 11290 static void 11291 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) 11292 { 11293 struct tracepoint *tp = (struct tracepoint *) self; 11294 11295 if (self->type == bp_fast_tracepoint) 11296 fprintf_unfiltered (fp, "ftrace"); 11297 if (self->type == bp_static_tracepoint) 11298 fprintf_unfiltered (fp, "strace"); 11299 else if (self->type == bp_tracepoint) 11300 fprintf_unfiltered (fp, "trace"); 11301 else 11302 internal_error (__FILE__, __LINE__, 11303 _("unhandled tracepoint type %d"), (int) self->type); 11304 11305 fprintf_unfiltered (fp, " %s", self->addr_string); 11306 print_recreate_thread (self, fp); 11307 11308 if (tp->pass_count) 11309 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); 11310 } 11311 11312 struct breakpoint_ops tracepoint_breakpoint_ops; 11313 11314 /* Delete a breakpoint and clean up all traces of it in the data 11315 structures. */ 11316 11317 void 11318 delete_breakpoint (struct breakpoint *bpt) 11319 { 11320 struct breakpoint *b; 11321 11322 gdb_assert (bpt != NULL); 11323 11324 /* Has this bp already been deleted? This can happen because 11325 multiple lists can hold pointers to bp's. bpstat lists are 11326 especial culprits. 11327 11328 One example of this happening is a watchpoint's scope bp. When 11329 the scope bp triggers, we notice that the watchpoint is out of 11330 scope, and delete it. We also delete its scope bp. But the 11331 scope bp is marked "auto-deleting", and is already on a bpstat. 11332 That bpstat is then checked for auto-deleting bp's, which are 11333 deleted. 11334 11335 A real solution to this problem might involve reference counts in 11336 bp's, and/or giving them pointers back to their referencing 11337 bpstat's, and teaching delete_breakpoint to only free a bp's 11338 storage when no more references were extent. A cheaper bandaid 11339 was chosen. */ 11340 if (bpt->type == bp_none) 11341 return; 11342 11343 /* At least avoid this stale reference until the reference counting 11344 of breakpoints gets resolved. */ 11345 if (bpt->related_breakpoint != bpt) 11346 { 11347 struct breakpoint *related; 11348 struct watchpoint *w; 11349 11350 if (bpt->type == bp_watchpoint_scope) 11351 w = (struct watchpoint *) bpt->related_breakpoint; 11352 else if (bpt->related_breakpoint->type == bp_watchpoint_scope) 11353 w = (struct watchpoint *) bpt; 11354 else 11355 w = NULL; 11356 if (w != NULL) 11357 watchpoint_del_at_next_stop (w); 11358 11359 /* Unlink bpt from the bpt->related_breakpoint ring. */ 11360 for (related = bpt; related->related_breakpoint != bpt; 11361 related = related->related_breakpoint); 11362 related->related_breakpoint = bpt->related_breakpoint; 11363 bpt->related_breakpoint = bpt; 11364 } 11365 11366 /* watch_command_1 creates a watchpoint but only sets its number if 11367 update_watchpoint succeeds in creating its bp_locations. If there's 11368 a problem in that process, we'll be asked to delete the half-created 11369 watchpoint. In that case, don't announce the deletion. */ 11370 if (bpt->number) 11371 observer_notify_breakpoint_deleted (bpt); 11372 11373 if (breakpoint_chain == bpt) 11374 breakpoint_chain = bpt->next; 11375 11376 ALL_BREAKPOINTS (b) 11377 if (b->next == bpt) 11378 { 11379 b->next = bpt->next; 11380 break; 11381 } 11382 11383 /* Be sure no bpstat's are pointing at the breakpoint after it's 11384 been freed. */ 11385 /* FIXME, how can we find all bpstat's? We just check stop_bpstat 11386 in all threads for now. Note that we cannot just remove bpstats 11387 pointing at bpt from the stop_bpstat list entirely, as breakpoint 11388 commands are associated with the bpstat; if we remove it here, 11389 then the later call to bpstat_do_actions (&stop_bpstat); in 11390 event-top.c won't do anything, and temporary breakpoints with 11391 commands won't work. */ 11392 11393 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); 11394 11395 /* Now that breakpoint is removed from breakpoint list, update the 11396 global location list. This will remove locations that used to 11397 belong to this breakpoint. Do this before freeing the breakpoint 11398 itself, since remove_breakpoint looks at location's owner. It 11399 might be better design to have location completely 11400 self-contained, but it's not the case now. */ 11401 update_global_location_list (0); 11402 11403 bpt->ops->dtor (bpt); 11404 /* On the chance that someone will soon try again to delete this 11405 same bp, we mark it as deleted before freeing its storage. */ 11406 bpt->type = bp_none; 11407 xfree (bpt); 11408 } 11409 11410 static void 11411 do_delete_breakpoint_cleanup (void *b) 11412 { 11413 delete_breakpoint (b); 11414 } 11415 11416 struct cleanup * 11417 make_cleanup_delete_breakpoint (struct breakpoint *b) 11418 { 11419 return make_cleanup (do_delete_breakpoint_cleanup, b); 11420 } 11421 11422 /* Iterator function to call a user-provided callback function once 11423 for each of B and its related breakpoints. */ 11424 11425 static void 11426 iterate_over_related_breakpoints (struct breakpoint *b, 11427 void (*function) (struct breakpoint *, 11428 void *), 11429 void *data) 11430 { 11431 struct breakpoint *related; 11432 11433 related = b; 11434 do 11435 { 11436 struct breakpoint *next; 11437 11438 /* FUNCTION may delete RELATED. */ 11439 next = related->related_breakpoint; 11440 11441 if (next == related) 11442 { 11443 /* RELATED is the last ring entry. */ 11444 function (related, data); 11445 11446 /* FUNCTION may have deleted it, so we'd never reach back to 11447 B. There's nothing left to do anyway, so just break 11448 out. */ 11449 break; 11450 } 11451 else 11452 function (related, data); 11453 11454 related = next; 11455 } 11456 while (related != b); 11457 } 11458 11459 static void 11460 do_delete_breakpoint (struct breakpoint *b, void *ignore) 11461 { 11462 delete_breakpoint (b); 11463 } 11464 11465 /* A callback for map_breakpoint_numbers that calls 11466 delete_breakpoint. */ 11467 11468 static void 11469 do_map_delete_breakpoint (struct breakpoint *b, void *ignore) 11470 { 11471 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); 11472 } 11473 11474 void 11475 delete_command (char *arg, int from_tty) 11476 { 11477 struct breakpoint *b, *b_tmp; 11478 11479 dont_repeat (); 11480 11481 if (arg == 0) 11482 { 11483 int breaks_to_delete = 0; 11484 11485 /* Delete all breakpoints if no argument. Do not delete 11486 internal breakpoints, these have to be deleted with an 11487 explicit breakpoint number argument. */ 11488 ALL_BREAKPOINTS (b) 11489 if (user_breakpoint_p (b)) 11490 { 11491 breaks_to_delete = 1; 11492 break; 11493 } 11494 11495 /* Ask user only if there are some breakpoints to delete. */ 11496 if (!from_tty 11497 || (breaks_to_delete && query (_("Delete all breakpoints? ")))) 11498 { 11499 ALL_BREAKPOINTS_SAFE (b, b_tmp) 11500 if (user_breakpoint_p (b)) 11501 delete_breakpoint (b); 11502 } 11503 } 11504 else 11505 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); 11506 } 11507 11508 static int 11509 all_locations_are_pending (struct bp_location *loc) 11510 { 11511 for (; loc; loc = loc->next) 11512 if (!loc->shlib_disabled 11513 && !loc->pspace->executing_startup) 11514 return 0; 11515 return 1; 11516 } 11517 11518 /* Subroutine of update_breakpoint_locations to simplify it. 11519 Return non-zero if multiple fns in list LOC have the same name. 11520 Null names are ignored. */ 11521 11522 static int 11523 ambiguous_names_p (struct bp_location *loc) 11524 { 11525 struct bp_location *l; 11526 htab_t htab = htab_create_alloc (13, htab_hash_string, 11527 (int (*) (const void *, 11528 const void *)) streq, 11529 NULL, xcalloc, xfree); 11530 11531 for (l = loc; l != NULL; l = l->next) 11532 { 11533 const char **slot; 11534 const char *name = l->function_name; 11535 11536 /* Allow for some names to be NULL, ignore them. */ 11537 if (name == NULL) 11538 continue; 11539 11540 slot = (const char **) htab_find_slot (htab, (const void *) name, 11541 INSERT); 11542 /* NOTE: We can assume slot != NULL here because xcalloc never 11543 returns NULL. */ 11544 if (*slot != NULL) 11545 { 11546 htab_delete (htab); 11547 return 1; 11548 } 11549 *slot = name; 11550 } 11551 11552 htab_delete (htab); 11553 return 0; 11554 } 11555 11556 /* When symbols change, it probably means the sources changed as well, 11557 and it might mean the static tracepoint markers are no longer at 11558 the same address or line numbers they used to be at last we 11559 checked. Losing your static tracepoints whenever you rebuild is 11560 undesirable. This function tries to resync/rematch gdb static 11561 tracepoints with the markers on the target, for static tracepoints 11562 that have not been set by marker id. Static tracepoint that have 11563 been set by marker id are reset by marker id in breakpoint_re_set. 11564 The heuristic is: 11565 11566 1) For a tracepoint set at a specific address, look for a marker at 11567 the old PC. If one is found there, assume to be the same marker. 11568 If the name / string id of the marker found is different from the 11569 previous known name, assume that means the user renamed the marker 11570 in the sources, and output a warning. 11571 11572 2) For a tracepoint set at a given line number, look for a marker 11573 at the new address of the old line number. If one is found there, 11574 assume to be the same marker. If the name / string id of the 11575 marker found is different from the previous known name, assume that 11576 means the user renamed the marker in the sources, and output a 11577 warning. 11578 11579 3) If a marker is no longer found at the same address or line, it 11580 may mean the marker no longer exists. But it may also just mean 11581 the code changed a bit. Maybe the user added a few lines of code 11582 that made the marker move up or down (in line number terms). Ask 11583 the target for info about the marker with the string id as we knew 11584 it. If found, update line number and address in the matching 11585 static tracepoint. This will get confused if there's more than one 11586 marker with the same ID (possible in UST, although unadvised 11587 precisely because it confuses tools). */ 11588 11589 static struct symtab_and_line 11590 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) 11591 { 11592 struct tracepoint *tp = (struct tracepoint *) b; 11593 struct static_tracepoint_marker marker; 11594 CORE_ADDR pc; 11595 int i; 11596 11597 pc = sal.pc; 11598 if (sal.line) 11599 find_line_pc (sal.symtab, sal.line, &pc); 11600 11601 if (target_static_tracepoint_marker_at (pc, &marker)) 11602 { 11603 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) 11604 warning (_("static tracepoint %d changed probed marker from %s to %s"), 11605 b->number, 11606 tp->static_trace_marker_id, marker.str_id); 11607 11608 xfree (tp->static_trace_marker_id); 11609 tp->static_trace_marker_id = xstrdup (marker.str_id); 11610 release_static_tracepoint_marker (&marker); 11611 11612 return sal; 11613 } 11614 11615 /* Old marker wasn't found on target at lineno. Try looking it up 11616 by string ID. */ 11617 if (!sal.explicit_pc 11618 && sal.line != 0 11619 && sal.symtab != NULL 11620 && tp->static_trace_marker_id != NULL) 11621 { 11622 VEC(static_tracepoint_marker_p) *markers; 11623 11624 markers 11625 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); 11626 11627 if (!VEC_empty(static_tracepoint_marker_p, markers)) 11628 { 11629 struct symtab_and_line sal2; 11630 struct symbol *sym; 11631 struct static_tracepoint_marker *tpmarker; 11632 struct ui_out *uiout = current_uiout; 11633 11634 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); 11635 11636 xfree (tp->static_trace_marker_id); 11637 tp->static_trace_marker_id = xstrdup (tpmarker->str_id); 11638 11639 warning (_("marker for static tracepoint %d (%s) not " 11640 "found at previous line number"), 11641 b->number, tp->static_trace_marker_id); 11642 11643 init_sal (&sal2); 11644 11645 sal2.pc = tpmarker->address; 11646 11647 sal2 = find_pc_line (tpmarker->address, 0); 11648 sym = find_pc_sect_function (tpmarker->address, NULL); 11649 ui_out_text (uiout, "Now in "); 11650 if (sym) 11651 { 11652 ui_out_field_string (uiout, "func", 11653 SYMBOL_PRINT_NAME (sym)); 11654 ui_out_text (uiout, " at "); 11655 } 11656 ui_out_field_string (uiout, "file", sal2.symtab->filename); 11657 ui_out_text (uiout, ":"); 11658 11659 if (ui_out_is_mi_like_p (uiout)) 11660 { 11661 char *fullname = symtab_to_fullname (sal2.symtab); 11662 11663 if (fullname) 11664 ui_out_field_string (uiout, "fullname", fullname); 11665 } 11666 11667 ui_out_field_int (uiout, "line", sal2.line); 11668 ui_out_text (uiout, "\n"); 11669 11670 b->loc->line_number = sal2.line; 11671 11672 xfree (b->loc->source_file); 11673 if (sym) 11674 b->loc->source_file = xstrdup (sal2.symtab->filename); 11675 else 11676 b->loc->source_file = NULL; 11677 11678 xfree (b->addr_string); 11679 b->addr_string = xstrprintf ("%s:%d", 11680 sal2.symtab->filename, 11681 b->loc->line_number); 11682 11683 /* Might be nice to check if function changed, and warn if 11684 so. */ 11685 11686 release_static_tracepoint_marker (tpmarker); 11687 } 11688 } 11689 return sal; 11690 } 11691 11692 /* Returns 1 iff locations A and B are sufficiently same that 11693 we don't need to report breakpoint as changed. */ 11694 11695 static int 11696 locations_are_equal (struct bp_location *a, struct bp_location *b) 11697 { 11698 while (a && b) 11699 { 11700 if (a->address != b->address) 11701 return 0; 11702 11703 if (a->shlib_disabled != b->shlib_disabled) 11704 return 0; 11705 11706 if (a->enabled != b->enabled) 11707 return 0; 11708 11709 a = a->next; 11710 b = b->next; 11711 } 11712 11713 if ((a == NULL) != (b == NULL)) 11714 return 0; 11715 11716 return 1; 11717 } 11718 11719 /* Create new breakpoint locations for B (a hardware or software breakpoint) 11720 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is 11721 a ranged breakpoint. */ 11722 11723 void 11724 update_breakpoint_locations (struct breakpoint *b, 11725 struct symtabs_and_lines sals, 11726 struct symtabs_and_lines sals_end) 11727 { 11728 int i; 11729 struct bp_location *existing_locations = b->loc; 11730 11731 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) 11732 { 11733 /* Ranged breakpoints have only one start location and one end 11734 location. */ 11735 b->enable_state = bp_disabled; 11736 update_global_location_list (1); 11737 printf_unfiltered (_("Could not reset ranged breakpoint %d: " 11738 "multiple locations found\n"), 11739 b->number); 11740 return; 11741 } 11742 11743 /* If there's no new locations, and all existing locations are 11744 pending, don't do anything. This optimizes the common case where 11745 all locations are in the same shared library, that was unloaded. 11746 We'd like to retain the location, so that when the library is 11747 loaded again, we don't loose the enabled/disabled status of the 11748 individual locations. */ 11749 if (all_locations_are_pending (existing_locations) && sals.nelts == 0) 11750 return; 11751 11752 b->loc = NULL; 11753 11754 for (i = 0; i < sals.nelts; ++i) 11755 { 11756 struct bp_location *new_loc; 11757 11758 switch_to_program_space_and_thread (sals.sals[i].pspace); 11759 11760 new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); 11761 11762 /* Reparse conditions, they might contain references to the 11763 old symtab. */ 11764 if (b->cond_string != NULL) 11765 { 11766 char *s; 11767 struct gdb_exception e; 11768 11769 s = b->cond_string; 11770 TRY_CATCH (e, RETURN_MASK_ERROR) 11771 { 11772 new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 11773 0); 11774 } 11775 if (e.reason < 0) 11776 { 11777 warning (_("failed to reevaluate condition " 11778 "for breakpoint %d: %s"), 11779 b->number, e.message); 11780 new_loc->enabled = 0; 11781 } 11782 } 11783 11784 if (sals_end.nelts) 11785 { 11786 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); 11787 11788 new_loc->length = end - sals.sals[0].pc + 1; 11789 } 11790 } 11791 11792 /* Update locations of permanent breakpoints. */ 11793 if (b->enable_state == bp_permanent) 11794 make_breakpoint_permanent (b); 11795 11796 /* If possible, carry over 'disable' status from existing 11797 breakpoints. */ 11798 { 11799 struct bp_location *e = existing_locations; 11800 /* If there are multiple breakpoints with the same function name, 11801 e.g. for inline functions, comparing function names won't work. 11802 Instead compare pc addresses; this is just a heuristic as things 11803 may have moved, but in practice it gives the correct answer 11804 often enough until a better solution is found. */ 11805 int have_ambiguous_names = ambiguous_names_p (b->loc); 11806 11807 for (; e; e = e->next) 11808 { 11809 if (!e->enabled && e->function_name) 11810 { 11811 struct bp_location *l = b->loc; 11812 if (have_ambiguous_names) 11813 { 11814 for (; l; l = l->next) 11815 if (breakpoint_locations_match (e, l)) 11816 { 11817 l->enabled = 0; 11818 break; 11819 } 11820 } 11821 else 11822 { 11823 for (; l; l = l->next) 11824 if (l->function_name 11825 && strcmp (e->function_name, l->function_name) == 0) 11826 { 11827 l->enabled = 0; 11828 break; 11829 } 11830 } 11831 } 11832 } 11833 } 11834 11835 if (!locations_are_equal (existing_locations, b->loc)) 11836 observer_notify_breakpoint_modified (b); 11837 11838 update_global_location_list (1); 11839 } 11840 11841 /* Find the SaL locations corresponding to the given ADDR_STRING. 11842 On return, FOUND will be 1 if any SaL was found, zero otherwise. */ 11843 11844 static struct symtabs_and_lines 11845 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) 11846 { 11847 char *s; 11848 int marker_spec; 11849 struct symtabs_and_lines sals = {0}; 11850 volatile struct gdb_exception e; 11851 11852 s = addr_string; 11853 marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); 11854 11855 TRY_CATCH (e, RETURN_MASK_ERROR) 11856 { 11857 if (marker_spec) 11858 { 11859 struct tracepoint *tp = (struct tracepoint *) b; 11860 11861 sals = decode_static_tracepoint_spec (&s); 11862 if (sals.nelts > tp->static_trace_marker_id_idx) 11863 { 11864 sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx]; 11865 sals.nelts = 1; 11866 } 11867 else 11868 error (_("marker %s not found"), tp->static_trace_marker_id); 11869 } 11870 else 11871 { 11872 struct linespec_result canonical; 11873 11874 init_linespec_result (&canonical); 11875 decode_line_full (&s, DECODE_LINE_FUNFIRSTLINE, 11876 (struct symtab *) NULL, 0, 11877 &canonical, multiple_symbols_all, 11878 b->filter); 11879 11880 /* We should get 0 or 1 resulting SALs. */ 11881 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); 11882 11883 if (VEC_length (linespec_sals, canonical.sals) > 0) 11884 { 11885 struct linespec_sals *lsal; 11886 11887 lsal = VEC_index (linespec_sals, canonical.sals, 0); 11888 sals = lsal->sals; 11889 /* Arrange it so the destructor does not free the 11890 contents. */ 11891 lsal->sals.sals = NULL; 11892 } 11893 11894 destroy_linespec_result (&canonical); 11895 } 11896 } 11897 if (e.reason < 0) 11898 { 11899 int not_found_and_ok = 0; 11900 /* For pending breakpoints, it's expected that parsing will 11901 fail until the right shared library is loaded. User has 11902 already told to create pending breakpoints and don't need 11903 extra messages. If breakpoint is in bp_shlib_disabled 11904 state, then user already saw the message about that 11905 breakpoint being disabled, and don't want to see more 11906 errors. */ 11907 if (e.error == NOT_FOUND_ERROR 11908 && (b->condition_not_parsed 11909 || (b->loc && b->loc->shlib_disabled) 11910 || (b->loc && b->loc->pspace->executing_startup) 11911 || b->enable_state == bp_disabled)) 11912 not_found_and_ok = 1; 11913 11914 if (!not_found_and_ok) 11915 { 11916 /* We surely don't want to warn about the same breakpoint 11917 10 times. One solution, implemented here, is disable 11918 the breakpoint on error. Another solution would be to 11919 have separate 'warning emitted' flag. Since this 11920 happens only when a binary has changed, I don't know 11921 which approach is better. */ 11922 b->enable_state = bp_disabled; 11923 throw_exception (e); 11924 } 11925 } 11926 11927 if (e.reason == 0 || e.error != NOT_FOUND_ERROR) 11928 { 11929 int i; 11930 11931 for (i = 0; i < sals.nelts; ++i) 11932 resolve_sal_pc (&sals.sals[i]); 11933 if (b->condition_not_parsed && s && s[0]) 11934 { 11935 char *cond_string = 0; 11936 int thread = -1; 11937 int task = 0; 11938 11939 find_condition_and_thread (s, sals.sals[0].pc, 11940 &cond_string, &thread, &task); 11941 if (cond_string) 11942 b->cond_string = cond_string; 11943 b->thread = thread; 11944 b->task = task; 11945 b->condition_not_parsed = 0; 11946 } 11947 11948 if (b->type == bp_static_tracepoint && !marker_spec) 11949 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); 11950 11951 *found = 1; 11952 } 11953 else 11954 *found = 0; 11955 11956 return sals; 11957 } 11958 11959 /* The default re_set method, for typical hardware or software 11960 breakpoints. Reevaluate the breakpoint and recreate its 11961 locations. */ 11962 11963 static void 11964 breakpoint_re_set_default (struct breakpoint *b) 11965 { 11966 int found; 11967 struct symtabs_and_lines sals, sals_end; 11968 struct symtabs_and_lines expanded = {0}; 11969 struct symtabs_and_lines expanded_end = {0}; 11970 11971 sals = addr_string_to_sals (b, b->addr_string, &found); 11972 if (found) 11973 { 11974 make_cleanup (xfree, sals.sals); 11975 expanded = sals; 11976 } 11977 11978 if (b->addr_string_range_end) 11979 { 11980 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); 11981 if (found) 11982 { 11983 make_cleanup (xfree, sals_end.sals); 11984 expanded_end = sals_end; 11985 } 11986 } 11987 11988 update_breakpoint_locations (b, expanded, expanded_end); 11989 } 11990 11991 /* Prepare the global context for a re-set of breakpoint B. */ 11992 11993 static struct cleanup * 11994 prepare_re_set_context (struct breakpoint *b) 11995 { 11996 struct cleanup *cleanups; 11997 11998 input_radix = b->input_radix; 11999 cleanups = save_current_space_and_thread (); 12000 if (b->pspace != NULL) 12001 switch_to_program_space_and_thread (b->pspace); 12002 set_language (b->language); 12003 12004 return cleanups; 12005 } 12006 12007 /* Reset a breakpoint given it's struct breakpoint * BINT. 12008 The value we return ends up being the return value from catch_errors. 12009 Unused in this case. */ 12010 12011 static int 12012 breakpoint_re_set_one (void *bint) 12013 { 12014 /* Get past catch_errs. */ 12015 struct breakpoint *b = (struct breakpoint *) bint; 12016 struct cleanup *cleanups; 12017 12018 cleanups = prepare_re_set_context (b); 12019 b->ops->re_set (b); 12020 do_cleanups (cleanups); 12021 return 0; 12022 } 12023 12024 /* Re-set all breakpoints after symbols have been re-loaded. */ 12025 void 12026 breakpoint_re_set (void) 12027 { 12028 struct breakpoint *b, *b_tmp; 12029 enum language save_language; 12030 int save_input_radix; 12031 struct cleanup *old_chain; 12032 12033 save_language = current_language->la_language; 12034 save_input_radix = input_radix; 12035 old_chain = save_current_program_space (); 12036 12037 ALL_BREAKPOINTS_SAFE (b, b_tmp) 12038 { 12039 /* Format possible error msg. */ 12040 char *message = xstrprintf ("Error in re-setting breakpoint %d: ", 12041 b->number); 12042 struct cleanup *cleanups = make_cleanup (xfree, message); 12043 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); 12044 do_cleanups (cleanups); 12045 } 12046 set_language (save_language); 12047 input_radix = save_input_radix; 12048 12049 jit_breakpoint_re_set (); 12050 12051 do_cleanups (old_chain); 12052 12053 create_overlay_event_breakpoint (); 12054 create_longjmp_master_breakpoint (); 12055 create_std_terminate_master_breakpoint (); 12056 create_exception_master_breakpoint (); 12057 12058 /* While we're at it, reset the skip list too. */ 12059 skip_re_set (); 12060 } 12061 12062 /* Reset the thread number of this breakpoint: 12063 12064 - If the breakpoint is for all threads, leave it as-is. 12065 - Else, reset it to the current thread for inferior_ptid. */ 12066 void 12067 breakpoint_re_set_thread (struct breakpoint *b) 12068 { 12069 if (b->thread != -1) 12070 { 12071 if (in_thread_list (inferior_ptid)) 12072 b->thread = pid_to_thread_id (inferior_ptid); 12073 12074 /* We're being called after following a fork. The new fork is 12075 selected as current, and unless this was a vfork will have a 12076 different program space from the original thread. Reset that 12077 as well. */ 12078 b->loc->pspace = current_program_space; 12079 } 12080 } 12081 12082 /* Set ignore-count of breakpoint number BPTNUM to COUNT. 12083 If from_tty is nonzero, it prints a message to that effect, 12084 which ends with a period (no newline). */ 12085 12086 void 12087 set_ignore_count (int bptnum, int count, int from_tty) 12088 { 12089 struct breakpoint *b; 12090 12091 if (count < 0) 12092 count = 0; 12093 12094 ALL_BREAKPOINTS (b) 12095 if (b->number == bptnum) 12096 { 12097 if (is_tracepoint (b)) 12098 { 12099 if (from_tty && count != 0) 12100 printf_filtered (_("Ignore count ignored for tracepoint %d."), 12101 bptnum); 12102 return; 12103 } 12104 12105 b->ignore_count = count; 12106 if (from_tty) 12107 { 12108 if (count == 0) 12109 printf_filtered (_("Will stop next time " 12110 "breakpoint %d is reached."), 12111 bptnum); 12112 else if (count == 1) 12113 printf_filtered (_("Will ignore next crossing of breakpoint %d."), 12114 bptnum); 12115 else 12116 printf_filtered (_("Will ignore next %d " 12117 "crossings of breakpoint %d."), 12118 count, bptnum); 12119 } 12120 breakpoints_changed (); 12121 observer_notify_breakpoint_modified (b); 12122 return; 12123 } 12124 12125 error (_("No breakpoint number %d."), bptnum); 12126 } 12127 12128 /* Command to set ignore-count of breakpoint N to COUNT. */ 12129 12130 static void 12131 ignore_command (char *args, int from_tty) 12132 { 12133 char *p = args; 12134 int num; 12135 12136 if (p == 0) 12137 error_no_arg (_("a breakpoint number")); 12138 12139 num = get_number (&p); 12140 if (num == 0) 12141 error (_("bad breakpoint number: '%s'"), args); 12142 if (*p == 0) 12143 error (_("Second argument (specified ignore-count) is missing.")); 12144 12145 set_ignore_count (num, 12146 longest_to_int (value_as_long (parse_and_eval (p))), 12147 from_tty); 12148 if (from_tty) 12149 printf_filtered ("\n"); 12150 } 12151 12152 /* Call FUNCTION on each of the breakpoints 12153 whose numbers are given in ARGS. */ 12154 12155 static void 12156 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, 12157 void *), 12158 void *data) 12159 { 12160 int num; 12161 struct breakpoint *b, *tmp; 12162 int match; 12163 struct get_number_or_range_state state; 12164 12165 if (args == 0) 12166 error_no_arg (_("one or more breakpoint numbers")); 12167 12168 init_number_or_range (&state, args); 12169 12170 while (!state.finished) 12171 { 12172 char *p = state.string; 12173 12174 match = 0; 12175 12176 num = get_number_or_range (&state); 12177 if (num == 0) 12178 { 12179 warning (_("bad breakpoint number at or near '%s'"), p); 12180 } 12181 else 12182 { 12183 ALL_BREAKPOINTS_SAFE (b, tmp) 12184 if (b->number == num) 12185 { 12186 match = 1; 12187 function (b, data); 12188 break; 12189 } 12190 if (match == 0) 12191 printf_unfiltered (_("No breakpoint number %d.\n"), num); 12192 } 12193 } 12194 } 12195 12196 static struct bp_location * 12197 find_location_by_number (char *number) 12198 { 12199 char *dot = strchr (number, '.'); 12200 char *p1; 12201 int bp_num; 12202 int loc_num; 12203 struct breakpoint *b; 12204 struct bp_location *loc; 12205 12206 *dot = '\0'; 12207 12208 p1 = number; 12209 bp_num = get_number (&p1); 12210 if (bp_num == 0) 12211 error (_("Bad breakpoint number '%s'"), number); 12212 12213 ALL_BREAKPOINTS (b) 12214 if (b->number == bp_num) 12215 { 12216 break; 12217 } 12218 12219 if (!b || b->number != bp_num) 12220 error (_("Bad breakpoint number '%s'"), number); 12221 12222 p1 = dot+1; 12223 loc_num = get_number (&p1); 12224 if (loc_num == 0) 12225 error (_("Bad breakpoint location number '%s'"), number); 12226 12227 --loc_num; 12228 loc = b->loc; 12229 for (;loc_num && loc; --loc_num, loc = loc->next) 12230 ; 12231 if (!loc) 12232 error (_("Bad breakpoint location number '%s'"), dot+1); 12233 12234 return loc; 12235 } 12236 12237 12238 /* Set ignore-count of breakpoint number BPTNUM to COUNT. 12239 If from_tty is nonzero, it prints a message to that effect, 12240 which ends with a period (no newline). */ 12241 12242 void 12243 disable_breakpoint (struct breakpoint *bpt) 12244 { 12245 /* Never disable a watchpoint scope breakpoint; we want to 12246 hit them when we leave scope so we can delete both the 12247 watchpoint and its scope breakpoint at that time. */ 12248 if (bpt->type == bp_watchpoint_scope) 12249 return; 12250 12251 /* You can't disable permanent breakpoints. */ 12252 if (bpt->enable_state == bp_permanent) 12253 return; 12254 12255 bpt->enable_state = bp_disabled; 12256 12257 if (target_supports_enable_disable_tracepoint () 12258 && current_trace_status ()->running && is_tracepoint (bpt)) 12259 { 12260 struct bp_location *location; 12261 12262 for (location = bpt->loc; location; location = location->next) 12263 target_disable_tracepoint (location); 12264 } 12265 12266 update_global_location_list (0); 12267 12268 observer_notify_breakpoint_modified (bpt); 12269 } 12270 12271 /* A callback for iterate_over_related_breakpoints. */ 12272 12273 static void 12274 do_disable_breakpoint (struct breakpoint *b, void *ignore) 12275 { 12276 disable_breakpoint (b); 12277 } 12278 12279 /* A callback for map_breakpoint_numbers that calls 12280 disable_breakpoint. */ 12281 12282 static void 12283 do_map_disable_breakpoint (struct breakpoint *b, void *ignore) 12284 { 12285 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); 12286 } 12287 12288 static void 12289 disable_command (char *args, int from_tty) 12290 { 12291 if (args == 0) 12292 { 12293 struct breakpoint *bpt; 12294 12295 ALL_BREAKPOINTS (bpt) 12296 if (user_breakpoint_p (bpt)) 12297 disable_breakpoint (bpt); 12298 } 12299 else if (strchr (args, '.')) 12300 { 12301 struct bp_location *loc = find_location_by_number (args); 12302 if (loc) 12303 { 12304 loc->enabled = 0; 12305 if (target_supports_enable_disable_tracepoint () 12306 && current_trace_status ()->running && loc->owner 12307 && is_tracepoint (loc->owner)) 12308 target_disable_tracepoint (loc); 12309 } 12310 update_global_location_list (0); 12311 } 12312 else 12313 map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); 12314 } 12315 12316 static void 12317 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) 12318 { 12319 int target_resources_ok; 12320 12321 if (bpt->type == bp_hardware_breakpoint) 12322 { 12323 int i; 12324 i = hw_breakpoint_used_count (); 12325 target_resources_ok = 12326 target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 12327 i + 1, 0); 12328 if (target_resources_ok == 0) 12329 error (_("No hardware breakpoint support in the target.")); 12330 else if (target_resources_ok < 0) 12331 error (_("Hardware breakpoints used exceeds limit.")); 12332 } 12333 12334 if (is_watchpoint (bpt)) 12335 { 12336 /* Initialize it just to avoid a GCC false warning. */ 12337 enum enable_state orig_enable_state = 0; 12338 struct gdb_exception e; 12339 12340 TRY_CATCH (e, RETURN_MASK_ALL) 12341 { 12342 struct watchpoint *w = (struct watchpoint *) bpt; 12343 12344 orig_enable_state = bpt->enable_state; 12345 bpt->enable_state = bp_enabled; 12346 update_watchpoint (w, 1 /* reparse */); 12347 } 12348 if (e.reason < 0) 12349 { 12350 bpt->enable_state = orig_enable_state; 12351 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), 12352 bpt->number); 12353 return; 12354 } 12355 } 12356 12357 if (bpt->enable_state != bp_permanent) 12358 bpt->enable_state = bp_enabled; 12359 12360 if (target_supports_enable_disable_tracepoint () 12361 && current_trace_status ()->running && is_tracepoint (bpt)) 12362 { 12363 struct bp_location *location; 12364 12365 for (location = bpt->loc; location; location = location->next) 12366 target_enable_tracepoint (location); 12367 } 12368 12369 bpt->disposition = disposition; 12370 update_global_location_list (1); 12371 breakpoints_changed (); 12372 12373 observer_notify_breakpoint_modified (bpt); 12374 } 12375 12376 12377 void 12378 enable_breakpoint (struct breakpoint *bpt) 12379 { 12380 enable_breakpoint_disp (bpt, bpt->disposition); 12381 } 12382 12383 static void 12384 do_enable_breakpoint (struct breakpoint *bpt, void *arg) 12385 { 12386 enable_breakpoint (bpt); 12387 } 12388 12389 /* A callback for map_breakpoint_numbers that calls 12390 enable_breakpoint. */ 12391 12392 static void 12393 do_map_enable_breakpoint (struct breakpoint *b, void *ignore) 12394 { 12395 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); 12396 } 12397 12398 /* The enable command enables the specified breakpoints (or all defined 12399 breakpoints) so they once again become (or continue to be) effective 12400 in stopping the inferior. */ 12401 12402 static void 12403 enable_command (char *args, int from_tty) 12404 { 12405 if (args == 0) 12406 { 12407 struct breakpoint *bpt; 12408 12409 ALL_BREAKPOINTS (bpt) 12410 if (user_breakpoint_p (bpt)) 12411 enable_breakpoint (bpt); 12412 } 12413 else if (strchr (args, '.')) 12414 { 12415 struct bp_location *loc = find_location_by_number (args); 12416 if (loc) 12417 { 12418 loc->enabled = 1; 12419 if (target_supports_enable_disable_tracepoint () 12420 && current_trace_status ()->running && loc->owner 12421 && is_tracepoint (loc->owner)) 12422 target_enable_tracepoint (loc); 12423 } 12424 update_global_location_list (1); 12425 } 12426 else 12427 map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); 12428 } 12429 12430 static void 12431 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) 12432 { 12433 enum bpdisp disp = *(enum bpdisp *) arg; 12434 12435 enable_breakpoint_disp (bpt, disp); 12436 } 12437 12438 static void 12439 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) 12440 { 12441 enum bpdisp disp = disp_disable; 12442 12443 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); 12444 } 12445 12446 static void 12447 enable_once_command (char *args, int from_tty) 12448 { 12449 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); 12450 } 12451 12452 static void 12453 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) 12454 { 12455 enum bpdisp disp = disp_del; 12456 12457 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); 12458 } 12459 12460 static void 12461 enable_delete_command (char *args, int from_tty) 12462 { 12463 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); 12464 } 12465 12466 static void 12467 set_breakpoint_cmd (char *args, int from_tty) 12468 { 12469 } 12470 12471 static void 12472 show_breakpoint_cmd (char *args, int from_tty) 12473 { 12474 } 12475 12476 /* Invalidate last known value of any hardware watchpoint if 12477 the memory which that value represents has been written to by 12478 GDB itself. */ 12479 12480 static void 12481 invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, 12482 const bfd_byte *data) 12483 { 12484 struct breakpoint *bp; 12485 12486 ALL_BREAKPOINTS (bp) 12487 if (bp->enable_state == bp_enabled 12488 && bp->type == bp_hardware_watchpoint) 12489 { 12490 struct watchpoint *wp = (struct watchpoint *) bp; 12491 12492 if (wp->val_valid && wp->val) 12493 { 12494 struct bp_location *loc; 12495 12496 for (loc = bp->loc; loc != NULL; loc = loc->next) 12497 if (loc->loc_type == bp_loc_hardware_watchpoint 12498 && loc->address + loc->length > addr 12499 && addr + len > loc->address) 12500 { 12501 value_free (wp->val); 12502 wp->val = NULL; 12503 wp->val_valid = 0; 12504 } 12505 } 12506 } 12507 } 12508 12509 /* Use the last displayed codepoint's values, or nothing 12510 if they aren't valid. */ 12511 12512 struct symtabs_and_lines 12513 decode_line_spec_1 (char *string, int flags) 12514 { 12515 struct symtabs_and_lines sals; 12516 12517 if (string == 0) 12518 error (_("Empty line specification.")); 12519 if (last_displayed_sal_is_valid ()) 12520 sals = decode_line_1 (&string, flags, 12521 get_last_displayed_symtab (), 12522 get_last_displayed_line ()); 12523 else 12524 sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0); 12525 if (*string) 12526 error (_("Junk at end of line specification: %s"), string); 12527 return sals; 12528 } 12529 12530 /* Create and insert a raw software breakpoint at PC. Return an 12531 identifier, which should be used to remove the breakpoint later. 12532 In general, places which call this should be using something on the 12533 breakpoint chain instead; this function should be eliminated 12534 someday. */ 12535 12536 void * 12537 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, 12538 struct address_space *aspace, CORE_ADDR pc) 12539 { 12540 struct bp_target_info *bp_tgt; 12541 12542 bp_tgt = XZALLOC (struct bp_target_info); 12543 12544 bp_tgt->placed_address_space = aspace; 12545 bp_tgt->placed_address = pc; 12546 12547 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) 12548 { 12549 /* Could not insert the breakpoint. */ 12550 xfree (bp_tgt); 12551 return NULL; 12552 } 12553 12554 return bp_tgt; 12555 } 12556 12557 /* Remove a breakpoint BP inserted by 12558 deprecated_insert_raw_breakpoint. */ 12559 12560 int 12561 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) 12562 { 12563 struct bp_target_info *bp_tgt = bp; 12564 int ret; 12565 12566 ret = target_remove_breakpoint (gdbarch, bp_tgt); 12567 xfree (bp_tgt); 12568 12569 return ret; 12570 } 12571 12572 /* One (or perhaps two) breakpoints used for software single 12573 stepping. */ 12574 12575 static void *single_step_breakpoints[2]; 12576 static struct gdbarch *single_step_gdbarch[2]; 12577 12578 /* Create and insert a breakpoint for software single step. */ 12579 12580 void 12581 insert_single_step_breakpoint (struct gdbarch *gdbarch, 12582 struct address_space *aspace, 12583 CORE_ADDR next_pc) 12584 { 12585 void **bpt_p; 12586 12587 if (single_step_breakpoints[0] == NULL) 12588 { 12589 bpt_p = &single_step_breakpoints[0]; 12590 single_step_gdbarch[0] = gdbarch; 12591 } 12592 else 12593 { 12594 gdb_assert (single_step_breakpoints[1] == NULL); 12595 bpt_p = &single_step_breakpoints[1]; 12596 single_step_gdbarch[1] = gdbarch; 12597 } 12598 12599 /* NOTE drow/2006-04-11: A future improvement to this function would 12600 be to only create the breakpoints once, and actually put them on 12601 the breakpoint chain. That would let us use set_raw_breakpoint. 12602 We could adjust the addresses each time they were needed. Doing 12603 this requires corresponding changes elsewhere where single step 12604 breakpoints are handled, however. So, for now, we use this. */ 12605 12606 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); 12607 if (*bpt_p == NULL) 12608 error (_("Could not insert single-step breakpoint at %s"), 12609 paddress (gdbarch, next_pc)); 12610 } 12611 12612 /* Check if the breakpoints used for software single stepping 12613 were inserted or not. */ 12614 12615 int 12616 single_step_breakpoints_inserted (void) 12617 { 12618 return (single_step_breakpoints[0] != NULL 12619 || single_step_breakpoints[1] != NULL); 12620 } 12621 12622 /* Remove and delete any breakpoints used for software single step. */ 12623 12624 void 12625 remove_single_step_breakpoints (void) 12626 { 12627 gdb_assert (single_step_breakpoints[0] != NULL); 12628 12629 /* See insert_single_step_breakpoint for more about this deprecated 12630 call. */ 12631 deprecated_remove_raw_breakpoint (single_step_gdbarch[0], 12632 single_step_breakpoints[0]); 12633 single_step_gdbarch[0] = NULL; 12634 single_step_breakpoints[0] = NULL; 12635 12636 if (single_step_breakpoints[1] != NULL) 12637 { 12638 deprecated_remove_raw_breakpoint (single_step_gdbarch[1], 12639 single_step_breakpoints[1]); 12640 single_step_gdbarch[1] = NULL; 12641 single_step_breakpoints[1] = NULL; 12642 } 12643 } 12644 12645 /* Delete software single step breakpoints without removing them from 12646 the inferior. This is intended to be used if the inferior's address 12647 space where they were inserted is already gone, e.g. after exit or 12648 exec. */ 12649 12650 void 12651 cancel_single_step_breakpoints (void) 12652 { 12653 int i; 12654 12655 for (i = 0; i < 2; i++) 12656 if (single_step_breakpoints[i]) 12657 { 12658 xfree (single_step_breakpoints[i]); 12659 single_step_breakpoints[i] = NULL; 12660 single_step_gdbarch[i] = NULL; 12661 } 12662 } 12663 12664 /* Detach software single-step breakpoints from INFERIOR_PTID without 12665 removing them. */ 12666 12667 static void 12668 detach_single_step_breakpoints (void) 12669 { 12670 int i; 12671 12672 for (i = 0; i < 2; i++) 12673 if (single_step_breakpoints[i]) 12674 target_remove_breakpoint (single_step_gdbarch[i], 12675 single_step_breakpoints[i]); 12676 } 12677 12678 /* Check whether a software single-step breakpoint is inserted at 12679 PC. */ 12680 12681 static int 12682 single_step_breakpoint_inserted_here_p (struct address_space *aspace, 12683 CORE_ADDR pc) 12684 { 12685 int i; 12686 12687 for (i = 0; i < 2; i++) 12688 { 12689 struct bp_target_info *bp_tgt = single_step_breakpoints[i]; 12690 if (bp_tgt 12691 && breakpoint_address_match (bp_tgt->placed_address_space, 12692 bp_tgt->placed_address, 12693 aspace, pc)) 12694 return 1; 12695 } 12696 12697 return 0; 12698 } 12699 12700 /* Returns 0 if 'bp' is NOT a syscall catchpoint, 12701 non-zero otherwise. */ 12702 static int 12703 is_syscall_catchpoint_enabled (struct breakpoint *bp) 12704 { 12705 if (syscall_catchpoint_p (bp) 12706 && bp->enable_state != bp_disabled 12707 && bp->enable_state != bp_call_disabled) 12708 return 1; 12709 else 12710 return 0; 12711 } 12712 12713 int 12714 catch_syscall_enabled (void) 12715 { 12716 struct inferior *inf = current_inferior (); 12717 12718 return inf->total_syscalls_count != 0; 12719 } 12720 12721 int 12722 catching_syscall_number (int syscall_number) 12723 { 12724 struct breakpoint *bp; 12725 12726 ALL_BREAKPOINTS (bp) 12727 if (is_syscall_catchpoint_enabled (bp)) 12728 { 12729 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; 12730 12731 if (c->syscalls_to_be_caught) 12732 { 12733 int i, iter; 12734 for (i = 0; 12735 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 12736 i++) 12737 if (syscall_number == iter) 12738 return 1; 12739 } 12740 else 12741 return 1; 12742 } 12743 12744 return 0; 12745 } 12746 12747 /* Complete syscall names. Used by "catch syscall". */ 12748 static char ** 12749 catch_syscall_completer (struct cmd_list_element *cmd, 12750 char *text, char *word) 12751 { 12752 const char **list = get_syscall_names (); 12753 char **retlist 12754 = (list == NULL) ? NULL : complete_on_enum (list, text, word); 12755 12756 xfree (list); 12757 return retlist; 12758 } 12759 12760 /* Tracepoint-specific operations. */ 12761 12762 /* Set tracepoint count to NUM. */ 12763 static void 12764 set_tracepoint_count (int num) 12765 { 12766 tracepoint_count = num; 12767 set_internalvar_integer (lookup_internalvar ("tpnum"), num); 12768 } 12769 12770 void 12771 trace_command (char *arg, int from_tty) 12772 { 12773 if (create_breakpoint (get_current_arch (), 12774 arg, 12775 NULL, 0, 1 /* parse arg */, 12776 0 /* tempflag */, 12777 bp_tracepoint /* type_wanted */, 12778 0 /* Ignore count */, 12779 pending_break_support, 12780 &tracepoint_breakpoint_ops, 12781 from_tty, 12782 1 /* enabled */, 12783 0 /* internal */, 0)) 12784 set_tracepoint_count (breakpoint_count); 12785 } 12786 12787 void 12788 ftrace_command (char *arg, int from_tty) 12789 { 12790 if (create_breakpoint (get_current_arch (), 12791 arg, 12792 NULL, 0, 1 /* parse arg */, 12793 0 /* tempflag */, 12794 bp_fast_tracepoint /* type_wanted */, 12795 0 /* Ignore count */, 12796 pending_break_support, 12797 &tracepoint_breakpoint_ops, 12798 from_tty, 12799 1 /* enabled */, 12800 0 /* internal */, 0)) 12801 set_tracepoint_count (breakpoint_count); 12802 } 12803 12804 /* strace command implementation. Creates a static tracepoint. */ 12805 12806 void 12807 strace_command (char *arg, int from_tty) 12808 { 12809 if (create_breakpoint (get_current_arch (), 12810 arg, 12811 NULL, 0, 1 /* parse arg */, 12812 0 /* tempflag */, 12813 bp_static_tracepoint /* type_wanted */, 12814 0 /* Ignore count */, 12815 pending_break_support, 12816 &tracepoint_breakpoint_ops, 12817 from_tty, 12818 1 /* enabled */, 12819 0 /* internal */, 0)) 12820 set_tracepoint_count (breakpoint_count); 12821 } 12822 12823 /* Set up a fake reader function that gets command lines from a linked 12824 list that was acquired during tracepoint uploading. */ 12825 12826 static struct uploaded_tp *this_utp; 12827 static int next_cmd; 12828 12829 static char * 12830 read_uploaded_action (void) 12831 { 12832 char *rslt; 12833 12834 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); 12835 12836 next_cmd++; 12837 12838 return rslt; 12839 } 12840 12841 /* Given information about a tracepoint as recorded on a target (which 12842 can be either a live system or a trace file), attempt to create an 12843 equivalent GDB tracepoint. This is not a reliable process, since 12844 the target does not necessarily have all the information used when 12845 the tracepoint was originally defined. */ 12846 12847 struct tracepoint * 12848 create_tracepoint_from_upload (struct uploaded_tp *utp) 12849 { 12850 char *addr_str, small_buf[100]; 12851 struct tracepoint *tp; 12852 12853 if (utp->at_string) 12854 addr_str = utp->at_string; 12855 else 12856 { 12857 /* In the absence of a source location, fall back to raw 12858 address. Since there is no way to confirm that the address 12859 means the same thing as when the trace was started, warn the 12860 user. */ 12861 warning (_("Uploaded tracepoint %d has no " 12862 "source location, using raw address"), 12863 utp->number); 12864 sprintf (small_buf, "*%s", hex_string (utp->addr)); 12865 addr_str = small_buf; 12866 } 12867 12868 /* There's not much we can do with a sequence of bytecodes. */ 12869 if (utp->cond && !utp->cond_string) 12870 warning (_("Uploaded tracepoint %d condition " 12871 "has no source form, ignoring it"), 12872 utp->number); 12873 12874 if (!create_breakpoint (get_current_arch (), 12875 addr_str, 12876 utp->cond_string, -1, 0 /* parse cond/thread */, 12877 0 /* tempflag */, 12878 utp->type /* type_wanted */, 12879 0 /* Ignore count */, 12880 pending_break_support, 12881 &tracepoint_breakpoint_ops, 12882 0 /* from_tty */, 12883 utp->enabled /* enabled */, 12884 0 /* internal */, 12885 CREATE_BREAKPOINT_FLAGS_INSERTED)) 12886 return NULL; 12887 12888 set_tracepoint_count (breakpoint_count); 12889 12890 /* Get the tracepoint we just created. */ 12891 tp = get_tracepoint (tracepoint_count); 12892 gdb_assert (tp != NULL); 12893 12894 if (utp->pass > 0) 12895 { 12896 sprintf (small_buf, "%d %d", utp->pass, tp->base.number); 12897 12898 trace_pass_command (small_buf, 0); 12899 } 12900 12901 /* If we have uploaded versions of the original commands, set up a 12902 special-purpose "reader" function and call the usual command line 12903 reader, then pass the result to the breakpoint command-setting 12904 function. */ 12905 if (!VEC_empty (char_ptr, utp->cmd_strings)) 12906 { 12907 struct command_line *cmd_list; 12908 12909 this_utp = utp; 12910 next_cmd = 0; 12911 12912 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); 12913 12914 breakpoint_set_commands (&tp->base, cmd_list); 12915 } 12916 else if (!VEC_empty (char_ptr, utp->actions) 12917 || !VEC_empty (char_ptr, utp->step_actions)) 12918 warning (_("Uploaded tracepoint %d actions " 12919 "have no source form, ignoring them"), 12920 utp->number); 12921 12922 /* Copy any status information that might be available. */ 12923 tp->base.hit_count = utp->hit_count; 12924 tp->traceframe_usage = utp->traceframe_usage; 12925 12926 return tp; 12927 } 12928 12929 /* Print information on tracepoint number TPNUM_EXP, or all if 12930 omitted. */ 12931 12932 static void 12933 tracepoints_info (char *args, int from_tty) 12934 { 12935 struct ui_out *uiout = current_uiout; 12936 int num_printed; 12937 12938 num_printed = breakpoint_1 (args, 0, is_tracepoint); 12939 12940 if (num_printed == 0) 12941 { 12942 if (args == NULL || *args == '\0') 12943 ui_out_message (uiout, 0, "No tracepoints.\n"); 12944 else 12945 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); 12946 } 12947 12948 default_collect_info (); 12949 } 12950 12951 /* The 'enable trace' command enables tracepoints. 12952 Not supported by all targets. */ 12953 static void 12954 enable_trace_command (char *args, int from_tty) 12955 { 12956 enable_command (args, from_tty); 12957 } 12958 12959 /* The 'disable trace' command disables tracepoints. 12960 Not supported by all targets. */ 12961 static void 12962 disable_trace_command (char *args, int from_tty) 12963 { 12964 disable_command (args, from_tty); 12965 } 12966 12967 /* Remove a tracepoint (or all if no argument). */ 12968 static void 12969 delete_trace_command (char *arg, int from_tty) 12970 { 12971 struct breakpoint *b, *b_tmp; 12972 12973 dont_repeat (); 12974 12975 if (arg == 0) 12976 { 12977 int breaks_to_delete = 0; 12978 12979 /* Delete all breakpoints if no argument. 12980 Do not delete internal or call-dummy breakpoints, these 12981 have to be deleted with an explicit breakpoint number 12982 argument. */ 12983 ALL_TRACEPOINTS (b) 12984 if (is_tracepoint (b) && user_breakpoint_p (b)) 12985 { 12986 breaks_to_delete = 1; 12987 break; 12988 } 12989 12990 /* Ask user only if there are some breakpoints to delete. */ 12991 if (!from_tty 12992 || (breaks_to_delete && query (_("Delete all tracepoints? ")))) 12993 { 12994 ALL_BREAKPOINTS_SAFE (b, b_tmp) 12995 if (is_tracepoint (b) && user_breakpoint_p (b)) 12996 delete_breakpoint (b); 12997 } 12998 } 12999 else 13000 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); 13001 } 13002 13003 /* Helper function for trace_pass_command. */ 13004 13005 static void 13006 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) 13007 { 13008 tp->pass_count = count; 13009 observer_notify_tracepoint_modified (tp->base.number); 13010 if (from_tty) 13011 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), 13012 tp->base.number, count); 13013 } 13014 13015 /* Set passcount for tracepoint. 13016 13017 First command argument is passcount, second is tracepoint number. 13018 If tracepoint number omitted, apply to most recently defined. 13019 Also accepts special argument "all". */ 13020 13021 static void 13022 trace_pass_command (char *args, int from_tty) 13023 { 13024 struct tracepoint *t1; 13025 unsigned int count; 13026 13027 if (args == 0 || *args == 0) 13028 error (_("passcount command requires an " 13029 "argument (count + optional TP num)")); 13030 13031 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ 13032 13033 while (*args && isspace ((int) *args)) 13034 args++; 13035 13036 if (*args && strncasecmp (args, "all", 3) == 0) 13037 { 13038 struct breakpoint *b; 13039 13040 args += 3; /* Skip special argument "all". */ 13041 if (*args) 13042 error (_("Junk at end of arguments.")); 13043 13044 ALL_TRACEPOINTS (b) 13045 { 13046 t1 = (struct tracepoint *) b; 13047 trace_pass_set_count (t1, count, from_tty); 13048 } 13049 } 13050 else if (*args == '\0') 13051 { 13052 t1 = get_tracepoint_by_number (&args, NULL, 1); 13053 if (t1) 13054 trace_pass_set_count (t1, count, from_tty); 13055 } 13056 else 13057 { 13058 struct get_number_or_range_state state; 13059 13060 init_number_or_range (&state, args); 13061 while (!state.finished) 13062 { 13063 t1 = get_tracepoint_by_number (&args, &state, 1); 13064 if (t1) 13065 trace_pass_set_count (t1, count, from_tty); 13066 } 13067 } 13068 } 13069 13070 struct tracepoint * 13071 get_tracepoint (int num) 13072 { 13073 struct breakpoint *t; 13074 13075 ALL_TRACEPOINTS (t) 13076 if (t->number == num) 13077 return (struct tracepoint *) t; 13078 13079 return NULL; 13080 } 13081 13082 /* Find the tracepoint with the given target-side number (which may be 13083 different from the tracepoint number after disconnecting and 13084 reconnecting). */ 13085 13086 struct tracepoint * 13087 get_tracepoint_by_number_on_target (int num) 13088 { 13089 struct breakpoint *b; 13090 13091 ALL_TRACEPOINTS (b) 13092 { 13093 struct tracepoint *t = (struct tracepoint *) b; 13094 13095 if (t->number_on_target == num) 13096 return t; 13097 } 13098 13099 return NULL; 13100 } 13101 13102 /* Utility: parse a tracepoint number and look it up in the list. 13103 If STATE is not NULL, use, get_number_or_range_state and ignore ARG. 13104 If OPTIONAL_P is true, then if the argument is missing, the most 13105 recent tracepoint (tracepoint_count) is returned. */ 13106 struct tracepoint * 13107 get_tracepoint_by_number (char **arg, 13108 struct get_number_or_range_state *state, 13109 int optional_p) 13110 { 13111 extern int tracepoint_count; 13112 struct breakpoint *t; 13113 int tpnum; 13114 char *instring = arg == NULL ? NULL : *arg; 13115 13116 if (state) 13117 { 13118 gdb_assert (!state->finished); 13119 tpnum = get_number_or_range (state); 13120 } 13121 else if (arg == NULL || *arg == NULL || ! **arg) 13122 { 13123 if (optional_p) 13124 tpnum = tracepoint_count; 13125 else 13126 error_no_arg (_("tracepoint number")); 13127 } 13128 else 13129 tpnum = get_number (arg); 13130 13131 if (tpnum <= 0) 13132 { 13133 if (instring && *instring) 13134 printf_filtered (_("bad tracepoint number at or near '%s'\n"), 13135 instring); 13136 else 13137 printf_filtered (_("Tracepoint argument missing " 13138 "and no previous tracepoint\n")); 13139 return NULL; 13140 } 13141 13142 ALL_TRACEPOINTS (t) 13143 if (t->number == tpnum) 13144 { 13145 return (struct tracepoint *) t; 13146 } 13147 13148 printf_unfiltered ("No tracepoint number %d.\n", tpnum); 13149 return NULL; 13150 } 13151 13152 void 13153 print_recreate_thread (struct breakpoint *b, struct ui_file *fp) 13154 { 13155 if (b->thread != -1) 13156 fprintf_unfiltered (fp, " thread %d", b->thread); 13157 13158 if (b->task != 0) 13159 fprintf_unfiltered (fp, " task %d", b->task); 13160 13161 fprintf_unfiltered (fp, "\n"); 13162 } 13163 13164 /* Save information on user settable breakpoints (watchpoints, etc) to 13165 a new script file named FILENAME. If FILTER is non-NULL, call it 13166 on each breakpoint and only include the ones for which it returns 13167 non-zero. */ 13168 13169 static void 13170 save_breakpoints (char *filename, int from_tty, 13171 int (*filter) (const struct breakpoint *)) 13172 { 13173 struct breakpoint *tp; 13174 int any = 0; 13175 char *pathname; 13176 struct cleanup *cleanup; 13177 struct ui_file *fp; 13178 int extra_trace_bits = 0; 13179 13180 if (filename == 0 || *filename == 0) 13181 error (_("Argument required (file name in which to save)")); 13182 13183 /* See if we have anything to save. */ 13184 ALL_BREAKPOINTS (tp) 13185 { 13186 /* Skip internal and momentary breakpoints. */ 13187 if (!user_breakpoint_p (tp)) 13188 continue; 13189 13190 /* If we have a filter, only save the breakpoints it accepts. */ 13191 if (filter && !filter (tp)) 13192 continue; 13193 13194 any = 1; 13195 13196 if (is_tracepoint (tp)) 13197 { 13198 extra_trace_bits = 1; 13199 13200 /* We can stop searching. */ 13201 break; 13202 } 13203 } 13204 13205 if (!any) 13206 { 13207 warning (_("Nothing to save.")); 13208 return; 13209 } 13210 13211 pathname = tilde_expand (filename); 13212 cleanup = make_cleanup (xfree, pathname); 13213 fp = gdb_fopen (pathname, "w"); 13214 if (!fp) 13215 error (_("Unable to open file '%s' for saving (%s)"), 13216 filename, safe_strerror (errno)); 13217 make_cleanup_ui_file_delete (fp); 13218 13219 if (extra_trace_bits) 13220 save_trace_state_variables (fp); 13221 13222 ALL_BREAKPOINTS (tp) 13223 { 13224 /* Skip internal and momentary breakpoints. */ 13225 if (!user_breakpoint_p (tp)) 13226 continue; 13227 13228 /* If we have a filter, only save the breakpoints it accepts. */ 13229 if (filter && !filter (tp)) 13230 continue; 13231 13232 tp->ops->print_recreate (tp, fp); 13233 13234 /* Note, we can't rely on tp->number for anything, as we can't 13235 assume the recreated breakpoint numbers will match. Use $bpnum 13236 instead. */ 13237 13238 if (tp->cond_string) 13239 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); 13240 13241 if (tp->ignore_count) 13242 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); 13243 13244 if (tp->commands) 13245 { 13246 volatile struct gdb_exception ex; 13247 13248 fprintf_unfiltered (fp, " commands\n"); 13249 13250 ui_out_redirect (current_uiout, fp); 13251 TRY_CATCH (ex, RETURN_MASK_ALL) 13252 { 13253 print_command_lines (current_uiout, tp->commands->commands, 2); 13254 } 13255 ui_out_redirect (current_uiout, NULL); 13256 13257 if (ex.reason < 0) 13258 throw_exception (ex); 13259 13260 fprintf_unfiltered (fp, " end\n"); 13261 } 13262 13263 if (tp->enable_state == bp_disabled) 13264 fprintf_unfiltered (fp, "disable\n"); 13265 13266 /* If this is a multi-location breakpoint, check if the locations 13267 should be individually disabled. Watchpoint locations are 13268 special, and not user visible. */ 13269 if (!is_watchpoint (tp) && tp->loc && tp->loc->next) 13270 { 13271 struct bp_location *loc; 13272 int n = 1; 13273 13274 for (loc = tp->loc; loc != NULL; loc = loc->next, n++) 13275 if (!loc->enabled) 13276 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); 13277 } 13278 } 13279 13280 if (extra_trace_bits && *default_collect) 13281 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); 13282 13283 do_cleanups (cleanup); 13284 if (from_tty) 13285 printf_filtered (_("Saved to file '%s'.\n"), filename); 13286 } 13287 13288 /* The `save breakpoints' command. */ 13289 13290 static void 13291 save_breakpoints_command (char *args, int from_tty) 13292 { 13293 save_breakpoints (args, from_tty, NULL); 13294 } 13295 13296 /* The `save tracepoints' command. */ 13297 13298 static void 13299 save_tracepoints_command (char *args, int from_tty) 13300 { 13301 save_breakpoints (args, from_tty, is_tracepoint); 13302 } 13303 13304 /* Create a vector of all tracepoints. */ 13305 13306 VEC(breakpoint_p) * 13307 all_tracepoints (void) 13308 { 13309 VEC(breakpoint_p) *tp_vec = 0; 13310 struct breakpoint *tp; 13311 13312 ALL_TRACEPOINTS (tp) 13313 { 13314 VEC_safe_push (breakpoint_p, tp_vec, tp); 13315 } 13316 13317 return tp_vec; 13318 } 13319 13320 13321 /* This help string is used for the break, hbreak, tbreak and thbreak 13322 commands. It is defined as a macro to prevent duplication. 13323 COMMAND should be a string constant containing the name of the 13324 command. */ 13325 #define BREAK_ARGS_HELP(command) \ 13326 command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ 13327 LOCATION may be a line number, function name, or \"*\" and an address.\n\ 13328 If a line number is specified, break at start of code for that line.\n\ 13329 If a function is specified, break at start of code for that function.\n\ 13330 If an address is specified, break at that exact address.\n\ 13331 With no LOCATION, uses current execution address of the selected\n\ 13332 stack frame. This is useful for breaking on return to a stack frame.\n\ 13333 \n\ 13334 THREADNUM is the number from \"info threads\".\n\ 13335 CONDITION is a boolean expression.\n\ 13336 \n\ 13337 Multiple breakpoints at one place are permitted, and useful if their\n\ 13338 conditions are different.\n\ 13339 \n\ 13340 Do \"help breakpoints\" for info on other commands dealing with breakpoints." 13341 13342 /* List of subcommands for "catch". */ 13343 static struct cmd_list_element *catch_cmdlist; 13344 13345 /* List of subcommands for "tcatch". */ 13346 static struct cmd_list_element *tcatch_cmdlist; 13347 13348 void 13349 add_catch_command (char *name, char *docstring, 13350 void (*sfunc) (char *args, int from_tty, 13351 struct cmd_list_element *command), 13352 char **(*completer) (struct cmd_list_element *cmd, 13353 char *text, char *word), 13354 void *user_data_catch, 13355 void *user_data_tcatch) 13356 { 13357 struct cmd_list_element *command; 13358 13359 command = add_cmd (name, class_breakpoint, NULL, docstring, 13360 &catch_cmdlist); 13361 set_cmd_sfunc (command, sfunc); 13362 set_cmd_context (command, user_data_catch); 13363 set_cmd_completer (command, completer); 13364 13365 command = add_cmd (name, class_breakpoint, NULL, docstring, 13366 &tcatch_cmdlist); 13367 set_cmd_sfunc (command, sfunc); 13368 set_cmd_context (command, user_data_tcatch); 13369 set_cmd_completer (command, completer); 13370 } 13371 13372 static void 13373 clear_syscall_counts (struct inferior *inf) 13374 { 13375 inf->total_syscalls_count = 0; 13376 inf->any_syscall_count = 0; 13377 VEC_free (int, inf->syscalls_counts); 13378 } 13379 13380 static void 13381 save_command (char *arg, int from_tty) 13382 { 13383 printf_unfiltered (_("\"save\" must be followed by " 13384 "the name of a save subcommand.\n")); 13385 help_list (save_cmdlist, "save ", -1, gdb_stdout); 13386 } 13387 13388 struct breakpoint * 13389 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), 13390 void *data) 13391 { 13392 struct breakpoint *b, *b_tmp; 13393 13394 ALL_BREAKPOINTS_SAFE (b, b_tmp) 13395 { 13396 if ((*callback) (b, data)) 13397 return b; 13398 } 13399 13400 return NULL; 13401 } 13402 13403 /* Zero if any of the breakpoint's locations could be a location where 13404 functions have been inlined, nonzero otherwise. */ 13405 13406 static int 13407 is_non_inline_function (struct breakpoint *b) 13408 { 13409 /* The shared library event breakpoint is set on the address of a 13410 non-inline function. */ 13411 if (b->type == bp_shlib_event) 13412 return 1; 13413 13414 return 0; 13415 } 13416 13417 /* Nonzero if the specified PC cannot be a location where functions 13418 have been inlined. */ 13419 13420 int 13421 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc) 13422 { 13423 struct breakpoint *b; 13424 struct bp_location *bl; 13425 13426 ALL_BREAKPOINTS (b) 13427 { 13428 if (!is_non_inline_function (b)) 13429 continue; 13430 13431 for (bl = b->loc; bl != NULL; bl = bl->next) 13432 { 13433 if (!bl->shlib_disabled 13434 && bpstat_check_location (bl, aspace, pc)) 13435 return 1; 13436 } 13437 } 13438 13439 return 0; 13440 } 13441 13442 void 13443 initialize_breakpoint_ops (void) 13444 { 13445 static int initialized = 0; 13446 13447 struct breakpoint_ops *ops; 13448 13449 if (initialized) 13450 return; 13451 initialized = 1; 13452 13453 /* The breakpoint_ops structure to be inherit by all kinds of 13454 breakpoints (real breakpoints, i.e., user "break" breakpoints, 13455 internal and momentary breakpoints, etc.). */ 13456 ops = &bkpt_base_breakpoint_ops; 13457 *ops = base_breakpoint_ops; 13458 ops->re_set = bkpt_re_set; 13459 ops->insert_location = bkpt_insert_location; 13460 ops->remove_location = bkpt_remove_location; 13461 ops->breakpoint_hit = bkpt_breakpoint_hit; 13462 13463 /* The breakpoint_ops structure to be used in regular breakpoints. */ 13464 ops = &bkpt_breakpoint_ops; 13465 *ops = bkpt_base_breakpoint_ops; 13466 ops->re_set = bkpt_re_set; 13467 ops->resources_needed = bkpt_resources_needed; 13468 ops->print_it = bkpt_print_it; 13469 ops->print_mention = bkpt_print_mention; 13470 ops->print_recreate = bkpt_print_recreate; 13471 13472 /* Ranged breakpoints. */ 13473 ops = &ranged_breakpoint_ops; 13474 *ops = bkpt_breakpoint_ops; 13475 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; 13476 ops->resources_needed = resources_needed_ranged_breakpoint; 13477 ops->print_it = print_it_ranged_breakpoint; 13478 ops->print_one = print_one_ranged_breakpoint; 13479 ops->print_one_detail = print_one_detail_ranged_breakpoint; 13480 ops->print_mention = print_mention_ranged_breakpoint; 13481 ops->print_recreate = print_recreate_ranged_breakpoint; 13482 13483 /* Internal breakpoints. */ 13484 ops = &internal_breakpoint_ops; 13485 *ops = bkpt_base_breakpoint_ops; 13486 ops->re_set = internal_bkpt_re_set; 13487 ops->check_status = internal_bkpt_check_status; 13488 ops->print_it = internal_bkpt_print_it; 13489 ops->print_mention = internal_bkpt_print_mention; 13490 13491 /* Momentary breakpoints. */ 13492 ops = &momentary_breakpoint_ops; 13493 *ops = bkpt_base_breakpoint_ops; 13494 ops->re_set = momentary_bkpt_re_set; 13495 ops->check_status = momentary_bkpt_check_status; 13496 ops->print_it = momentary_bkpt_print_it; 13497 ops->print_mention = momentary_bkpt_print_mention; 13498 13499 /* GNU v3 exception catchpoints. */ 13500 ops = &gnu_v3_exception_catchpoint_ops; 13501 *ops = bkpt_breakpoint_ops; 13502 ops->print_it = print_it_exception_catchpoint; 13503 ops->print_one = print_one_exception_catchpoint; 13504 ops->print_mention = print_mention_exception_catchpoint; 13505 ops->print_recreate = print_recreate_exception_catchpoint; 13506 13507 /* Watchpoints. */ 13508 ops = &watchpoint_breakpoint_ops; 13509 *ops = base_breakpoint_ops; 13510 ops->dtor = dtor_watchpoint; 13511 ops->re_set = re_set_watchpoint; 13512 ops->insert_location = insert_watchpoint; 13513 ops->remove_location = remove_watchpoint; 13514 ops->breakpoint_hit = breakpoint_hit_watchpoint; 13515 ops->check_status = check_status_watchpoint; 13516 ops->resources_needed = resources_needed_watchpoint; 13517 ops->works_in_software_mode = works_in_software_mode_watchpoint; 13518 ops->print_it = print_it_watchpoint; 13519 ops->print_mention = print_mention_watchpoint; 13520 ops->print_recreate = print_recreate_watchpoint; 13521 13522 /* Masked watchpoints. */ 13523 ops = &masked_watchpoint_breakpoint_ops; 13524 *ops = watchpoint_breakpoint_ops; 13525 ops->insert_location = insert_masked_watchpoint; 13526 ops->remove_location = remove_masked_watchpoint; 13527 ops->resources_needed = resources_needed_masked_watchpoint; 13528 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; 13529 ops->print_it = print_it_masked_watchpoint; 13530 ops->print_one_detail = print_one_detail_masked_watchpoint; 13531 ops->print_mention = print_mention_masked_watchpoint; 13532 ops->print_recreate = print_recreate_masked_watchpoint; 13533 13534 /* Tracepoints. */ 13535 ops = &tracepoint_breakpoint_ops; 13536 *ops = base_breakpoint_ops; 13537 ops->re_set = tracepoint_re_set; 13538 ops->breakpoint_hit = tracepoint_breakpoint_hit; 13539 ops->print_one_detail = tracepoint_print_one_detail; 13540 ops->print_mention = tracepoint_print_mention; 13541 ops->print_recreate = tracepoint_print_recreate; 13542 13543 /* Fork catchpoints. */ 13544 ops = &catch_fork_breakpoint_ops; 13545 *ops = base_breakpoint_ops; 13546 ops->insert_location = insert_catch_fork; 13547 ops->remove_location = remove_catch_fork; 13548 ops->breakpoint_hit = breakpoint_hit_catch_fork; 13549 ops->print_it = print_it_catch_fork; 13550 ops->print_one = print_one_catch_fork; 13551 ops->print_mention = print_mention_catch_fork; 13552 ops->print_recreate = print_recreate_catch_fork; 13553 13554 /* Vfork catchpoints. */ 13555 ops = &catch_vfork_breakpoint_ops; 13556 *ops = base_breakpoint_ops; 13557 ops->insert_location = insert_catch_vfork; 13558 ops->remove_location = remove_catch_vfork; 13559 ops->breakpoint_hit = breakpoint_hit_catch_vfork; 13560 ops->print_it = print_it_catch_vfork; 13561 ops->print_one = print_one_catch_vfork; 13562 ops->print_mention = print_mention_catch_vfork; 13563 ops->print_recreate = print_recreate_catch_vfork; 13564 13565 /* Exec catchpoints. */ 13566 ops = &catch_exec_breakpoint_ops; 13567 *ops = base_breakpoint_ops; 13568 ops->dtor = dtor_catch_exec; 13569 ops->insert_location = insert_catch_exec; 13570 ops->remove_location = remove_catch_exec; 13571 ops->breakpoint_hit = breakpoint_hit_catch_exec; 13572 ops->print_it = print_it_catch_exec; 13573 ops->print_one = print_one_catch_exec; 13574 ops->print_mention = print_mention_catch_exec; 13575 ops->print_recreate = print_recreate_catch_exec; 13576 13577 /* Syscall catchpoints. */ 13578 ops = &catch_syscall_breakpoint_ops; 13579 *ops = base_breakpoint_ops; 13580 ops->dtor = dtor_catch_syscall; 13581 ops->insert_location = insert_catch_syscall; 13582 ops->remove_location = remove_catch_syscall; 13583 ops->breakpoint_hit = breakpoint_hit_catch_syscall; 13584 ops->print_it = print_it_catch_syscall; 13585 ops->print_one = print_one_catch_syscall; 13586 ops->print_mention = print_mention_catch_syscall; 13587 ops->print_recreate = print_recreate_catch_syscall; 13588 } 13589 13590 void 13591 _initialize_breakpoint (void) 13592 { 13593 struct cmd_list_element *c; 13594 13595 initialize_breakpoint_ops (); 13596 13597 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); 13598 observer_attach_inferior_exit (clear_syscall_counts); 13599 observer_attach_memory_changed (invalidate_bp_value_on_memory_change); 13600 13601 breakpoint_objfile_key = register_objfile_data (); 13602 13603 breakpoint_chain = 0; 13604 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful 13605 before a breakpoint is set. */ 13606 breakpoint_count = 0; 13607 13608 tracepoint_count = 0; 13609 13610 add_com ("ignore", class_breakpoint, ignore_command, _("\ 13611 Set ignore-count of breakpoint number N to COUNT.\n\ 13612 Usage is `ignore N COUNT'.")); 13613 if (xdb_commands) 13614 add_com_alias ("bc", "ignore", class_breakpoint, 1); 13615 13616 add_com ("commands", class_breakpoint, commands_command, _("\ 13617 Set commands to be executed when a breakpoint is hit.\n\ 13618 Give breakpoint number as argument after \"commands\".\n\ 13619 With no argument, the targeted breakpoint is the last one set.\n\ 13620 The commands themselves follow starting on the next line.\n\ 13621 Type a line containing \"end\" to indicate the end of them.\n\ 13622 Give \"silent\" as the first line to make the breakpoint silent;\n\ 13623 then no output is printed when it is hit, except what the commands print.")); 13624 13625 add_com ("condition", class_breakpoint, condition_command, _("\ 13626 Specify breakpoint number N to break only if COND is true.\n\ 13627 Usage is `condition N COND', where N is an integer and COND is an\n\ 13628 expression to be evaluated whenever breakpoint N is reached.")); 13629 13630 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ 13631 Set a temporary breakpoint.\n\ 13632 Like \"break\" except the breakpoint is only temporary,\n\ 13633 so it will be deleted when hit. Equivalent to \"break\" followed\n\ 13634 by using \"enable delete\" on the breakpoint number.\n\ 13635 \n" 13636 BREAK_ARGS_HELP ("tbreak"))); 13637 set_cmd_completer (c, location_completer); 13638 13639 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ 13640 Set a hardware assisted breakpoint.\n\ 13641 Like \"break\" except the breakpoint requires hardware support,\n\ 13642 some target hardware may not have this support.\n\ 13643 \n" 13644 BREAK_ARGS_HELP ("hbreak"))); 13645 set_cmd_completer (c, location_completer); 13646 13647 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ 13648 Set a temporary hardware assisted breakpoint.\n\ 13649 Like \"hbreak\" except the breakpoint is only temporary,\n\ 13650 so it will be deleted when hit.\n\ 13651 \n" 13652 BREAK_ARGS_HELP ("thbreak"))); 13653 set_cmd_completer (c, location_completer); 13654 13655 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ 13656 Enable some breakpoints.\n\ 13657 Give breakpoint numbers (separated by spaces) as arguments.\n\ 13658 With no subcommand, breakpoints are enabled until you command otherwise.\n\ 13659 This is used to cancel the effect of the \"disable\" command.\n\ 13660 With a subcommand you can enable temporarily."), 13661 &enablelist, "enable ", 1, &cmdlist); 13662 if (xdb_commands) 13663 add_com ("ab", class_breakpoint, enable_command, _("\ 13664 Enable some breakpoints.\n\ 13665 Give breakpoint numbers (separated by spaces) as arguments.\n\ 13666 With no subcommand, breakpoints are enabled until you command otherwise.\n\ 13667 This is used to cancel the effect of the \"disable\" command.\n\ 13668 With a subcommand you can enable temporarily.")); 13669 13670 add_com_alias ("en", "enable", class_breakpoint, 1); 13671 13672 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ 13673 Enable some breakpoints.\n\ 13674 Give breakpoint numbers (separated by spaces) as arguments.\n\ 13675 This is used to cancel the effect of the \"disable\" command.\n\ 13676 May be abbreviated to simply \"enable\".\n"), 13677 &enablebreaklist, "enable breakpoints ", 1, &enablelist); 13678 13679 add_cmd ("once", no_class, enable_once_command, _("\ 13680 Enable breakpoints for one hit. Give breakpoint numbers.\n\ 13681 If a breakpoint is hit while enabled in this fashion, it becomes disabled."), 13682 &enablebreaklist); 13683 13684 add_cmd ("delete", no_class, enable_delete_command, _("\ 13685 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ 13686 If a breakpoint is hit while enabled in this fashion, it is deleted."), 13687 &enablebreaklist); 13688 13689 add_cmd ("delete", no_class, enable_delete_command, _("\ 13690 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ 13691 If a breakpoint is hit while enabled in this fashion, it is deleted."), 13692 &enablelist); 13693 13694 add_cmd ("once", no_class, enable_once_command, _("\ 13695 Enable breakpoints for one hit. Give breakpoint numbers.\n\ 13696 If a breakpoint is hit while enabled in this fashion, it becomes disabled."), 13697 &enablelist); 13698 13699 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ 13700 Disable some breakpoints.\n\ 13701 Arguments are breakpoint numbers with spaces in between.\n\ 13702 To disable all breakpoints, give no argument.\n\ 13703 A disabled breakpoint is not forgotten, but has no effect until re-enabled."), 13704 &disablelist, "disable ", 1, &cmdlist); 13705 add_com_alias ("dis", "disable", class_breakpoint, 1); 13706 add_com_alias ("disa", "disable", class_breakpoint, 1); 13707 if (xdb_commands) 13708 add_com ("sb", class_breakpoint, disable_command, _("\ 13709 Disable some breakpoints.\n\ 13710 Arguments are breakpoint numbers with spaces in between.\n\ 13711 To disable all breakpoints, give no argument.\n\ 13712 A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); 13713 13714 add_cmd ("breakpoints", class_alias, disable_command, _("\ 13715 Disable some breakpoints.\n\ 13716 Arguments are breakpoint numbers with spaces in between.\n\ 13717 To disable all breakpoints, give no argument.\n\ 13718 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ 13719 This command may be abbreviated \"disable\"."), 13720 &disablelist); 13721 13722 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ 13723 Delete some breakpoints or auto-display expressions.\n\ 13724 Arguments are breakpoint numbers with spaces in between.\n\ 13725 To delete all breakpoints, give no argument.\n\ 13726 \n\ 13727 Also a prefix command for deletion of other GDB objects.\n\ 13728 The \"unset\" command is also an alias for \"delete\"."), 13729 &deletelist, "delete ", 1, &cmdlist); 13730 add_com_alias ("d", "delete", class_breakpoint, 1); 13731 add_com_alias ("del", "delete", class_breakpoint, 1); 13732 if (xdb_commands) 13733 add_com ("db", class_breakpoint, delete_command, _("\ 13734 Delete some breakpoints.\n\ 13735 Arguments are breakpoint numbers with spaces in between.\n\ 13736 To delete all breakpoints, give no argument.\n")); 13737 13738 add_cmd ("breakpoints", class_alias, delete_command, _("\ 13739 Delete some breakpoints or auto-display expressions.\n\ 13740 Arguments are breakpoint numbers with spaces in between.\n\ 13741 To delete all breakpoints, give no argument.\n\ 13742 This command may be abbreviated \"delete\"."), 13743 &deletelist); 13744 13745 add_com ("clear", class_breakpoint, clear_command, _("\ 13746 Clear breakpoint at specified line or function.\n\ 13747 Argument may be line number, function name, or \"*\" and an address.\n\ 13748 If line number is specified, all breakpoints in that line are cleared.\n\ 13749 If function is specified, breakpoints at beginning of function are cleared.\n\ 13750 If an address is specified, breakpoints at that address are cleared.\n\ 13751 \n\ 13752 With no argument, clears all breakpoints in the line that the selected frame\n\ 13753 is executing in.\n\ 13754 \n\ 13755 See also the \"delete\" command which clears breakpoints by number.")); 13756 add_com_alias ("cl", "clear", class_breakpoint, 1); 13757 13758 c = add_com ("break", class_breakpoint, break_command, _("\ 13759 Set breakpoint at specified line or function.\n" 13760 BREAK_ARGS_HELP ("break"))); 13761 set_cmd_completer (c, location_completer); 13762 13763 add_com_alias ("b", "break", class_run, 1); 13764 add_com_alias ("br", "break", class_run, 1); 13765 add_com_alias ("bre", "break", class_run, 1); 13766 add_com_alias ("brea", "break", class_run, 1); 13767 13768 if (xdb_commands) 13769 add_com_alias ("ba", "break", class_breakpoint, 1); 13770 13771 if (dbx_commands) 13772 { 13773 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ 13774 Break in function/address or break at a line in the current file."), 13775 &stoplist, "stop ", 1, &cmdlist); 13776 add_cmd ("in", class_breakpoint, stopin_command, 13777 _("Break in function or address."), &stoplist); 13778 add_cmd ("at", class_breakpoint, stopat_command, 13779 _("Break at a line in the current file."), &stoplist); 13780 add_com ("status", class_info, breakpoints_info, _("\ 13781 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ 13782 The \"Type\" column indicates one of:\n\ 13783 \tbreakpoint - normal breakpoint\n\ 13784 \twatchpoint - watchpoint\n\ 13785 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 13786 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 13787 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 13788 address and file/line number respectively.\n\ 13789 \n\ 13790 Convenience variable \"$_\" and default examine address for \"x\"\n\ 13791 are set to the address of the last breakpoint listed unless the command\n\ 13792 is prefixed with \"server \".\n\n\ 13793 Convenience variable \"$bpnum\" contains the number of the last\n\ 13794 breakpoint set.")); 13795 } 13796 13797 add_info ("breakpoints", breakpoints_info, _("\ 13798 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ 13799 The \"Type\" column indicates one of:\n\ 13800 \tbreakpoint - normal breakpoint\n\ 13801 \twatchpoint - watchpoint\n\ 13802 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 13803 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 13804 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 13805 address and file/line number respectively.\n\ 13806 \n\ 13807 Convenience variable \"$_\" and default examine address for \"x\"\n\ 13808 are set to the address of the last breakpoint listed unless the command\n\ 13809 is prefixed with \"server \".\n\n\ 13810 Convenience variable \"$bpnum\" contains the number of the last\n\ 13811 breakpoint set.")); 13812 13813 add_info_alias ("b", "breakpoints", 1); 13814 13815 if (xdb_commands) 13816 add_com ("lb", class_breakpoint, breakpoints_info, _("\ 13817 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ 13818 The \"Type\" column indicates one of:\n\ 13819 \tbreakpoint - normal breakpoint\n\ 13820 \twatchpoint - watchpoint\n\ 13821 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 13822 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 13823 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 13824 address and file/line number respectively.\n\ 13825 \n\ 13826 Convenience variable \"$_\" and default examine address for \"x\"\n\ 13827 are set to the address of the last breakpoint listed unless the command\n\ 13828 is prefixed with \"server \".\n\n\ 13829 Convenience variable \"$bpnum\" contains the number of the last\n\ 13830 breakpoint set.")); 13831 13832 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ 13833 Status of all breakpoints, or breakpoint number NUMBER.\n\ 13834 The \"Type\" column indicates one of:\n\ 13835 \tbreakpoint - normal breakpoint\n\ 13836 \twatchpoint - watchpoint\n\ 13837 \tlongjmp - internal breakpoint used to step through longjmp()\n\ 13838 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ 13839 \tuntil - internal breakpoint used by the \"until\" command\n\ 13840 \tfinish - internal breakpoint used by the \"finish\" command\n\ 13841 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 13842 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 13843 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 13844 address and file/line number respectively.\n\ 13845 \n\ 13846 Convenience variable \"$_\" and default examine address for \"x\"\n\ 13847 are set to the address of the last breakpoint listed unless the command\n\ 13848 is prefixed with \"server \".\n\n\ 13849 Convenience variable \"$bpnum\" contains the number of the last\n\ 13850 breakpoint set."), 13851 &maintenanceinfolist); 13852 13853 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ 13854 Set catchpoints to catch events."), 13855 &catch_cmdlist, "catch ", 13856 0/*allow-unknown*/, &cmdlist); 13857 13858 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ 13859 Set temporary catchpoints to catch events."), 13860 &tcatch_cmdlist, "tcatch ", 13861 0/*allow-unknown*/, &cmdlist); 13862 13863 /* Add catch and tcatch sub-commands. */ 13864 add_catch_command ("catch", _("\ 13865 Catch an exception, when caught.\n\ 13866 With an argument, catch only exceptions with the given name."), 13867 catch_catch_command, 13868 NULL, 13869 CATCH_PERMANENT, 13870 CATCH_TEMPORARY); 13871 add_catch_command ("throw", _("\ 13872 Catch an exception, when thrown.\n\ 13873 With an argument, catch only exceptions with the given name."), 13874 catch_throw_command, 13875 NULL, 13876 CATCH_PERMANENT, 13877 CATCH_TEMPORARY); 13878 add_catch_command ("fork", _("Catch calls to fork."), 13879 catch_fork_command_1, 13880 NULL, 13881 (void *) (uintptr_t) catch_fork_permanent, 13882 (void *) (uintptr_t) catch_fork_temporary); 13883 add_catch_command ("vfork", _("Catch calls to vfork."), 13884 catch_fork_command_1, 13885 NULL, 13886 (void *) (uintptr_t) catch_vfork_permanent, 13887 (void *) (uintptr_t) catch_vfork_temporary); 13888 add_catch_command ("exec", _("Catch calls to exec."), 13889 catch_exec_command_1, 13890 NULL, 13891 CATCH_PERMANENT, 13892 CATCH_TEMPORARY); 13893 add_catch_command ("syscall", _("\ 13894 Catch system calls by their names and/or numbers.\n\ 13895 Arguments say which system calls to catch. If no arguments\n\ 13896 are given, every system call will be caught.\n\ 13897 Arguments, if given, should be one or more system call names\n\ 13898 (if your system supports that), or system call numbers."), 13899 catch_syscall_command_1, 13900 catch_syscall_completer, 13901 CATCH_PERMANENT, 13902 CATCH_TEMPORARY); 13903 13904 c = add_com ("watch", class_breakpoint, watch_command, _("\ 13905 Set a watchpoint for an expression.\n\ 13906 Usage: watch [-l|-location] EXPRESSION\n\ 13907 A watchpoint stops execution of your program whenever the value of\n\ 13908 an expression changes.\n\ 13909 If -l or -location is given, this evaluates EXPRESSION and watches\n\ 13910 the memory to which it refers.")); 13911 set_cmd_completer (c, expression_completer); 13912 13913 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ 13914 Set a read watchpoint for an expression.\n\ 13915 Usage: rwatch [-l|-location] EXPRESSION\n\ 13916 A watchpoint stops execution of your program whenever the value of\n\ 13917 an expression is read.\n\ 13918 If -l or -location is given, this evaluates EXPRESSION and watches\n\ 13919 the memory to which it refers.")); 13920 set_cmd_completer (c, expression_completer); 13921 13922 c = add_com ("awatch", class_breakpoint, awatch_command, _("\ 13923 Set a watchpoint for an expression.\n\ 13924 Usage: awatch [-l|-location] EXPRESSION\n\ 13925 A watchpoint stops execution of your program whenever the value of\n\ 13926 an expression is either read or written.\n\ 13927 If -l or -location is given, this evaluates EXPRESSION and watches\n\ 13928 the memory to which it refers.")); 13929 set_cmd_completer (c, expression_completer); 13930 13931 add_info ("watchpoints", watchpoints_info, _("\ 13932 Status of specified watchpoints (all watchpoints if no argument).")); 13933 13934 /* XXX: cagney/2005-02-23: This should be a boolean, and should 13935 respond to changes - contrary to the description. */ 13936 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, 13937 &can_use_hw_watchpoints, _("\ 13938 Set debugger's willingness to use watchpoint hardware."), _("\ 13939 Show debugger's willingness to use watchpoint hardware."), _("\ 13940 If zero, gdb will not use hardware for new watchpoints, even if\n\ 13941 such is available. (However, any hardware watchpoints that were\n\ 13942 created before setting this to nonzero, will continue to use watchpoint\n\ 13943 hardware.)"), 13944 NULL, 13945 show_can_use_hw_watchpoints, 13946 &setlist, &showlist); 13947 13948 can_use_hw_watchpoints = 1; 13949 13950 /* Tracepoint manipulation commands. */ 13951 13952 c = add_com ("trace", class_breakpoint, trace_command, _("\ 13953 Set a tracepoint at specified line or function.\n\ 13954 \n" 13955 BREAK_ARGS_HELP ("trace") "\n\ 13956 Do \"help tracepoints\" for info on other tracepoint commands.")); 13957 set_cmd_completer (c, location_completer); 13958 13959 add_com_alias ("tp", "trace", class_alias, 0); 13960 add_com_alias ("tr", "trace", class_alias, 1); 13961 add_com_alias ("tra", "trace", class_alias, 1); 13962 add_com_alias ("trac", "trace", class_alias, 1); 13963 13964 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ 13965 Set a fast tracepoint at specified line or function.\n\ 13966 \n" 13967 BREAK_ARGS_HELP ("ftrace") "\n\ 13968 Do \"help tracepoints\" for info on other tracepoint commands.")); 13969 set_cmd_completer (c, location_completer); 13970 13971 c = add_com ("strace", class_breakpoint, strace_command, _("\ 13972 Set a static tracepoint at specified line, function or marker.\n\ 13973 \n\ 13974 strace [LOCATION] [if CONDITION]\n\ 13975 LOCATION may be a line number, function name, \"*\" and an address,\n\ 13976 or -m MARKER_ID.\n\ 13977 If a line number is specified, probe the marker at start of code\n\ 13978 for that line. If a function is specified, probe the marker at start\n\ 13979 of code for that function. If an address is specified, probe the marker\n\ 13980 at that exact address. If a marker id is specified, probe the marker\n\ 13981 with that name. With no LOCATION, uses current execution address of\n\ 13982 the selected stack frame.\n\ 13983 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ 13984 This collects arbitrary user data passed in the probe point call to the\n\ 13985 tracing library. You can inspect it when analyzing the trace buffer,\n\ 13986 by printing the $_sdata variable like any other convenience variable.\n\ 13987 \n\ 13988 CONDITION is a boolean expression.\n\ 13989 \n\ 13990 Multiple tracepoints at one place are permitted, and useful if their\n\ 13991 conditions are different.\n\ 13992 \n\ 13993 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ 13994 Do \"help tracepoints\" for info on other tracepoint commands.")); 13995 set_cmd_completer (c, location_completer); 13996 13997 add_info ("tracepoints", tracepoints_info, _("\ 13998 Status of specified tracepoints (all tracepoints if no argument).\n\ 13999 Convenience variable \"$tpnum\" contains the number of the\n\ 14000 last tracepoint set.")); 14001 14002 add_info_alias ("tp", "tracepoints", 1); 14003 14004 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ 14005 Delete specified tracepoints.\n\ 14006 Arguments are tracepoint numbers, separated by spaces.\n\ 14007 No argument means delete all tracepoints."), 14008 &deletelist); 14009 14010 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ 14011 Disable specified tracepoints.\n\ 14012 Arguments are tracepoint numbers, separated by spaces.\n\ 14013 No argument means disable all tracepoints."), 14014 &disablelist); 14015 deprecate_cmd (c, "disable"); 14016 14017 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ 14018 Enable specified tracepoints.\n\ 14019 Arguments are tracepoint numbers, separated by spaces.\n\ 14020 No argument means enable all tracepoints."), 14021 &enablelist); 14022 deprecate_cmd (c, "enable"); 14023 14024 add_com ("passcount", class_trace, trace_pass_command, _("\ 14025 Set the passcount for a tracepoint.\n\ 14026 The trace will end when the tracepoint has been passed 'count' times.\n\ 14027 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ 14028 if TPNUM is omitted, passcount refers to the last tracepoint defined.")); 14029 14030 add_prefix_cmd ("save", class_breakpoint, save_command, 14031 _("Save breakpoint definitions as a script."), 14032 &save_cmdlist, "save ", 14033 0/*allow-unknown*/, &cmdlist); 14034 14035 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ 14036 Save current breakpoint definitions as a script.\n\ 14037 This includes all types of breakpoints (breakpoints, watchpoints,\n\ 14038 catchpoints, tracepoints). Use the 'source' command in another debug\n\ 14039 session to restore them."), 14040 &save_cmdlist); 14041 set_cmd_completer (c, filename_completer); 14042 14043 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ 14044 Save current tracepoint definitions as a script.\n\ 14045 Use the 'source' command in another debug session to restore them."), 14046 &save_cmdlist); 14047 set_cmd_completer (c, filename_completer); 14048 14049 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); 14050 deprecate_cmd (c, "save tracepoints"); 14051 14052 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ 14053 Breakpoint specific settings\n\ 14054 Configure various breakpoint-specific variables such as\n\ 14055 pending breakpoint behavior"), 14056 &breakpoint_set_cmdlist, "set breakpoint ", 14057 0/*allow-unknown*/, &setlist); 14058 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ 14059 Breakpoint specific settings\n\ 14060 Configure various breakpoint-specific variables such as\n\ 14061 pending breakpoint behavior"), 14062 &breakpoint_show_cmdlist, "show breakpoint ", 14063 0/*allow-unknown*/, &showlist); 14064 14065 add_setshow_auto_boolean_cmd ("pending", no_class, 14066 &pending_break_support, _("\ 14067 Set debugger's behavior regarding pending breakpoints."), _("\ 14068 Show debugger's behavior regarding pending breakpoints."), _("\ 14069 If on, an unrecognized breakpoint location will cause gdb to create a\n\ 14070 pending breakpoint. If off, an unrecognized breakpoint location results in\n\ 14071 an error. If auto, an unrecognized breakpoint location results in a\n\ 14072 user-query to see if a pending breakpoint should be created."), 14073 NULL, 14074 show_pending_break_support, 14075 &breakpoint_set_cmdlist, 14076 &breakpoint_show_cmdlist); 14077 14078 pending_break_support = AUTO_BOOLEAN_AUTO; 14079 14080 add_setshow_boolean_cmd ("auto-hw", no_class, 14081 &automatic_hardware_breakpoints, _("\ 14082 Set automatic usage of hardware breakpoints."), _("\ 14083 Show automatic usage of hardware breakpoints."), _("\ 14084 If set, the debugger will automatically use hardware breakpoints for\n\ 14085 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ 14086 a warning will be emitted for such breakpoints."), 14087 NULL, 14088 show_automatic_hardware_breakpoints, 14089 &breakpoint_set_cmdlist, 14090 &breakpoint_show_cmdlist); 14091 14092 add_setshow_enum_cmd ("always-inserted", class_support, 14093 always_inserted_enums, &always_inserted_mode, _("\ 14094 Set mode for inserting breakpoints."), _("\ 14095 Show mode for inserting breakpoints."), _("\ 14096 When this mode is off, breakpoints are inserted in inferior when it is\n\ 14097 resumed, and removed when execution stops. When this mode is on,\n\ 14098 breakpoints are inserted immediately and removed only when the user\n\ 14099 deletes the breakpoint. When this mode is auto (which is the default),\n\ 14100 the behaviour depends on the non-stop setting (see help set non-stop).\n\ 14101 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ 14102 behaves as if always-inserted mode is on; if gdb is controlling the\n\ 14103 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), 14104 NULL, 14105 &show_always_inserted_mode, 14106 &breakpoint_set_cmdlist, 14107 &breakpoint_show_cmdlist); 14108 14109 add_com ("break-range", class_breakpoint, break_range_command, _("\ 14110 Set a breakpoint for an address range.\n\ 14111 break-range START-LOCATION, END-LOCATION\n\ 14112 where START-LOCATION and END-LOCATION can be one of the following:\n\ 14113 LINENUM, for that line in the current file,\n\ 14114 FILE:LINENUM, for that line in that file,\n\ 14115 +OFFSET, for that number of lines after the current line\n\ 14116 or the start of the range\n\ 14117 FUNCTION, for the first line in that function,\n\ 14118 FILE:FUNCTION, to distinguish among like-named static functions.\n\ 14119 *ADDRESS, for the instruction at that address.\n\ 14120 \n\ 14121 The breakpoint will stop execution of the inferior whenever it executes\n\ 14122 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ 14123 range (including START-LOCATION and END-LOCATION).")); 14124 14125 automatic_hardware_breakpoints = 1; 14126 14127 observer_attach_about_to_proceed (breakpoint_about_to_proceed); 14128 } 14129