1 /* Target-struct-independent code to start (run) and stop an inferior process. 2 Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996 3 Free Software Foundation, Inc. 4 5 This file is part of GDB. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 20 21 #include "defs.h" 22 #include "gdb_string.h" 23 #include <ctype.h> 24 #include "symtab.h" 25 #include "frame.h" 26 #include "inferior.h" 27 #include "breakpoint.h" 28 #include "wait.h" 29 #include "gdbcore.h" 30 #include "gdbcmd.h" 31 #include "target.h" 32 #include "gdbthread.h" 33 #include "annotate.h" 34 35 #include <signal.h> 36 37 /* Prototypes for local functions */ 38 39 static void signals_info PARAMS ((char *, int)); 40 41 static void handle_command PARAMS ((char *, int)); 42 43 static void sig_print_info PARAMS ((enum target_signal)); 44 45 static void sig_print_header PARAMS ((void)); 46 47 static void resume_cleanups PARAMS ((int)); 48 49 static int hook_stop_stub PARAMS ((char *)); 50 51 static void delete_breakpoint_current_contents PARAMS ((PTR)); 52 53 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the 54 program. It needs to examine the jmp_buf argument and extract the PC 55 from it. The return value is non-zero on success, zero otherwise. */ 56 57 #ifndef GET_LONGJMP_TARGET 58 #define GET_LONGJMP_TARGET(PC_ADDR) 0 59 #endif 60 61 62 /* Some machines have trampoline code that sits between function callers 63 and the actual functions themselves. If this machine doesn't have 64 such things, disable their processing. */ 65 66 #ifndef SKIP_TRAMPOLINE_CODE 67 #define SKIP_TRAMPOLINE_CODE(pc) 0 68 #endif 69 70 /* Dynamic function trampolines are similar to solib trampolines in that they 71 are between the caller and the callee. The difference is that when you 72 enter a dynamic trampoline, you can't determine the callee's address. Some 73 (usually complex) code needs to run in the dynamic trampoline to figure out 74 the callee's address. This macro is usually called twice. First, when we 75 enter the trampoline (looks like a normal function call at that point). It 76 should return the PC of a point within the trampoline where the callee's 77 address is known. Second, when we hit the breakpoint, this routine returns 78 the callee's address. At that point, things proceed as per a step resume 79 breakpoint. */ 80 81 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC 82 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0 83 #endif 84 85 /* For SVR4 shared libraries, each call goes through a small piece of 86 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates 87 to nonzero if we are current stopped in one of these. */ 88 89 #ifndef IN_SOLIB_CALL_TRAMPOLINE 90 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0 91 #endif 92 93 /* In some shared library schemes, the return path from a shared library 94 call may need to go through a trampoline too. */ 95 96 #ifndef IN_SOLIB_RETURN_TRAMPOLINE 97 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0 98 #endif 99 100 /* On some systems, the PC may be left pointing at an instruction that won't 101 actually be executed. This is usually indicated by a bit in the PSW. If 102 we find ourselves in such a state, then we step the target beyond the 103 nullified instruction before returning control to the user so as to avoid 104 confusion. */ 105 106 #ifndef INSTRUCTION_NULLIFIED 107 #define INSTRUCTION_NULLIFIED 0 108 #endif 109 110 /* Tables of how to react to signals; the user sets them. */ 111 112 static unsigned char *signal_stop; 113 static unsigned char *signal_print; 114 static unsigned char *signal_program; 115 116 #define SET_SIGS(nsigs,sigs,flags) \ 117 do { \ 118 int signum = (nsigs); \ 119 while (signum-- > 0) \ 120 if ((sigs)[signum]) \ 121 (flags)[signum] = 1; \ 122 } while (0) 123 124 #define UNSET_SIGS(nsigs,sigs,flags) \ 125 do { \ 126 int signum = (nsigs); \ 127 while (signum-- > 0) \ 128 if ((sigs)[signum]) \ 129 (flags)[signum] = 0; \ 130 } while (0) 131 132 133 /* Command list pointer for the "stop" placeholder. */ 134 135 static struct cmd_list_element *stop_command; 136 137 /* Nonzero if breakpoints are now inserted in the inferior. */ 138 139 static int breakpoints_inserted; 140 141 /* Function inferior was in as of last step command. */ 142 143 static struct symbol *step_start_function; 144 145 /* Nonzero if we are expecting a trace trap and should proceed from it. */ 146 147 static int trap_expected; 148 149 #ifdef SOLIB_ADD 150 /* Nonzero if we want to give control to the user when we're notified 151 of shared library events by the dynamic linker. */ 152 static int stop_on_solib_events; 153 #endif 154 155 #ifdef HP_OS_BUG 156 /* Nonzero if the next time we try to continue the inferior, it will 157 step one instruction and generate a spurious trace trap. 158 This is used to compensate for a bug in HP-UX. */ 159 160 static int trap_expected_after_continue; 161 #endif 162 163 /* Nonzero means expecting a trace trap 164 and should stop the inferior and return silently when it happens. */ 165 166 int stop_after_trap; 167 168 /* Nonzero means expecting a trap and caller will handle it themselves. 169 It is used after attach, due to attaching to a process; 170 when running in the shell before the child program has been exec'd; 171 and when running some kinds of remote stuff (FIXME?). */ 172 173 int stop_soon_quietly; 174 175 /* Nonzero if proceed is being used for a "finish" command or a similar 176 situation when stop_registers should be saved. */ 177 178 int proceed_to_finish; 179 180 /* Save register contents here when about to pop a stack dummy frame, 181 if-and-only-if proceed_to_finish is set. 182 Thus this contains the return value from the called function (assuming 183 values are returned in a register). */ 184 185 char stop_registers[REGISTER_BYTES]; 186 187 /* Nonzero if program stopped due to error trying to insert breakpoints. */ 188 189 static int breakpoints_failed; 190 191 /* Nonzero after stop if current stack frame should be printed. */ 192 193 static int stop_print_frame; 194 195 196 /* Things to clean up if we QUIT out of resume (). */ 197 /* ARGSUSED */ 198 static void 199 resume_cleanups (arg) 200 int arg; 201 { 202 normal_stop (); 203 } 204 205 /* Resume the inferior, but allow a QUIT. This is useful if the user 206 wants to interrupt some lengthy single-stepping operation 207 (for child processes, the SIGINT goes to the inferior, and so 208 we get a SIGINT random_signal, but for remote debugging and perhaps 209 other targets, that's not true). 210 211 STEP nonzero if we should step (zero to continue instead). 212 SIG is the signal to give the inferior (zero for none). */ 213 void 214 resume (step, sig) 215 int step; 216 enum target_signal sig; 217 { 218 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); 219 QUIT; 220 221 #ifdef CANNOT_STEP_BREAKPOINT 222 /* Most targets can step a breakpoint instruction, thus executing it 223 normally. But if this one cannot, just continue and we will hit 224 it anyway. */ 225 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) 226 step = 0; 227 #endif 228 229 #ifdef NO_SINGLE_STEP 230 if (step) { 231 single_step(sig); /* Do it the hard way, w/temp breakpoints */ 232 step = 0; /* ...and don't ask hardware to do it. */ 233 } 234 #endif 235 236 /* Handle any optimized stores to the inferior NOW... */ 237 #ifdef DO_DEFERRED_STORES 238 DO_DEFERRED_STORES; 239 #endif 240 241 /* Install inferior's terminal modes. */ 242 target_terminal_inferior (); 243 244 target_resume (-1, step, sig); 245 discard_cleanups (old_cleanups); 246 } 247 248 249 /* Clear out all variables saying what to do when inferior is continued. 250 First do this, then set the ones you want, then call `proceed'. */ 251 252 void 253 clear_proceed_status () 254 { 255 trap_expected = 0; 256 step_range_start = 0; 257 step_range_end = 0; 258 step_frame_address = 0; 259 step_over_calls = -1; 260 stop_after_trap = 0; 261 stop_soon_quietly = 0; 262 proceed_to_finish = 0; 263 breakpoint_proceeded = 1; /* We're about to proceed... */ 264 265 /* Discard any remaining commands or status from previous stop. */ 266 bpstat_clear (&stop_bpstat); 267 } 268 269 /* Basic routine for continuing the program in various fashions. 270 271 ADDR is the address to resume at, or -1 for resume where stopped. 272 SIGGNAL is the signal to give it, or 0 for none, 273 or -1 for act according to how it stopped. 274 STEP is nonzero if should trap after one instruction. 275 -1 means return after that and print nothing. 276 You should probably set various step_... variables 277 before calling here, if you are stepping. 278 279 You should call clear_proceed_status before calling proceed. */ 280 281 void 282 proceed (addr, siggnal, step) 283 CORE_ADDR addr; 284 enum target_signal siggnal; 285 int step; 286 { 287 int oneproc = 0; 288 289 if (step > 0) 290 step_start_function = find_pc_function (read_pc ()); 291 if (step < 0) 292 stop_after_trap = 1; 293 294 if (addr == (CORE_ADDR)-1) 295 { 296 /* If there is a breakpoint at the address we will resume at, 297 step one instruction before inserting breakpoints 298 so that we do not stop right away. */ 299 300 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) 301 oneproc = 1; 302 303 #ifdef STEP_SKIPS_DELAY 304 /* Check breakpoint_here_p first, because breakpoint_here_p is fast 305 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY 306 is slow (it needs to read memory from the target). */ 307 if (breakpoint_here_p (read_pc () + 4) 308 && STEP_SKIPS_DELAY (read_pc ())) 309 oneproc = 1; 310 #endif /* STEP_SKIPS_DELAY */ 311 } 312 else 313 write_pc (addr); 314 315 #ifdef PREPARE_TO_PROCEED 316 /* In a multi-threaded task we may select another thread and then continue. 317 318 In this case the thread that stopped at a breakpoint will immediately 319 cause another stop, if it is not stepped over first. On the other hand, 320 if (ADDR != -1) we only want to single step over the breakpoint if we did 321 switch to another thread. 322 323 If we are single stepping, don't do any of the above. 324 (Note that in the current implementation single stepping another 325 thread after a breakpoint and then continuing will cause the original 326 breakpoint to be hit again, but you can always continue, so it's not 327 a big deal.) */ 328 329 if (! step && PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ())) 330 oneproc = 1; 331 #endif /* PREPARE_TO_PROCEED */ 332 333 #ifdef HP_OS_BUG 334 if (trap_expected_after_continue) 335 { 336 /* If (step == 0), a trap will be automatically generated after 337 the first instruction is executed. Force step one 338 instruction to clear this condition. This should not occur 339 if step is nonzero, but it is harmless in that case. */ 340 oneproc = 1; 341 trap_expected_after_continue = 0; 342 } 343 #endif /* HP_OS_BUG */ 344 345 if (oneproc) 346 /* We will get a trace trap after one instruction. 347 Continue it automatically and insert breakpoints then. */ 348 trap_expected = 1; 349 else 350 { 351 int temp = insert_breakpoints (); 352 if (temp) 353 { 354 print_sys_errmsg ("ptrace", temp); 355 error ("Cannot insert breakpoints.\n\ 356 The same program may be running in another process."); 357 } 358 breakpoints_inserted = 1; 359 } 360 361 if (siggnal != TARGET_SIGNAL_DEFAULT) 362 stop_signal = siggnal; 363 /* If this signal should not be seen by program, 364 give it zero. Used for debugging signals. */ 365 else if (!signal_program[stop_signal]) 366 stop_signal = TARGET_SIGNAL_0; 367 368 annotate_starting (); 369 370 /* Make sure that output from GDB appears before output from the 371 inferior. */ 372 gdb_flush (gdb_stdout); 373 374 /* Resume inferior. */ 375 resume (oneproc || step || bpstat_should_step (), stop_signal); 376 377 /* Wait for it to stop (if not standalone) 378 and in any case decode why it stopped, and act accordingly. */ 379 380 wait_for_inferior (); 381 normal_stop (); 382 } 383 384 /* Record the pc and sp of the program the last time it stopped. 385 These are just used internally by wait_for_inferior, but need 386 to be preserved over calls to it and cleared when the inferior 387 is started. */ 388 static CORE_ADDR prev_pc; 389 static CORE_ADDR prev_func_start; 390 static char *prev_func_name; 391 392 393 /* Start remote-debugging of a machine over a serial link. */ 394 395 void 396 start_remote () 397 { 398 init_thread_list (); 399 init_wait_for_inferior (); 400 clear_proceed_status (); 401 stop_soon_quietly = 1; 402 trap_expected = 0; 403 wait_for_inferior (); 404 normal_stop (); 405 } 406 407 /* Initialize static vars when a new inferior begins. */ 408 409 void 410 init_wait_for_inferior () 411 { 412 /* These are meaningless until the first time through wait_for_inferior. */ 413 prev_pc = 0; 414 prev_func_start = 0; 415 prev_func_name = NULL; 416 417 #ifdef HP_OS_BUG 418 trap_expected_after_continue = 0; 419 #endif 420 breakpoints_inserted = 0; 421 breakpoint_init_inferior (); 422 423 /* Don't confuse first call to proceed(). */ 424 stop_signal = TARGET_SIGNAL_0; 425 } 426 427 static void 428 delete_breakpoint_current_contents (arg) 429 PTR arg; 430 { 431 struct breakpoint **breakpointp = (struct breakpoint **)arg; 432 if (*breakpointp != NULL) 433 delete_breakpoint (*breakpointp); 434 } 435 436 /* Wait for control to return from inferior to debugger. 437 If inferior gets a signal, we may decide to start it up again 438 instead of returning. That is why there is a loop in this function. 439 When this function actually returns it means the inferior 440 should be left stopped and GDB should read more commands. */ 441 442 void 443 wait_for_inferior () 444 { 445 struct cleanup *old_cleanups; 446 struct target_waitstatus w; 447 int another_trap; 448 int random_signal = 0; 449 CORE_ADDR stop_func_start; 450 CORE_ADDR stop_func_end; 451 char *stop_func_name; 452 #if 0 453 CORE_ADDR prologue_pc = 0; 454 #endif 455 CORE_ADDR tmp; 456 struct symtab_and_line sal; 457 int remove_breakpoints_on_following_step = 0; 458 int current_line; 459 struct symtab *current_symtab; 460 int handling_longjmp = 0; /* FIXME */ 461 struct breakpoint *step_resume_breakpoint = NULL; 462 struct breakpoint *through_sigtramp_breakpoint = NULL; 463 int pid; 464 int update_step_sp = 0; 465 466 old_cleanups = make_cleanup (delete_breakpoint_current_contents, 467 &step_resume_breakpoint); 468 make_cleanup (delete_breakpoint_current_contents, 469 &through_sigtramp_breakpoint); 470 sal = find_pc_line(prev_pc, 0); 471 current_line = sal.line; 472 current_symtab = sal.symtab; 473 474 /* Are we stepping? */ 475 #define CURRENTLY_STEPPING() \ 476 ((through_sigtramp_breakpoint == NULL \ 477 && !handling_longjmp \ 478 && ((step_range_end && step_resume_breakpoint == NULL) \ 479 || trap_expected)) \ 480 || bpstat_should_step ()) 481 482 while (1) 483 { 484 /* We have to invalidate the registers BEFORE calling target_wait because 485 they can be loaded from the target while in target_wait. This makes 486 remote debugging a bit more efficient for those targets that provide 487 critical registers as part of their normal status mechanism. */ 488 489 registers_changed (); 490 491 if (target_wait_hook) 492 pid = target_wait_hook (-1, &w); 493 else 494 pid = target_wait (-1, &w); 495 496 /* Gross. 497 498 We goto this label from elsewhere in wait_for_inferior when we want 499 to continue the main loop without calling "wait" and trashing the 500 waitstatus contained in W. */ 501 have_waited: 502 503 flush_cached_frames (); 504 505 /* If it's a new process, add it to the thread database */ 506 507 if (pid != inferior_pid 508 && !in_thread_list (pid)) 509 { 510 fprintf_unfiltered (gdb_stderr, "[New %s]\n", target_pid_to_str (pid)); 511 add_thread (pid); 512 513 /* We may want to consider not doing a resume here in order to give 514 the user a chance to play with the new thread. It might be good 515 to make that a user-settable option. */ 516 517 /* At this point, all threads are stopped (happens automatically in 518 either the OS or the native code). Therefore we need to continue 519 all threads in order to make progress. */ 520 521 target_resume (-1, 0, TARGET_SIGNAL_0); 522 continue; 523 } 524 525 switch (w.kind) 526 { 527 case TARGET_WAITKIND_LOADED: 528 /* Ignore it gracefully. */ 529 if (breakpoints_inserted) 530 { 531 mark_breakpoints_out (); 532 insert_breakpoints (); 533 } 534 resume (0, TARGET_SIGNAL_0); 535 continue; 536 537 case TARGET_WAITKIND_SPURIOUS: 538 resume (0, TARGET_SIGNAL_0); 539 continue; 540 541 case TARGET_WAITKIND_EXITED: 542 target_terminal_ours (); /* Must do this before mourn anyway */ 543 annotate_exited (w.value.integer); 544 if (w.value.integer) 545 printf_filtered ("\nProgram exited with code 0%o.\n", 546 (unsigned int)w.value.integer); 547 else 548 printf_filtered ("\nProgram exited normally.\n"); 549 550 /* Record the exit code in the convenience variable $_exitcode, so 551 that the user can inspect this again later. */ 552 set_internalvar (lookup_internalvar ("_exitcode"), 553 value_from_longest (builtin_type_int, 554 (LONGEST) w.value.integer)); 555 gdb_flush (gdb_stdout); 556 target_mourn_inferior (); 557 #ifdef NO_SINGLE_STEP 558 one_stepped = 0; 559 #endif 560 stop_print_frame = 0; 561 goto stop_stepping; 562 563 case TARGET_WAITKIND_SIGNALLED: 564 stop_print_frame = 0; 565 stop_signal = w.value.sig; 566 target_terminal_ours (); /* Must do this before mourn anyway */ 567 annotate_signalled (); 568 569 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED 570 mean it is already dead? This has been here since GDB 2.8, so 571 perhaps it means rms didn't understand unix waitstatuses? 572 For the moment I'm just kludging around this in remote.c 573 rather than trying to change it here --kingdon, 5 Dec 1994. */ 574 target_kill (); /* kill mourns as well */ 575 576 printf_filtered ("\nProgram terminated with signal "); 577 annotate_signal_name (); 578 printf_filtered ("%s", target_signal_to_name (stop_signal)); 579 annotate_signal_name_end (); 580 printf_filtered (", "); 581 annotate_signal_string (); 582 printf_filtered ("%s", target_signal_to_string (stop_signal)); 583 annotate_signal_string_end (); 584 printf_filtered (".\n"); 585 586 printf_filtered ("The program no longer exists.\n"); 587 gdb_flush (gdb_stdout); 588 #ifdef NO_SINGLE_STEP 589 one_stepped = 0; 590 #endif 591 goto stop_stepping; 592 593 case TARGET_WAITKIND_STOPPED: 594 /* This is the only case in which we keep going; the above cases 595 end in a continue or goto. */ 596 break; 597 } 598 599 stop_signal = w.value.sig; 600 601 stop_pc = read_pc_pid (pid); 602 603 /* See if a thread hit a thread-specific breakpoint that was meant for 604 another thread. If so, then step that thread past the breakpoint, 605 and continue it. */ 606 607 if (stop_signal == TARGET_SIGNAL_TRAP) 608 { 609 #ifdef NO_SINGLE_STEP 610 if (one_stepped) 611 random_signal = 0; 612 else 613 #endif 614 if (breakpoints_inserted 615 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK)) 616 { 617 random_signal = 0; 618 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid)) 619 { 620 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */ 621 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid); 622 623 remove_breakpoints (); 624 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */ 625 /* FIXME: What if a signal arrives instead of the single-step 626 happening? */ 627 628 if (target_wait_hook) 629 target_wait_hook (pid, &w); 630 else 631 target_wait (pid, &w); 632 insert_breakpoints (); 633 634 /* We need to restart all the threads now. */ 635 target_resume (-1, 0, TARGET_SIGNAL_0); 636 continue; 637 } 638 } 639 } 640 else 641 random_signal = 1; 642 643 /* See if something interesting happened to the non-current thread. If 644 so, then switch to that thread, and eventually give control back to 645 the user. */ 646 647 if (pid != inferior_pid) 648 { 649 int printed = 0; 650 651 /* If it's a random signal for a non-current thread, notify user 652 if he's expressed an interest. */ 653 654 if (random_signal 655 && signal_print[stop_signal]) 656 { 657 printed = 1; 658 target_terminal_ours_for_output (); 659 printf_filtered ("\nProgram received signal %s, %s.\n", 660 target_signal_to_name (stop_signal), 661 target_signal_to_string (stop_signal)); 662 gdb_flush (gdb_stdout); 663 } 664 665 /* If it's not SIGTRAP and not a signal we want to stop for, then 666 continue the thread. */ 667 668 if (stop_signal != TARGET_SIGNAL_TRAP 669 && !signal_stop[stop_signal]) 670 { 671 if (printed) 672 target_terminal_inferior (); 673 674 /* Clear the signal if it should not be passed. */ 675 if (signal_program[stop_signal] == 0) 676 stop_signal = TARGET_SIGNAL_0; 677 678 target_resume (pid, 0, stop_signal); 679 continue; 680 } 681 682 /* It's a SIGTRAP or a signal we're interested in. Switch threads, 683 and fall into the rest of wait_for_inferior(). */ 684 685 /* Save infrun state for the old thread. */ 686 save_infrun_state (inferior_pid, prev_pc, 687 prev_func_start, prev_func_name, 688 trap_expected, step_resume_breakpoint, 689 through_sigtramp_breakpoint, 690 step_range_start, step_range_end, 691 step_frame_address, handling_longjmp, 692 another_trap); 693 694 inferior_pid = pid; 695 696 /* Load infrun state for the new thread. */ 697 load_infrun_state (inferior_pid, &prev_pc, 698 &prev_func_start, &prev_func_name, 699 &trap_expected, &step_resume_breakpoint, 700 &through_sigtramp_breakpoint, 701 &step_range_start, &step_range_end, 702 &step_frame_address, &handling_longjmp, 703 &another_trap); 704 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid)); 705 706 flush_cached_frames (); 707 } 708 709 #ifdef NO_SINGLE_STEP 710 if (one_stepped) 711 single_step (0); /* This actually cleans up the ss */ 712 #endif /* NO_SINGLE_STEP */ 713 714 /* If PC is pointing at a nullified instruction, then step beyond 715 it so that the user won't be confused when GDB appears to be ready 716 to execute it. */ 717 718 if (INSTRUCTION_NULLIFIED) 719 { 720 struct target_waitstatus tmpstatus; 721 722 registers_changed (); 723 target_resume (pid, 1, TARGET_SIGNAL_0); 724 725 /* We may have received a signal that we want to pass to 726 the inferior; therefore, we must not clobber the waitstatus 727 in W. So we call wait ourselves, then continue the loop 728 at the "have_waited" label. */ 729 if (target_wait_hook) 730 target_wait_hook (pid, &tmpstatus); 731 else 732 target_wait (pid, &tmpstatus); 733 734 735 goto have_waited; 736 } 737 738 #ifdef HAVE_STEPPABLE_WATCHPOINT 739 /* It may not be necessary to disable the watchpoint to stop over 740 it. For example, the PA can (with some kernel cooperation) 741 single step over a watchpoint without disabling the watchpoint. */ 742 if (STOPPED_BY_WATCHPOINT (w)) 743 { 744 resume (1, 0); 745 continue; 746 } 747 #endif 748 749 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT 750 /* It is far more common to need to disable a watchpoint 751 to step the inferior over it. FIXME. What else might 752 a debug register or page protection watchpoint scheme need 753 here? */ 754 if (STOPPED_BY_WATCHPOINT (w)) 755 { 756 /* At this point, we are stopped at an instruction which has attempted to write 757 to a piece of memory under control of a watchpoint. The instruction hasn't 758 actually executed yet. If we were to evaluate the watchpoint expression 759 now, we would get the old value, and therefore no change would seem to have 760 occurred. 761 762 In order to make watchpoints work `right', we really need to complete the 763 memory write, and then evaluate the watchpoint expression. The following 764 code does that by removing the watchpoint (actually, all watchpoints and 765 breakpoints), single-stepping the target, re-inserting watchpoints, and then 766 falling through to let normal single-step processing handle proceed. Since 767 this includes evaluating watchpoints, things will come to a stop in the 768 correct manner. */ 769 770 write_pc (stop_pc - DECR_PC_AFTER_BREAK); 771 772 remove_breakpoints (); 773 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */ 774 775 if (target_wait_hook) 776 target_wait_hook (pid, &w); 777 else 778 target_wait (pid, &w); 779 insert_breakpoints (); 780 /* FIXME-maybe: is this cleaner than setting a flag? Does it 781 handle things like signals arriving and other things happening 782 in combination correctly? */ 783 goto have_waited; 784 } 785 #endif 786 787 #ifdef HAVE_CONTINUABLE_WATCHPOINT 788 /* It may be possible to simply continue after a watchpoint. */ 789 STOPPED_BY_WATCHPOINT (w); 790 #endif 791 792 stop_func_start = 0; 793 stop_func_end = 0; 794 stop_func_name = 0; 795 /* Don't care about return value; stop_func_start and stop_func_name 796 will both be 0 if it doesn't work. */ 797 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start, 798 &stop_func_end); 799 stop_func_start += FUNCTION_START_OFFSET; 800 another_trap = 0; 801 bpstat_clear (&stop_bpstat); 802 stop_step = 0; 803 stop_stack_dummy = 0; 804 stop_print_frame = 1; 805 random_signal = 0; 806 stopped_by_random_signal = 0; 807 breakpoints_failed = 0; 808 809 /* Look at the cause of the stop, and decide what to do. 810 The alternatives are: 811 1) break; to really stop and return to the debugger, 812 2) drop through to start up again 813 (set another_trap to 1 to single step once) 814 3) set random_signal to 1, and the decision between 1 and 2 815 will be made according to the signal handling tables. */ 816 817 /* First, distinguish signals caused by the debugger from signals 818 that have to do with the program's own actions. 819 Note that breakpoint insns may cause SIGTRAP or SIGILL 820 or SIGEMT, depending on the operating system version. 821 Here we detect when a SIGILL or SIGEMT is really a breakpoint 822 and change it to SIGTRAP. */ 823 824 if (stop_signal == TARGET_SIGNAL_TRAP 825 || (breakpoints_inserted && 826 (stop_signal == TARGET_SIGNAL_ILL 827 || stop_signal == TARGET_SIGNAL_EMT 828 )) 829 || stop_soon_quietly) 830 { 831 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) 832 { 833 stop_print_frame = 0; 834 break; 835 } 836 if (stop_soon_quietly) 837 break; 838 839 /* Don't even think about breakpoints 840 if just proceeded over a breakpoint. 841 842 However, if we are trying to proceed over a breakpoint 843 and end up in sigtramp, then through_sigtramp_breakpoint 844 will be set and we should check whether we've hit the 845 step breakpoint. */ 846 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected 847 && through_sigtramp_breakpoint == NULL) 848 bpstat_clear (&stop_bpstat); 849 else 850 { 851 /* See if there is a breakpoint at the current PC. */ 852 stop_bpstat = bpstat_stop_status 853 (&stop_pc, 854 (DECR_PC_AFTER_BREAK ? 855 /* Notice the case of stepping through a jump 856 that lands just after a breakpoint. 857 Don't confuse that with hitting the breakpoint. 858 What we check for is that 1) stepping is going on 859 and 2) the pc before the last insn does not match 860 the address of the breakpoint before the current pc. */ 861 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK 862 && CURRENTLY_STEPPING ()) : 863 0) 864 ); 865 /* Following in case break condition called a 866 function. */ 867 stop_print_frame = 1; 868 } 869 870 if (stop_signal == TARGET_SIGNAL_TRAP) 871 random_signal 872 = !(bpstat_explains_signal (stop_bpstat) 873 || trap_expected 874 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET 875 || PC_IN_CALL_DUMMY (stop_pc, read_sp (), 876 FRAME_FP (get_current_frame ())) 877 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */ 878 || (step_range_end && step_resume_breakpoint == NULL)); 879 else 880 { 881 random_signal 882 = !(bpstat_explains_signal (stop_bpstat) 883 /* End of a stack dummy. Some systems (e.g. Sony 884 news) give another signal besides SIGTRAP, 885 so check here as well as above. */ 886 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET 887 || PC_IN_CALL_DUMMY (stop_pc, read_sp (), 888 FRAME_FP (get_current_frame ())) 889 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */ 890 ); 891 if (!random_signal) 892 stop_signal = TARGET_SIGNAL_TRAP; 893 } 894 } 895 else 896 random_signal = 1; 897 898 /* For the program's own signals, act according to 899 the signal handling tables. */ 900 901 if (random_signal) 902 { 903 /* Signal not for debugging purposes. */ 904 int printed = 0; 905 906 stopped_by_random_signal = 1; 907 908 if (signal_print[stop_signal]) 909 { 910 printed = 1; 911 target_terminal_ours_for_output (); 912 annotate_signal (); 913 printf_filtered ("\nProgram received signal "); 914 annotate_signal_name (); 915 printf_filtered ("%s", target_signal_to_name (stop_signal)); 916 annotate_signal_name_end (); 917 printf_filtered (", "); 918 annotate_signal_string (); 919 printf_filtered ("%s", target_signal_to_string (stop_signal)); 920 annotate_signal_string_end (); 921 printf_filtered (".\n"); 922 gdb_flush (gdb_stdout); 923 } 924 if (signal_stop[stop_signal]) 925 break; 926 /* If not going to stop, give terminal back 927 if we took it away. */ 928 else if (printed) 929 target_terminal_inferior (); 930 931 /* Clear the signal if it should not be passed. */ 932 if (signal_program[stop_signal] == 0) 933 stop_signal = TARGET_SIGNAL_0; 934 935 /* I'm not sure whether this needs to be check_sigtramp2 or 936 whether it could/should be keep_going. */ 937 goto check_sigtramp2; 938 } 939 940 /* Handle cases caused by hitting a breakpoint. */ 941 { 942 CORE_ADDR jmp_buf_pc; 943 struct bpstat_what what; 944 945 what = bpstat_what (stop_bpstat); 946 947 if (what.call_dummy) 948 { 949 stop_stack_dummy = 1; 950 #ifdef HP_OS_BUG 951 trap_expected_after_continue = 1; 952 #endif 953 } 954 955 switch (what.main_action) 956 { 957 case BPSTAT_WHAT_SET_LONGJMP_RESUME: 958 /* If we hit the breakpoint at longjmp, disable it for the 959 duration of this command. Then, install a temporary 960 breakpoint at the target of the jmp_buf. */ 961 disable_longjmp_breakpoint(); 962 remove_breakpoints (); 963 breakpoints_inserted = 0; 964 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going; 965 966 /* Need to blow away step-resume breakpoint, as it 967 interferes with us */ 968 if (step_resume_breakpoint != NULL) 969 { 970 delete_breakpoint (step_resume_breakpoint); 971 step_resume_breakpoint = NULL; 972 } 973 /* Not sure whether we need to blow this away too, but probably 974 it is like the step-resume breakpoint. */ 975 if (through_sigtramp_breakpoint != NULL) 976 { 977 delete_breakpoint (through_sigtramp_breakpoint); 978 through_sigtramp_breakpoint = NULL; 979 } 980 981 #if 0 982 /* FIXME - Need to implement nested temporary breakpoints */ 983 if (step_over_calls > 0) 984 set_longjmp_resume_breakpoint(jmp_buf_pc, 985 get_current_frame()); 986 else 987 #endif /* 0 */ 988 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL); 989 handling_longjmp = 1; /* FIXME */ 990 goto keep_going; 991 992 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: 993 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: 994 remove_breakpoints (); 995 breakpoints_inserted = 0; 996 #if 0 997 /* FIXME - Need to implement nested temporary breakpoints */ 998 if (step_over_calls 999 && (FRAME_FP (get_current_frame ()) 1000 INNER_THAN step_frame_address)) 1001 { 1002 another_trap = 1; 1003 goto keep_going; 1004 } 1005 #endif /* 0 */ 1006 disable_longjmp_breakpoint(); 1007 handling_longjmp = 0; /* FIXME */ 1008 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) 1009 break; 1010 /* else fallthrough */ 1011 1012 case BPSTAT_WHAT_SINGLE: 1013 if (breakpoints_inserted) 1014 remove_breakpoints (); 1015 breakpoints_inserted = 0; 1016 another_trap = 1; 1017 /* Still need to check other stuff, at least the case 1018 where we are stepping and step out of the right range. */ 1019 break; 1020 1021 case BPSTAT_WHAT_STOP_NOISY: 1022 stop_print_frame = 1; 1023 1024 /* We are about to nuke the step_resume_breakpoint and 1025 through_sigtramp_breakpoint via the cleanup chain, so 1026 no need to worry about it here. */ 1027 1028 goto stop_stepping; 1029 1030 case BPSTAT_WHAT_STOP_SILENT: 1031 stop_print_frame = 0; 1032 1033 /* We are about to nuke the step_resume_breakpoint and 1034 through_sigtramp_breakpoint via the cleanup chain, so 1035 no need to worry about it here. */ 1036 1037 goto stop_stepping; 1038 1039 case BPSTAT_WHAT_STEP_RESUME: 1040 delete_breakpoint (step_resume_breakpoint); 1041 step_resume_breakpoint = NULL; 1042 break; 1043 1044 case BPSTAT_WHAT_THROUGH_SIGTRAMP: 1045 if (through_sigtramp_breakpoint) 1046 delete_breakpoint (through_sigtramp_breakpoint); 1047 through_sigtramp_breakpoint = NULL; 1048 1049 /* If were waiting for a trap, hitting the step_resume_break 1050 doesn't count as getting it. */ 1051 if (trap_expected) 1052 another_trap = 1; 1053 break; 1054 1055 case BPSTAT_WHAT_CHECK_SHLIBS: 1056 #ifdef SOLIB_ADD 1057 { 1058 extern int auto_solib_add; 1059 1060 /* Remove breakpoints, we eventually want to step over the 1061 shlib event breakpoint, and SOLIB_ADD might adjust 1062 breakpoint addresses via breakpoint_re_set. */ 1063 if (breakpoints_inserted) 1064 remove_breakpoints (); 1065 breakpoints_inserted = 0; 1066 1067 /* Check for any newly added shared libraries if we're 1068 supposed to be adding them automatically. */ 1069 if (auto_solib_add) 1070 { 1071 /* Switch terminal for any messages produced by 1072 breakpoint_re_set. */ 1073 target_terminal_ours_for_output (); 1074 SOLIB_ADD (NULL, 0, NULL); 1075 target_terminal_inferior (); 1076 } 1077 1078 /* Try to reenable shared library breakpoints, additional 1079 code segments in shared libraries might be mapped in now. */ 1080 re_enable_breakpoints_in_shlibs (); 1081 1082 /* If requested, stop when the dynamic linker notifies 1083 gdb of events. This allows the user to get control 1084 and place breakpoints in initializer routines for 1085 dynamically loaded objects (among other things). */ 1086 if (stop_on_solib_events) 1087 { 1088 stop_print_frame = 0; 1089 goto stop_stepping; 1090 } 1091 else 1092 { 1093 /* We want to step over this breakpoint, then keep going. */ 1094 another_trap = 1; 1095 break; 1096 } 1097 } 1098 #endif 1099 break; 1100 1101 case BPSTAT_WHAT_LAST: 1102 /* Not a real code, but listed here to shut up gcc -Wall. */ 1103 1104 case BPSTAT_WHAT_KEEP_CHECKING: 1105 break; 1106 } 1107 } 1108 1109 /* We come here if we hit a breakpoint but should not 1110 stop for it. Possibly we also were stepping 1111 and should stop for that. So fall through and 1112 test for stepping. But, if not stepping, 1113 do not stop. */ 1114 1115 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET 1116 /* This is the old way of detecting the end of the stack dummy. 1117 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets 1118 handled above. As soon as we can test it on all of them, all 1119 architectures should define it. */ 1120 1121 /* If this is the breakpoint at the end of a stack dummy, 1122 just stop silently, unless the user was doing an si/ni, in which 1123 case she'd better know what she's doing. */ 1124 1125 if (PC_IN_CALL_DUMMY (stop_pc, read_sp (), FRAME_FP (get_current_frame ())) 1126 && !step_range_end) 1127 { 1128 stop_print_frame = 0; 1129 stop_stack_dummy = 1; 1130 #ifdef HP_OS_BUG 1131 trap_expected_after_continue = 1; 1132 #endif 1133 break; 1134 } 1135 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */ 1136 1137 if (step_resume_breakpoint) 1138 /* Having a step-resume breakpoint overrides anything 1139 else having to do with stepping commands until 1140 that breakpoint is reached. */ 1141 /* I'm not sure whether this needs to be check_sigtramp2 or 1142 whether it could/should be keep_going. */ 1143 goto check_sigtramp2; 1144 1145 if (step_range_end == 0) 1146 /* Likewise if we aren't even stepping. */ 1147 /* I'm not sure whether this needs to be check_sigtramp2 or 1148 whether it could/should be keep_going. */ 1149 goto check_sigtramp2; 1150 1151 /* If stepping through a line, keep going if still within it. */ 1152 if (stop_pc >= step_range_start 1153 && stop_pc < step_range_end 1154 #if 0 1155 /* I haven't a clue what might trigger this clause, and it seems wrong anyway, 1156 so I've disabled it until someone complains. -Stu 10/24/95 */ 1157 1158 /* The step range might include the start of the 1159 function, so if we are at the start of the 1160 step range and either the stack or frame pointers 1161 just changed, we've stepped outside */ 1162 && !(stop_pc == step_range_start 1163 && FRAME_FP (get_current_frame ()) 1164 && (read_sp () INNER_THAN step_sp 1165 || FRAME_FP (get_current_frame ()) != step_frame_address)) 1166 #endif 1167 ) 1168 { 1169 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal. 1170 So definately need to check for sigtramp here. */ 1171 goto check_sigtramp2; 1172 } 1173 1174 /* We stepped out of the stepping range. */ 1175 1176 /* We can't update step_sp every time through the loop, because 1177 reading the stack pointer would slow down stepping too much. 1178 But we can update it every time we leave the step range. */ 1179 update_step_sp = 1; 1180 1181 /* Did we just take a signal? */ 1182 if (IN_SIGTRAMP (stop_pc, stop_func_name) 1183 && !IN_SIGTRAMP (prev_pc, prev_func_name) 1184 && read_sp () INNER_THAN step_sp) 1185 { 1186 /* We've just taken a signal; go until we are back to 1187 the point where we took it and one more. */ 1188 1189 /* This code is needed at least in the following case: 1190 The user types "next" and then a signal arrives (before 1191 the "next" is done). */ 1192 1193 /* Note that if we are stopped at a breakpoint, then we need 1194 the step_resume breakpoint to override any breakpoints at 1195 the same location, so that we will still step over the 1196 breakpoint even though the signal happened. */ 1197 1198 { 1199 struct symtab_and_line sr_sal; 1200 1201 sr_sal.pc = prev_pc; 1202 sr_sal.symtab = NULL; 1203 sr_sal.line = 0; 1204 /* We could probably be setting the frame to 1205 step_frame_address; I don't think anyone thought to try it. */ 1206 step_resume_breakpoint = 1207 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); 1208 if (breakpoints_inserted) 1209 insert_breakpoints (); 1210 } 1211 1212 /* If this is stepi or nexti, make sure that the stepping range 1213 gets us past that instruction. */ 1214 if (step_range_end == 1) 1215 /* FIXME: Does this run afoul of the code below which, if 1216 we step into the middle of a line, resets the stepping 1217 range? */ 1218 step_range_end = (step_range_start = prev_pc) + 1; 1219 1220 remove_breakpoints_on_following_step = 1; 1221 goto keep_going; 1222 } 1223 1224 #if 0 1225 /* I disabled this test because it was too complicated and slow. The 1226 SKIP_PROLOGUE was especially slow, because it caused unnecessary 1227 prologue examination on various architectures. The code in the #else 1228 clause has been tested on the Sparc, Mips, PA, and Power 1229 architectures, so it's pretty likely to be correct. -Stu 10/24/95 */ 1230 1231 /* See if we left the step range due to a subroutine call that 1232 we should proceed to the end of. */ 1233 1234 if (stop_func_start) 1235 { 1236 struct symtab *s; 1237 1238 /* Do this after the IN_SIGTRAMP check; it might give 1239 an error. */ 1240 prologue_pc = stop_func_start; 1241 1242 /* Don't skip the prologue if this is assembly source */ 1243 s = find_pc_symtab (stop_pc); 1244 if (s && s->language != language_asm) 1245 SKIP_PROLOGUE (prologue_pc); 1246 } 1247 1248 if (!(step_sp INNER_THAN read_sp ()) /* don't mistake (sig)return as a call */ 1249 && (/* Might be a non-recursive call. If the symbols are missing 1250 enough that stop_func_start == prev_func_start even though 1251 they are really two functions, we will treat some calls as 1252 jumps. */ 1253 stop_func_start != prev_func_start 1254 1255 /* Might be a recursive call if either we have a prologue 1256 or the call instruction itself saves the PC on the stack. */ 1257 || prologue_pc != stop_func_start 1258 || read_sp () != step_sp) 1259 && (/* PC is completely out of bounds of any known objfiles. Treat 1260 like a subroutine call. */ 1261 ! stop_func_start 1262 1263 /* If we do a call, we will be at the start of a function... */ 1264 || stop_pc == stop_func_start 1265 1266 /* ...except on the Alpha with -O (and also Irix 5 and 1267 perhaps others), in which we might call the address 1268 after the load of gp. Since prologues don't contain 1269 calls, we can't return to within one, and we don't 1270 jump back into them, so this check is OK. */ 1271 1272 || stop_pc < prologue_pc 1273 1274 /* ...and if it is a leaf function, the prologue might 1275 consist of gp loading only, so the call transfers to 1276 the first instruction after the prologue. */ 1277 || (stop_pc == prologue_pc 1278 1279 /* Distinguish this from the case where we jump back 1280 to the first instruction after the prologue, 1281 within a function. */ 1282 && stop_func_start != prev_func_start) 1283 1284 /* If we end up in certain places, it means we did a subroutine 1285 call. I'm not completely sure this is necessary now that we 1286 have the above checks with stop_func_start (and now that 1287 find_pc_partial_function is pickier). */ 1288 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name) 1289 1290 /* If none of the above apply, it is a jump within a function, 1291 or a return from a subroutine. The other case is longjmp, 1292 which can no longer happen here as long as the 1293 handling_longjmp stuff is working. */ 1294 )) 1295 #else 1296 /* This test is a much more streamlined, (but hopefully correct) 1297 replacement for the code above. It's been tested on the Sparc, 1298 Mips, PA, and Power architectures with good results. */ 1299 1300 if (stop_pc == stop_func_start /* Quick test */ 1301 || in_prologue (stop_pc, stop_func_start) 1302 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name) 1303 || stop_func_start == 0) 1304 #endif 1305 1306 { 1307 /* It's a subroutine call. */ 1308 1309 if (step_over_calls == 0) 1310 { 1311 /* I presume that step_over_calls is only 0 when we're 1312 supposed to be stepping at the assembly language level 1313 ("stepi"). Just stop. */ 1314 stop_step = 1; 1315 break; 1316 } 1317 1318 if (step_over_calls > 0) 1319 /* We're doing a "next". */ 1320 goto step_over_function; 1321 1322 /* If we are in a function call trampoline (a stub between 1323 the calling routine and the real function), locate the real 1324 function. That's what tells us (a) whether we want to step 1325 into it at all, and (b) what prologue we want to run to 1326 the end of, if we do step into it. */ 1327 tmp = SKIP_TRAMPOLINE_CODE (stop_pc); 1328 if (tmp != 0) 1329 stop_func_start = tmp; 1330 else 1331 { 1332 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc); 1333 if (tmp) 1334 { 1335 struct symtab_and_line xxx; 1336 1337 xxx.pc = tmp; 1338 xxx.symtab = NULL; 1339 xxx.line = 0; 1340 step_resume_breakpoint = 1341 set_momentary_breakpoint (xxx, NULL, bp_step_resume); 1342 insert_breakpoints (); 1343 goto keep_going; 1344 } 1345 } 1346 1347 /* If we have line number information for the function we 1348 are thinking of stepping into, step into it. 1349 1350 If there are several symtabs at that PC (e.g. with include 1351 files), just want to know whether *any* of them have line 1352 numbers. find_pc_line handles this. */ 1353 { 1354 struct symtab_and_line tmp_sal; 1355 1356 tmp_sal = find_pc_line (stop_func_start, 0); 1357 if (tmp_sal.line != 0) 1358 goto step_into_function; 1359 } 1360 1361 step_over_function: 1362 /* A subroutine call has happened. */ 1363 { 1364 /* Set a special breakpoint after the return */ 1365 struct symtab_and_line sr_sal; 1366 sr_sal.pc = 1367 ADDR_BITS_REMOVE 1368 (SAVED_PC_AFTER_CALL (get_current_frame ())); 1369 sr_sal.symtab = NULL; 1370 sr_sal.line = 0; 1371 step_resume_breakpoint = 1372 set_momentary_breakpoint (sr_sal, get_current_frame (), 1373 bp_step_resume); 1374 step_resume_breakpoint->frame = step_frame_address; 1375 if (breakpoints_inserted) 1376 insert_breakpoints (); 1377 } 1378 goto keep_going; 1379 1380 step_into_function: 1381 /* Subroutine call with source code we should not step over. 1382 Do step to the first line of code in it. */ 1383 { 1384 struct symtab *s; 1385 1386 s = find_pc_symtab (stop_pc); 1387 if (s && s->language != language_asm) 1388 SKIP_PROLOGUE (stop_func_start); 1389 } 1390 sal = find_pc_line (stop_func_start, 0); 1391 /* Use the step_resume_break to step until 1392 the end of the prologue, even if that involves jumps 1393 (as it seems to on the vax under 4.2). */ 1394 /* If the prologue ends in the middle of a source line, 1395 continue to the end of that source line (if it is still 1396 within the function). Otherwise, just go to end of prologue. */ 1397 #ifdef PROLOGUE_FIRSTLINE_OVERLAP 1398 /* no, don't either. It skips any code that's 1399 legitimately on the first line. */ 1400 #else 1401 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end) 1402 stop_func_start = sal.end; 1403 #endif 1404 1405 if (stop_func_start == stop_pc) 1406 { 1407 /* We are already there: stop now. */ 1408 stop_step = 1; 1409 break; 1410 } 1411 else 1412 /* Put the step-breakpoint there and go until there. */ 1413 { 1414 struct symtab_and_line sr_sal; 1415 1416 sr_sal.pc = stop_func_start; 1417 sr_sal.symtab = NULL; 1418 sr_sal.line = 0; 1419 /* Do not specify what the fp should be when we stop 1420 since on some machines the prologue 1421 is where the new fp value is established. */ 1422 step_resume_breakpoint = 1423 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); 1424 if (breakpoints_inserted) 1425 insert_breakpoints (); 1426 1427 /* And make sure stepping stops right away then. */ 1428 step_range_end = step_range_start; 1429 } 1430 goto keep_going; 1431 } 1432 1433 /* We've wandered out of the step range. */ 1434 1435 sal = find_pc_line(stop_pc, 0); 1436 1437 if (step_range_end == 1) 1438 { 1439 /* It is stepi or nexti. We always want to stop stepping after 1440 one instruction. */ 1441 stop_step = 1; 1442 break; 1443 } 1444 1445 /* If we're in the return path from a shared library trampoline, 1446 we want to proceed through the trampoline when stepping. */ 1447 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name)) 1448 { 1449 CORE_ADDR tmp; 1450 1451 /* Determine where this trampoline returns. */ 1452 tmp = SKIP_TRAMPOLINE_CODE (stop_pc); 1453 1454 /* Only proceed through if we know where it's going. */ 1455 if (tmp) 1456 { 1457 /* And put the step-breakpoint there and go until there. */ 1458 struct symtab_and_line sr_sal; 1459 1460 sr_sal.pc = tmp; 1461 sr_sal.symtab = NULL; 1462 sr_sal.line = 0; 1463 /* Do not specify what the fp should be when we stop 1464 since on some machines the prologue 1465 is where the new fp value is established. */ 1466 step_resume_breakpoint = 1467 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); 1468 if (breakpoints_inserted) 1469 insert_breakpoints (); 1470 1471 /* Restart without fiddling with the step ranges or 1472 other state. */ 1473 goto keep_going; 1474 } 1475 } 1476 1477 if (sal.line == 0) 1478 { 1479 /* We have no line number information. That means to stop 1480 stepping (does this always happen right after one instruction, 1481 when we do "s" in a function with no line numbers, 1482 or can this happen as a result of a return or longjmp?). */ 1483 stop_step = 1; 1484 break; 1485 } 1486 1487 if (stop_pc == sal.pc 1488 && (current_line != sal.line || current_symtab != sal.symtab)) 1489 { 1490 /* We are at the start of a different line. So stop. Note that 1491 we don't stop if we step into the middle of a different line. 1492 That is said to make things like for (;;) statements work 1493 better. */ 1494 stop_step = 1; 1495 break; 1496 } 1497 1498 /* We aren't done stepping. 1499 1500 Optimize by setting the stepping range to the line. 1501 (We might not be in the original line, but if we entered a 1502 new line in mid-statement, we continue stepping. This makes 1503 things like for(;;) statements work better.) */ 1504 1505 if (stop_func_end && sal.end >= stop_func_end) 1506 { 1507 /* If this is the last line of the function, don't keep stepping 1508 (it would probably step us out of the function). 1509 This is particularly necessary for a one-line function, 1510 in which after skipping the prologue we better stop even though 1511 we will be in mid-line. */ 1512 stop_step = 1; 1513 break; 1514 } 1515 step_range_start = sal.pc; 1516 step_range_end = sal.end; 1517 step_frame_address = FRAME_FP (get_current_frame ()); 1518 current_line = sal.line; 1519 current_symtab = sal.symtab; 1520 goto keep_going; 1521 1522 check_sigtramp2: 1523 if (trap_expected 1524 && IN_SIGTRAMP (stop_pc, stop_func_name) 1525 && !IN_SIGTRAMP (prev_pc, prev_func_name) 1526 && read_sp () INNER_THAN step_sp) 1527 { 1528 /* What has happened here is that we have just stepped the inferior 1529 with a signal (because it is a signal which shouldn't make 1530 us stop), thus stepping into sigtramp. 1531 1532 So we need to set a step_resume_break_address breakpoint 1533 and continue until we hit it, and then step. FIXME: This should 1534 be more enduring than a step_resume breakpoint; we should know 1535 that we will later need to keep going rather than re-hitting 1536 the breakpoint here (see testsuite/gdb.t06/signals.exp where 1537 it says "exceedingly difficult"). */ 1538 struct symtab_and_line sr_sal; 1539 1540 sr_sal.pc = prev_pc; 1541 sr_sal.symtab = NULL; 1542 sr_sal.line = 0; 1543 /* We perhaps could set the frame if we kept track of what 1544 the frame corresponding to prev_pc was. But we don't, 1545 so don't. */ 1546 through_sigtramp_breakpoint = 1547 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp); 1548 if (breakpoints_inserted) 1549 insert_breakpoints (); 1550 1551 remove_breakpoints_on_following_step = 1; 1552 another_trap = 1; 1553 } 1554 1555 keep_going: 1556 /* Come to this label when you need to resume the inferior. 1557 It's really much cleaner to do a goto than a maze of if-else 1558 conditions. */ 1559 1560 /* Save the pc before execution, to compare with pc after stop. */ 1561 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ 1562 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER 1563 BREAK is defined, the 1564 original pc would not have 1565 been at the start of a 1566 function. */ 1567 prev_func_name = stop_func_name; 1568 1569 if (update_step_sp) 1570 step_sp = read_sp (); 1571 update_step_sp = 0; 1572 1573 /* If we did not do break;, it means we should keep 1574 running the inferior and not return to debugger. */ 1575 1576 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) 1577 { 1578 /* We took a signal (which we are supposed to pass through to 1579 the inferior, else we'd have done a break above) and we 1580 haven't yet gotten our trap. Simply continue. */ 1581 resume (CURRENTLY_STEPPING (), stop_signal); 1582 } 1583 else 1584 { 1585 /* Either the trap was not expected, but we are continuing 1586 anyway (the user asked that this signal be passed to the 1587 child) 1588 -- or -- 1589 The signal was SIGTRAP, e.g. it was our signal, but we 1590 decided we should resume from it. 1591 1592 We're going to run this baby now! 1593 1594 Insert breakpoints now, unless we are trying 1595 to one-proceed past a breakpoint. */ 1596 /* If we've just finished a special step resume and we don't 1597 want to hit a breakpoint, pull em out. */ 1598 if (step_resume_breakpoint == NULL 1599 && through_sigtramp_breakpoint == NULL 1600 && remove_breakpoints_on_following_step) 1601 { 1602 remove_breakpoints_on_following_step = 0; 1603 remove_breakpoints (); 1604 breakpoints_inserted = 0; 1605 } 1606 else if (!breakpoints_inserted && 1607 (through_sigtramp_breakpoint != NULL || !another_trap)) 1608 { 1609 breakpoints_failed = insert_breakpoints (); 1610 if (breakpoints_failed) 1611 break; 1612 breakpoints_inserted = 1; 1613 } 1614 1615 trap_expected = another_trap; 1616 1617 if (stop_signal == TARGET_SIGNAL_TRAP) 1618 stop_signal = TARGET_SIGNAL_0; 1619 1620 #ifdef SHIFT_INST_REGS 1621 /* I'm not sure when this following segment applies. I do know, now, 1622 that we shouldn't rewrite the regs when we were stopped by a 1623 random signal from the inferior process. */ 1624 /* FIXME: Shouldn't this be based on the valid bit of the SXIP? 1625 (this is only used on the 88k). */ 1626 1627 if (!bpstat_explains_signal (stop_bpstat) 1628 && (stop_signal != TARGET_SIGNAL_CHLD) 1629 && !stopped_by_random_signal) 1630 SHIFT_INST_REGS(); 1631 #endif /* SHIFT_INST_REGS */ 1632 1633 resume (CURRENTLY_STEPPING (), stop_signal); 1634 } 1635 } 1636 1637 stop_stepping: 1638 if (target_has_execution) 1639 { 1640 /* Assuming the inferior still exists, set these up for next 1641 time, just like we did above if we didn't break out of the 1642 loop. */ 1643 prev_pc = read_pc (); 1644 prev_func_start = stop_func_start; 1645 prev_func_name = stop_func_name; 1646 } 1647 do_cleanups (old_cleanups); 1648 } 1649 1650 /* Here to return control to GDB when the inferior stops for real. 1651 Print appropriate messages, remove breakpoints, give terminal our modes. 1652 1653 STOP_PRINT_FRAME nonzero means print the executing frame 1654 (pc, function, args, file, line number and line text). 1655 BREAKPOINTS_FAILED nonzero means stop was due to error 1656 attempting to insert breakpoints. */ 1657 1658 void 1659 normal_stop () 1660 { 1661 /* Make sure that the current_frame's pc is correct. This 1662 is a correction for setting up the frame info before doing 1663 DECR_PC_AFTER_BREAK */ 1664 if (target_has_execution && get_current_frame()) 1665 (get_current_frame ())->pc = read_pc (); 1666 1667 if (breakpoints_failed) 1668 { 1669 target_terminal_ours_for_output (); 1670 print_sys_errmsg ("ptrace", breakpoints_failed); 1671 printf_filtered ("Stopped; cannot insert breakpoints.\n\ 1672 The same program may be running in another process.\n"); 1673 } 1674 1675 if (target_has_execution && breakpoints_inserted) 1676 if (remove_breakpoints ()) 1677 { 1678 target_terminal_ours_for_output (); 1679 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\ 1680 It might be running in another process.\n\ 1681 Further execution is probably impossible.\n"); 1682 } 1683 1684 breakpoints_inserted = 0; 1685 1686 /* Delete the breakpoint we stopped at, if it wants to be deleted. 1687 Delete any breakpoint that is to be deleted at the next stop. */ 1688 1689 breakpoint_auto_delete (stop_bpstat); 1690 1691 /* If an auto-display called a function and that got a signal, 1692 delete that auto-display to avoid an infinite recursion. */ 1693 1694 if (stopped_by_random_signal) 1695 disable_current_display (); 1696 1697 if (step_multi && stop_step) 1698 goto done; 1699 1700 target_terminal_ours (); 1701 1702 if (stop_bpstat 1703 && stop_bpstat->breakpoint_at 1704 && stop_bpstat->breakpoint_at->type == bp_shlib_event) 1705 printf_filtered ("Stopped due to shared library event\n"); 1706 1707 /* Look up the hook_stop and run it if it exists. */ 1708 1709 if (stop_command->hook) 1710 { 1711 catch_errors (hook_stop_stub, (char *)stop_command->hook, 1712 "Error while running hook_stop:\n", RETURN_MASK_ALL); 1713 } 1714 1715 if (!target_has_stack) 1716 goto done; 1717 1718 /* Select innermost stack frame except on return from a stack dummy routine, 1719 or if the program has exited. Print it without a level number if 1720 we have changed functions or hit a breakpoint. Print source line 1721 if we have one. */ 1722 if (!stop_stack_dummy) 1723 { 1724 select_frame (get_current_frame (), 0); 1725 1726 if (stop_print_frame) 1727 { 1728 int source_only; 1729 1730 source_only = bpstat_print (stop_bpstat); 1731 source_only = source_only || 1732 ( stop_step 1733 && step_frame_address == FRAME_FP (get_current_frame ()) 1734 && step_start_function == find_pc_function (stop_pc)); 1735 1736 print_stack_frame (selected_frame, -1, source_only? -1: 1); 1737 1738 /* Display the auto-display expressions. */ 1739 do_displays (); 1740 } 1741 } 1742 1743 /* Save the function value return registers, if we care. 1744 We might be about to restore their previous contents. */ 1745 if (proceed_to_finish) 1746 read_register_bytes (0, stop_registers, REGISTER_BYTES); 1747 1748 if (stop_stack_dummy) 1749 { 1750 /* Pop the empty frame that contains the stack dummy. 1751 POP_FRAME ends with a setting of the current frame, so we 1752 can use that next. */ 1753 POP_FRAME; 1754 /* Set stop_pc to what it was before we called the function. Can't rely 1755 on restore_inferior_status because that only gets called if we don't 1756 stop in the called function. */ 1757 stop_pc = read_pc(); 1758 select_frame (get_current_frame (), 0); 1759 } 1760 done: 1761 annotate_stopped (); 1762 } 1763 1764 static int 1765 hook_stop_stub (cmd) 1766 char *cmd; 1767 { 1768 execute_user_command ((struct cmd_list_element *)cmd, 0); 1769 return (0); 1770 } 1771 1772 int signal_stop_state (signo) 1773 int signo; 1774 { 1775 return signal_stop[signo]; 1776 } 1777 1778 int signal_print_state (signo) 1779 int signo; 1780 { 1781 return signal_print[signo]; 1782 } 1783 1784 int signal_pass_state (signo) 1785 int signo; 1786 { 1787 return signal_program[signo]; 1788 } 1789 1790 static void 1791 sig_print_header () 1792 { 1793 printf_filtered ("\ 1794 Signal Stop\tPrint\tPass to program\tDescription\n"); 1795 } 1796 1797 static void 1798 sig_print_info (oursig) 1799 enum target_signal oursig; 1800 { 1801 char *name = target_signal_to_name (oursig); 1802 printf_filtered ("%s", name); 1803 printf_filtered ("%*.*s ", 13 - strlen (name), 13 - strlen (name), 1804 " "); 1805 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); 1806 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); 1807 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); 1808 printf_filtered ("%s\n", target_signal_to_string (oursig)); 1809 } 1810 1811 /* Specify how various signals in the inferior should be handled. */ 1812 1813 static void 1814 handle_command (args, from_tty) 1815 char *args; 1816 int from_tty; 1817 { 1818 char **argv; 1819 int digits, wordlen; 1820 int sigfirst, signum, siglast; 1821 enum target_signal oursig; 1822 int allsigs; 1823 int nsigs; 1824 unsigned char *sigs; 1825 struct cleanup *old_chain; 1826 1827 if (args == NULL) 1828 { 1829 error_no_arg ("signal to handle"); 1830 } 1831 1832 /* Allocate and zero an array of flags for which signals to handle. */ 1833 1834 nsigs = (int)TARGET_SIGNAL_LAST; 1835 sigs = (unsigned char *) alloca (nsigs); 1836 memset (sigs, 0, nsigs); 1837 1838 /* Break the command line up into args. */ 1839 1840 argv = buildargv (args); 1841 if (argv == NULL) 1842 { 1843 nomem (0); 1844 } 1845 old_chain = make_cleanup (freeargv, (char *) argv); 1846 1847 /* Walk through the args, looking for signal oursigs, signal names, and 1848 actions. Signal numbers and signal names may be interspersed with 1849 actions, with the actions being performed for all signals cumulatively 1850 specified. Signal ranges can be specified as <LOW>-<HIGH>. */ 1851 1852 while (*argv != NULL) 1853 { 1854 wordlen = strlen (*argv); 1855 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;} 1856 allsigs = 0; 1857 sigfirst = siglast = -1; 1858 1859 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) 1860 { 1861 /* Apply action to all signals except those used by the 1862 debugger. Silently skip those. */ 1863 allsigs = 1; 1864 sigfirst = 0; 1865 siglast = nsigs - 1; 1866 } 1867 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) 1868 { 1869 SET_SIGS (nsigs, sigs, signal_stop); 1870 SET_SIGS (nsigs, sigs, signal_print); 1871 } 1872 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) 1873 { 1874 UNSET_SIGS (nsigs, sigs, signal_program); 1875 } 1876 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) 1877 { 1878 SET_SIGS (nsigs, sigs, signal_print); 1879 } 1880 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) 1881 { 1882 SET_SIGS (nsigs, sigs, signal_program); 1883 } 1884 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) 1885 { 1886 UNSET_SIGS (nsigs, sigs, signal_stop); 1887 } 1888 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) 1889 { 1890 SET_SIGS (nsigs, sigs, signal_program); 1891 } 1892 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) 1893 { 1894 UNSET_SIGS (nsigs, sigs, signal_print); 1895 UNSET_SIGS (nsigs, sigs, signal_stop); 1896 } 1897 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) 1898 { 1899 UNSET_SIGS (nsigs, sigs, signal_program); 1900 } 1901 else if (digits > 0) 1902 { 1903 /* It is numeric. The numeric signal refers to our own internal 1904 signal numbering from target.h, not to host/target signal number. 1905 This is a feature; users really should be using symbolic names 1906 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc. 1907 will work right anyway. */ 1908 1909 sigfirst = siglast = (int) target_signal_from_command (atoi (*argv)); 1910 if ((*argv)[digits] == '-') 1911 { 1912 siglast = 1913 (int) target_signal_from_command (atoi ((*argv) + digits + 1)); 1914 } 1915 if (sigfirst > siglast) 1916 { 1917 /* Bet he didn't figure we'd think of this case... */ 1918 signum = sigfirst; 1919 sigfirst = siglast; 1920 siglast = signum; 1921 } 1922 } 1923 else 1924 { 1925 oursig = target_signal_from_name (*argv); 1926 if (oursig != TARGET_SIGNAL_UNKNOWN) 1927 { 1928 sigfirst = siglast = (int)oursig; 1929 } 1930 else 1931 { 1932 /* Not a number and not a recognized flag word => complain. */ 1933 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); 1934 } 1935 } 1936 1937 /* If any signal numbers or symbol names were found, set flags for 1938 which signals to apply actions to. */ 1939 1940 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) 1941 { 1942 switch ((enum target_signal)signum) 1943 { 1944 case TARGET_SIGNAL_TRAP: 1945 case TARGET_SIGNAL_INT: 1946 if (!allsigs && !sigs[signum]) 1947 { 1948 if (query ("%s is used by the debugger.\n\ 1949 Are you sure you want to change it? ", 1950 target_signal_to_name 1951 ((enum target_signal)signum))) 1952 { 1953 sigs[signum] = 1; 1954 } 1955 else 1956 { 1957 printf_unfiltered ("Not confirmed, unchanged.\n"); 1958 gdb_flush (gdb_stdout); 1959 } 1960 } 1961 break; 1962 case TARGET_SIGNAL_0: 1963 case TARGET_SIGNAL_DEFAULT: 1964 case TARGET_SIGNAL_UNKNOWN: 1965 /* Make sure that "all" doesn't print these. */ 1966 break; 1967 default: 1968 sigs[signum] = 1; 1969 break; 1970 } 1971 } 1972 1973 argv++; 1974 } 1975 1976 target_notice_signals(inferior_pid); 1977 1978 if (from_tty) 1979 { 1980 /* Show the results. */ 1981 sig_print_header (); 1982 for (signum = 0; signum < nsigs; signum++) 1983 { 1984 if (sigs[signum]) 1985 { 1986 sig_print_info (signum); 1987 } 1988 } 1989 } 1990 1991 do_cleanups (old_chain); 1992 } 1993 1994 /* Print current contents of the tables set by the handle command. 1995 It is possible we should just be printing signals actually used 1996 by the current target (but for things to work right when switching 1997 targets, all signals should be in the signal tables). */ 1998 1999 static void 2000 signals_info (signum_exp, from_tty) 2001 char *signum_exp; 2002 int from_tty; 2003 { 2004 enum target_signal oursig; 2005 sig_print_header (); 2006 2007 if (signum_exp) 2008 { 2009 /* First see if this is a symbol name. */ 2010 oursig = target_signal_from_name (signum_exp); 2011 if (oursig == TARGET_SIGNAL_UNKNOWN) 2012 { 2013 /* No, try numeric. */ 2014 oursig = 2015 target_signal_from_command (parse_and_eval_address (signum_exp)); 2016 } 2017 sig_print_info (oursig); 2018 return; 2019 } 2020 2021 printf_filtered ("\n"); 2022 /* These ugly casts brought to you by the native VAX compiler. */ 2023 for (oursig = TARGET_SIGNAL_FIRST; 2024 (int)oursig < (int)TARGET_SIGNAL_LAST; 2025 oursig = (enum target_signal)((int)oursig + 1)) 2026 { 2027 QUIT; 2028 2029 if (oursig != TARGET_SIGNAL_UNKNOWN 2030 && oursig != TARGET_SIGNAL_DEFAULT 2031 && oursig != TARGET_SIGNAL_0) 2032 sig_print_info (oursig); 2033 } 2034 2035 printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); 2036 } 2037 2038 /* Save all of the information associated with the inferior<==>gdb 2039 connection. INF_STATUS is a pointer to a "struct inferior_status" 2040 (defined in inferior.h). */ 2041 2042 void 2043 save_inferior_status (inf_status, restore_stack_info) 2044 struct inferior_status *inf_status; 2045 int restore_stack_info; 2046 { 2047 inf_status->stop_signal = stop_signal; 2048 inf_status->stop_pc = stop_pc; 2049 inf_status->stop_step = stop_step; 2050 inf_status->stop_stack_dummy = stop_stack_dummy; 2051 inf_status->stopped_by_random_signal = stopped_by_random_signal; 2052 inf_status->trap_expected = trap_expected; 2053 inf_status->step_range_start = step_range_start; 2054 inf_status->step_range_end = step_range_end; 2055 inf_status->step_frame_address = step_frame_address; 2056 inf_status->step_over_calls = step_over_calls; 2057 inf_status->stop_after_trap = stop_after_trap; 2058 inf_status->stop_soon_quietly = stop_soon_quietly; 2059 /* Save original bpstat chain here; replace it with copy of chain. 2060 If caller's caller is walking the chain, they'll be happier if we 2061 hand them back the original chain when restore_i_s is called. */ 2062 inf_status->stop_bpstat = stop_bpstat; 2063 stop_bpstat = bpstat_copy (stop_bpstat); 2064 inf_status->breakpoint_proceeded = breakpoint_proceeded; 2065 inf_status->restore_stack_info = restore_stack_info; 2066 inf_status->proceed_to_finish = proceed_to_finish; 2067 2068 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES); 2069 2070 read_register_bytes (0, inf_status->registers, REGISTER_BYTES); 2071 2072 record_selected_frame (&(inf_status->selected_frame_address), 2073 &(inf_status->selected_level)); 2074 return; 2075 } 2076 2077 struct restore_selected_frame_args { 2078 CORE_ADDR frame_address; 2079 int level; 2080 }; 2081 2082 static int restore_selected_frame PARAMS ((char *)); 2083 2084 /* Restore the selected frame. args is really a struct 2085 restore_selected_frame_args * (declared as char * for catch_errors) 2086 telling us what frame to restore. Returns 1 for success, or 0 for 2087 failure. An error message will have been printed on error. */ 2088 2089 static int 2090 restore_selected_frame (args) 2091 char *args; 2092 { 2093 struct restore_selected_frame_args *fr = 2094 (struct restore_selected_frame_args *) args; 2095 struct frame_info *frame; 2096 int level = fr->level; 2097 2098 frame = find_relative_frame (get_current_frame (), &level); 2099 2100 /* If inf_status->selected_frame_address is NULL, there was no 2101 previously selected frame. */ 2102 if (frame == NULL || 2103 FRAME_FP (frame) != fr->frame_address || 2104 level != 0) 2105 { 2106 warning ("Unable to restore previously selected frame.\n"); 2107 return 0; 2108 } 2109 select_frame (frame, fr->level); 2110 return(1); 2111 } 2112 2113 void 2114 restore_inferior_status (inf_status) 2115 struct inferior_status *inf_status; 2116 { 2117 stop_signal = inf_status->stop_signal; 2118 stop_pc = inf_status->stop_pc; 2119 stop_step = inf_status->stop_step; 2120 stop_stack_dummy = inf_status->stop_stack_dummy; 2121 stopped_by_random_signal = inf_status->stopped_by_random_signal; 2122 trap_expected = inf_status->trap_expected; 2123 step_range_start = inf_status->step_range_start; 2124 step_range_end = inf_status->step_range_end; 2125 step_frame_address = inf_status->step_frame_address; 2126 step_over_calls = inf_status->step_over_calls; 2127 stop_after_trap = inf_status->stop_after_trap; 2128 stop_soon_quietly = inf_status->stop_soon_quietly; 2129 bpstat_clear (&stop_bpstat); 2130 stop_bpstat = inf_status->stop_bpstat; 2131 breakpoint_proceeded = inf_status->breakpoint_proceeded; 2132 proceed_to_finish = inf_status->proceed_to_finish; 2133 2134 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES); 2135 2136 /* The inferior can be gone if the user types "print exit(0)" 2137 (and perhaps other times). */ 2138 if (target_has_execution) 2139 write_register_bytes (0, inf_status->registers, REGISTER_BYTES); 2140 2141 /* The inferior can be gone if the user types "print exit(0)" 2142 (and perhaps other times). */ 2143 2144 /* FIXME: If we are being called after stopping in a function which 2145 is called from gdb, we should not be trying to restore the 2146 selected frame; it just prints a spurious error message (The 2147 message is useful, however, in detecting bugs in gdb (like if gdb 2148 clobbers the stack)). In fact, should we be restoring the 2149 inferior status at all in that case? . */ 2150 2151 if (target_has_stack && inf_status->restore_stack_info) 2152 { 2153 struct restore_selected_frame_args fr; 2154 fr.level = inf_status->selected_level; 2155 fr.frame_address = inf_status->selected_frame_address; 2156 /* The point of catch_errors is that if the stack is clobbered, 2157 walking the stack might encounter a garbage pointer and error() 2158 trying to dereference it. */ 2159 if (catch_errors (restore_selected_frame, &fr, 2160 "Unable to restore previously selected frame:\n", 2161 RETURN_MASK_ERROR) == 0) 2162 /* Error in restoring the selected frame. Select the innermost 2163 frame. */ 2164 select_frame (get_current_frame (), 0); 2165 } 2166 } 2167 2168 2169 void 2170 _initialize_infrun () 2171 { 2172 register int i; 2173 register int numsigs; 2174 2175 add_info ("signals", signals_info, 2176 "What debugger does when program gets various signals.\n\ 2177 Specify a signal as argument to print info on that signal only."); 2178 add_info_alias ("handle", "signals", 0); 2179 2180 add_com ("handle", class_run, handle_command, 2181 concat ("Specify how to handle a signal.\n\ 2182 Args are signals and actions to apply to those signals.\n\ 2183 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ 2184 from 1-15 are allowed for compatibility with old versions of GDB.\n\ 2185 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ 2186 The special arg \"all\" is recognized to mean all signals except those\n\ 2187 used by the debugger, typically SIGTRAP and SIGINT.\n", 2188 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ 2189 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ 2190 Stop means reenter debugger if this signal happens (implies print).\n\ 2191 Print means print a message if this signal happens.\n\ 2192 Pass means let program see this signal; otherwise program doesn't know.\n\ 2193 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ 2194 Pass and Stop may be combined.", NULL)); 2195 2196 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command, 2197 "There is no `stop' command, but you can set a hook on `stop'.\n\ 2198 This allows you to set a list of commands to be run each time execution\n\ 2199 of the program stops.", &cmdlist); 2200 2201 numsigs = (int)TARGET_SIGNAL_LAST; 2202 signal_stop = (unsigned char *) 2203 xmalloc (sizeof (signal_stop[0]) * numsigs); 2204 signal_print = (unsigned char *) 2205 xmalloc (sizeof (signal_print[0]) * numsigs); 2206 signal_program = (unsigned char *) 2207 xmalloc (sizeof (signal_program[0]) * numsigs); 2208 for (i = 0; i < numsigs; i++) 2209 { 2210 signal_stop[i] = 1; 2211 signal_print[i] = 1; 2212 signal_program[i] = 1; 2213 } 2214 2215 /* Signals caused by debugger's own actions 2216 should not be given to the program afterwards. */ 2217 signal_program[TARGET_SIGNAL_TRAP] = 0; 2218 signal_program[TARGET_SIGNAL_INT] = 0; 2219 2220 /* Signals that are not errors should not normally enter the debugger. */ 2221 signal_stop[TARGET_SIGNAL_ALRM] = 0; 2222 signal_print[TARGET_SIGNAL_ALRM] = 0; 2223 signal_stop[TARGET_SIGNAL_VTALRM] = 0; 2224 signal_print[TARGET_SIGNAL_VTALRM] = 0; 2225 signal_stop[TARGET_SIGNAL_PROF] = 0; 2226 signal_print[TARGET_SIGNAL_PROF] = 0; 2227 signal_stop[TARGET_SIGNAL_CHLD] = 0; 2228 signal_print[TARGET_SIGNAL_CHLD] = 0; 2229 signal_stop[TARGET_SIGNAL_IO] = 0; 2230 signal_print[TARGET_SIGNAL_IO] = 0; 2231 signal_stop[TARGET_SIGNAL_POLL] = 0; 2232 signal_print[TARGET_SIGNAL_POLL] = 0; 2233 signal_stop[TARGET_SIGNAL_URG] = 0; 2234 signal_print[TARGET_SIGNAL_URG] = 0; 2235 2236 #ifdef SOLIB_ADD 2237 add_show_from_set 2238 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger, 2239 (char *) &stop_on_solib_events, 2240 "Set stopping for shared library events.\n\ 2241 If nonzero, gdb will give control to the user when the dynamic linker\n\ 2242 notifies gdb of shared library events. The most common event of interest\n\ 2243 to the user would be loading/unloading of a new library.\n", 2244 &setlist), 2245 &showlist); 2246 #endif 2247 } 2248