1/* Target-struct-independent code to start (run) and stop an inferior 2 process. 3 4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 6 Free Software Foundation, Inc. 7 8 This file is part of GDB. 9 10 This program is free software; you can redistribute it and/or modify 11 it under the terms of the GNU General Public License as published by 12 the Free Software Foundation; either version 3 of the License, or 13 (at your option) any later version. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 22 23#include "defs.h" 24#include "gdb_string.h" 25#include <ctype.h> 26#include "symtab.h" 27#include "frame.h" 28#include "inferior.h" 29#include "exceptions.h" 30#include "breakpoint.h" 31#include "gdb_wait.h" 32#include "gdbcore.h" 33#include "gdbcmd.h" 34#include "cli/cli-script.h" 35#include "target.h" 36#include "gdbthread.h" 37#include "annotate.h" 38#include "symfile.h" 39#include "top.h" 40#include <signal.h> 41#include "inf-loop.h" 42#include "regcache.h" 43#include "value.h" 44#include "observer.h" 45#include "language.h" 46#include "solib.h" 47#include "main.h" 48 49#include "gdb_assert.h" 50#include "mi/mi-common.h" 51 52/* Prototypes for local functions */ 53 54static void signals_info (char *, int); 55 56static void handle_command (char *, int); 57 58static void sig_print_info (enum target_signal); 59 60static void sig_print_header (void); 61 62static void resume_cleanups (void *); 63 64static int hook_stop_stub (void *); 65 66static int restore_selected_frame (void *); 67 68static void build_infrun (void); 69 70static int follow_fork (void); 71 72static void set_schedlock_func (char *args, int from_tty, 73 struct cmd_list_element *c); 74 75struct execution_control_state; 76 77static int currently_stepping (struct execution_control_state *ecs); 78 79static void xdb_handle_command (char *args, int from_tty); 80 81static int prepare_to_proceed (void); 82 83void _initialize_infrun (void); 84 85int inferior_ignoring_leading_exec_events = 0; 86 87/* When set, stop the 'step' command if we enter a function which has 88 no line number information. The normal behavior is that we step 89 over such function. */ 90int step_stop_if_no_debug = 0; 91static void 92show_step_stop_if_no_debug (struct ui_file *file, int from_tty, 93 struct cmd_list_element *c, const char *value) 94{ 95 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value); 96} 97 98/* In asynchronous mode, but simulating synchronous execution. */ 99 100int sync_execution = 0; 101 102/* wait_for_inferior and normal_stop use this to notify the user 103 when the inferior stopped in a different thread than it had been 104 running in. */ 105 106static ptid_t previous_inferior_ptid; 107 108/* This is true for configurations that may follow through execl() and 109 similar functions. At present this is only true for HP-UX native. */ 110 111#ifndef MAY_FOLLOW_EXEC 112#define MAY_FOLLOW_EXEC (0) 113#endif 114 115static int may_follow_exec = MAY_FOLLOW_EXEC; 116 117static int debug_infrun = 0; 118static void 119show_debug_infrun (struct ui_file *file, int from_tty, 120 struct cmd_list_element *c, const char *value) 121{ 122 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value); 123} 124 125/* If the program uses ELF-style shared libraries, then calls to 126 functions in shared libraries go through stubs, which live in a 127 table called the PLT (Procedure Linkage Table). The first time the 128 function is called, the stub sends control to the dynamic linker, 129 which looks up the function's real address, patches the stub so 130 that future calls will go directly to the function, and then passes 131 control to the function. 132 133 If we are stepping at the source level, we don't want to see any of 134 this --- we just want to skip over the stub and the dynamic linker. 135 The simple approach is to single-step until control leaves the 136 dynamic linker. 137 138 However, on some systems (e.g., Red Hat's 5.2 distribution) the 139 dynamic linker calls functions in the shared C library, so you 140 can't tell from the PC alone whether the dynamic linker is still 141 running. In this case, we use a step-resume breakpoint to get us 142 past the dynamic linker, as if we were using "next" to step over a 143 function call. 144 145 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic 146 linker code or not. Normally, this means we single-step. However, 147 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an 148 address where we can place a step-resume breakpoint to get past the 149 linker's symbol resolution function. 150 151 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a 152 pretty portable way, by comparing the PC against the address ranges 153 of the dynamic linker's sections. 154 155 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since 156 it depends on internal details of the dynamic linker. It's usually 157 not too hard to figure out where to put a breakpoint, but it 158 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of 159 sanity checking. If it can't figure things out, returning zero and 160 getting the (possibly confusing) stepping behavior is better than 161 signalling an error, which will obscure the change in the 162 inferior's state. */ 163 164/* This function returns TRUE if pc is the address of an instruction 165 that lies within the dynamic linker (such as the event hook, or the 166 dld itself). 167 168 This function must be used only when a dynamic linker event has 169 been caught, and the inferior is being stepped out of the hook, or 170 undefined results are guaranteed. */ 171 172#ifndef SOLIB_IN_DYNAMIC_LINKER 173#define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 174#endif 175 176 177/* Convert the #defines into values. This is temporary until wfi control 178 flow is completely sorted out. */ 179 180#ifndef CANNOT_STEP_HW_WATCHPOINTS 181#define CANNOT_STEP_HW_WATCHPOINTS 0 182#else 183#undef CANNOT_STEP_HW_WATCHPOINTS 184#define CANNOT_STEP_HW_WATCHPOINTS 1 185#endif 186 187/* Tables of how to react to signals; the user sets them. */ 188 189static unsigned char *signal_stop; 190static unsigned char *signal_print; 191static unsigned char *signal_program; 192 193#define SET_SIGS(nsigs,sigs,flags) \ 194 do { \ 195 int signum = (nsigs); \ 196 while (signum-- > 0) \ 197 if ((sigs)[signum]) \ 198 (flags)[signum] = 1; \ 199 } while (0) 200 201#define UNSET_SIGS(nsigs,sigs,flags) \ 202 do { \ 203 int signum = (nsigs); \ 204 while (signum-- > 0) \ 205 if ((sigs)[signum]) \ 206 (flags)[signum] = 0; \ 207 } while (0) 208 209/* Value to pass to target_resume() to cause all threads to resume */ 210 211#define RESUME_ALL (pid_to_ptid (-1)) 212 213/* Command list pointer for the "stop" placeholder. */ 214 215static struct cmd_list_element *stop_command; 216 217/* Nonzero if breakpoints are now inserted in the inferior. */ 218 219static int breakpoints_inserted; 220 221/* Function inferior was in as of last step command. */ 222 223static struct symbol *step_start_function; 224 225/* Nonzero if we are expecting a trace trap and should proceed from it. */ 226 227static int trap_expected; 228 229/* Nonzero if we want to give control to the user when we're notified 230 of shared library events by the dynamic linker. */ 231static int stop_on_solib_events; 232static void 233show_stop_on_solib_events (struct ui_file *file, int from_tty, 234 struct cmd_list_element *c, const char *value) 235{ 236 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"), 237 value); 238} 239 240/* Nonzero means expecting a trace trap 241 and should stop the inferior and return silently when it happens. */ 242 243int stop_after_trap; 244 245/* Nonzero means expecting a trap and caller will handle it themselves. 246 It is used after attach, due to attaching to a process; 247 when running in the shell before the child program has been exec'd; 248 and when running some kinds of remote stuff (FIXME?). */ 249 250enum stop_kind stop_soon; 251 252/* Nonzero if proceed is being used for a "finish" command or a similar 253 situation when stop_registers should be saved. */ 254 255int proceed_to_finish; 256 257/* Save register contents here when about to pop a stack dummy frame, 258 if-and-only-if proceed_to_finish is set. 259 Thus this contains the return value from the called function (assuming 260 values are returned in a register). */ 261 262struct regcache *stop_registers; 263 264/* Nonzero after stop if current stack frame should be printed. */ 265 266static int stop_print_frame; 267 268static struct breakpoint *step_resume_breakpoint = NULL; 269 270/* This is a cached copy of the pid/waitstatus of the last event 271 returned by target_wait()/deprecated_target_wait_hook(). This 272 information is returned by get_last_target_status(). */ 273static ptid_t target_last_wait_ptid; 274static struct target_waitstatus target_last_waitstatus; 275 276/* This is used to remember when a fork, vfork or exec event 277 was caught by a catchpoint, and thus the event is to be 278 followed at the next resume of the inferior, and not 279 immediately. */ 280static struct 281{ 282 enum target_waitkind kind; 283 struct 284 { 285 int parent_pid; 286 int child_pid; 287 } 288 fork_event; 289 char *execd_pathname; 290} 291pending_follow; 292 293static const char follow_fork_mode_child[] = "child"; 294static const char follow_fork_mode_parent[] = "parent"; 295 296static const char *follow_fork_mode_kind_names[] = { 297 follow_fork_mode_child, 298 follow_fork_mode_parent, 299 NULL 300}; 301 302static const char *follow_fork_mode_string = follow_fork_mode_parent; 303static void 304show_follow_fork_mode_string (struct ui_file *file, int from_tty, 305 struct cmd_list_element *c, const char *value) 306{ 307 fprintf_filtered (file, _("\ 308Debugger response to a program call of fork or vfork is \"%s\".\n"), 309 value); 310} 311 312 313static int 314follow_fork (void) 315{ 316 int follow_child = (follow_fork_mode_string == follow_fork_mode_child); 317 318 return target_follow_fork (follow_child); 319} 320 321void 322follow_inferior_reset_breakpoints (void) 323{ 324 /* Was there a step_resume breakpoint? (There was if the user 325 did a "next" at the fork() call.) If so, explicitly reset its 326 thread number. 327 328 step_resumes are a form of bp that are made to be per-thread. 329 Since we created the step_resume bp when the parent process 330 was being debugged, and now are switching to the child process, 331 from the breakpoint package's viewpoint, that's a switch of 332 "threads". We must update the bp's notion of which thread 333 it is for, or it'll be ignored when it triggers. */ 334 335 if (step_resume_breakpoint) 336 breakpoint_re_set_thread (step_resume_breakpoint); 337 338 /* Reinsert all breakpoints in the child. The user may have set 339 breakpoints after catching the fork, in which case those 340 were never set in the child, but only in the parent. This makes 341 sure the inserted breakpoints match the breakpoint list. */ 342 343 breakpoint_re_set (); 344 insert_breakpoints (); 345} 346 347/* EXECD_PATHNAME is assumed to be non-NULL. */ 348 349static void 350follow_exec (int pid, char *execd_pathname) 351{ 352 int saved_pid = pid; 353 struct target_ops *tgt; 354 355 if (!may_follow_exec) 356 return; 357 358 /* This is an exec event that we actually wish to pay attention to. 359 Refresh our symbol table to the newly exec'd program, remove any 360 momentary bp's, etc. 361 362 If there are breakpoints, they aren't really inserted now, 363 since the exec() transformed our inferior into a fresh set 364 of instructions. 365 366 We want to preserve symbolic breakpoints on the list, since 367 we have hopes that they can be reset after the new a.out's 368 symbol table is read. 369 370 However, any "raw" breakpoints must be removed from the list 371 (e.g., the solib bp's), since their address is probably invalid 372 now. 373 374 And, we DON'T want to call delete_breakpoints() here, since 375 that may write the bp's "shadow contents" (the instruction 376 value that was overwritten witha TRAP instruction). Since 377 we now have a new a.out, those shadow contents aren't valid. */ 378 update_breakpoints_after_exec (); 379 380 /* If there was one, it's gone now. We cannot truly step-to-next 381 statement through an exec(). */ 382 step_resume_breakpoint = NULL; 383 step_range_start = 0; 384 step_range_end = 0; 385 386 /* What is this a.out's name? */ 387 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname); 388 389 /* We've followed the inferior through an exec. Therefore, the 390 inferior has essentially been killed & reborn. */ 391 392 /* First collect the run target in effect. */ 393 tgt = find_run_target (); 394 /* If we can't find one, things are in a very strange state... */ 395 if (tgt == NULL) 396 error (_("Could find run target to save before following exec")); 397 398 gdb_flush (gdb_stdout); 399 target_mourn_inferior (); 400 inferior_ptid = pid_to_ptid (saved_pid); 401 /* Because mourn_inferior resets inferior_ptid. */ 402 push_target (tgt); 403 404 /* That a.out is now the one to use. */ 405 exec_file_attach (execd_pathname, 0); 406 407 /* And also is where symbols can be found. */ 408 symbol_file_add_main (execd_pathname, 0); 409 410 /* Reset the shared library package. This ensures that we get 411 a shlib event when the child reaches "_start", at which point 412 the dld will have had a chance to initialize the child. */ 413#if defined(SOLIB_RESTART) 414 SOLIB_RESTART (); 415#endif 416#ifdef SOLIB_CREATE_INFERIOR_HOOK 417 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); 418#else 419 solib_create_inferior_hook (); 420#endif 421 422 /* Reinsert all breakpoints. (Those which were symbolic have 423 been reset to the proper address in the new a.out, thanks 424 to symbol_file_command...) */ 425 insert_breakpoints (); 426 427 /* The next resume of this inferior should bring it to the shlib 428 startup breakpoints. (If the user had also set bp's on 429 "main" from the old (parent) process, then they'll auto- 430 matically get reset there in the new process.) */ 431} 432 433/* Non-zero if we just simulating a single-step. This is needed 434 because we cannot remove the breakpoints in the inferior process 435 until after the `wait' in `wait_for_inferior'. */ 436static int singlestep_breakpoints_inserted_p = 0; 437 438/* The thread we inserted single-step breakpoints for. */ 439static ptid_t singlestep_ptid; 440 441/* PC when we started this single-step. */ 442static CORE_ADDR singlestep_pc; 443 444/* If another thread hit the singlestep breakpoint, we save the original 445 thread here so that we can resume single-stepping it later. */ 446static ptid_t saved_singlestep_ptid; 447static int stepping_past_singlestep_breakpoint; 448 449 450/* Things to clean up if we QUIT out of resume (). */ 451static void 452resume_cleanups (void *ignore) 453{ 454 normal_stop (); 455} 456 457static const char schedlock_off[] = "off"; 458static const char schedlock_on[] = "on"; 459static const char schedlock_step[] = "step"; 460static const char *scheduler_enums[] = { 461 schedlock_off, 462 schedlock_on, 463 schedlock_step, 464 NULL 465}; 466static const char *scheduler_mode = schedlock_off; 467static void 468show_scheduler_mode (struct ui_file *file, int from_tty, 469 struct cmd_list_element *c, const char *value) 470{ 471 fprintf_filtered (file, _("\ 472Mode for locking scheduler during execution is \"%s\".\n"), 473 value); 474} 475 476static void 477set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) 478{ 479 if (!target_can_lock_scheduler) 480 { 481 scheduler_mode = schedlock_off; 482 error (_("Target '%s' cannot support this command."), target_shortname); 483 } 484} 485 486 487/* Resume the inferior, but allow a QUIT. This is useful if the user 488 wants to interrupt some lengthy single-stepping operation 489 (for child processes, the SIGINT goes to the inferior, and so 490 we get a SIGINT random_signal, but for remote debugging and perhaps 491 other targets, that's not true). 492 493 STEP nonzero if we should step (zero to continue instead). 494 SIG is the signal to give the inferior (zero for none). */ 495void 496resume (int step, enum target_signal sig) 497{ 498 int should_resume = 1; 499 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); 500 QUIT; 501 502 if (debug_infrun) 503 fprintf_unfiltered (gdb_stdlog, "infrun: resume (step=%d, signal=%d)\n", 504 step, sig); 505 506 /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */ 507 508 509 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping 510 over an instruction that causes a page fault without triggering 511 a hardware watchpoint. The kernel properly notices that it shouldn't 512 stop, because the hardware watchpoint is not triggered, but it forgets 513 the step request and continues the program normally. 514 Work around the problem by removing hardware watchpoints if a step is 515 requested, GDB will check for a hardware watchpoint trigger after the 516 step anyway. */ 517 if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted) 518 remove_hw_watchpoints (); 519 520 521 /* Normally, by the time we reach `resume', the breakpoints are either 522 removed or inserted, as appropriate. The exception is if we're sitting 523 at a permanent breakpoint; we need to step over it, but permanent 524 breakpoints can't be removed. So we have to test for it here. */ 525 if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here) 526 { 527 if (gdbarch_skip_permanent_breakpoint_p (current_gdbarch)) 528 gdbarch_skip_permanent_breakpoint (current_gdbarch, 529 get_current_regcache ()); 530 else 531 error (_("\ 532The program is stopped at a permanent breakpoint, but GDB does not know\n\ 533how to step past a permanent breakpoint on this architecture. Try using\n\ 534a command like `return' or `jump' to continue execution.")); 535 } 536 537 if (step && gdbarch_software_single_step_p (current_gdbarch)) 538 { 539 /* Do it the hard way, w/temp breakpoints */ 540 if (gdbarch_software_single_step (current_gdbarch, get_current_frame ())) 541 { 542 /* ...and don't ask hardware to do it. */ 543 step = 0; 544 /* and do not pull these breakpoints until after a `wait' in 545 `wait_for_inferior' */ 546 singlestep_breakpoints_inserted_p = 1; 547 singlestep_ptid = inferior_ptid; 548 singlestep_pc = read_pc (); 549 } 550 } 551 552 /* If there were any forks/vforks/execs that were caught and are 553 now to be followed, then do so. */ 554 switch (pending_follow.kind) 555 { 556 case TARGET_WAITKIND_FORKED: 557 case TARGET_WAITKIND_VFORKED: 558 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; 559 if (follow_fork ()) 560 should_resume = 0; 561 break; 562 563 case TARGET_WAITKIND_EXECD: 564 /* follow_exec is called as soon as the exec event is seen. */ 565 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; 566 break; 567 568 default: 569 break; 570 } 571 572 /* Install inferior's terminal modes. */ 573 target_terminal_inferior (); 574 575 if (should_resume) 576 { 577 ptid_t resume_ptid; 578 579 resume_ptid = RESUME_ALL; /* Default */ 580 581 if ((step || singlestep_breakpoints_inserted_p) 582 && (stepping_past_singlestep_breakpoint 583 || (!breakpoints_inserted && breakpoint_here_p (read_pc ())))) 584 { 585 /* Stepping past a breakpoint without inserting breakpoints. 586 Make sure only the current thread gets to step, so that 587 other threads don't sneak past breakpoints while they are 588 not inserted. */ 589 590 resume_ptid = inferior_ptid; 591 } 592 593 if ((scheduler_mode == schedlock_on) 594 || (scheduler_mode == schedlock_step 595 && (step || singlestep_breakpoints_inserted_p))) 596 { 597 /* User-settable 'scheduler' mode requires solo thread resume. */ 598 resume_ptid = inferior_ptid; 599 } 600 601 if (gdbarch_cannot_step_breakpoint (current_gdbarch)) 602 { 603 /* Most targets can step a breakpoint instruction, thus 604 executing it normally. But if this one cannot, just 605 continue and we will hit it anyway. */ 606 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) 607 step = 0; 608 } 609 target_resume (resume_ptid, step, sig); 610 } 611 612 discard_cleanups (old_cleanups); 613} 614 615 616/* Clear out all variables saying what to do when inferior is continued. 617 First do this, then set the ones you want, then call `proceed'. */ 618 619void 620clear_proceed_status (void) 621{ 622 trap_expected = 0; 623 step_range_start = 0; 624 step_range_end = 0; 625 step_frame_id = null_frame_id; 626 step_over_calls = STEP_OVER_UNDEBUGGABLE; 627 stop_after_trap = 0; 628 stop_soon = NO_STOP_QUIETLY; 629 proceed_to_finish = 0; 630 breakpoint_proceeded = 1; /* We're about to proceed... */ 631 632 if (stop_registers) 633 { 634 regcache_xfree (stop_registers); 635 stop_registers = NULL; 636 } 637 638 /* Discard any remaining commands or status from previous stop. */ 639 bpstat_clear (&stop_bpstat); 640} 641 642/* This should be suitable for any targets that support threads. */ 643 644static int 645prepare_to_proceed (void) 646{ 647 ptid_t wait_ptid; 648 struct target_waitstatus wait_status; 649 650 /* Get the last target status returned by target_wait(). */ 651 get_last_target_status (&wait_ptid, &wait_status); 652 653 /* Make sure we were stopped either at a breakpoint, or because 654 of a Ctrl-C. */ 655 if (wait_status.kind != TARGET_WAITKIND_STOPPED 656 || (wait_status.value.sig != TARGET_SIGNAL_TRAP 657 && wait_status.value.sig != TARGET_SIGNAL_INT)) 658 { 659 return 0; 660 } 661 662 if (!ptid_equal (wait_ptid, minus_one_ptid) 663 && !ptid_equal (inferior_ptid, wait_ptid)) 664 { 665 /* Switched over from WAIT_PID. */ 666 CORE_ADDR wait_pc = read_pc_pid (wait_ptid); 667 668 if (wait_pc != read_pc ()) 669 { 670 /* Switch back to WAIT_PID thread. */ 671 inferior_ptid = wait_ptid; 672 673 /* FIXME: This stuff came from switch_to_thread() in 674 thread.c (which should probably be a public function). */ 675 reinit_frame_cache (); 676 registers_changed (); 677 stop_pc = wait_pc; 678 } 679 680 /* We return 1 to indicate that there is a breakpoint here, 681 so we need to step over it before continuing to avoid 682 hitting it straight away. */ 683 if (breakpoint_here_p (wait_pc)) 684 return 1; 685 } 686 687 return 0; 688 689} 690 691/* Record the pc of the program the last time it stopped. This is 692 just used internally by wait_for_inferior, but need to be preserved 693 over calls to it and cleared when the inferior is started. */ 694static CORE_ADDR prev_pc; 695 696/* Basic routine for continuing the program in various fashions. 697 698 ADDR is the address to resume at, or -1 for resume where stopped. 699 SIGGNAL is the signal to give it, or 0 for none, 700 or -1 for act according to how it stopped. 701 STEP is nonzero if should trap after one instruction. 702 -1 means return after that and print nothing. 703 You should probably set various step_... variables 704 before calling here, if you are stepping. 705 706 You should call clear_proceed_status before calling proceed. */ 707 708void 709proceed (CORE_ADDR addr, enum target_signal siggnal, int step) 710{ 711 int oneproc = 0; 712 713 if (step > 0) 714 step_start_function = find_pc_function (read_pc ()); 715 if (step < 0) 716 stop_after_trap = 1; 717 718 if (addr == (CORE_ADDR) -1) 719 { 720 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) 721 /* There is a breakpoint at the address we will resume at, 722 step one instruction before inserting breakpoints so that 723 we do not stop right away (and report a second hit at this 724 breakpoint). */ 725 oneproc = 1; 726 else if (gdbarch_single_step_through_delay_p (current_gdbarch) 727 && gdbarch_single_step_through_delay (current_gdbarch, 728 get_current_frame ())) 729 /* We stepped onto an instruction that needs to be stepped 730 again before re-inserting the breakpoint, do so. */ 731 oneproc = 1; 732 } 733 else 734 { 735 write_pc (addr); 736 } 737 738 if (debug_infrun) 739 fprintf_unfiltered (gdb_stdlog, 740 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n", 741 paddr_nz (addr), siggnal, step); 742 743 /* In a multi-threaded task we may select another thread 744 and then continue or step. 745 746 But if the old thread was stopped at a breakpoint, it 747 will immediately cause another breakpoint stop without 748 any execution (i.e. it will report a breakpoint hit 749 incorrectly). So we must step over it first. 750 751 prepare_to_proceed checks the current thread against the thread 752 that reported the most recent event. If a step-over is required 753 it returns TRUE and sets the current thread to the old thread. */ 754 if (prepare_to_proceed () && breakpoint_here_p (read_pc ())) 755 oneproc = 1; 756 757 if (oneproc) 758 /* We will get a trace trap after one instruction. 759 Continue it automatically and insert breakpoints then. */ 760 trap_expected = 1; 761 else 762 { 763 insert_breakpoints (); 764 /* If we get here there was no call to error() in 765 insert breakpoints -- so they were inserted. */ 766 breakpoints_inserted = 1; 767 } 768 769 if (siggnal != TARGET_SIGNAL_DEFAULT) 770 stop_signal = siggnal; 771 /* If this signal should not be seen by program, 772 give it zero. Used for debugging signals. */ 773 else if (!signal_program[stop_signal]) 774 stop_signal = TARGET_SIGNAL_0; 775 776 annotate_starting (); 777 778 /* Make sure that output from GDB appears before output from the 779 inferior. */ 780 gdb_flush (gdb_stdout); 781 782 /* Refresh prev_pc value just prior to resuming. This used to be 783 done in stop_stepping, however, setting prev_pc there did not handle 784 scenarios such as inferior function calls or returning from 785 a function via the return command. In those cases, the prev_pc 786 value was not set properly for subsequent commands. The prev_pc value 787 is used to initialize the starting line number in the ecs. With an 788 invalid value, the gdb next command ends up stopping at the position 789 represented by the next line table entry past our start position. 790 On platforms that generate one line table entry per line, this 791 is not a problem. However, on the ia64, the compiler generates 792 extraneous line table entries that do not increase the line number. 793 When we issue the gdb next command on the ia64 after an inferior call 794 or a return command, we often end up a few instructions forward, still 795 within the original line we started. 796 797 An attempt was made to have init_execution_control_state () refresh 798 the prev_pc value before calculating the line number. This approach 799 did not work because on platforms that use ptrace, the pc register 800 cannot be read unless the inferior is stopped. At that point, we 801 are not guaranteed the inferior is stopped and so the read_pc () 802 call can fail. Setting the prev_pc value here ensures the value is 803 updated correctly when the inferior is stopped. */ 804 prev_pc = read_pc (); 805 806 /* Resume inferior. */ 807 resume (oneproc || step || bpstat_should_step (), stop_signal); 808 809 /* Wait for it to stop (if not standalone) 810 and in any case decode why it stopped, and act accordingly. */ 811 /* Do this only if we are not using the event loop, or if the target 812 does not support asynchronous execution. */ 813 if (!target_can_async_p ()) 814 { 815 wait_for_inferior (); 816 normal_stop (); 817 } 818} 819 820 821/* Start remote-debugging of a machine over a serial link. */ 822 823void 824start_remote (int from_tty) 825{ 826 init_thread_list (); 827 init_wait_for_inferior (); 828 stop_soon = STOP_QUIETLY_REMOTE; 829 trap_expected = 0; 830 831 /* Always go on waiting for the target, regardless of the mode. */ 832 /* FIXME: cagney/1999-09-23: At present it isn't possible to 833 indicate to wait_for_inferior that a target should timeout if 834 nothing is returned (instead of just blocking). Because of this, 835 targets expecting an immediate response need to, internally, set 836 things up so that the target_wait() is forced to eventually 837 timeout. */ 838 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to 839 differentiate to its caller what the state of the target is after 840 the initial open has been performed. Here we're assuming that 841 the target has stopped. It should be possible to eventually have 842 target_open() return to the caller an indication that the target 843 is currently running and GDB state should be set to the same as 844 for an async run. */ 845 wait_for_inferior (); 846 847 /* Now that the inferior has stopped, do any bookkeeping like 848 loading shared libraries. We want to do this before normal_stop, 849 so that the displayed frame is up to date. */ 850 post_create_inferior (¤t_target, from_tty); 851 852 normal_stop (); 853} 854 855/* Initialize static vars when a new inferior begins. */ 856 857void 858init_wait_for_inferior (void) 859{ 860 /* These are meaningless until the first time through wait_for_inferior. */ 861 prev_pc = 0; 862 863 breakpoints_inserted = 0; 864 breakpoint_init_inferior (inf_starting); 865 866 /* Don't confuse first call to proceed(). */ 867 stop_signal = TARGET_SIGNAL_0; 868 869 /* The first resume is not following a fork/vfork/exec. */ 870 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ 871 872 clear_proceed_status (); 873 874 stepping_past_singlestep_breakpoint = 0; 875} 876 877/* This enum encodes possible reasons for doing a target_wait, so that 878 wfi can call target_wait in one place. (Ultimately the call will be 879 moved out of the infinite loop entirely.) */ 880 881enum infwait_states 882{ 883 infwait_normal_state, 884 infwait_thread_hop_state, 885 infwait_nonstep_watch_state 886}; 887 888/* Why did the inferior stop? Used to print the appropriate messages 889 to the interface from within handle_inferior_event(). */ 890enum inferior_stop_reason 891{ 892 /* Step, next, nexti, stepi finished. */ 893 END_STEPPING_RANGE, 894 /* Inferior terminated by signal. */ 895 SIGNAL_EXITED, 896 /* Inferior exited. */ 897 EXITED, 898 /* Inferior received signal, and user asked to be notified. */ 899 SIGNAL_RECEIVED 900}; 901 902/* This structure contains what used to be local variables in 903 wait_for_inferior. Probably many of them can return to being 904 locals in handle_inferior_event. */ 905 906struct execution_control_state 907{ 908 struct target_waitstatus ws; 909 struct target_waitstatus *wp; 910 int another_trap; 911 int random_signal; 912 CORE_ADDR stop_func_start; 913 CORE_ADDR stop_func_end; 914 char *stop_func_name; 915 struct symtab_and_line sal; 916 int current_line; 917 struct symtab *current_symtab; 918 int handling_longjmp; /* FIXME */ 919 ptid_t ptid; 920 ptid_t saved_inferior_ptid; 921 int step_after_step_resume_breakpoint; 922 int stepping_through_solib_after_catch; 923 bpstat stepping_through_solib_catchpoints; 924 int new_thread_event; 925 struct target_waitstatus tmpstatus; 926 enum infwait_states infwait_state; 927 ptid_t waiton_ptid; 928 int wait_some_more; 929}; 930 931void init_execution_control_state (struct execution_control_state *ecs); 932 933void handle_inferior_event (struct execution_control_state *ecs); 934 935static void step_into_function (struct execution_control_state *ecs); 936static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame); 937static void insert_step_resume_breakpoint_at_caller (struct frame_info *); 938static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, 939 struct frame_id sr_id); 940static void stop_stepping (struct execution_control_state *ecs); 941static void prepare_to_wait (struct execution_control_state *ecs); 942static void keep_going (struct execution_control_state *ecs); 943static void print_stop_reason (enum inferior_stop_reason stop_reason, 944 int stop_info); 945 946/* Wait for control to return from inferior to debugger. 947 If inferior gets a signal, we may decide to start it up again 948 instead of returning. That is why there is a loop in this function. 949 When this function actually returns it means the inferior 950 should be left stopped and GDB should read more commands. */ 951 952void 953wait_for_inferior (void) 954{ 955 struct cleanup *old_cleanups; 956 struct execution_control_state ecss; 957 struct execution_control_state *ecs; 958 959 if (debug_infrun) 960 fprintf_unfiltered (gdb_stdlog, "infrun: wait_for_inferior\n"); 961 962 old_cleanups = make_cleanup (delete_step_resume_breakpoint, 963 &step_resume_breakpoint); 964 965 /* wfi still stays in a loop, so it's OK just to take the address of 966 a local to get the ecs pointer. */ 967 ecs = &ecss; 968 969 /* Fill in with reasonable starting values. */ 970 init_execution_control_state (ecs); 971 972 /* We'll update this if & when we switch to a new thread. */ 973 previous_inferior_ptid = inferior_ptid; 974 975 overlay_cache_invalid = 1; 976 977 /* We have to invalidate the registers BEFORE calling target_wait 978 because they can be loaded from the target while in target_wait. 979 This makes remote debugging a bit more efficient for those 980 targets that provide critical registers as part of their normal 981 status mechanism. */ 982 983 registers_changed (); 984 985 while (1) 986 { 987 if (deprecated_target_wait_hook) 988 ecs->ptid = deprecated_target_wait_hook (ecs->waiton_ptid, ecs->wp); 989 else 990 ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp); 991 992 /* Now figure out what to do with the result of the result. */ 993 handle_inferior_event (ecs); 994 995 if (!ecs->wait_some_more) 996 break; 997 } 998 do_cleanups (old_cleanups); 999} 1000 1001/* Asynchronous version of wait_for_inferior. It is called by the 1002 event loop whenever a change of state is detected on the file 1003 descriptor corresponding to the target. It can be called more than 1004 once to complete a single execution command. In such cases we need 1005 to keep the state in a global variable ASYNC_ECSS. If it is the 1006 last time that this function is called for a single execution 1007 command, then report to the user that the inferior has stopped, and 1008 do the necessary cleanups. */ 1009 1010struct execution_control_state async_ecss; 1011struct execution_control_state *async_ecs; 1012 1013void 1014fetch_inferior_event (void *client_data) 1015{ 1016 static struct cleanup *old_cleanups; 1017 1018 async_ecs = &async_ecss; 1019 1020 if (!async_ecs->wait_some_more) 1021 { 1022 old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint, 1023 &step_resume_breakpoint); 1024 1025 /* Fill in with reasonable starting values. */ 1026 init_execution_control_state (async_ecs); 1027 1028 /* We'll update this if & when we switch to a new thread. */ 1029 previous_inferior_ptid = inferior_ptid; 1030 1031 overlay_cache_invalid = 1; 1032 1033 /* We have to invalidate the registers BEFORE calling target_wait 1034 because they can be loaded from the target while in target_wait. 1035 This makes remote debugging a bit more efficient for those 1036 targets that provide critical registers as part of their normal 1037 status mechanism. */ 1038 1039 registers_changed (); 1040 } 1041 1042 if (deprecated_target_wait_hook) 1043 async_ecs->ptid = 1044 deprecated_target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp); 1045 else 1046 async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp); 1047 1048 /* Now figure out what to do with the result of the result. */ 1049 handle_inferior_event (async_ecs); 1050 1051 if (!async_ecs->wait_some_more) 1052 { 1053 /* Do only the cleanups that have been added by this 1054 function. Let the continuations for the commands do the rest, 1055 if there are any. */ 1056 do_exec_cleanups (old_cleanups); 1057 normal_stop (); 1058 if (step_multi && stop_step) 1059 inferior_event_handler (INF_EXEC_CONTINUE, NULL); 1060 else 1061 inferior_event_handler (INF_EXEC_COMPLETE, NULL); 1062 } 1063} 1064 1065/* Prepare an execution control state for looping through a 1066 wait_for_inferior-type loop. */ 1067 1068void 1069init_execution_control_state (struct execution_control_state *ecs) 1070{ 1071 ecs->another_trap = 0; 1072 ecs->random_signal = 0; 1073 ecs->step_after_step_resume_breakpoint = 0; 1074 ecs->handling_longjmp = 0; /* FIXME */ 1075 ecs->stepping_through_solib_after_catch = 0; 1076 ecs->stepping_through_solib_catchpoints = NULL; 1077 ecs->sal = find_pc_line (prev_pc, 0); 1078 ecs->current_line = ecs->sal.line; 1079 ecs->current_symtab = ecs->sal.symtab; 1080 ecs->infwait_state = infwait_normal_state; 1081 ecs->waiton_ptid = pid_to_ptid (-1); 1082 ecs->wp = &(ecs->ws); 1083} 1084 1085/* Return the cached copy of the last pid/waitstatus returned by 1086 target_wait()/deprecated_target_wait_hook(). The data is actually 1087 cached by handle_inferior_event(), which gets called immediately 1088 after target_wait()/deprecated_target_wait_hook(). */ 1089 1090void 1091get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) 1092{ 1093 *ptidp = target_last_wait_ptid; 1094 *status = target_last_waitstatus; 1095} 1096 1097void 1098nullify_last_target_wait_ptid (void) 1099{ 1100 target_last_wait_ptid = minus_one_ptid; 1101} 1102 1103/* Switch thread contexts, maintaining "infrun state". */ 1104 1105static void 1106context_switch (struct execution_control_state *ecs) 1107{ 1108 /* Caution: it may happen that the new thread (or the old one!) 1109 is not in the thread list. In this case we must not attempt 1110 to "switch context", or we run the risk that our context may 1111 be lost. This may happen as a result of the target module 1112 mishandling thread creation. */ 1113 1114 if (debug_infrun) 1115 { 1116 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", 1117 target_pid_to_str (inferior_ptid)); 1118 fprintf_unfiltered (gdb_stdlog, "to %s\n", 1119 target_pid_to_str (ecs->ptid)); 1120 } 1121 1122 if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid)) 1123 { /* Perform infrun state context switch: */ 1124 /* Save infrun state for the old thread. */ 1125 save_infrun_state (inferior_ptid, prev_pc, 1126 trap_expected, step_resume_breakpoint, 1127 step_range_start, 1128 step_range_end, &step_frame_id, 1129 ecs->handling_longjmp, ecs->another_trap, 1130 ecs->stepping_through_solib_after_catch, 1131 ecs->stepping_through_solib_catchpoints, 1132 ecs->current_line, ecs->current_symtab); 1133 1134 /* Load infrun state for the new thread. */ 1135 load_infrun_state (ecs->ptid, &prev_pc, 1136 &trap_expected, &step_resume_breakpoint, 1137 &step_range_start, 1138 &step_range_end, &step_frame_id, 1139 &ecs->handling_longjmp, &ecs->another_trap, 1140 &ecs->stepping_through_solib_after_catch, 1141 &ecs->stepping_through_solib_catchpoints, 1142 &ecs->current_line, &ecs->current_symtab); 1143 } 1144 inferior_ptid = ecs->ptid; 1145 reinit_frame_cache (); 1146} 1147 1148static void 1149adjust_pc_after_break (struct execution_control_state *ecs) 1150{ 1151 CORE_ADDR breakpoint_pc; 1152 1153 /* If this target does not decrement the PC after breakpoints, then 1154 we have nothing to do. */ 1155 if (gdbarch_decr_pc_after_break (current_gdbarch) == 0) 1156 return; 1157 1158 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If 1159 we aren't, just return. 1160 1161 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not 1162 affected by gdbarch_decr_pc_after_break. Other waitkinds which are 1163 implemented by software breakpoints should be handled through the normal 1164 breakpoint layer. 1165 1166 NOTE drow/2004-01-31: On some targets, breakpoints may generate 1167 different signals (SIGILL or SIGEMT for instance), but it is less 1168 clear where the PC is pointing afterwards. It may not match 1169 gdbarch_decr_pc_after_break. I don't know any specific target that 1170 generates these signals at breakpoints (the code has been in GDB since at 1171 least 1992) so I can not guess how to handle them here. 1172 1173 In earlier versions of GDB, a target with 1174 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a 1175 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any 1176 target with both of these set in GDB history, and it seems unlikely to be 1177 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ 1178 1179 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) 1180 return; 1181 1182 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP) 1183 return; 1184 1185 /* Find the location where (if we've hit a breakpoint) the 1186 breakpoint would be. */ 1187 breakpoint_pc = read_pc_pid (ecs->ptid) - gdbarch_decr_pc_after_break 1188 (current_gdbarch); 1189 1190 /* Check whether there actually is a software breakpoint inserted 1191 at that location. */ 1192 if (software_breakpoint_inserted_here_p (breakpoint_pc)) 1193 { 1194 /* When using hardware single-step, a SIGTRAP is reported for both 1195 a completed single-step and a software breakpoint. Need to 1196 differentiate between the two, as the latter needs adjusting 1197 but the former does not. 1198 1199 The SIGTRAP can be due to a completed hardware single-step only if 1200 - we didn't insert software single-step breakpoints 1201 - the thread to be examined is still the current thread 1202 - this thread is currently being stepped 1203 1204 If any of these events did not occur, we must have stopped due 1205 to hitting a software breakpoint, and have to back up to the 1206 breakpoint address. 1207 1208 As a special case, we could have hardware single-stepped a 1209 software breakpoint. In this case (prev_pc == breakpoint_pc), 1210 we also need to back up to the breakpoint address. */ 1211 1212 if (singlestep_breakpoints_inserted_p 1213 || !ptid_equal (ecs->ptid, inferior_ptid) 1214 || !currently_stepping (ecs) 1215 || prev_pc == breakpoint_pc) 1216 write_pc_pid (breakpoint_pc, ecs->ptid); 1217 } 1218} 1219 1220/* Given an execution control state that has been freshly filled in 1221 by an event from the inferior, figure out what it means and take 1222 appropriate action. */ 1223 1224int stepped_after_stopped_by_watchpoint; 1225 1226void 1227handle_inferior_event (struct execution_control_state *ecs) 1228{ 1229 /* NOTE: bje/2005-05-02: If you're looking at this code and thinking 1230 that the variable stepped_after_stopped_by_watchpoint isn't used, 1231 then you're wrong! See remote.c:remote_stopped_data_address. */ 1232 1233 int sw_single_step_trap_p = 0; 1234 int stopped_by_watchpoint = -1; /* Mark as unknown. */ 1235 1236 /* Cache the last pid/waitstatus. */ 1237 target_last_wait_ptid = ecs->ptid; 1238 target_last_waitstatus = *ecs->wp; 1239 1240 adjust_pc_after_break (ecs); 1241 1242 switch (ecs->infwait_state) 1243 { 1244 case infwait_thread_hop_state: 1245 if (debug_infrun) 1246 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n"); 1247 /* Cancel the waiton_ptid. */ 1248 ecs->waiton_ptid = pid_to_ptid (-1); 1249 break; 1250 1251 case infwait_normal_state: 1252 if (debug_infrun) 1253 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n"); 1254 stepped_after_stopped_by_watchpoint = 0; 1255 break; 1256 1257 case infwait_nonstep_watch_state: 1258 if (debug_infrun) 1259 fprintf_unfiltered (gdb_stdlog, 1260 "infrun: infwait_nonstep_watch_state\n"); 1261 insert_breakpoints (); 1262 1263 /* FIXME-maybe: is this cleaner than setting a flag? Does it 1264 handle things like signals arriving and other things happening 1265 in combination correctly? */ 1266 stepped_after_stopped_by_watchpoint = 1; 1267 break; 1268 1269 default: 1270 internal_error (__FILE__, __LINE__, _("bad switch")); 1271 } 1272 ecs->infwait_state = infwait_normal_state; 1273 1274 reinit_frame_cache (); 1275 1276 /* If it's a new process, add it to the thread database */ 1277 1278 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) 1279 && !ptid_equal (ecs->ptid, minus_one_ptid) 1280 && !in_thread_list (ecs->ptid)); 1281 1282 if (ecs->ws.kind != TARGET_WAITKIND_EXITED 1283 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) 1284 { 1285 add_thread (ecs->ptid); 1286 1287 ui_out_text (uiout, "[New "); 1288 ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid)); 1289 ui_out_text (uiout, "]\n"); 1290 } 1291 1292 switch (ecs->ws.kind) 1293 { 1294 case TARGET_WAITKIND_LOADED: 1295 if (debug_infrun) 1296 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); 1297 /* Ignore gracefully during startup of the inferior, as it might 1298 be the shell which has just loaded some objects, otherwise 1299 add the symbols for the newly loaded objects. Also ignore at 1300 the beginning of an attach or remote session; we will query 1301 the full list of libraries once the connection is 1302 established. */ 1303 if (stop_soon == NO_STOP_QUIETLY) 1304 { 1305 int breakpoints_were_inserted; 1306 1307 /* Remove breakpoints, SOLIB_ADD might adjust 1308 breakpoint addresses via breakpoint_re_set. */ 1309 breakpoints_were_inserted = breakpoints_inserted; 1310 if (breakpoints_inserted) 1311 remove_breakpoints (); 1312 breakpoints_inserted = 0; 1313 1314 /* Check for any newly added shared libraries if we're 1315 supposed to be adding them automatically. Switch 1316 terminal for any messages produced by 1317 breakpoint_re_set. */ 1318 target_terminal_ours_for_output (); 1319 /* NOTE: cagney/2003-11-25: Make certain that the target 1320 stack's section table is kept up-to-date. Architectures, 1321 (e.g., PPC64), use the section table to perform 1322 operations such as address => section name and hence 1323 require the table to contain all sections (including 1324 those found in shared libraries). */ 1325 /* NOTE: cagney/2003-11-25: Pass current_target and not 1326 exec_ops to SOLIB_ADD. This is because current GDB is 1327 only tooled to propagate section_table changes out from 1328 the "current_target" (see target_resize_to_sections), and 1329 not up from the exec stratum. This, of course, isn't 1330 right. "infrun.c" should only interact with the 1331 exec/process stratum, instead relying on the target stack 1332 to propagate relevant changes (stop, section table 1333 changed, ...) up to other layers. */ 1334#ifdef SOLIB_ADD 1335 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); 1336#else 1337 solib_add (NULL, 0, ¤t_target, auto_solib_add); 1338#endif 1339 target_terminal_inferior (); 1340 1341 /* Try to reenable shared library breakpoints, additional 1342 code segments in shared libraries might be mapped in now. */ 1343 re_enable_breakpoints_in_shlibs (); 1344 1345 /* If requested, stop when the dynamic linker notifies 1346 gdb of events. This allows the user to get control 1347 and place breakpoints in initializer routines for 1348 dynamically loaded objects (among other things). */ 1349 if (stop_on_solib_events) 1350 { 1351 stop_stepping (ecs); 1352 return; 1353 } 1354 1355 /* NOTE drow/2007-05-11: This might be a good place to check 1356 for "catch load". */ 1357 1358 /* Reinsert breakpoints and continue. */ 1359 if (breakpoints_were_inserted) 1360 { 1361 insert_breakpoints (); 1362 breakpoints_inserted = 1; 1363 } 1364 } 1365 1366 /* If we are skipping through a shell, or through shared library 1367 loading that we aren't interested in, resume the program. If 1368 we're running the program normally, also resume. But stop if 1369 we're attaching or setting up a remote connection. */ 1370 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) 1371 { 1372 resume (0, TARGET_SIGNAL_0); 1373 prepare_to_wait (ecs); 1374 return; 1375 } 1376 1377 break; 1378 1379 case TARGET_WAITKIND_SPURIOUS: 1380 if (debug_infrun) 1381 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n"); 1382 resume (0, TARGET_SIGNAL_0); 1383 prepare_to_wait (ecs); 1384 return; 1385 1386 case TARGET_WAITKIND_EXITED: 1387 if (debug_infrun) 1388 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n"); 1389 target_terminal_ours (); /* Must do this before mourn anyway */ 1390 print_stop_reason (EXITED, ecs->ws.value.integer); 1391 1392 /* Record the exit code in the convenience variable $_exitcode, so 1393 that the user can inspect this again later. */ 1394 set_internalvar (lookup_internalvar ("_exitcode"), 1395 value_from_longest (builtin_type_int, 1396 (LONGEST) ecs->ws.value.integer)); 1397 gdb_flush (gdb_stdout); 1398 target_mourn_inferior (); 1399 singlestep_breakpoints_inserted_p = 0; 1400 stop_print_frame = 0; 1401 stop_stepping (ecs); 1402 return; 1403 1404 case TARGET_WAITKIND_SIGNALLED: 1405 if (debug_infrun) 1406 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n"); 1407 stop_print_frame = 0; 1408 stop_signal = ecs->ws.value.sig; 1409 target_terminal_ours (); /* Must do this before mourn anyway */ 1410 1411 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't 1412 reach here unless the inferior is dead. However, for years 1413 target_kill() was called here, which hints that fatal signals aren't 1414 really fatal on some systems. If that's true, then some changes 1415 may be needed. */ 1416 target_mourn_inferior (); 1417 1418 print_stop_reason (SIGNAL_EXITED, stop_signal); 1419 singlestep_breakpoints_inserted_p = 0; 1420 stop_stepping (ecs); 1421 return; 1422 1423 /* The following are the only cases in which we keep going; 1424 the above cases end in a continue or goto. */ 1425 case TARGET_WAITKIND_FORKED: 1426 case TARGET_WAITKIND_VFORKED: 1427 if (debug_infrun) 1428 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n"); 1429 stop_signal = TARGET_SIGNAL_TRAP; 1430 pending_follow.kind = ecs->ws.kind; 1431 1432 pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); 1433 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; 1434 1435 if (!ptid_equal (ecs->ptid, inferior_ptid)) 1436 { 1437 context_switch (ecs); 1438 reinit_frame_cache (); 1439 } 1440 1441 stop_pc = read_pc (); 1442 1443 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid, 0); 1444 1445 ecs->random_signal = !bpstat_explains_signal (stop_bpstat); 1446 1447 /* If no catchpoint triggered for this, then keep going. */ 1448 if (ecs->random_signal) 1449 { 1450 stop_signal = TARGET_SIGNAL_0; 1451 keep_going (ecs); 1452 return; 1453 } 1454 goto process_event_stop_test; 1455 1456 case TARGET_WAITKIND_EXECD: 1457 if (debug_infrun) 1458 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n"); 1459 stop_signal = TARGET_SIGNAL_TRAP; 1460 1461 /* NOTE drow/2002-12-05: This code should be pushed down into the 1462 target_wait function. Until then following vfork on HP/UX 10.20 1463 is probably broken by this. Of course, it's broken anyway. */ 1464 /* Is this a target which reports multiple exec events per actual 1465 call to exec()? (HP-UX using ptrace does, for example.) If so, 1466 ignore all but the last one. Just resume the exec'r, and wait 1467 for the next exec event. */ 1468 if (inferior_ignoring_leading_exec_events) 1469 { 1470 inferior_ignoring_leading_exec_events--; 1471 target_resume (ecs->ptid, 0, TARGET_SIGNAL_0); 1472 prepare_to_wait (ecs); 1473 return; 1474 } 1475 inferior_ignoring_leading_exec_events = 1476 target_reported_exec_events_per_exec_call () - 1; 1477 1478 pending_follow.execd_pathname = 1479 savestring (ecs->ws.value.execd_pathname, 1480 strlen (ecs->ws.value.execd_pathname)); 1481 1482 /* This causes the eventpoints and symbol table to be reset. Must 1483 do this now, before trying to determine whether to stop. */ 1484 follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); 1485 xfree (pending_follow.execd_pathname); 1486 1487 stop_pc = read_pc_pid (ecs->ptid); 1488 ecs->saved_inferior_ptid = inferior_ptid; 1489 inferior_ptid = ecs->ptid; 1490 1491 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid, 0); 1492 1493 ecs->random_signal = !bpstat_explains_signal (stop_bpstat); 1494 inferior_ptid = ecs->saved_inferior_ptid; 1495 1496 if (!ptid_equal (ecs->ptid, inferior_ptid)) 1497 { 1498 context_switch (ecs); 1499 reinit_frame_cache (); 1500 } 1501 1502 /* If no catchpoint triggered for this, then keep going. */ 1503 if (ecs->random_signal) 1504 { 1505 stop_signal = TARGET_SIGNAL_0; 1506 keep_going (ecs); 1507 return; 1508 } 1509 goto process_event_stop_test; 1510 1511 /* Be careful not to try to gather much state about a thread 1512 that's in a syscall. It's frequently a losing proposition. */ 1513 case TARGET_WAITKIND_SYSCALL_ENTRY: 1514 if (debug_infrun) 1515 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n"); 1516 resume (0, TARGET_SIGNAL_0); 1517 prepare_to_wait (ecs); 1518 return; 1519 1520 /* Before examining the threads further, step this thread to 1521 get it entirely out of the syscall. (We get notice of the 1522 event when the thread is just on the verge of exiting a 1523 syscall. Stepping one instruction seems to get it back 1524 into user code.) */ 1525 case TARGET_WAITKIND_SYSCALL_RETURN: 1526 if (debug_infrun) 1527 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n"); 1528 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); 1529 prepare_to_wait (ecs); 1530 return; 1531 1532 case TARGET_WAITKIND_STOPPED: 1533 if (debug_infrun) 1534 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n"); 1535 stop_signal = ecs->ws.value.sig; 1536 break; 1537 1538 /* We had an event in the inferior, but we are not interested 1539 in handling it at this level. The lower layers have already 1540 done what needs to be done, if anything. 1541 1542 One of the possible circumstances for this is when the 1543 inferior produces output for the console. The inferior has 1544 not stopped, and we are ignoring the event. Another possible 1545 circumstance is any event which the lower level knows will be 1546 reported multiple times without an intervening resume. */ 1547 case TARGET_WAITKIND_IGNORE: 1548 if (debug_infrun) 1549 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n"); 1550 prepare_to_wait (ecs); 1551 return; 1552 } 1553 1554 /* We may want to consider not doing a resume here in order to give 1555 the user a chance to play with the new thread. It might be good 1556 to make that a user-settable option. */ 1557 1558 /* At this point, all threads are stopped (happens automatically in 1559 either the OS or the native code). Therefore we need to continue 1560 all threads in order to make progress. */ 1561 if (ecs->new_thread_event) 1562 { 1563 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); 1564 prepare_to_wait (ecs); 1565 return; 1566 } 1567 1568 stop_pc = read_pc_pid (ecs->ptid); 1569 1570 if (debug_infrun) 1571 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = 0x%s\n", paddr_nz (stop_pc)); 1572 1573 if (stepping_past_singlestep_breakpoint) 1574 { 1575 gdb_assert (singlestep_breakpoints_inserted_p); 1576 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid)); 1577 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid)); 1578 1579 stepping_past_singlestep_breakpoint = 0; 1580 1581 /* We've either finished single-stepping past the single-step 1582 breakpoint, or stopped for some other reason. It would be nice if 1583 we could tell, but we can't reliably. */ 1584 if (stop_signal == TARGET_SIGNAL_TRAP) 1585 { 1586 if (debug_infrun) 1587 fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n"); 1588 /* Pull the single step breakpoints out of the target. */ 1589 remove_single_step_breakpoints (); 1590 singlestep_breakpoints_inserted_p = 0; 1591 1592 ecs->random_signal = 0; 1593 1594 ecs->ptid = saved_singlestep_ptid; 1595 context_switch (ecs); 1596 if (deprecated_context_hook) 1597 deprecated_context_hook (pid_to_thread_id (ecs->ptid)); 1598 1599 resume (1, TARGET_SIGNAL_0); 1600 prepare_to_wait (ecs); 1601 return; 1602 } 1603 } 1604 1605 stepping_past_singlestep_breakpoint = 0; 1606 1607 /* See if a thread hit a thread-specific breakpoint that was meant for 1608 another thread. If so, then step that thread past the breakpoint, 1609 and continue it. */ 1610 1611 if (stop_signal == TARGET_SIGNAL_TRAP) 1612 { 1613 int thread_hop_needed = 0; 1614 1615 /* Check if a regular breakpoint has been hit before checking 1616 for a potential single step breakpoint. Otherwise, GDB will 1617 not see this breakpoint hit when stepping onto breakpoints. */ 1618 if (breakpoints_inserted && breakpoint_here_p (stop_pc)) 1619 { 1620 ecs->random_signal = 0; 1621 if (!breakpoint_thread_match (stop_pc, ecs->ptid)) 1622 thread_hop_needed = 1; 1623 } 1624 else if (singlestep_breakpoints_inserted_p) 1625 { 1626 /* We have not context switched yet, so this should be true 1627 no matter which thread hit the singlestep breakpoint. */ 1628 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid)); 1629 if (debug_infrun) 1630 fprintf_unfiltered (gdb_stdlog, "infrun: software single step " 1631 "trap for %s\n", 1632 target_pid_to_str (ecs->ptid)); 1633 1634 ecs->random_signal = 0; 1635 /* The call to in_thread_list is necessary because PTIDs sometimes 1636 change when we go from single-threaded to multi-threaded. If 1637 the singlestep_ptid is still in the list, assume that it is 1638 really different from ecs->ptid. */ 1639 if (!ptid_equal (singlestep_ptid, ecs->ptid) 1640 && in_thread_list (singlestep_ptid)) 1641 { 1642 /* If the PC of the thread we were trying to single-step 1643 has changed, discard this event (which we were going 1644 to ignore anyway), and pretend we saw that thread 1645 trap. This prevents us continuously moving the 1646 single-step breakpoint forward, one instruction at a 1647 time. If the PC has changed, then the thread we were 1648 trying to single-step has trapped or been signalled, 1649 but the event has not been reported to GDB yet. 1650 1651 There might be some cases where this loses signal 1652 information, if a signal has arrived at exactly the 1653 same time that the PC changed, but this is the best 1654 we can do with the information available. Perhaps we 1655 should arrange to report all events for all threads 1656 when they stop, or to re-poll the remote looking for 1657 this particular thread (i.e. temporarily enable 1658 schedlock). */ 1659 if (read_pc_pid (singlestep_ptid) != singlestep_pc) 1660 { 1661 if (debug_infrun) 1662 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread," 1663 " but expected thread advanced also\n"); 1664 1665 /* The current context still belongs to 1666 singlestep_ptid. Don't swap here, since that's 1667 the context we want to use. Just fudge our 1668 state and continue. */ 1669 ecs->ptid = singlestep_ptid; 1670 stop_pc = read_pc_pid (ecs->ptid); 1671 } 1672 else 1673 { 1674 if (debug_infrun) 1675 fprintf_unfiltered (gdb_stdlog, 1676 "infrun: unexpected thread\n"); 1677 1678 thread_hop_needed = 1; 1679 stepping_past_singlestep_breakpoint = 1; 1680 saved_singlestep_ptid = singlestep_ptid; 1681 } 1682 } 1683 } 1684 1685 if (thread_hop_needed) 1686 { 1687 int remove_status; 1688 1689 if (debug_infrun) 1690 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n"); 1691 1692 /* Saw a breakpoint, but it was hit by the wrong thread. 1693 Just continue. */ 1694 1695 if (singlestep_breakpoints_inserted_p) 1696 { 1697 /* Pull the single step breakpoints out of the target. */ 1698 remove_single_step_breakpoints (); 1699 singlestep_breakpoints_inserted_p = 0; 1700 } 1701 1702 remove_status = remove_breakpoints (); 1703 /* Did we fail to remove breakpoints? If so, try 1704 to set the PC past the bp. (There's at least 1705 one situation in which we can fail to remove 1706 the bp's: On HP-UX's that use ttrace, we can't 1707 change the address space of a vforking child 1708 process until the child exits (well, okay, not 1709 then either :-) or execs. */ 1710 if (remove_status != 0) 1711 { 1712 /* FIXME! This is obviously non-portable! */ 1713 write_pc_pid (stop_pc + 4, ecs->ptid); 1714 /* We need to restart all the threads now, 1715 * unles we're running in scheduler-locked mode. 1716 * Use currently_stepping to determine whether to 1717 * step or continue. 1718 */ 1719 /* FIXME MVS: is there any reason not to call resume()? */ 1720 if (scheduler_mode == schedlock_on) 1721 target_resume (ecs->ptid, 1722 currently_stepping (ecs), TARGET_SIGNAL_0); 1723 else 1724 target_resume (RESUME_ALL, 1725 currently_stepping (ecs), TARGET_SIGNAL_0); 1726 prepare_to_wait (ecs); 1727 return; 1728 } 1729 else 1730 { /* Single step */ 1731 breakpoints_inserted = 0; 1732 if (!ptid_equal (inferior_ptid, ecs->ptid)) 1733 context_switch (ecs); 1734 ecs->waiton_ptid = ecs->ptid; 1735 ecs->wp = &(ecs->ws); 1736 ecs->another_trap = 1; 1737 1738 ecs->infwait_state = infwait_thread_hop_state; 1739 keep_going (ecs); 1740 registers_changed (); 1741 return; 1742 } 1743 } 1744 else if (singlestep_breakpoints_inserted_p) 1745 { 1746 sw_single_step_trap_p = 1; 1747 ecs->random_signal = 0; 1748 } 1749 } 1750 else 1751 ecs->random_signal = 1; 1752 1753 /* See if something interesting happened to the non-current thread. If 1754 so, then switch to that thread. */ 1755 if (!ptid_equal (ecs->ptid, inferior_ptid)) 1756 { 1757 if (debug_infrun) 1758 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n"); 1759 1760 context_switch (ecs); 1761 1762 if (deprecated_context_hook) 1763 deprecated_context_hook (pid_to_thread_id (ecs->ptid)); 1764 } 1765 1766 if (singlestep_breakpoints_inserted_p) 1767 { 1768 /* Pull the single step breakpoints out of the target. */ 1769 remove_single_step_breakpoints (); 1770 singlestep_breakpoints_inserted_p = 0; 1771 } 1772 1773 /* It may not be necessary to disable the watchpoint to stop over 1774 it. For example, the PA can (with some kernel cooperation) 1775 single step over a watchpoint without disabling the watchpoint. */ 1776 if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) 1777 { 1778 if (debug_infrun) 1779 fprintf_unfiltered (gdb_stdlog, "infrun: STOPPED_BY_WATCHPOINT\n"); 1780 resume (1, 0); 1781 prepare_to_wait (ecs); 1782 return; 1783 } 1784 1785 /* It is far more common to need to disable a watchpoint to step 1786 the inferior over it. FIXME. What else might a debug 1787 register or page protection watchpoint scheme need here? */ 1788 if (gdbarch_have_nonsteppable_watchpoint (current_gdbarch) 1789 && STOPPED_BY_WATCHPOINT (ecs->ws)) 1790 { 1791 /* At this point, we are stopped at an instruction which has 1792 attempted to write to a piece of memory under control of 1793 a watchpoint. The instruction hasn't actually executed 1794 yet. If we were to evaluate the watchpoint expression 1795 now, we would get the old value, and therefore no change 1796 would seem to have occurred. 1797 1798 In order to make watchpoints work `right', we really need 1799 to complete the memory write, and then evaluate the 1800 watchpoint expression. The following code does that by 1801 removing the watchpoint (actually, all watchpoints and 1802 breakpoints), single-stepping the target, re-inserting 1803 watchpoints, and then falling through to let normal 1804 single-step processing handle proceed. Since this 1805 includes evaluating watchpoints, things will come to a 1806 stop in the correct manner. */ 1807 1808 if (debug_infrun) 1809 fprintf_unfiltered (gdb_stdlog, "infrun: STOPPED_BY_WATCHPOINT\n"); 1810 remove_breakpoints (); 1811 registers_changed (); 1812 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */ 1813 1814 ecs->waiton_ptid = ecs->ptid; 1815 ecs->wp = &(ecs->ws); 1816 ecs->infwait_state = infwait_nonstep_watch_state; 1817 prepare_to_wait (ecs); 1818 return; 1819 } 1820 1821 /* It may be possible to simply continue after a watchpoint. */ 1822 if (HAVE_CONTINUABLE_WATCHPOINT) 1823 stopped_by_watchpoint = STOPPED_BY_WATCHPOINT (ecs->ws); 1824 1825 ecs->stop_func_start = 0; 1826 ecs->stop_func_end = 0; 1827 ecs->stop_func_name = 0; 1828 /* Don't care about return value; stop_func_start and stop_func_name 1829 will both be 0 if it doesn't work. */ 1830 find_pc_partial_function (stop_pc, &ecs->stop_func_name, 1831 &ecs->stop_func_start, &ecs->stop_func_end); 1832 ecs->stop_func_start 1833 += gdbarch_deprecated_function_start_offset (current_gdbarch); 1834 ecs->another_trap = 0; 1835 bpstat_clear (&stop_bpstat); 1836 stop_step = 0; 1837 stop_stack_dummy = 0; 1838 stop_print_frame = 1; 1839 ecs->random_signal = 0; 1840 stopped_by_random_signal = 0; 1841 1842 if (stop_signal == TARGET_SIGNAL_TRAP 1843 && trap_expected 1844 && gdbarch_single_step_through_delay_p (current_gdbarch) 1845 && currently_stepping (ecs)) 1846 { 1847 /* We're trying to step of a breakpoint. Turns out that we're 1848 also on an instruction that needs to be stepped multiple 1849 times before it's been fully executing. E.g., architectures 1850 with a delay slot. It needs to be stepped twice, once for 1851 the instruction and once for the delay slot. */ 1852 int step_through_delay 1853 = gdbarch_single_step_through_delay (current_gdbarch, 1854 get_current_frame ()); 1855 if (debug_infrun && step_through_delay) 1856 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n"); 1857 if (step_range_end == 0 && step_through_delay) 1858 { 1859 /* The user issued a continue when stopped at a breakpoint. 1860 Set up for another trap and get out of here. */ 1861 ecs->another_trap = 1; 1862 keep_going (ecs); 1863 return; 1864 } 1865 else if (step_through_delay) 1866 { 1867 /* The user issued a step when stopped at a breakpoint. 1868 Maybe we should stop, maybe we should not - the delay 1869 slot *might* correspond to a line of source. In any 1870 case, don't decide that here, just set ecs->another_trap, 1871 making sure we single-step again before breakpoints are 1872 re-inserted. */ 1873 ecs->another_trap = 1; 1874 } 1875 } 1876 1877 /* Look at the cause of the stop, and decide what to do. 1878 The alternatives are: 1879 1) break; to really stop and return to the debugger, 1880 2) drop through to start up again 1881 (set ecs->another_trap to 1 to single step once) 1882 3) set ecs->random_signal to 1, and the decision between 1 and 2 1883 will be made according to the signal handling tables. */ 1884 1885 /* First, distinguish signals caused by the debugger from signals 1886 that have to do with the program's own actions. Note that 1887 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending 1888 on the operating system version. Here we detect when a SIGILL or 1889 SIGEMT is really a breakpoint and change it to SIGTRAP. We do 1890 something similar for SIGSEGV, since a SIGSEGV will be generated 1891 when we're trying to execute a breakpoint instruction on a 1892 non-executable stack. This happens for call dummy breakpoints 1893 for architectures like SPARC that place call dummies on the 1894 stack. */ 1895 1896 if (stop_signal == TARGET_SIGNAL_TRAP 1897 || (breakpoints_inserted 1898 && (stop_signal == TARGET_SIGNAL_ILL 1899 || stop_signal == TARGET_SIGNAL_SEGV 1900 || stop_signal == TARGET_SIGNAL_EMT)) 1901 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP 1902 || stop_soon == STOP_QUIETLY_REMOTE) 1903 { 1904 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) 1905 { 1906 if (debug_infrun) 1907 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n"); 1908 stop_print_frame = 0; 1909 stop_stepping (ecs); 1910 return; 1911 } 1912 1913 /* This is originated from start_remote(), start_inferior() and 1914 shared libraries hook functions. */ 1915 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) 1916 { 1917 if (debug_infrun) 1918 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); 1919 stop_stepping (ecs); 1920 return; 1921 } 1922 1923 /* This originates from attach_command(). We need to overwrite 1924 the stop_signal here, because some kernels don't ignore a 1925 SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call. 1926 See more comments in inferior.h. */ 1927 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP) 1928 { 1929 stop_stepping (ecs); 1930 if (stop_signal == TARGET_SIGNAL_STOP) 1931 stop_signal = TARGET_SIGNAL_0; 1932 return; 1933 } 1934 1935 /* Don't even think about breakpoints if just proceeded over a 1936 breakpoint. */ 1937 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected) 1938 { 1939 if (debug_infrun) 1940 fprintf_unfiltered (gdb_stdlog, "infrun: trap expected\n"); 1941 bpstat_clear (&stop_bpstat); 1942 } 1943 else 1944 { 1945 /* See if there is a breakpoint at the current PC. */ 1946 stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid, 1947 stopped_by_watchpoint); 1948 1949 /* Following in case break condition called a 1950 function. */ 1951 stop_print_frame = 1; 1952 } 1953 1954 /* NOTE: cagney/2003-03-29: These two checks for a random signal 1955 at one stage in the past included checks for an inferior 1956 function call's call dummy's return breakpoint. The original 1957 comment, that went with the test, read: 1958 1959 ``End of a stack dummy. Some systems (e.g. Sony news) give 1960 another signal besides SIGTRAP, so check here as well as 1961 above.'' 1962 1963 If someone ever tries to get get call dummys on a 1964 non-executable stack to work (where the target would stop 1965 with something like a SIGSEGV), then those tests might need 1966 to be re-instated. Given, however, that the tests were only 1967 enabled when momentary breakpoints were not being used, I 1968 suspect that it won't be the case. 1969 1970 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to 1971 be necessary for call dummies on a non-executable stack on 1972 SPARC. */ 1973 1974 if (stop_signal == TARGET_SIGNAL_TRAP) 1975 ecs->random_signal 1976 = !(bpstat_explains_signal (stop_bpstat) 1977 || trap_expected 1978 || (step_range_end && step_resume_breakpoint == NULL)); 1979 else 1980 { 1981 ecs->random_signal = !bpstat_explains_signal (stop_bpstat); 1982 if (!ecs->random_signal) 1983 stop_signal = TARGET_SIGNAL_TRAP; 1984 } 1985 } 1986 1987 /* When we reach this point, we've pretty much decided 1988 that the reason for stopping must've been a random 1989 (unexpected) signal. */ 1990 1991 else 1992 ecs->random_signal = 1; 1993 1994process_event_stop_test: 1995 /* For the program's own signals, act according to 1996 the signal handling tables. */ 1997 1998 if (ecs->random_signal) 1999 { 2000 /* Signal not for debugging purposes. */ 2001 int printed = 0; 2002 2003 if (debug_infrun) 2004 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n", stop_signal); 2005 2006 stopped_by_random_signal = 1; 2007 2008 if (signal_print[stop_signal]) 2009 { 2010 printed = 1; 2011 target_terminal_ours_for_output (); 2012 print_stop_reason (SIGNAL_RECEIVED, stop_signal); 2013 } 2014 if (signal_stop[stop_signal]) 2015 { 2016 stop_stepping (ecs); 2017 return; 2018 } 2019 /* If not going to stop, give terminal back 2020 if we took it away. */ 2021 else if (printed) 2022 target_terminal_inferior (); 2023 2024 /* Clear the signal if it should not be passed. */ 2025 if (signal_program[stop_signal] == 0) 2026 stop_signal = TARGET_SIGNAL_0; 2027 2028 if (prev_pc == read_pc () 2029 && !breakpoints_inserted 2030 && breakpoint_here_p (read_pc ()) 2031 && step_resume_breakpoint == NULL) 2032 { 2033 /* We were just starting a new sequence, attempting to 2034 single-step off of a breakpoint and expecting a SIGTRAP. 2035 Intead this signal arrives. This signal will take us out 2036 of the stepping range so GDB needs to remember to, when 2037 the signal handler returns, resume stepping off that 2038 breakpoint. */ 2039 /* To simplify things, "continue" is forced to use the same 2040 code paths as single-step - set a breakpoint at the 2041 signal return address and then, once hit, step off that 2042 breakpoint. */ 2043 2044 insert_step_resume_breakpoint_at_frame (get_current_frame ()); 2045 ecs->step_after_step_resume_breakpoint = 1; 2046 keep_going (ecs); 2047 return; 2048 } 2049 2050 if (step_range_end != 0 2051 && stop_signal != TARGET_SIGNAL_0 2052 && stop_pc >= step_range_start && stop_pc < step_range_end 2053 && frame_id_eq (get_frame_id (get_current_frame ()), 2054 step_frame_id) 2055 && step_resume_breakpoint == NULL) 2056 { 2057 /* The inferior is about to take a signal that will take it 2058 out of the single step range. Set a breakpoint at the 2059 current PC (which is presumably where the signal handler 2060 will eventually return) and then allow the inferior to 2061 run free. 2062 2063 Note that this is only needed for a signal delivered 2064 while in the single-step range. Nested signals aren't a 2065 problem as they eventually all return. */ 2066 insert_step_resume_breakpoint_at_frame (get_current_frame ()); 2067 keep_going (ecs); 2068 return; 2069 } 2070 2071 /* Note: step_resume_breakpoint may be non-NULL. This occures 2072 when either there's a nested signal, or when there's a 2073 pending signal enabled just as the signal handler returns 2074 (leaving the inferior at the step-resume-breakpoint without 2075 actually executing it). Either way continue until the 2076 breakpoint is really hit. */ 2077 keep_going (ecs); 2078 return; 2079 } 2080 2081 /* Handle cases caused by hitting a breakpoint. */ 2082 { 2083 CORE_ADDR jmp_buf_pc; 2084 struct bpstat_what what; 2085 2086 what = bpstat_what (stop_bpstat); 2087 2088 if (what.call_dummy) 2089 { 2090 stop_stack_dummy = 1; 2091 } 2092 2093 switch (what.main_action) 2094 { 2095 case BPSTAT_WHAT_SET_LONGJMP_RESUME: 2096 /* If we hit the breakpoint at longjmp, disable it for the 2097 duration of this command. Then, install a temporary 2098 breakpoint at the target of the jmp_buf. */ 2099 if (debug_infrun) 2100 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n"); 2101 disable_longjmp_breakpoint (); 2102 remove_breakpoints (); 2103 breakpoints_inserted = 0; 2104 if (!gdbarch_get_longjmp_target_p (current_gdbarch) 2105 || !gdbarch_get_longjmp_target (current_gdbarch, 2106 get_current_frame (), &jmp_buf_pc)) 2107 { 2108 keep_going (ecs); 2109 return; 2110 } 2111 2112 /* Need to blow away step-resume breakpoint, as it 2113 interferes with us */ 2114 if (step_resume_breakpoint != NULL) 2115 { 2116 delete_step_resume_breakpoint (&step_resume_breakpoint); 2117 } 2118 2119 set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id); 2120 ecs->handling_longjmp = 1; /* FIXME */ 2121 keep_going (ecs); 2122 return; 2123 2124 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: 2125 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: 2126 if (debug_infrun) 2127 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n"); 2128 remove_breakpoints (); 2129 breakpoints_inserted = 0; 2130 disable_longjmp_breakpoint (); 2131 ecs->handling_longjmp = 0; /* FIXME */ 2132 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) 2133 break; 2134 /* else fallthrough */ 2135 2136 case BPSTAT_WHAT_SINGLE: 2137 if (debug_infrun) 2138 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n"); 2139 if (breakpoints_inserted) 2140 remove_breakpoints (); 2141 breakpoints_inserted = 0; 2142 ecs->another_trap = 1; 2143 /* Still need to check other stuff, at least the case 2144 where we are stepping and step out of the right range. */ 2145 break; 2146 2147 case BPSTAT_WHAT_STOP_NOISY: 2148 if (debug_infrun) 2149 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n"); 2150 stop_print_frame = 1; 2151 2152 /* We are about to nuke the step_resume_breakpointt via the 2153 cleanup chain, so no need to worry about it here. */ 2154 2155 stop_stepping (ecs); 2156 return; 2157 2158 case BPSTAT_WHAT_STOP_SILENT: 2159 if (debug_infrun) 2160 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n"); 2161 stop_print_frame = 0; 2162 2163 /* We are about to nuke the step_resume_breakpoin via the 2164 cleanup chain, so no need to worry about it here. */ 2165 2166 stop_stepping (ecs); 2167 return; 2168 2169 case BPSTAT_WHAT_STEP_RESUME: 2170 /* This proably demands a more elegant solution, but, yeah 2171 right... 2172 2173 This function's use of the simple variable 2174 step_resume_breakpoint doesn't seem to accomodate 2175 simultaneously active step-resume bp's, although the 2176 breakpoint list certainly can. 2177 2178 If we reach here and step_resume_breakpoint is already 2179 NULL, then apparently we have multiple active 2180 step-resume bp's. We'll just delete the breakpoint we 2181 stopped at, and carry on. 2182 2183 Correction: what the code currently does is delete a 2184 step-resume bp, but it makes no effort to ensure that 2185 the one deleted is the one currently stopped at. MVS */ 2186 2187 if (debug_infrun) 2188 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n"); 2189 2190 if (step_resume_breakpoint == NULL) 2191 { 2192 step_resume_breakpoint = 2193 bpstat_find_step_resume_breakpoint (stop_bpstat); 2194 } 2195 delete_step_resume_breakpoint (&step_resume_breakpoint); 2196 if (ecs->step_after_step_resume_breakpoint) 2197 { 2198 /* Back when the step-resume breakpoint was inserted, we 2199 were trying to single-step off a breakpoint. Go back 2200 to doing that. */ 2201 ecs->step_after_step_resume_breakpoint = 0; 2202 remove_breakpoints (); 2203 breakpoints_inserted = 0; 2204 ecs->another_trap = 1; 2205 keep_going (ecs); 2206 return; 2207 } 2208 break; 2209 2210 case BPSTAT_WHAT_CHECK_SHLIBS: 2211 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: 2212 { 2213 if (debug_infrun) 2214 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n"); 2215 /* Remove breakpoints, we eventually want to step over the 2216 shlib event breakpoint, and SOLIB_ADD might adjust 2217 breakpoint addresses via breakpoint_re_set. */ 2218 if (breakpoints_inserted) 2219 remove_breakpoints (); 2220 breakpoints_inserted = 0; 2221 2222 /* Check for any newly added shared libraries if we're 2223 supposed to be adding them automatically. Switch 2224 terminal for any messages produced by 2225 breakpoint_re_set. */ 2226 target_terminal_ours_for_output (); 2227 /* NOTE: cagney/2003-11-25: Make certain that the target 2228 stack's section table is kept up-to-date. Architectures, 2229 (e.g., PPC64), use the section table to perform 2230 operations such as address => section name and hence 2231 require the table to contain all sections (including 2232 those found in shared libraries). */ 2233 /* NOTE: cagney/2003-11-25: Pass current_target and not 2234 exec_ops to SOLIB_ADD. This is because current GDB is 2235 only tooled to propagate section_table changes out from 2236 the "current_target" (see target_resize_to_sections), and 2237 not up from the exec stratum. This, of course, isn't 2238 right. "infrun.c" should only interact with the 2239 exec/process stratum, instead relying on the target stack 2240 to propagate relevant changes (stop, section table 2241 changed, ...) up to other layers. */ 2242#ifdef SOLIB_ADD 2243 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); 2244#else 2245 solib_add (NULL, 0, ¤t_target, auto_solib_add); 2246#endif 2247 target_terminal_inferior (); 2248 2249 /* Try to reenable shared library breakpoints, additional 2250 code segments in shared libraries might be mapped in now. */ 2251 re_enable_breakpoints_in_shlibs (); 2252 2253 /* If requested, stop when the dynamic linker notifies 2254 gdb of events. This allows the user to get control 2255 and place breakpoints in initializer routines for 2256 dynamically loaded objects (among other things). */ 2257 if (stop_on_solib_events || stop_stack_dummy) 2258 { 2259 stop_stepping (ecs); 2260 return; 2261 } 2262 2263 /* If we stopped due to an explicit catchpoint, then the 2264 (see above) call to SOLIB_ADD pulled in any symbols 2265 from a newly-loaded library, if appropriate. 2266 2267 We do want the inferior to stop, but not where it is 2268 now, which is in the dynamic linker callback. Rather, 2269 we would like it stop in the user's program, just after 2270 the call that caused this catchpoint to trigger. That 2271 gives the user a more useful vantage from which to 2272 examine their program's state. */ 2273 else if (what.main_action 2274 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) 2275 { 2276 /* ??rehrauer: If I could figure out how to get the 2277 right return PC from here, we could just set a temp 2278 breakpoint and resume. I'm not sure we can without 2279 cracking open the dld's shared libraries and sniffing 2280 their unwind tables and text/data ranges, and that's 2281 not a terribly portable notion. 2282 2283 Until that time, we must step the inferior out of the 2284 dld callback, and also out of the dld itself (and any 2285 code or stubs in libdld.sl, such as "shl_load" and 2286 friends) until we reach non-dld code. At that point, 2287 we can stop stepping. */ 2288 bpstat_get_triggered_catchpoints (stop_bpstat, 2289 &ecs-> 2290 stepping_through_solib_catchpoints); 2291 ecs->stepping_through_solib_after_catch = 1; 2292 2293 /* Be sure to lift all breakpoints, so the inferior does 2294 actually step past this point... */ 2295 ecs->another_trap = 1; 2296 break; 2297 } 2298 else 2299 { 2300 /* We want to step over this breakpoint, then keep going. */ 2301 ecs->another_trap = 1; 2302 break; 2303 } 2304 } 2305 break; 2306 2307 case BPSTAT_WHAT_LAST: 2308 /* Not a real code, but listed here to shut up gcc -Wall. */ 2309 2310 case BPSTAT_WHAT_KEEP_CHECKING: 2311 break; 2312 } 2313 } 2314 2315 /* We come here if we hit a breakpoint but should not 2316 stop for it. Possibly we also were stepping 2317 and should stop for that. So fall through and 2318 test for stepping. But, if not stepping, 2319 do not stop. */ 2320 2321 /* Are we stepping to get the inferior out of the dynamic linker's 2322 hook (and possibly the dld itself) after catching a shlib 2323 event? */ 2324 if (ecs->stepping_through_solib_after_catch) 2325 { 2326#if defined(SOLIB_ADD) 2327 /* Have we reached our destination? If not, keep going. */ 2328 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) 2329 { 2330 if (debug_infrun) 2331 fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n"); 2332 ecs->another_trap = 1; 2333 keep_going (ecs); 2334 return; 2335 } 2336#endif 2337 if (debug_infrun) 2338 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n"); 2339 /* Else, stop and report the catchpoint(s) whose triggering 2340 caused us to begin stepping. */ 2341 ecs->stepping_through_solib_after_catch = 0; 2342 bpstat_clear (&stop_bpstat); 2343 stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); 2344 bpstat_clear (&ecs->stepping_through_solib_catchpoints); 2345 stop_print_frame = 1; 2346 stop_stepping (ecs); 2347 return; 2348 } 2349 2350 if (step_resume_breakpoint) 2351 { 2352 if (debug_infrun) 2353 fprintf_unfiltered (gdb_stdlog, 2354 "infrun: step-resume breakpoint is inserted\n"); 2355 2356 /* Having a step-resume breakpoint overrides anything 2357 else having to do with stepping commands until 2358 that breakpoint is reached. */ 2359 keep_going (ecs); 2360 return; 2361 } 2362 2363 if (step_range_end == 0) 2364 { 2365 if (debug_infrun) 2366 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n"); 2367 /* Likewise if we aren't even stepping. */ 2368 keep_going (ecs); 2369 return; 2370 } 2371 2372 /* If stepping through a line, keep going if still within it. 2373 2374 Note that step_range_end is the address of the first instruction 2375 beyond the step range, and NOT the address of the last instruction 2376 within it! */ 2377 if (stop_pc >= step_range_start && stop_pc < step_range_end) 2378 { 2379 if (debug_infrun) 2380 fprintf_unfiltered (gdb_stdlog, "infrun: stepping inside range [0x%s-0x%s]\n", 2381 paddr_nz (step_range_start), 2382 paddr_nz (step_range_end)); 2383 keep_going (ecs); 2384 return; 2385 } 2386 2387 /* We stepped out of the stepping range. */ 2388 2389 /* If we are stepping at the source level and entered the runtime 2390 loader dynamic symbol resolution code, we keep on single stepping 2391 until we exit the run time loader code and reach the callee's 2392 address. */ 2393 if (step_over_calls == STEP_OVER_UNDEBUGGABLE 2394#ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE 2395 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc) 2396#else 2397 && in_solib_dynsym_resolve_code (stop_pc) 2398#endif 2399 ) 2400 { 2401 CORE_ADDR pc_after_resolver = 2402 gdbarch_skip_solib_resolver (current_gdbarch, stop_pc); 2403 2404 if (debug_infrun) 2405 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n"); 2406 2407 if (pc_after_resolver) 2408 { 2409 /* Set up a step-resume breakpoint at the address 2410 indicated by SKIP_SOLIB_RESOLVER. */ 2411 struct symtab_and_line sr_sal; 2412 init_sal (&sr_sal); 2413 sr_sal.pc = pc_after_resolver; 2414 2415 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); 2416 } 2417 2418 keep_going (ecs); 2419 return; 2420 } 2421 2422 if (step_range_end != 1 2423 && (step_over_calls == STEP_OVER_UNDEBUGGABLE 2424 || step_over_calls == STEP_OVER_ALL) 2425 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME) 2426 { 2427 if (debug_infrun) 2428 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n"); 2429 /* The inferior, while doing a "step" or "next", has ended up in 2430 a signal trampoline (either by a signal being delivered or by 2431 the signal handler returning). Just single-step until the 2432 inferior leaves the trampoline (either by calling the handler 2433 or returning). */ 2434 keep_going (ecs); 2435 return; 2436 } 2437 2438 /* Check for subroutine calls. The check for the current frame 2439 equalling the step ID is not necessary - the check of the 2440 previous frame's ID is sufficient - but it is a common case and 2441 cheaper than checking the previous frame's ID. 2442 2443 NOTE: frame_id_eq will never report two invalid frame IDs as 2444 being equal, so to get into this block, both the current and 2445 previous frame must have valid frame IDs. */ 2446 if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id) 2447 && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id)) 2448 { 2449 CORE_ADDR real_stop_pc; 2450 2451 if (debug_infrun) 2452 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n"); 2453 2454 if ((step_over_calls == STEP_OVER_NONE) 2455 || ((step_range_end == 1) 2456 && in_prologue (prev_pc, ecs->stop_func_start))) 2457 { 2458 /* I presume that step_over_calls is only 0 when we're 2459 supposed to be stepping at the assembly language level 2460 ("stepi"). Just stop. */ 2461 /* Also, maybe we just did a "nexti" inside a prolog, so we 2462 thought it was a subroutine call but it was not. Stop as 2463 well. FENN */ 2464 stop_step = 1; 2465 print_stop_reason (END_STEPPING_RANGE, 0); 2466 stop_stepping (ecs); 2467 return; 2468 } 2469 2470 if (step_over_calls == STEP_OVER_ALL) 2471 { 2472 /* We're doing a "next", set a breakpoint at callee's return 2473 address (the address at which the caller will 2474 resume). */ 2475 insert_step_resume_breakpoint_at_caller (get_current_frame ()); 2476 keep_going (ecs); 2477 return; 2478 } 2479 2480 /* If we are in a function call trampoline (a stub between the 2481 calling routine and the real function), locate the real 2482 function. That's what tells us (a) whether we want to step 2483 into it at all, and (b) what prologue we want to run to the 2484 end of, if we do step into it. */ 2485 real_stop_pc = skip_language_trampoline (get_current_frame (), stop_pc); 2486 if (real_stop_pc == 0) 2487 real_stop_pc = gdbarch_skip_trampoline_code 2488 (current_gdbarch, get_current_frame (), stop_pc); 2489 if (real_stop_pc != 0) 2490 ecs->stop_func_start = real_stop_pc; 2491 2492 if ( 2493#ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE 2494 IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs->stop_func_start) 2495#else 2496 in_solib_dynsym_resolve_code (ecs->stop_func_start) 2497#endif 2498) 2499 { 2500 struct symtab_and_line sr_sal; 2501 init_sal (&sr_sal); 2502 sr_sal.pc = ecs->stop_func_start; 2503 2504 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); 2505 keep_going (ecs); 2506 return; 2507 } 2508 2509 /* If we have line number information for the function we are 2510 thinking of stepping into, step into it. 2511 2512 If there are several symtabs at that PC (e.g. with include 2513 files), just want to know whether *any* of them have line 2514 numbers. find_pc_line handles this. */ 2515 { 2516 struct symtab_and_line tmp_sal; 2517 2518 tmp_sal = find_pc_line (ecs->stop_func_start, 0); 2519 if (tmp_sal.line != 0) 2520 { 2521 step_into_function (ecs); 2522 return; 2523 } 2524 } 2525 2526 /* If we have no line number and the step-stop-if-no-debug is 2527 set, we stop the step so that the user has a chance to switch 2528 in assembly mode. */ 2529 if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug) 2530 { 2531 stop_step = 1; 2532 print_stop_reason (END_STEPPING_RANGE, 0); 2533 stop_stepping (ecs); 2534 return; 2535 } 2536 2537 /* Set a breakpoint at callee's return address (the address at 2538 which the caller will resume). */ 2539 insert_step_resume_breakpoint_at_caller (get_current_frame ()); 2540 keep_going (ecs); 2541 return; 2542 } 2543 2544 /* If we're in the return path from a shared library trampoline, 2545 we want to proceed through the trampoline when stepping. */ 2546 if (gdbarch_in_solib_return_trampoline (current_gdbarch, 2547 stop_pc, ecs->stop_func_name)) 2548 { 2549 /* Determine where this trampoline returns. */ 2550 CORE_ADDR real_stop_pc; 2551 real_stop_pc = gdbarch_skip_trampoline_code 2552 (current_gdbarch, get_current_frame (), stop_pc); 2553 2554 if (debug_infrun) 2555 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n"); 2556 2557 /* Only proceed through if we know where it's going. */ 2558 if (real_stop_pc) 2559 { 2560 /* And put the step-breakpoint there and go until there. */ 2561 struct symtab_and_line sr_sal; 2562 2563 init_sal (&sr_sal); /* initialize to zeroes */ 2564 sr_sal.pc = real_stop_pc; 2565 sr_sal.section = find_pc_overlay (sr_sal.pc); 2566 2567 /* Do not specify what the fp should be when we stop since 2568 on some machines the prologue is where the new fp value 2569 is established. */ 2570 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); 2571 2572 /* Restart without fiddling with the step ranges or 2573 other state. */ 2574 keep_going (ecs); 2575 return; 2576 } 2577 } 2578 2579 ecs->sal = find_pc_line (stop_pc, 0); 2580 2581 /* NOTE: tausq/2004-05-24: This if block used to be done before all 2582 the trampoline processing logic, however, there are some trampolines 2583 that have no names, so we should do trampoline handling first. */ 2584 if (step_over_calls == STEP_OVER_UNDEBUGGABLE 2585 && ecs->stop_func_name == NULL 2586 && ecs->sal.line == 0) 2587 { 2588 if (debug_infrun) 2589 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n"); 2590 2591 /* The inferior just stepped into, or returned to, an 2592 undebuggable function (where there is no debugging information 2593 and no line number corresponding to the address where the 2594 inferior stopped). Since we want to skip this kind of code, 2595 we keep going until the inferior returns from this 2596 function - unless the user has asked us not to (via 2597 set step-mode) or we no longer know how to get back 2598 to the call site. */ 2599 if (step_stop_if_no_debug 2600 || !frame_id_p (frame_unwind_id (get_current_frame ()))) 2601 { 2602 /* If we have no line number and the step-stop-if-no-debug 2603 is set, we stop the step so that the user has a chance to 2604 switch in assembly mode. */ 2605 stop_step = 1; 2606 print_stop_reason (END_STEPPING_RANGE, 0); 2607 stop_stepping (ecs); 2608 return; 2609 } 2610 else 2611 { 2612 /* Set a breakpoint at callee's return address (the address 2613 at which the caller will resume). */ 2614 insert_step_resume_breakpoint_at_caller (get_current_frame ()); 2615 keep_going (ecs); 2616 return; 2617 } 2618 } 2619 2620 if (step_range_end == 1) 2621 { 2622 /* It is stepi or nexti. We always want to stop stepping after 2623 one instruction. */ 2624 if (debug_infrun) 2625 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n"); 2626 stop_step = 1; 2627 print_stop_reason (END_STEPPING_RANGE, 0); 2628 stop_stepping (ecs); 2629 return; 2630 } 2631 2632 if (ecs->sal.line == 0) 2633 { 2634 /* We have no line number information. That means to stop 2635 stepping (does this always happen right after one instruction, 2636 when we do "s" in a function with no line numbers, 2637 or can this happen as a result of a return or longjmp?). */ 2638 if (debug_infrun) 2639 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n"); 2640 stop_step = 1; 2641 print_stop_reason (END_STEPPING_RANGE, 0); 2642 stop_stepping (ecs); 2643 return; 2644 } 2645 2646 if ((stop_pc == ecs->sal.pc) 2647 && (ecs->current_line != ecs->sal.line 2648 || ecs->current_symtab != ecs->sal.symtab)) 2649 { 2650 /* We are at the start of a different line. So stop. Note that 2651 we don't stop if we step into the middle of a different line. 2652 That is said to make things like for (;;) statements work 2653 better. */ 2654 if (debug_infrun) 2655 fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n"); 2656 stop_step = 1; 2657 print_stop_reason (END_STEPPING_RANGE, 0); 2658 stop_stepping (ecs); 2659 return; 2660 } 2661 2662 /* We aren't done stepping. 2663 2664 Optimize by setting the stepping range to the line. 2665 (We might not be in the original line, but if we entered a 2666 new line in mid-statement, we continue stepping. This makes 2667 things like for(;;) statements work better.) */ 2668 2669 if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end) 2670 { 2671 /* If this is the last line of the function, don't keep stepping 2672 (it would probably step us out of the function). 2673 This is particularly necessary for a one-line function, 2674 in which after skipping the prologue we better stop even though 2675 we will be in mid-line. */ 2676 if (debug_infrun) 2677 fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different function\n"); 2678 stop_step = 1; 2679 print_stop_reason (END_STEPPING_RANGE, 0); 2680 stop_stepping (ecs); 2681 return; 2682 } 2683 step_range_start = ecs->sal.pc; 2684 step_range_end = ecs->sal.end; 2685 step_frame_id = get_frame_id (get_current_frame ()); 2686 ecs->current_line = ecs->sal.line; 2687 ecs->current_symtab = ecs->sal.symtab; 2688 2689 /* In the case where we just stepped out of a function into the 2690 middle of a line of the caller, continue stepping, but 2691 step_frame_id must be modified to current frame */ 2692#if 0 2693 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too 2694 generous. It will trigger on things like a step into a frameless 2695 stackless leaf function. I think the logic should instead look 2696 at the unwound frame ID has that should give a more robust 2697 indication of what happened. */ 2698 if (step - ID == current - ID) 2699 still stepping in same function; 2700 else if (step - ID == unwind (current - ID)) 2701 stepped into a function; 2702 else 2703 stepped out of a function; 2704 /* Of course this assumes that the frame ID unwind code is robust 2705 and we're willing to introduce frame unwind logic into this 2706 function. Fortunately, those days are nearly upon us. */ 2707#endif 2708 { 2709 struct frame_id current_frame = get_frame_id (get_current_frame ()); 2710 if (!(frame_id_inner (current_frame, step_frame_id))) 2711 step_frame_id = current_frame; 2712 } 2713 2714 if (debug_infrun) 2715 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n"); 2716 keep_going (ecs); 2717} 2718 2719/* Are we in the middle of stepping? */ 2720 2721static int 2722currently_stepping (struct execution_control_state *ecs) 2723{ 2724 return ((!ecs->handling_longjmp 2725 && ((step_range_end && step_resume_breakpoint == NULL) 2726 || trap_expected)) 2727 || ecs->stepping_through_solib_after_catch 2728 || bpstat_should_step ()); 2729} 2730 2731/* Subroutine call with source code we should not step over. Do step 2732 to the first line of code in it. */ 2733 2734static void 2735step_into_function (struct execution_control_state *ecs) 2736{ 2737 struct symtab *s; 2738 struct symtab_and_line sr_sal; 2739 2740 s = find_pc_symtab (stop_pc); 2741 if (s && s->language != language_asm) 2742 ecs->stop_func_start = gdbarch_skip_prologue 2743 (current_gdbarch, ecs->stop_func_start); 2744 2745 ecs->sal = find_pc_line (ecs->stop_func_start, 0); 2746 /* Use the step_resume_break to step until the end of the prologue, 2747 even if that involves jumps (as it seems to on the vax under 2748 4.2). */ 2749 /* If the prologue ends in the middle of a source line, continue to 2750 the end of that source line (if it is still within the function). 2751 Otherwise, just go to end of prologue. */ 2752 if (ecs->sal.end 2753 && ecs->sal.pc != ecs->stop_func_start 2754 && ecs->sal.end < ecs->stop_func_end) 2755 ecs->stop_func_start = ecs->sal.end; 2756 2757 /* Architectures which require breakpoint adjustment might not be able 2758 to place a breakpoint at the computed address. If so, the test 2759 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust 2760 ecs->stop_func_start to an address at which a breakpoint may be 2761 legitimately placed. 2762 2763 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not 2764 made, GDB will enter an infinite loop when stepping through 2765 optimized code consisting of VLIW instructions which contain 2766 subinstructions corresponding to different source lines. On 2767 FR-V, it's not permitted to place a breakpoint on any but the 2768 first subinstruction of a VLIW instruction. When a breakpoint is 2769 set, GDB will adjust the breakpoint address to the beginning of 2770 the VLIW instruction. Thus, we need to make the corresponding 2771 adjustment here when computing the stop address. */ 2772 2773 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch)) 2774 { 2775 ecs->stop_func_start 2776 = gdbarch_adjust_breakpoint_address (current_gdbarch, 2777 ecs->stop_func_start); 2778 } 2779 2780 if (ecs->stop_func_start == stop_pc) 2781 { 2782 /* We are already there: stop now. */ 2783 stop_step = 1; 2784 print_stop_reason (END_STEPPING_RANGE, 0); 2785 stop_stepping (ecs); 2786 return; 2787 } 2788 else 2789 { 2790 /* Put the step-breakpoint there and go until there. */ 2791 init_sal (&sr_sal); /* initialize to zeroes */ 2792 sr_sal.pc = ecs->stop_func_start; 2793 sr_sal.section = find_pc_overlay (ecs->stop_func_start); 2794 2795 /* Do not specify what the fp should be when we stop since on 2796 some machines the prologue is where the new fp value is 2797 established. */ 2798 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id); 2799 2800 /* And make sure stepping stops right away then. */ 2801 step_range_end = step_range_start; 2802 } 2803 keep_going (ecs); 2804} 2805 2806/* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID. 2807 This is used to both functions and to skip over code. */ 2808 2809static void 2810insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal, 2811 struct frame_id sr_id) 2812{ 2813 /* There should never be more than one step-resume breakpoint per 2814 thread, so we should never be setting a new 2815 step_resume_breakpoint when one is already active. */ 2816 gdb_assert (step_resume_breakpoint == NULL); 2817 2818 if (debug_infrun) 2819 fprintf_unfiltered (gdb_stdlog, 2820 "infrun: inserting step-resume breakpoint at 0x%s\n", 2821 paddr_nz (sr_sal.pc)); 2822 2823 step_resume_breakpoint = set_momentary_breakpoint (sr_sal, sr_id, 2824 bp_step_resume); 2825 if (breakpoints_inserted) 2826 insert_breakpoints (); 2827} 2828 2829/* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used 2830 to skip a potential signal handler. 2831 2832 This is called with the interrupted function's frame. The signal 2833 handler, when it returns, will resume the interrupted function at 2834 RETURN_FRAME.pc. */ 2835 2836static void 2837insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame) 2838{ 2839 struct symtab_and_line sr_sal; 2840 2841 init_sal (&sr_sal); /* initialize to zeros */ 2842 2843 sr_sal.pc = gdbarch_addr_bits_remove 2844 (current_gdbarch, get_frame_pc (return_frame)); 2845 sr_sal.section = find_pc_overlay (sr_sal.pc); 2846 2847 insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame)); 2848} 2849 2850/* Similar to insert_step_resume_breakpoint_at_frame, except 2851 but a breakpoint at the previous frame's PC. This is used to 2852 skip a function after stepping into it (for "next" or if the called 2853 function has no debugging information). 2854 2855 The current function has almost always been reached by single 2856 stepping a call or return instruction. NEXT_FRAME belongs to the 2857 current function, and the breakpoint will be set at the caller's 2858 resume address. 2859 2860 This is a separate function rather than reusing 2861 insert_step_resume_breakpoint_at_frame in order to avoid 2862 get_prev_frame, which may stop prematurely (see the implementation 2863 of frame_unwind_id for an example). */ 2864 2865static void 2866insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) 2867{ 2868 struct symtab_and_line sr_sal; 2869 2870 /* We shouldn't have gotten here if we don't know where the call site 2871 is. */ 2872 gdb_assert (frame_id_p (frame_unwind_id (next_frame))); 2873 2874 init_sal (&sr_sal); /* initialize to zeros */ 2875 2876 sr_sal.pc = gdbarch_addr_bits_remove 2877 (current_gdbarch, frame_pc_unwind (next_frame)); 2878 sr_sal.section = find_pc_overlay (sr_sal.pc); 2879 2880 insert_step_resume_breakpoint_at_sal (sr_sal, frame_unwind_id (next_frame)); 2881} 2882 2883static void 2884stop_stepping (struct execution_control_state *ecs) 2885{ 2886 if (debug_infrun) 2887 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n"); 2888 2889 /* Let callers know we don't want to wait for the inferior anymore. */ 2890 ecs->wait_some_more = 0; 2891} 2892 2893/* This function handles various cases where we need to continue 2894 waiting for the inferior. */ 2895/* (Used to be the keep_going: label in the old wait_for_inferior) */ 2896 2897static void 2898keep_going (struct execution_control_state *ecs) 2899{ 2900 /* Save the pc before execution, to compare with pc after stop. */ 2901 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ 2902 2903 /* If we did not do break;, it means we should keep running the 2904 inferior and not return to debugger. */ 2905 2906 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) 2907 { 2908 /* We took a signal (which we are supposed to pass through to 2909 the inferior, else we'd have done a break above) and we 2910 haven't yet gotten our trap. Simply continue. */ 2911 resume (currently_stepping (ecs), stop_signal); 2912 } 2913 else 2914 { 2915 /* Either the trap was not expected, but we are continuing 2916 anyway (the user asked that this signal be passed to the 2917 child) 2918 -- or -- 2919 The signal was SIGTRAP, e.g. it was our signal, but we 2920 decided we should resume from it. 2921 2922 We're going to run this baby now! */ 2923 2924 if (!breakpoints_inserted && !ecs->another_trap) 2925 { 2926 /* Stop stepping when inserting breakpoints 2927 has failed. */ 2928 if (insert_breakpoints () != 0) 2929 { 2930 stop_stepping (ecs); 2931 return; 2932 } 2933 breakpoints_inserted = 1; 2934 } 2935 2936 trap_expected = ecs->another_trap; 2937 2938 /* Do not deliver SIGNAL_TRAP (except when the user explicitly 2939 specifies that such a signal should be delivered to the 2940 target program). 2941 2942 Typically, this would occure when a user is debugging a 2943 target monitor on a simulator: the target monitor sets a 2944 breakpoint; the simulator encounters this break-point and 2945 halts the simulation handing control to GDB; GDB, noteing 2946 that the break-point isn't valid, returns control back to the 2947 simulator; the simulator then delivers the hardware 2948 equivalent of a SIGNAL_TRAP to the program being debugged. */ 2949 2950 if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal]) 2951 stop_signal = TARGET_SIGNAL_0; 2952 2953 2954 resume (currently_stepping (ecs), stop_signal); 2955 } 2956 2957 prepare_to_wait (ecs); 2958} 2959 2960/* This function normally comes after a resume, before 2961 handle_inferior_event exits. It takes care of any last bits of 2962 housekeeping, and sets the all-important wait_some_more flag. */ 2963 2964static void 2965prepare_to_wait (struct execution_control_state *ecs) 2966{ 2967 if (debug_infrun) 2968 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n"); 2969 if (ecs->infwait_state == infwait_normal_state) 2970 { 2971 overlay_cache_invalid = 1; 2972 2973 /* We have to invalidate the registers BEFORE calling 2974 target_wait because they can be loaded from the target while 2975 in target_wait. This makes remote debugging a bit more 2976 efficient for those targets that provide critical registers 2977 as part of their normal status mechanism. */ 2978 2979 registers_changed (); 2980 ecs->waiton_ptid = pid_to_ptid (-1); 2981 ecs->wp = &(ecs->ws); 2982 } 2983 /* This is the old end of the while loop. Let everybody know we 2984 want to wait for the inferior some more and get called again 2985 soon. */ 2986 ecs->wait_some_more = 1; 2987} 2988 2989/* Print why the inferior has stopped. We always print something when 2990 the inferior exits, or receives a signal. The rest of the cases are 2991 dealt with later on in normal_stop() and print_it_typical(). Ideally 2992 there should be a call to this function from handle_inferior_event() 2993 each time stop_stepping() is called.*/ 2994static void 2995print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info) 2996{ 2997 switch (stop_reason) 2998 { 2999 case END_STEPPING_RANGE: 3000 /* We are done with a step/next/si/ni command. */ 3001 /* For now print nothing. */ 3002 /* Print a message only if not in the middle of doing a "step n" 3003 operation for n > 1 */ 3004 if (!step_multi || !stop_step) 3005 if (ui_out_is_mi_like_p (uiout)) 3006 ui_out_field_string 3007 (uiout, "reason", 3008 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE)); 3009 break; 3010 case SIGNAL_EXITED: 3011 /* The inferior was terminated by a signal. */ 3012 annotate_signalled (); 3013 if (ui_out_is_mi_like_p (uiout)) 3014 ui_out_field_string 3015 (uiout, "reason", 3016 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED)); 3017 ui_out_text (uiout, "\nProgram terminated with signal "); 3018 annotate_signal_name (); 3019 ui_out_field_string (uiout, "signal-name", 3020 target_signal_to_name (stop_info)); 3021 annotate_signal_name_end (); 3022 ui_out_text (uiout, ", "); 3023 annotate_signal_string (); 3024 ui_out_field_string (uiout, "signal-meaning", 3025 target_signal_to_string (stop_info)); 3026 annotate_signal_string_end (); 3027 ui_out_text (uiout, ".\n"); 3028 ui_out_text (uiout, "The program no longer exists.\n"); 3029 break; 3030 case EXITED: 3031 /* The inferior program is finished. */ 3032 annotate_exited (stop_info); 3033 if (stop_info) 3034 { 3035 if (ui_out_is_mi_like_p (uiout)) 3036 ui_out_field_string (uiout, "reason", 3037 async_reason_lookup (EXEC_ASYNC_EXITED)); 3038 ui_out_text (uiout, "\nProgram exited with code "); 3039 ui_out_field_fmt (uiout, "exit-code", "0%o", 3040 (unsigned int) stop_info); 3041 ui_out_text (uiout, ".\n"); 3042 } 3043 else 3044 { 3045 if (ui_out_is_mi_like_p (uiout)) 3046 ui_out_field_string 3047 (uiout, "reason", 3048 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); 3049 ui_out_text (uiout, "\nProgram exited normally.\n"); 3050 } 3051 /* Support the --return-child-result option. */ 3052 return_child_result_value = stop_info; 3053 break; 3054 case SIGNAL_RECEIVED: 3055 /* Signal received. The signal table tells us to print about 3056 it. */ 3057 annotate_signal (); 3058 ui_out_text (uiout, "\nProgram received signal "); 3059 annotate_signal_name (); 3060 if (ui_out_is_mi_like_p (uiout)) 3061 ui_out_field_string 3062 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); 3063 ui_out_field_string (uiout, "signal-name", 3064 target_signal_to_name (stop_info)); 3065 annotate_signal_name_end (); 3066 ui_out_text (uiout, ", "); 3067 annotate_signal_string (); 3068 ui_out_field_string (uiout, "signal-meaning", 3069 target_signal_to_string (stop_info)); 3070 annotate_signal_string_end (); 3071 ui_out_text (uiout, ".\n"); 3072 break; 3073 default: 3074 internal_error (__FILE__, __LINE__, 3075 _("print_stop_reason: unrecognized enum value")); 3076 break; 3077 } 3078} 3079 3080 3081/* Here to return control to GDB when the inferior stops for real. 3082 Print appropriate messages, remove breakpoints, give terminal our modes. 3083 3084 STOP_PRINT_FRAME nonzero means print the executing frame 3085 (pc, function, args, file, line number and line text). 3086 BREAKPOINTS_FAILED nonzero means stop was due to error 3087 attempting to insert breakpoints. */ 3088 3089void 3090normal_stop (void) 3091{ 3092 struct target_waitstatus last; 3093 ptid_t last_ptid; 3094 3095 get_last_target_status (&last_ptid, &last); 3096 3097 /* As with the notification of thread events, we want to delay 3098 notifying the user that we've switched thread context until 3099 the inferior actually stops. 3100 3101 There's no point in saying anything if the inferior has exited. 3102 Note that SIGNALLED here means "exited with a signal", not 3103 "received a signal". */ 3104 if (!ptid_equal (previous_inferior_ptid, inferior_ptid) 3105 && target_has_execution 3106 && last.kind != TARGET_WAITKIND_SIGNALLED 3107 && last.kind != TARGET_WAITKIND_EXITED) 3108 { 3109 target_terminal_ours_for_output (); 3110 printf_filtered (_("[Switching to %s]\n"), 3111 target_pid_or_tid_to_str (inferior_ptid)); 3112 previous_inferior_ptid = inferior_ptid; 3113 } 3114 3115 /* NOTE drow/2004-01-17: Is this still necessary? */ 3116 /* Make sure that the current_frame's pc is correct. This 3117 is a correction for setting up the frame info before doing 3118 gdbarch_decr_pc_after_break */ 3119 if (target_has_execution) 3120 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to 3121 gdbarch_decr_pc_after_break, the program counter can change. Ask the 3122 frame code to check for this and sort out any resultant mess. 3123 gdbarch_decr_pc_after_break needs to just go away. */ 3124 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ()); 3125 3126 if (target_has_execution && breakpoints_inserted) 3127 { 3128 if (remove_breakpoints ()) 3129 { 3130 target_terminal_ours_for_output (); 3131 printf_filtered (_("\ 3132Cannot remove breakpoints because program is no longer writable.\n\ 3133It might be running in another process.\n\ 3134Further execution is probably impossible.\n")); 3135 } 3136 } 3137 breakpoints_inserted = 0; 3138 3139 /* Delete the breakpoint we stopped at, if it wants to be deleted. 3140 Delete any breakpoint that is to be deleted at the next stop. */ 3141 3142 breakpoint_auto_delete (stop_bpstat); 3143 3144 /* If an auto-display called a function and that got a signal, 3145 delete that auto-display to avoid an infinite recursion. */ 3146 3147 if (stopped_by_random_signal) 3148 disable_current_display (); 3149 3150 /* Don't print a message if in the middle of doing a "step n" 3151 operation for n > 1 */ 3152 if (step_multi && stop_step) 3153 goto done; 3154 3155 target_terminal_ours (); 3156 3157 /* Set the current source location. This will also happen if we 3158 display the frame below, but the current SAL will be incorrect 3159 during a user hook-stop function. */ 3160 if (target_has_stack && !stop_stack_dummy) 3161 set_current_sal_from_frame (get_current_frame (), 1); 3162 3163 /* Look up the hook_stop and run it (CLI internally handles problem 3164 of stop_command's pre-hook not existing). */ 3165 if (stop_command) 3166 catch_errors (hook_stop_stub, stop_command, 3167 "Error while running hook_stop:\n", RETURN_MASK_ALL); 3168 3169 if (!target_has_stack) 3170 { 3171 3172 goto done; 3173 } 3174 3175 /* Select innermost stack frame - i.e., current frame is frame 0, 3176 and current location is based on that. 3177 Don't do this on return from a stack dummy routine, 3178 or if the program has exited. */ 3179 3180 if (!stop_stack_dummy) 3181 { 3182 select_frame (get_current_frame ()); 3183 3184 /* Print current location without a level number, if 3185 we have changed functions or hit a breakpoint. 3186 Print source line if we have one. 3187 bpstat_print() contains the logic deciding in detail 3188 what to print, based on the event(s) that just occurred. */ 3189 3190 if (stop_print_frame) 3191 { 3192 int bpstat_ret; 3193 int source_flag; 3194 int do_frame_printing = 1; 3195 3196 bpstat_ret = bpstat_print (stop_bpstat); 3197 switch (bpstat_ret) 3198 { 3199 case PRINT_UNKNOWN: 3200 /* If we had hit a shared library event breakpoint, 3201 bpstat_print would print out this message. If we hit 3202 an OS-level shared library event, do the same 3203 thing. */ 3204 if (last.kind == TARGET_WAITKIND_LOADED) 3205 { 3206 printf_filtered (_("Stopped due to shared library event\n")); 3207 source_flag = SRC_LINE; /* something bogus */ 3208 do_frame_printing = 0; 3209 break; 3210 } 3211 3212 /* FIXME: cagney/2002-12-01: Given that a frame ID does 3213 (or should) carry around the function and does (or 3214 should) use that when doing a frame comparison. */ 3215 if (stop_step 3216 && frame_id_eq (step_frame_id, 3217 get_frame_id (get_current_frame ())) 3218 && step_start_function == find_pc_function (stop_pc)) 3219 source_flag = SRC_LINE; /* finished step, just print source line */ 3220 else 3221 source_flag = SRC_AND_LOC; /* print location and source line */ 3222 break; 3223 case PRINT_SRC_AND_LOC: 3224 source_flag = SRC_AND_LOC; /* print location and source line */ 3225 break; 3226 case PRINT_SRC_ONLY: 3227 source_flag = SRC_LINE; 3228 break; 3229 case PRINT_NOTHING: 3230 source_flag = SRC_LINE; /* something bogus */ 3231 do_frame_printing = 0; 3232 break; 3233 default: 3234 internal_error (__FILE__, __LINE__, _("Unknown value.")); 3235 } 3236 3237 if (ui_out_is_mi_like_p (uiout)) 3238 ui_out_field_int (uiout, "thread-id", 3239 pid_to_thread_id (inferior_ptid)); 3240 /* The behavior of this routine with respect to the source 3241 flag is: 3242 SRC_LINE: Print only source line 3243 LOCATION: Print only location 3244 SRC_AND_LOC: Print location and source line */ 3245 if (do_frame_printing) 3246 print_stack_frame (get_selected_frame (NULL), 0, source_flag); 3247 3248 /* Display the auto-display expressions. */ 3249 do_displays (); 3250 } 3251 } 3252 3253 /* Save the function value return registers, if we care. 3254 We might be about to restore their previous contents. */ 3255 if (proceed_to_finish) 3256 { 3257 /* This should not be necessary. */ 3258 if (stop_registers) 3259 regcache_xfree (stop_registers); 3260 3261 /* NB: The copy goes through to the target picking up the value of 3262 all the registers. */ 3263 stop_registers = regcache_dup (get_current_regcache ()); 3264 } 3265 3266 if (stop_stack_dummy) 3267 { 3268 /* Pop the empty frame that contains the stack dummy. POP_FRAME 3269 ends with a setting of the current frame, so we can use that 3270 next. */ 3271 frame_pop (get_current_frame ()); 3272 /* Set stop_pc to what it was before we called the function. 3273 Can't rely on restore_inferior_status because that only gets 3274 called if we don't stop in the called function. */ 3275 stop_pc = read_pc (); 3276 select_frame (get_current_frame ()); 3277 } 3278 3279done: 3280 annotate_stopped (); 3281 observer_notify_normal_stop (stop_bpstat); 3282} 3283 3284static int 3285hook_stop_stub (void *cmd) 3286{ 3287 execute_cmd_pre_hook ((struct cmd_list_element *) cmd); 3288 return (0); 3289} 3290 3291int 3292signal_stop_state (int signo) 3293{ 3294 return signal_stop[signo]; 3295} 3296 3297int 3298signal_print_state (int signo) 3299{ 3300 return signal_print[signo]; 3301} 3302 3303int 3304signal_pass_state (int signo) 3305{ 3306 return signal_program[signo]; 3307} 3308 3309int 3310signal_stop_update (int signo, int state) 3311{ 3312 int ret = signal_stop[signo]; 3313 signal_stop[signo] = state; 3314 return ret; 3315} 3316 3317int 3318signal_print_update (int signo, int state) 3319{ 3320 int ret = signal_print[signo]; 3321 signal_print[signo] = state; 3322 return ret; 3323} 3324 3325int 3326signal_pass_update (int signo, int state) 3327{ 3328 int ret = signal_program[signo]; 3329 signal_program[signo] = state; 3330 return ret; 3331} 3332 3333static void 3334sig_print_header (void) 3335{ 3336 printf_filtered (_("\ 3337Signal Stop\tPrint\tPass to program\tDescription\n")); 3338} 3339 3340static void 3341sig_print_info (enum target_signal oursig) 3342{ 3343 char *name = target_signal_to_name (oursig); 3344 int name_padding = 13 - strlen (name); 3345 3346 if (name_padding <= 0) 3347 name_padding = 0; 3348 3349 printf_filtered ("%s", name); 3350 printf_filtered ("%*.*s ", name_padding, name_padding, " "); 3351 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); 3352 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); 3353 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); 3354 printf_filtered ("%s\n", target_signal_to_string (oursig)); 3355} 3356 3357/* Specify how various signals in the inferior should be handled. */ 3358 3359static void 3360handle_command (char *args, int from_tty) 3361{ 3362 char **argv; 3363 int digits, wordlen; 3364 int sigfirst, signum, siglast; 3365 enum target_signal oursig; 3366 int allsigs; 3367 int nsigs; 3368 unsigned char *sigs; 3369 struct cleanup *old_chain; 3370 3371 if (args == NULL) 3372 { 3373 error_no_arg (_("signal to handle")); 3374 } 3375 3376 /* Allocate and zero an array of flags for which signals to handle. */ 3377 3378 nsigs = (int) TARGET_SIGNAL_LAST; 3379 sigs = (unsigned char *) alloca (nsigs); 3380 memset (sigs, 0, nsigs); 3381 3382 /* Break the command line up into args. */ 3383 3384 argv = buildargv (args); 3385 if (argv == NULL) 3386 { 3387 nomem (0); 3388 } 3389 old_chain = make_cleanup_freeargv (argv); 3390 3391 /* Walk through the args, looking for signal oursigs, signal names, and 3392 actions. Signal numbers and signal names may be interspersed with 3393 actions, with the actions being performed for all signals cumulatively 3394 specified. Signal ranges can be specified as <LOW>-<HIGH>. */ 3395 3396 while (*argv != NULL) 3397 { 3398 wordlen = strlen (*argv); 3399 for (digits = 0; isdigit ((*argv)[digits]); digits++) 3400 {; 3401 } 3402 allsigs = 0; 3403 sigfirst = siglast = -1; 3404 3405 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) 3406 { 3407 /* Apply action to all signals except those used by the 3408 debugger. Silently skip those. */ 3409 allsigs = 1; 3410 sigfirst = 0; 3411 siglast = nsigs - 1; 3412 } 3413 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) 3414 { 3415 SET_SIGS (nsigs, sigs, signal_stop); 3416 SET_SIGS (nsigs, sigs, signal_print); 3417 } 3418 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) 3419 { 3420 UNSET_SIGS (nsigs, sigs, signal_program); 3421 } 3422 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) 3423 { 3424 SET_SIGS (nsigs, sigs, signal_print); 3425 } 3426 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) 3427 { 3428 SET_SIGS (nsigs, sigs, signal_program); 3429 } 3430 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) 3431 { 3432 UNSET_SIGS (nsigs, sigs, signal_stop); 3433 } 3434 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) 3435 { 3436 SET_SIGS (nsigs, sigs, signal_program); 3437 } 3438 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) 3439 { 3440 UNSET_SIGS (nsigs, sigs, signal_print); 3441 UNSET_SIGS (nsigs, sigs, signal_stop); 3442 } 3443 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) 3444 { 3445 UNSET_SIGS (nsigs, sigs, signal_program); 3446 } 3447 else if (digits > 0) 3448 { 3449 /* It is numeric. The numeric signal refers to our own 3450 internal signal numbering from target.h, not to host/target 3451 signal number. This is a feature; users really should be 3452 using symbolic names anyway, and the common ones like 3453 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ 3454 3455 sigfirst = siglast = (int) 3456 target_signal_from_command (atoi (*argv)); 3457 if ((*argv)[digits] == '-') 3458 { 3459 siglast = (int) 3460 target_signal_from_command (atoi ((*argv) + digits + 1)); 3461 } 3462 if (sigfirst > siglast) 3463 { 3464 /* Bet he didn't figure we'd think of this case... */ 3465 signum = sigfirst; 3466 sigfirst = siglast; 3467 siglast = signum; 3468 } 3469 } 3470 else 3471 { 3472 oursig = target_signal_from_name (*argv); 3473 if (oursig != TARGET_SIGNAL_UNKNOWN) 3474 { 3475 sigfirst = siglast = (int) oursig; 3476 } 3477 else 3478 { 3479 /* Not a number and not a recognized flag word => complain. */ 3480 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv); 3481 } 3482 } 3483 3484 /* If any signal numbers or symbol names were found, set flags for 3485 which signals to apply actions to. */ 3486 3487 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) 3488 { 3489 switch ((enum target_signal) signum) 3490 { 3491 case TARGET_SIGNAL_TRAP: 3492 case TARGET_SIGNAL_INT: 3493 if (!allsigs && !sigs[signum]) 3494 { 3495 if (query ("%s is used by the debugger.\n\ 3496Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum))) 3497 { 3498 sigs[signum] = 1; 3499 } 3500 else 3501 { 3502 printf_unfiltered (_("Not confirmed, unchanged.\n")); 3503 gdb_flush (gdb_stdout); 3504 } 3505 } 3506 break; 3507 case TARGET_SIGNAL_0: 3508 case TARGET_SIGNAL_DEFAULT: 3509 case TARGET_SIGNAL_UNKNOWN: 3510 /* Make sure that "all" doesn't print these. */ 3511 break; 3512 default: 3513 sigs[signum] = 1; 3514 break; 3515 } 3516 } 3517 3518 argv++; 3519 } 3520 3521 target_notice_signals (inferior_ptid); 3522 3523 if (from_tty) 3524 { 3525 /* Show the results. */ 3526 sig_print_header (); 3527 for (signum = 0; signum < nsigs; signum++) 3528 { 3529 if (sigs[signum]) 3530 { 3531 sig_print_info (signum); 3532 } 3533 } 3534 } 3535 3536 do_cleanups (old_chain); 3537} 3538 3539static void 3540xdb_handle_command (char *args, int from_tty) 3541{ 3542 char **argv; 3543 struct cleanup *old_chain; 3544 3545 /* Break the command line up into args. */ 3546 3547 argv = buildargv (args); 3548 if (argv == NULL) 3549 { 3550 nomem (0); 3551 } 3552 old_chain = make_cleanup_freeargv (argv); 3553 if (argv[1] != (char *) NULL) 3554 { 3555 char *argBuf; 3556 int bufLen; 3557 3558 bufLen = strlen (argv[0]) + 20; 3559 argBuf = (char *) xmalloc (bufLen); 3560 if (argBuf) 3561 { 3562 int validFlag = 1; 3563 enum target_signal oursig; 3564 3565 oursig = target_signal_from_name (argv[0]); 3566 memset (argBuf, 0, bufLen); 3567 if (strcmp (argv[1], "Q") == 0) 3568 sprintf (argBuf, "%s %s", argv[0], "noprint"); 3569 else 3570 { 3571 if (strcmp (argv[1], "s") == 0) 3572 { 3573 if (!signal_stop[oursig]) 3574 sprintf (argBuf, "%s %s", argv[0], "stop"); 3575 else 3576 sprintf (argBuf, "%s %s", argv[0], "nostop"); 3577 } 3578 else if (strcmp (argv[1], "i") == 0) 3579 { 3580 if (!signal_program[oursig]) 3581 sprintf (argBuf, "%s %s", argv[0], "pass"); 3582 else 3583 sprintf (argBuf, "%s %s", argv[0], "nopass"); 3584 } 3585 else if (strcmp (argv[1], "r") == 0) 3586 { 3587 if (!signal_print[oursig]) 3588 sprintf (argBuf, "%s %s", argv[0], "print"); 3589 else 3590 sprintf (argBuf, "%s %s", argv[0], "noprint"); 3591 } 3592 else 3593 validFlag = 0; 3594 } 3595 if (validFlag) 3596 handle_command (argBuf, from_tty); 3597 else 3598 printf_filtered (_("Invalid signal handling flag.\n")); 3599 if (argBuf) 3600 xfree (argBuf); 3601 } 3602 } 3603 do_cleanups (old_chain); 3604} 3605 3606/* Print current contents of the tables set by the handle command. 3607 It is possible we should just be printing signals actually used 3608 by the current target (but for things to work right when switching 3609 targets, all signals should be in the signal tables). */ 3610 3611static void 3612signals_info (char *signum_exp, int from_tty) 3613{ 3614 enum target_signal oursig; 3615 sig_print_header (); 3616 3617 if (signum_exp) 3618 { 3619 /* First see if this is a symbol name. */ 3620 oursig = target_signal_from_name (signum_exp); 3621 if (oursig == TARGET_SIGNAL_UNKNOWN) 3622 { 3623 /* No, try numeric. */ 3624 oursig = 3625 target_signal_from_command (parse_and_eval_long (signum_exp)); 3626 } 3627 sig_print_info (oursig); 3628 return; 3629 } 3630 3631 printf_filtered ("\n"); 3632 /* These ugly casts brought to you by the native VAX compiler. */ 3633 for (oursig = TARGET_SIGNAL_FIRST; 3634 (int) oursig < (int) TARGET_SIGNAL_LAST; 3635 oursig = (enum target_signal) ((int) oursig + 1)) 3636 { 3637 QUIT; 3638 3639 if (oursig != TARGET_SIGNAL_UNKNOWN 3640 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0) 3641 sig_print_info (oursig); 3642 } 3643 3644 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n")); 3645} 3646 3647struct inferior_status 3648{ 3649 enum target_signal stop_signal; 3650 CORE_ADDR stop_pc; 3651 bpstat stop_bpstat; 3652 int stop_step; 3653 int stop_stack_dummy; 3654 int stopped_by_random_signal; 3655 int trap_expected; 3656 CORE_ADDR step_range_start; 3657 CORE_ADDR step_range_end; 3658 struct frame_id step_frame_id; 3659 enum step_over_calls_kind step_over_calls; 3660 CORE_ADDR step_resume_break_address; 3661 int stop_after_trap; 3662 int stop_soon; 3663 3664 /* These are here because if call_function_by_hand has written some 3665 registers and then decides to call error(), we better not have changed 3666 any registers. */ 3667 struct regcache *registers; 3668 3669 /* A frame unique identifier. */ 3670 struct frame_id selected_frame_id; 3671 3672 int breakpoint_proceeded; 3673 int restore_stack_info; 3674 int proceed_to_finish; 3675}; 3676 3677void 3678write_inferior_status_register (struct inferior_status *inf_status, int regno, 3679 LONGEST val) 3680{ 3681 int size = register_size (current_gdbarch, regno); 3682 void *buf = alloca (size); 3683 store_signed_integer (buf, size, val); 3684 regcache_raw_write (inf_status->registers, regno, buf); 3685} 3686 3687/* Save all of the information associated with the inferior<==>gdb 3688 connection. INF_STATUS is a pointer to a "struct inferior_status" 3689 (defined in inferior.h). */ 3690 3691struct inferior_status * 3692save_inferior_status (int restore_stack_info) 3693{ 3694 struct inferior_status *inf_status = XMALLOC (struct inferior_status); 3695 3696 inf_status->stop_signal = stop_signal; 3697 inf_status->stop_pc = stop_pc; 3698 inf_status->stop_step = stop_step; 3699 inf_status->stop_stack_dummy = stop_stack_dummy; 3700 inf_status->stopped_by_random_signal = stopped_by_random_signal; 3701 inf_status->trap_expected = trap_expected; 3702 inf_status->step_range_start = step_range_start; 3703 inf_status->step_range_end = step_range_end; 3704 inf_status->step_frame_id = step_frame_id; 3705 inf_status->step_over_calls = step_over_calls; 3706 inf_status->stop_after_trap = stop_after_trap; 3707 inf_status->stop_soon = stop_soon; 3708 /* Save original bpstat chain here; replace it with copy of chain. 3709 If caller's caller is walking the chain, they'll be happier if we 3710 hand them back the original chain when restore_inferior_status is 3711 called. */ 3712 inf_status->stop_bpstat = stop_bpstat; 3713 stop_bpstat = bpstat_copy (stop_bpstat); 3714 inf_status->breakpoint_proceeded = breakpoint_proceeded; 3715 inf_status->restore_stack_info = restore_stack_info; 3716 inf_status->proceed_to_finish = proceed_to_finish; 3717 3718 inf_status->registers = regcache_dup (get_current_regcache ()); 3719 3720 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); 3721 return inf_status; 3722} 3723 3724static int 3725restore_selected_frame (void *args) 3726{ 3727 struct frame_id *fid = (struct frame_id *) args; 3728 struct frame_info *frame; 3729 3730 frame = frame_find_by_id (*fid); 3731 3732 /* If inf_status->selected_frame_id is NULL, there was no previously 3733 selected frame. */ 3734 if (frame == NULL) 3735 { 3736 warning (_("Unable to restore previously selected frame.")); 3737 return 0; 3738 } 3739 3740 select_frame (frame); 3741 3742 return (1); 3743} 3744 3745void 3746restore_inferior_status (struct inferior_status *inf_status) 3747{ 3748 stop_signal = inf_status->stop_signal; 3749 stop_pc = inf_status->stop_pc; 3750 stop_step = inf_status->stop_step; 3751 stop_stack_dummy = inf_status->stop_stack_dummy; 3752 stopped_by_random_signal = inf_status->stopped_by_random_signal; 3753 trap_expected = inf_status->trap_expected; 3754 step_range_start = inf_status->step_range_start; 3755 step_range_end = inf_status->step_range_end; 3756 step_frame_id = inf_status->step_frame_id; 3757 step_over_calls = inf_status->step_over_calls; 3758 stop_after_trap = inf_status->stop_after_trap; 3759 stop_soon = inf_status->stop_soon; 3760 bpstat_clear (&stop_bpstat); 3761 stop_bpstat = inf_status->stop_bpstat; 3762 breakpoint_proceeded = inf_status->breakpoint_proceeded; 3763 proceed_to_finish = inf_status->proceed_to_finish; 3764 3765 /* The inferior can be gone if the user types "print exit(0)" 3766 (and perhaps other times). */ 3767 if (target_has_execution) 3768 /* NB: The register write goes through to the target. */ 3769 regcache_cpy (get_current_regcache (), inf_status->registers); 3770 regcache_xfree (inf_status->registers); 3771 3772 /* FIXME: If we are being called after stopping in a function which 3773 is called from gdb, we should not be trying to restore the 3774 selected frame; it just prints a spurious error message (The 3775 message is useful, however, in detecting bugs in gdb (like if gdb 3776 clobbers the stack)). In fact, should we be restoring the 3777 inferior status at all in that case? . */ 3778 3779 if (target_has_stack && inf_status->restore_stack_info) 3780 { 3781 /* The point of catch_errors is that if the stack is clobbered, 3782 walking the stack might encounter a garbage pointer and 3783 error() trying to dereference it. */ 3784 if (catch_errors 3785 (restore_selected_frame, &inf_status->selected_frame_id, 3786 "Unable to restore previously selected frame:\n", 3787 RETURN_MASK_ERROR) == 0) 3788 /* Error in restoring the selected frame. Select the innermost 3789 frame. */ 3790 select_frame (get_current_frame ()); 3791 3792 } 3793 3794 xfree (inf_status); 3795} 3796 3797static void 3798do_restore_inferior_status_cleanup (void *sts) 3799{ 3800 restore_inferior_status (sts); 3801} 3802 3803struct cleanup * 3804make_cleanup_restore_inferior_status (struct inferior_status *inf_status) 3805{ 3806 return make_cleanup (do_restore_inferior_status_cleanup, inf_status); 3807} 3808 3809void 3810discard_inferior_status (struct inferior_status *inf_status) 3811{ 3812 /* See save_inferior_status for info on stop_bpstat. */ 3813 bpstat_clear (&inf_status->stop_bpstat); 3814 regcache_xfree (inf_status->registers); 3815 xfree (inf_status); 3816} 3817 3818int 3819inferior_has_forked (int pid, int *child_pid) 3820{ 3821 struct target_waitstatus last; 3822 ptid_t last_ptid; 3823 3824 get_last_target_status (&last_ptid, &last); 3825 3826 if (last.kind != TARGET_WAITKIND_FORKED) 3827 return 0; 3828 3829 if (ptid_get_pid (last_ptid) != pid) 3830 return 0; 3831 3832 *child_pid = last.value.related_pid; 3833 return 1; 3834} 3835 3836int 3837inferior_has_vforked (int pid, int *child_pid) 3838{ 3839 struct target_waitstatus last; 3840 ptid_t last_ptid; 3841 3842 get_last_target_status (&last_ptid, &last); 3843 3844 if (last.kind != TARGET_WAITKIND_VFORKED) 3845 return 0; 3846 3847 if (ptid_get_pid (last_ptid) != pid) 3848 return 0; 3849 3850 *child_pid = last.value.related_pid; 3851 return 1; 3852} 3853 3854int 3855inferior_has_execd (int pid, char **execd_pathname) 3856{ 3857 struct target_waitstatus last; 3858 ptid_t last_ptid; 3859 3860 get_last_target_status (&last_ptid, &last); 3861 3862 if (last.kind != TARGET_WAITKIND_EXECD) 3863 return 0; 3864 3865 if (ptid_get_pid (last_ptid) != pid) 3866 return 0; 3867 3868 *execd_pathname = xstrdup (last.value.execd_pathname); 3869 return 1; 3870} 3871 3872/* Oft used ptids */ 3873ptid_t null_ptid; 3874ptid_t minus_one_ptid; 3875 3876/* Create a ptid given the necessary PID, LWP, and TID components. */ 3877 3878ptid_t 3879ptid_build (int pid, long lwp, long tid) 3880{ 3881 ptid_t ptid; 3882 3883 ptid.pid = pid; 3884 ptid.lwp = lwp; 3885 ptid.tid = tid; 3886 return ptid; 3887} 3888 3889/* Create a ptid from just a pid. */ 3890 3891ptid_t 3892pid_to_ptid (int pid) 3893{ 3894 return ptid_build (pid, 0, 0); 3895} 3896 3897/* Fetch the pid (process id) component from a ptid. */ 3898 3899int 3900ptid_get_pid (ptid_t ptid) 3901{ 3902 return ptid.pid; 3903} 3904 3905/* Fetch the lwp (lightweight process) component from a ptid. */ 3906 3907long 3908ptid_get_lwp (ptid_t ptid) 3909{ 3910 return ptid.lwp; 3911} 3912 3913/* Fetch the tid (thread id) component from a ptid. */ 3914 3915long 3916ptid_get_tid (ptid_t ptid) 3917{ 3918 return ptid.tid; 3919} 3920 3921/* ptid_equal() is used to test equality of two ptids. */ 3922 3923int 3924ptid_equal (ptid_t ptid1, ptid_t ptid2) 3925{ 3926 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp 3927 && ptid1.tid == ptid2.tid); 3928} 3929 3930/* restore_inferior_ptid() will be used by the cleanup machinery 3931 to restore the inferior_ptid value saved in a call to 3932 save_inferior_ptid(). */ 3933 3934static void 3935restore_inferior_ptid (void *arg) 3936{ 3937 ptid_t *saved_ptid_ptr = arg; 3938 inferior_ptid = *saved_ptid_ptr; 3939 xfree (arg); 3940} 3941 3942/* Save the value of inferior_ptid so that it may be restored by a 3943 later call to do_cleanups(). Returns the struct cleanup pointer 3944 needed for later doing the cleanup. */ 3945 3946struct cleanup * 3947save_inferior_ptid (void) 3948{ 3949 ptid_t *saved_ptid_ptr; 3950 3951 saved_ptid_ptr = xmalloc (sizeof (ptid_t)); 3952 *saved_ptid_ptr = inferior_ptid; 3953 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); 3954} 3955 3956 3957void 3958_initialize_infrun (void) 3959{ 3960 int i; 3961 int numsigs; 3962 struct cmd_list_element *c; 3963 3964 add_info ("signals", signals_info, _("\ 3965What debugger does when program gets various signals.\n\ 3966Specify a signal as argument to print info on that signal only.")); 3967 add_info_alias ("handle", "signals", 0); 3968 3969 add_com ("handle", class_run, handle_command, _("\ 3970Specify how to handle a signal.\n\ 3971Args are signals and actions to apply to those signals.\n\ 3972Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ 3973from 1-15 are allowed for compatibility with old versions of GDB.\n\ 3974Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ 3975The special arg \"all\" is recognized to mean all signals except those\n\ 3976used by the debugger, typically SIGTRAP and SIGINT.\n\ 3977Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ 3978\"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ 3979Stop means reenter debugger if this signal happens (implies print).\n\ 3980Print means print a message if this signal happens.\n\ 3981Pass means let program see this signal; otherwise program doesn't know.\n\ 3982Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ 3983Pass and Stop may be combined.")); 3984 if (xdb_commands) 3985 { 3986 add_com ("lz", class_info, signals_info, _("\ 3987What debugger does when program gets various signals.\n\ 3988Specify a signal as argument to print info on that signal only.")); 3989 add_com ("z", class_run, xdb_handle_command, _("\ 3990Specify how to handle a signal.\n\ 3991Args are signals and actions to apply to those signals.\n\ 3992Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ 3993from 1-15 are allowed for compatibility with old versions of GDB.\n\ 3994Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ 3995The special arg \"all\" is recognized to mean all signals except those\n\ 3996used by the debugger, typically SIGTRAP and SIGINT.\n\ 3997Recognized actions include \"s\" (toggles between stop and nostop), \n\ 3998\"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ 3999nopass), \"Q\" (noprint)\n\ 4000Stop means reenter debugger if this signal happens (implies print).\n\ 4001Print means print a message if this signal happens.\n\ 4002Pass means let program see this signal; otherwise program doesn't know.\n\ 4003Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ 4004Pass and Stop may be combined.")); 4005 } 4006 4007 if (!dbx_commands) 4008 stop_command = add_cmd ("stop", class_obscure, 4009 not_just_help_class_command, _("\ 4010There is no `stop' command, but you can set a hook on `stop'.\n\ 4011This allows you to set a list of commands to be run each time execution\n\ 4012of the program stops."), &cmdlist); 4013 4014 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\ 4015Set inferior debugging."), _("\ 4016Show inferior debugging."), _("\ 4017When non-zero, inferior specific debugging is enabled."), 4018 NULL, 4019 show_debug_infrun, 4020 &setdebuglist, &showdebuglist); 4021 4022 numsigs = (int) TARGET_SIGNAL_LAST; 4023 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); 4024 signal_print = (unsigned char *) 4025 xmalloc (sizeof (signal_print[0]) * numsigs); 4026 signal_program = (unsigned char *) 4027 xmalloc (sizeof (signal_program[0]) * numsigs); 4028 for (i = 0; i < numsigs; i++) 4029 { 4030 signal_stop[i] = 1; 4031 signal_print[i] = 1; 4032 signal_program[i] = 1; 4033 } 4034 4035 /* Signals caused by debugger's own actions 4036 should not be given to the program afterwards. */ 4037 signal_program[TARGET_SIGNAL_TRAP] = 0; 4038 signal_program[TARGET_SIGNAL_INT] = 0; 4039 4040 /* Signals that are not errors should not normally enter the debugger. */ 4041 signal_stop[TARGET_SIGNAL_ALRM] = 0; 4042 signal_print[TARGET_SIGNAL_ALRM] = 0; 4043 signal_stop[TARGET_SIGNAL_VTALRM] = 0; 4044 signal_print[TARGET_SIGNAL_VTALRM] = 0; 4045 signal_stop[TARGET_SIGNAL_PROF] = 0; 4046 signal_print[TARGET_SIGNAL_PROF] = 0; 4047 signal_stop[TARGET_SIGNAL_CHLD] = 0; 4048 signal_print[TARGET_SIGNAL_CHLD] = 0; 4049 signal_stop[TARGET_SIGNAL_IO] = 0; 4050 signal_print[TARGET_SIGNAL_IO] = 0; 4051 signal_stop[TARGET_SIGNAL_POLL] = 0; 4052 signal_print[TARGET_SIGNAL_POLL] = 0; 4053 signal_stop[TARGET_SIGNAL_URG] = 0; 4054 signal_print[TARGET_SIGNAL_URG] = 0; 4055 signal_stop[TARGET_SIGNAL_WINCH] = 0; 4056 signal_print[TARGET_SIGNAL_WINCH] = 0; 4057 4058 /* These signals are used internally by user-level thread 4059 implementations. (See signal(5) on Solaris.) Like the above 4060 signals, a healthy program receives and handles them as part of 4061 its normal operation. */ 4062 signal_stop[TARGET_SIGNAL_LWP] = 0; 4063 signal_print[TARGET_SIGNAL_LWP] = 0; 4064 signal_stop[TARGET_SIGNAL_WAITING] = 0; 4065 signal_print[TARGET_SIGNAL_WAITING] = 0; 4066 signal_stop[TARGET_SIGNAL_CANCEL] = 0; 4067 signal_print[TARGET_SIGNAL_CANCEL] = 0; 4068 4069 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support, 4070 &stop_on_solib_events, _("\ 4071Set stopping for shared library events."), _("\ 4072Show stopping for shared library events."), _("\ 4073If nonzero, gdb will give control to the user when the dynamic linker\n\ 4074notifies gdb of shared library events. The most common event of interest\n\ 4075to the user would be loading/unloading of a new library."), 4076 NULL, 4077 show_stop_on_solib_events, 4078 &setlist, &showlist); 4079 4080 add_setshow_enum_cmd ("follow-fork-mode", class_run, 4081 follow_fork_mode_kind_names, 4082 &follow_fork_mode_string, _("\ 4083Set debugger response to a program call of fork or vfork."), _("\ 4084Show debugger response to a program call of fork or vfork."), _("\ 4085A fork or vfork creates a new process. follow-fork-mode can be:\n\ 4086 parent - the original process is debugged after a fork\n\ 4087 child - the new process is debugged after a fork\n\ 4088The unfollowed process will continue to run.\n\ 4089By default, the debugger will follow the parent process."), 4090 NULL, 4091 show_follow_fork_mode_string, 4092 &setlist, &showlist); 4093 4094 add_setshow_enum_cmd ("scheduler-locking", class_run, 4095 scheduler_enums, &scheduler_mode, _("\ 4096Set mode for locking scheduler during execution."), _("\ 4097Show mode for locking scheduler during execution."), _("\ 4098off == no locking (threads may preempt at any time)\n\ 4099on == full locking (no thread except the current thread may run)\n\ 4100step == scheduler locked during every single-step operation.\n\ 4101 In this mode, no other thread may run during a step command.\n\ 4102 Other threads may run while stepping over a function call ('next')."), 4103 set_schedlock_func, /* traps on target vector */ 4104 show_scheduler_mode, 4105 &setlist, &showlist); 4106 4107 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\ 4108Set mode of the step operation."), _("\ 4109Show mode of the step operation."), _("\ 4110When set, doing a step over a function without debug line information\n\ 4111will stop at the first instruction of that function. Otherwise, the\n\ 4112function is skipped and the step command stops at a different source line."), 4113 NULL, 4114 show_step_stop_if_no_debug, 4115 &setlist, &showlist); 4116 4117 /* ptid initializations */ 4118 null_ptid = ptid_build (0, 0, 0); 4119 minus_one_ptid = ptid_build (-1, 0, 0); 4120 inferior_ptid = null_ptid; 4121 target_last_wait_ptid = minus_one_ptid; 4122} 4123