198944Sobrien/* Target-struct-independent code to start (run) and stop an inferior 298944Sobrien process. 319370Spst 498944Sobrien Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 5130803Smarcel 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free 6130803Smarcel Software Foundation, Inc. 719370Spst 898944Sobrien This file is part of GDB. 919370Spst 1098944Sobrien This program is free software; you can redistribute it and/or modify 1198944Sobrien it under the terms of the GNU General Public License as published by 1298944Sobrien the Free Software Foundation; either version 2 of the License, or 1398944Sobrien (at your option) any later version. 1419370Spst 1598944Sobrien This program is distributed in the hope that it will be useful, 1698944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1798944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1898944Sobrien GNU General Public License for more details. 1919370Spst 2098944Sobrien You should have received a copy of the GNU General Public License 2198944Sobrien along with this program; if not, write to the Free Software 2298944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2398944Sobrien Boston, MA 02111-1307, USA. */ 2498944Sobrien 2519370Spst#include "defs.h" 2619370Spst#include "gdb_string.h" 2719370Spst#include <ctype.h> 2819370Spst#include "symtab.h" 2919370Spst#include "frame.h" 3019370Spst#include "inferior.h" 3119370Spst#include "breakpoint.h" 3298944Sobrien#include "gdb_wait.h" 3319370Spst#include "gdbcore.h" 3419370Spst#include "gdbcmd.h" 3598944Sobrien#include "cli/cli-script.h" 3619370Spst#include "target.h" 3746283Sdfr#include "gdbthread.h" 3819370Spst#include "annotate.h" 3998944Sobrien#include "symfile.h" 4098944Sobrien#include "top.h" 4119370Spst#include <signal.h> 4298944Sobrien#include "inf-loop.h" 4398944Sobrien#include "regcache.h" 4498944Sobrien#include "value.h" 45130803Smarcel#include "observer.h" 46130803Smarcel#include "language.h" 47130803Smarcel#include "gdb_assert.h" 4819370Spst 4919370Spst/* Prototypes for local functions */ 5019370Spst 5198944Sobrienstatic void signals_info (char *, int); 5219370Spst 5398944Sobrienstatic void handle_command (char *, int); 5419370Spst 5598944Sobrienstatic void sig_print_info (enum target_signal); 5619370Spst 5798944Sobrienstatic void sig_print_header (void); 5819370Spst 5998944Sobrienstatic void resume_cleanups (void *); 6019370Spst 6198944Sobrienstatic int hook_stop_stub (void *); 6219370Spst 6398944Sobrienstatic void delete_breakpoint_current_contents (void *); 6446283Sdfr 6598944Sobrienstatic int restore_selected_frame (void *); 6698944Sobrien 6798944Sobrienstatic void build_infrun (void); 6898944Sobrien 69130803Smarcelstatic int follow_fork (void); 7098944Sobrien 7198944Sobrienstatic void set_schedlock_func (char *args, int from_tty, 72130803Smarcel struct cmd_list_element *c); 7398944Sobrien 7498944Sobrienstruct execution_control_state; 7598944Sobrien 7698944Sobrienstatic int currently_stepping (struct execution_control_state *ecs); 7798944Sobrien 7898944Sobrienstatic void xdb_handle_command (char *args, int from_tty); 7998944Sobrien 80130803Smarcelstatic int prepare_to_proceed (void); 81130803Smarcel 8298944Sobrienvoid _initialize_infrun (void); 8398944Sobrien 8446283Sdfrint inferior_ignoring_startup_exec_events = 0; 8546283Sdfrint inferior_ignoring_leading_exec_events = 0; 8646283Sdfr 8798944Sobrien/* When set, stop the 'step' command if we enter a function which has 8898944Sobrien no line number information. The normal behavior is that we step 8998944Sobrien over such function. */ 9098944Sobrienint step_stop_if_no_debug = 0; 9146283Sdfr 9298944Sobrien/* In asynchronous mode, but simulating synchronous execution. */ 9346283Sdfr 9498944Sobrienint sync_execution = 0; 9546283Sdfr 9698944Sobrien/* wait_for_inferior and normal_stop use this to notify the user 9798944Sobrien when the inferior stopped in a different thread than it had been 9898944Sobrien running in. */ 9946283Sdfr 10098944Sobrienstatic ptid_t previous_inferior_ptid; 10146283Sdfr 10298944Sobrien/* This is true for configurations that may follow through execl() and 10398944Sobrien similar functions. At present this is only true for HP-UX native. */ 10419370Spst 10598944Sobrien#ifndef MAY_FOLLOW_EXEC 10698944Sobrien#define MAY_FOLLOW_EXEC (0) 10719370Spst#endif 10819370Spst 10998944Sobrienstatic int may_follow_exec = MAY_FOLLOW_EXEC; 11019370Spst 11198944Sobrien/* If the program uses ELF-style shared libraries, then calls to 11298944Sobrien functions in shared libraries go through stubs, which live in a 11398944Sobrien table called the PLT (Procedure Linkage Table). The first time the 11498944Sobrien function is called, the stub sends control to the dynamic linker, 11598944Sobrien which looks up the function's real address, patches the stub so 11698944Sobrien that future calls will go directly to the function, and then passes 11798944Sobrien control to the function. 11846283Sdfr 11998944Sobrien If we are stepping at the source level, we don't want to see any of 12098944Sobrien this --- we just want to skip over the stub and the dynamic linker. 12198944Sobrien The simple approach is to single-step until control leaves the 12298944Sobrien dynamic linker. 12398944Sobrien 12498944Sobrien However, on some systems (e.g., Red Hat's 5.2 distribution) the 12598944Sobrien dynamic linker calls functions in the shared C library, so you 12698944Sobrien can't tell from the PC alone whether the dynamic linker is still 12798944Sobrien running. In this case, we use a step-resume breakpoint to get us 12898944Sobrien past the dynamic linker, as if we were using "next" to step over a 12998944Sobrien function call. 13098944Sobrien 13198944Sobrien IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic 13298944Sobrien linker code or not. Normally, this means we single-step. However, 13398944Sobrien if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an 13498944Sobrien address where we can place a step-resume breakpoint to get past the 13598944Sobrien linker's symbol resolution function. 13698944Sobrien 13798944Sobrien IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a 13898944Sobrien pretty portable way, by comparing the PC against the address ranges 13998944Sobrien of the dynamic linker's sections. 14098944Sobrien 14198944Sobrien SKIP_SOLIB_RESOLVER is generally going to be system-specific, since 14298944Sobrien it depends on internal details of the dynamic linker. It's usually 14398944Sobrien not too hard to figure out where to put a breakpoint, but it 14498944Sobrien certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of 14598944Sobrien sanity checking. If it can't figure things out, returning zero and 14698944Sobrien getting the (possibly confusing) stepping behavior is better than 14798944Sobrien signalling an error, which will obscure the change in the 14898944Sobrien inferior's state. */ 14998944Sobrien 15046283Sdfr#ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE 15146283Sdfr#define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0 15246283Sdfr#endif 15346283Sdfr 15446283Sdfr/* This function returns TRUE if pc is the address of an instruction 15546283Sdfr that lies within the dynamic linker (such as the event hook, or the 15646283Sdfr dld itself). 15746283Sdfr 15846283Sdfr This function must be used only when a dynamic linker event has 15946283Sdfr been caught, and the inferior is being stepped out of the hook, or 16046283Sdfr undefined results are guaranteed. */ 16146283Sdfr 16246283Sdfr#ifndef SOLIB_IN_DYNAMIC_LINKER 16346283Sdfr#define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 16446283Sdfr#endif 16546283Sdfr 16646283Sdfr/* On MIPS16, a function that returns a floating point value may call 16746283Sdfr a library helper function to copy the return value to a floating point 16846283Sdfr register. The IGNORE_HELPER_CALL macro returns non-zero if we 16946283Sdfr should ignore (i.e. step over) this function call. */ 17046283Sdfr#ifndef IGNORE_HELPER_CALL 17146283Sdfr#define IGNORE_HELPER_CALL(pc) 0 17246283Sdfr#endif 17346283Sdfr 17419370Spst/* On some systems, the PC may be left pointing at an instruction that won't 17519370Spst actually be executed. This is usually indicated by a bit in the PSW. If 17619370Spst we find ourselves in such a state, then we step the target beyond the 17719370Spst nullified instruction before returning control to the user so as to avoid 17819370Spst confusion. */ 17919370Spst 18019370Spst#ifndef INSTRUCTION_NULLIFIED 18119370Spst#define INSTRUCTION_NULLIFIED 0 18219370Spst#endif 18319370Spst 18498944Sobrien/* We can't step off a permanent breakpoint in the ordinary way, because we 18598944Sobrien can't remove it. Instead, we have to advance the PC to the next 18698944Sobrien instruction. This macro should expand to a pointer to a function that 18798944Sobrien does that, or zero if we have no such function. If we don't have a 18898944Sobrien definition for it, we have to report an error. */ 189130803Smarcel#ifndef SKIP_PERMANENT_BREAKPOINT 19098944Sobrien#define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint) 19198944Sobrienstatic void 19298944Sobriendefault_skip_permanent_breakpoint (void) 19398944Sobrien{ 19498944Sobrien error ("\ 19598944SobrienThe program is stopped at a permanent breakpoint, but GDB does not know\n\ 19698944Sobrienhow to step past a permanent breakpoint on this architecture. Try using\n\ 19798944Sobriena command like `return' or `jump' to continue execution."); 19898944Sobrien} 19998944Sobrien#endif 20098944Sobrien 201130803Smarcel 20298944Sobrien/* Convert the #defines into values. This is temporary until wfi control 20398944Sobrien flow is completely sorted out. */ 20498944Sobrien 20598944Sobrien#ifndef HAVE_STEPPABLE_WATCHPOINT 20698944Sobrien#define HAVE_STEPPABLE_WATCHPOINT 0 20798944Sobrien#else 20898944Sobrien#undef HAVE_STEPPABLE_WATCHPOINT 20998944Sobrien#define HAVE_STEPPABLE_WATCHPOINT 1 21098944Sobrien#endif 21198944Sobrien 21298944Sobrien#ifndef CANNOT_STEP_HW_WATCHPOINTS 21398944Sobrien#define CANNOT_STEP_HW_WATCHPOINTS 0 21498944Sobrien#else 21598944Sobrien#undef CANNOT_STEP_HW_WATCHPOINTS 21698944Sobrien#define CANNOT_STEP_HW_WATCHPOINTS 1 21798944Sobrien#endif 21898944Sobrien 21919370Spst/* Tables of how to react to signals; the user sets them. */ 22019370Spst 22119370Spststatic unsigned char *signal_stop; 22219370Spststatic unsigned char *signal_print; 22319370Spststatic unsigned char *signal_program; 22419370Spst 22519370Spst#define SET_SIGS(nsigs,sigs,flags) \ 22619370Spst do { \ 22719370Spst int signum = (nsigs); \ 22819370Spst while (signum-- > 0) \ 22919370Spst if ((sigs)[signum]) \ 23019370Spst (flags)[signum] = 1; \ 23119370Spst } while (0) 23219370Spst 23319370Spst#define UNSET_SIGS(nsigs,sigs,flags) \ 23419370Spst do { \ 23519370Spst int signum = (nsigs); \ 23619370Spst while (signum-- > 0) \ 23719370Spst if ((sigs)[signum]) \ 23819370Spst (flags)[signum] = 0; \ 23919370Spst } while (0) 24019370Spst 24198944Sobrien/* Value to pass to target_resume() to cause all threads to resume */ 24219370Spst 24398944Sobrien#define RESUME_ALL (pid_to_ptid (-1)) 24498944Sobrien 24519370Spst/* Command list pointer for the "stop" placeholder. */ 24619370Spst 24719370Spststatic struct cmd_list_element *stop_command; 24819370Spst 24919370Spst/* Nonzero if breakpoints are now inserted in the inferior. */ 25019370Spst 25119370Spststatic int breakpoints_inserted; 25219370Spst 25319370Spst/* Function inferior was in as of last step command. */ 25419370Spst 25519370Spststatic struct symbol *step_start_function; 25619370Spst 25719370Spst/* Nonzero if we are expecting a trace trap and should proceed from it. */ 25819370Spst 25919370Spststatic int trap_expected; 26019370Spst 26146283Sdfr#ifdef SOLIB_ADD 26219370Spst/* Nonzero if we want to give control to the user when we're notified 26319370Spst of shared library events by the dynamic linker. */ 26419370Spststatic int stop_on_solib_events; 26546283Sdfr#endif 26619370Spst 26719370Spst#ifdef HP_OS_BUG 26819370Spst/* Nonzero if the next time we try to continue the inferior, it will 26919370Spst step one instruction and generate a spurious trace trap. 27019370Spst This is used to compensate for a bug in HP-UX. */ 27119370Spst 27219370Spststatic int trap_expected_after_continue; 27319370Spst#endif 27419370Spst 27519370Spst/* Nonzero means expecting a trace trap 27619370Spst and should stop the inferior and return silently when it happens. */ 27719370Spst 27819370Spstint stop_after_trap; 27919370Spst 28019370Spst/* Nonzero means expecting a trap and caller will handle it themselves. 28119370Spst It is used after attach, due to attaching to a process; 28219370Spst when running in the shell before the child program has been exec'd; 28319370Spst and when running some kinds of remote stuff (FIXME?). */ 28419370Spst 285130803Smarcelenum stop_kind stop_soon; 28619370Spst 28719370Spst/* Nonzero if proceed is being used for a "finish" command or a similar 28819370Spst situation when stop_registers should be saved. */ 28919370Spst 29019370Spstint proceed_to_finish; 29119370Spst 29219370Spst/* Save register contents here when about to pop a stack dummy frame, 29319370Spst if-and-only-if proceed_to_finish is set. 29419370Spst Thus this contains the return value from the called function (assuming 29519370Spst values are returned in a register). */ 29619370Spst 297130803Smarcelstruct regcache *stop_registers; 29819370Spst 29919370Spst/* Nonzero if program stopped due to error trying to insert breakpoints. */ 30019370Spst 30119370Spststatic int breakpoints_failed; 30219370Spst 30319370Spst/* Nonzero after stop if current stack frame should be printed. */ 30419370Spst 30519370Spststatic int stop_print_frame; 30619370Spst 30746283Sdfrstatic struct breakpoint *step_resume_breakpoint = NULL; 30846283Sdfrstatic struct breakpoint *through_sigtramp_breakpoint = NULL; 30919370Spst 31046283Sdfr/* On some platforms (e.g., HP-UX), hardware watchpoints have bad 31146283Sdfr interactions with an inferior that is running a kernel function 31246283Sdfr (aka, a system call or "syscall"). wait_for_inferior therefore 31346283Sdfr may have a need to know when the inferior is in a syscall. This 31446283Sdfr is a count of the number of inferior threads which are known to 31546283Sdfr currently be running in a syscall. */ 31646283Sdfrstatic int number_of_threads_in_syscalls; 31719370Spst 31898944Sobrien/* This is a cached copy of the pid/waitstatus of the last event 31998944Sobrien returned by target_wait()/target_wait_hook(). This information is 32098944Sobrien returned by get_last_target_status(). */ 32198944Sobrienstatic ptid_t target_last_wait_ptid; 32298944Sobrienstatic struct target_waitstatus target_last_waitstatus; 32398944Sobrien 32446283Sdfr/* This is used to remember when a fork, vfork or exec event 32546283Sdfr was caught by a catchpoint, and thus the event is to be 32646283Sdfr followed at the next resume of the inferior, and not 32746283Sdfr immediately. */ 32846283Sdfrstatic struct 329130803Smarcel{ 330130803Smarcel enum target_waitkind kind; 331130803Smarcel struct 33246283Sdfr { 333130803Smarcel int parent_pid; 334130803Smarcel int child_pid; 33546283Sdfr } 336130803Smarcel fork_event; 337130803Smarcel char *execd_pathname; 338130803Smarcel} 33946283Sdfrpending_follow; 34046283Sdfr 34198944Sobrienstatic const char follow_fork_mode_child[] = "child"; 34298944Sobrienstatic const char follow_fork_mode_parent[] = "parent"; 34398944Sobrien 344130803Smarcelstatic const char *follow_fork_mode_kind_names[] = { 34598944Sobrien follow_fork_mode_child, 34698944Sobrien follow_fork_mode_parent, 34798944Sobrien NULL 34898944Sobrien}; 34946283Sdfr 35098944Sobrienstatic const char *follow_fork_mode_string = follow_fork_mode_parent; 35119370Spst 35246283Sdfr 353130803Smarcelstatic int 354130803Smarcelfollow_fork (void) 35546283Sdfr{ 356130803Smarcel int follow_child = (follow_fork_mode_string == follow_fork_mode_child); 35746283Sdfr 358130803Smarcel return target_follow_fork (follow_child); 35946283Sdfr} 36046283Sdfr 361130803Smarcelvoid 362130803Smarcelfollow_inferior_reset_breakpoints (void) 36346283Sdfr{ 364130803Smarcel /* Was there a step_resume breakpoint? (There was if the user 365130803Smarcel did a "next" at the fork() call.) If so, explicitly reset its 366130803Smarcel thread number. 36746283Sdfr 368130803Smarcel step_resumes are a form of bp that are made to be per-thread. 369130803Smarcel Since we created the step_resume bp when the parent process 370130803Smarcel was being debugged, and now are switching to the child process, 371130803Smarcel from the breakpoint package's viewpoint, that's a switch of 372130803Smarcel "threads". We must update the bp's notion of which thread 373130803Smarcel it is for, or it'll be ignored when it triggers. */ 37446283Sdfr 375130803Smarcel if (step_resume_breakpoint) 376130803Smarcel breakpoint_re_set_thread (step_resume_breakpoint); 37746283Sdfr 378130803Smarcel /* Reinsert all breakpoints in the child. The user may have set 379130803Smarcel breakpoints after catching the fork, in which case those 380130803Smarcel were never set in the child, but only in the parent. This makes 381130803Smarcel sure the inserted breakpoints match the breakpoint list. */ 38246283Sdfr 383130803Smarcel breakpoint_re_set (); 384130803Smarcel insert_breakpoints (); 38546283Sdfr} 38646283Sdfr 38798944Sobrien/* EXECD_PATHNAME is assumed to be non-NULL. */ 38898944Sobrien 38946283Sdfrstatic void 39098944Sobrienfollow_exec (int pid, char *execd_pathname) 39146283Sdfr{ 39246283Sdfr int saved_pid = pid; 39398944Sobrien struct target_ops *tgt; 39446283Sdfr 39598944Sobrien if (!may_follow_exec) 39698944Sobrien return; 39798944Sobrien 39846283Sdfr /* This is an exec event that we actually wish to pay attention to. 39946283Sdfr Refresh our symbol table to the newly exec'd program, remove any 40046283Sdfr momentary bp's, etc. 40146283Sdfr 40246283Sdfr If there are breakpoints, they aren't really inserted now, 40346283Sdfr since the exec() transformed our inferior into a fresh set 40446283Sdfr of instructions. 40546283Sdfr 40646283Sdfr We want to preserve symbolic breakpoints on the list, since 40746283Sdfr we have hopes that they can be reset after the new a.out's 40846283Sdfr symbol table is read. 40946283Sdfr 41046283Sdfr However, any "raw" breakpoints must be removed from the list 41146283Sdfr (e.g., the solib bp's), since their address is probably invalid 41246283Sdfr now. 41346283Sdfr 41446283Sdfr And, we DON'T want to call delete_breakpoints() here, since 41546283Sdfr that may write the bp's "shadow contents" (the instruction 41646283Sdfr value that was overwritten witha TRAP instruction). Since 41746283Sdfr we now have a new a.out, those shadow contents aren't valid. */ 41846283Sdfr update_breakpoints_after_exec (); 41946283Sdfr 42046283Sdfr /* If there was one, it's gone now. We cannot truly step-to-next 42146283Sdfr statement through an exec(). */ 42246283Sdfr step_resume_breakpoint = NULL; 42346283Sdfr step_range_start = 0; 42446283Sdfr step_range_end = 0; 42546283Sdfr 42646283Sdfr /* If there was one, it's gone now. */ 42746283Sdfr through_sigtramp_breakpoint = NULL; 42846283Sdfr 42946283Sdfr /* What is this a.out's name? */ 43046283Sdfr printf_unfiltered ("Executing new program: %s\n", execd_pathname); 43146283Sdfr 43246283Sdfr /* We've followed the inferior through an exec. Therefore, the 43346283Sdfr inferior has essentially been killed & reborn. */ 43498944Sobrien 43598944Sobrien /* First collect the run target in effect. */ 43698944Sobrien tgt = find_run_target (); 43798944Sobrien /* If we can't find one, things are in a very strange state... */ 43898944Sobrien if (tgt == NULL) 43998944Sobrien error ("Could find run target to save before following exec"); 44098944Sobrien 44146283Sdfr gdb_flush (gdb_stdout); 44246283Sdfr target_mourn_inferior (); 44398944Sobrien inferior_ptid = pid_to_ptid (saved_pid); 444130803Smarcel /* Because mourn_inferior resets inferior_ptid. */ 44598944Sobrien push_target (tgt); 44646283Sdfr 44746283Sdfr /* That a.out is now the one to use. */ 44846283Sdfr exec_file_attach (execd_pathname, 0); 44946283Sdfr 45046283Sdfr /* And also is where symbols can be found. */ 45198944Sobrien symbol_file_add_main (execd_pathname, 0); 45246283Sdfr 45346283Sdfr /* Reset the shared library package. This ensures that we get 45446283Sdfr a shlib event when the child reaches "_start", at which point 45546283Sdfr the dld will have had a chance to initialize the child. */ 45698944Sobrien#if defined(SOLIB_RESTART) 45746283Sdfr SOLIB_RESTART (); 45898944Sobrien#endif 45998944Sobrien#ifdef SOLIB_CREATE_INFERIOR_HOOK 46098944Sobrien SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); 46198944Sobrien#endif 46246283Sdfr 46346283Sdfr /* Reinsert all breakpoints. (Those which were symbolic have 46446283Sdfr been reset to the proper address in the new a.out, thanks 46546283Sdfr to symbol_file_command...) */ 46646283Sdfr insert_breakpoints (); 46746283Sdfr 46846283Sdfr /* The next resume of this inferior should bring it to the shlib 46946283Sdfr startup breakpoints. (If the user had also set bp's on 47046283Sdfr "main" from the old (parent) process, then they'll auto- 47146283Sdfr matically get reset there in the new process.) */ 47246283Sdfr} 47346283Sdfr 47446283Sdfr/* Non-zero if we just simulating a single-step. This is needed 47546283Sdfr because we cannot remove the breakpoints in the inferior process 47646283Sdfr until after the `wait' in `wait_for_inferior'. */ 47746283Sdfrstatic int singlestep_breakpoints_inserted_p = 0; 478130803Smarcel 479130803Smarcel/* The thread we inserted single-step breakpoints for. */ 480130803Smarcelstatic ptid_t singlestep_ptid; 481130803Smarcel 482130803Smarcel/* If another thread hit the singlestep breakpoint, we save the original 483130803Smarcel thread here so that we can resume single-stepping it later. */ 484130803Smarcelstatic ptid_t saved_singlestep_ptid; 485130803Smarcelstatic int stepping_past_singlestep_breakpoint; 48646283Sdfr 48746283Sdfr 48819370Spst/* Things to clean up if we QUIT out of resume (). */ 48919370Spststatic void 49098944Sobrienresume_cleanups (void *ignore) 49119370Spst{ 49219370Spst normal_stop (); 49319370Spst} 49419370Spst 49598944Sobrienstatic const char schedlock_off[] = "off"; 49698944Sobrienstatic const char schedlock_on[] = "on"; 49798944Sobrienstatic const char schedlock_step[] = "step"; 49898944Sobrienstatic const char *scheduler_mode = schedlock_off; 499130803Smarcelstatic const char *scheduler_enums[] = { 50098944Sobrien schedlock_off, 50198944Sobrien schedlock_on, 50298944Sobrien schedlock_step, 50398944Sobrien NULL 50498944Sobrien}; 50546283Sdfr 50646283Sdfrstatic void 50798944Sobrienset_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) 50846283Sdfr{ 509130803Smarcel /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones 510130803Smarcel the set command passed as a parameter. The clone operation will 511130803Smarcel include (BUG?) any ``set'' command callback, if present. 512130803Smarcel Commands like ``info set'' call all the ``show'' command 513130803Smarcel callbacks. Unfortunately, for ``show'' commands cloned from 514130803Smarcel ``set'', this includes callbacks belonging to ``set'' commands. 515130803Smarcel Making this worse, this only occures if add_show_from_set() is 516130803Smarcel called after add_cmd_sfunc() (BUG?). */ 517130803Smarcel if (cmd_type (c) == set_cmd) 51846283Sdfr if (!target_can_lock_scheduler) 51946283Sdfr { 52046283Sdfr scheduler_mode = schedlock_off; 521130803Smarcel error ("Target '%s' cannot support this command.", target_shortname); 52246283Sdfr } 52346283Sdfr} 52446283Sdfr 52546283Sdfr 52619370Spst/* Resume the inferior, but allow a QUIT. This is useful if the user 52719370Spst wants to interrupt some lengthy single-stepping operation 52819370Spst (for child processes, the SIGINT goes to the inferior, and so 52919370Spst we get a SIGINT random_signal, but for remote debugging and perhaps 53019370Spst other targets, that's not true). 53119370Spst 53219370Spst STEP nonzero if we should step (zero to continue instead). 53319370Spst SIG is the signal to give the inferior (zero for none). */ 53419370Spstvoid 53598944Sobrienresume (int step, enum target_signal sig) 53619370Spst{ 53746283Sdfr int should_resume = 1; 53898944Sobrien struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); 53919370Spst QUIT; 54019370Spst 54198944Sobrien /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */ 54219370Spst 54398944Sobrien 54498944Sobrien /* Some targets (e.g. Solaris x86) have a kernel bug when stepping 54598944Sobrien over an instruction that causes a page fault without triggering 54698944Sobrien a hardware watchpoint. The kernel properly notices that it shouldn't 54798944Sobrien stop, because the hardware watchpoint is not triggered, but it forgets 54898944Sobrien the step request and continues the program normally. 54998944Sobrien Work around the problem by removing hardware watchpoints if a step is 55098944Sobrien requested, GDB will check for a hardware watchpoint trigger after the 55198944Sobrien step anyway. */ 55298944Sobrien if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted) 55398944Sobrien remove_hw_watchpoints (); 55498944Sobrien 555130803Smarcel 55698944Sobrien /* Normally, by the time we reach `resume', the breakpoints are either 55798944Sobrien removed or inserted, as appropriate. The exception is if we're sitting 55898944Sobrien at a permanent breakpoint; we need to step over it, but permanent 55998944Sobrien breakpoints can't be removed. So we have to test for it here. */ 56098944Sobrien if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here) 56198944Sobrien SKIP_PERMANENT_BREAKPOINT (); 56298944Sobrien 56398944Sobrien if (SOFTWARE_SINGLE_STEP_P () && step) 56446283Sdfr { 56546283Sdfr /* Do it the hard way, w/temp breakpoints */ 56698944Sobrien SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ ); 56746283Sdfr /* ...and don't ask hardware to do it. */ 56846283Sdfr step = 0; 56946283Sdfr /* and do not pull these breakpoints until after a `wait' in 57046283Sdfr `wait_for_inferior' */ 57146283Sdfr singlestep_breakpoints_inserted_p = 1; 572130803Smarcel singlestep_ptid = inferior_ptid; 57346283Sdfr } 57419370Spst 57519370Spst /* Handle any optimized stores to the inferior NOW... */ 57619370Spst#ifdef DO_DEFERRED_STORES 57719370Spst DO_DEFERRED_STORES; 57819370Spst#endif 57919370Spst 58046283Sdfr /* If there were any forks/vforks/execs that were caught and are 581130803Smarcel now to be followed, then do so. */ 58246283Sdfr switch (pending_follow.kind) 58346283Sdfr { 584130803Smarcel case TARGET_WAITKIND_FORKED: 585130803Smarcel case TARGET_WAITKIND_VFORKED: 58646283Sdfr pending_follow.kind = TARGET_WAITKIND_SPURIOUS; 587130803Smarcel if (follow_fork ()) 588130803Smarcel should_resume = 0; 58946283Sdfr break; 59046283Sdfr 591130803Smarcel case TARGET_WAITKIND_EXECD: 592130803Smarcel /* follow_exec is called as soon as the exec event is seen. */ 59346283Sdfr pending_follow.kind = TARGET_WAITKIND_SPURIOUS; 59446283Sdfr break; 59546283Sdfr 59646283Sdfr default: 59746283Sdfr break; 59846283Sdfr } 59946283Sdfr 60019370Spst /* Install inferior's terminal modes. */ 60119370Spst target_terminal_inferior (); 60219370Spst 60346283Sdfr if (should_resume) 60446283Sdfr { 60598944Sobrien ptid_t resume_ptid; 60698944Sobrien 607130803Smarcel resume_ptid = RESUME_ALL; /* Default */ 60898944Sobrien 60998944Sobrien if ((step || singlestep_breakpoints_inserted_p) && 610130803Smarcel (stepping_past_singlestep_breakpoint 611130803Smarcel || (!breakpoints_inserted && breakpoint_here_p (read_pc ())))) 61246283Sdfr { 61398944Sobrien /* Stepping past a breakpoint without inserting breakpoints. 61498944Sobrien Make sure only the current thread gets to step, so that 61598944Sobrien other threads don't sneak past breakpoints while they are 61698944Sobrien not inserted. */ 61746283Sdfr 61898944Sobrien resume_ptid = inferior_ptid; 61998944Sobrien } 62046283Sdfr 62198944Sobrien if ((scheduler_mode == schedlock_on) || 622130803Smarcel (scheduler_mode == schedlock_step && 62398944Sobrien (step || singlestep_breakpoints_inserted_p))) 62498944Sobrien { 62598944Sobrien /* User-settable 'scheduler' mode requires solo thread resume. */ 626130803Smarcel resume_ptid = inferior_ptid; 62746283Sdfr } 62846283Sdfr 629130803Smarcel if (CANNOT_STEP_BREAKPOINT) 630130803Smarcel { 631130803Smarcel /* Most targets can step a breakpoint instruction, thus 632130803Smarcel executing it normally. But if this one cannot, just 633130803Smarcel continue and we will hit it anyway. */ 634130803Smarcel if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) 635130803Smarcel step = 0; 636130803Smarcel } 63798944Sobrien target_resume (resume_ptid, step, sig); 63846283Sdfr } 63946283Sdfr 64019370Spst discard_cleanups (old_cleanups); 64119370Spst} 64246283Sdfr 64319370Spst 64419370Spst/* Clear out all variables saying what to do when inferior is continued. 64519370Spst First do this, then set the ones you want, then call `proceed'. */ 64619370Spst 64719370Spstvoid 64898944Sobrienclear_proceed_status (void) 64919370Spst{ 65019370Spst trap_expected = 0; 65119370Spst step_range_start = 0; 65219370Spst step_range_end = 0; 653130803Smarcel step_frame_id = null_frame_id; 65498944Sobrien step_over_calls = STEP_OVER_UNDEBUGGABLE; 65519370Spst stop_after_trap = 0; 656130803Smarcel stop_soon = NO_STOP_QUIETLY; 65719370Spst proceed_to_finish = 0; 65819370Spst breakpoint_proceeded = 1; /* We're about to proceed... */ 65919370Spst 66019370Spst /* Discard any remaining commands or status from previous stop. */ 66119370Spst bpstat_clear (&stop_bpstat); 66219370Spst} 66319370Spst 664130803Smarcel/* This should be suitable for any targets that support threads. */ 665130803Smarcel 666130803Smarcelstatic int 667130803Smarcelprepare_to_proceed (void) 668130803Smarcel{ 669130803Smarcel ptid_t wait_ptid; 670130803Smarcel struct target_waitstatus wait_status; 671130803Smarcel 672130803Smarcel /* Get the last target status returned by target_wait(). */ 673130803Smarcel get_last_target_status (&wait_ptid, &wait_status); 674130803Smarcel 675130803Smarcel /* Make sure we were stopped either at a breakpoint, or because 676130803Smarcel of a Ctrl-C. */ 677130803Smarcel if (wait_status.kind != TARGET_WAITKIND_STOPPED 678130803Smarcel || (wait_status.value.sig != TARGET_SIGNAL_TRAP && 679130803Smarcel wait_status.value.sig != TARGET_SIGNAL_INT)) 680130803Smarcel { 681130803Smarcel return 0; 682130803Smarcel } 683130803Smarcel 684130803Smarcel if (!ptid_equal (wait_ptid, minus_one_ptid) 685130803Smarcel && !ptid_equal (inferior_ptid, wait_ptid)) 686130803Smarcel { 687130803Smarcel /* Switched over from WAIT_PID. */ 688130803Smarcel CORE_ADDR wait_pc = read_pc_pid (wait_ptid); 689130803Smarcel 690130803Smarcel if (wait_pc != read_pc ()) 691130803Smarcel { 692130803Smarcel /* Switch back to WAIT_PID thread. */ 693130803Smarcel inferior_ptid = wait_ptid; 694130803Smarcel 695130803Smarcel /* FIXME: This stuff came from switch_to_thread() in 696130803Smarcel thread.c (which should probably be a public function). */ 697130803Smarcel flush_cached_frames (); 698130803Smarcel registers_changed (); 699130803Smarcel stop_pc = wait_pc; 700130803Smarcel select_frame (get_current_frame ()); 701130803Smarcel } 702130803Smarcel 703130803Smarcel /* We return 1 to indicate that there is a breakpoint here, 704130803Smarcel so we need to step over it before continuing to avoid 705130803Smarcel hitting it straight away. */ 706130803Smarcel if (breakpoint_here_p (wait_pc)) 707130803Smarcel return 1; 708130803Smarcel } 709130803Smarcel 710130803Smarcel return 0; 711130803Smarcel 712130803Smarcel} 713130803Smarcel 714130803Smarcel/* Record the pc of the program the last time it stopped. This is 715130803Smarcel just used internally by wait_for_inferior, but need to be preserved 716130803Smarcel over calls to it and cleared when the inferior is started. */ 717130803Smarcelstatic CORE_ADDR prev_pc; 718130803Smarcel 71919370Spst/* Basic routine for continuing the program in various fashions. 72019370Spst 72119370Spst ADDR is the address to resume at, or -1 for resume where stopped. 72219370Spst SIGGNAL is the signal to give it, or 0 for none, 72398944Sobrien or -1 for act according to how it stopped. 72419370Spst STEP is nonzero if should trap after one instruction. 72598944Sobrien -1 means return after that and print nothing. 72698944Sobrien You should probably set various step_... variables 72798944Sobrien before calling here, if you are stepping. 72819370Spst 72919370Spst You should call clear_proceed_status before calling proceed. */ 73019370Spst 73119370Spstvoid 73298944Sobrienproceed (CORE_ADDR addr, enum target_signal siggnal, int step) 73319370Spst{ 73419370Spst int oneproc = 0; 73519370Spst 73619370Spst if (step > 0) 73719370Spst step_start_function = find_pc_function (read_pc ()); 73819370Spst if (step < 0) 73919370Spst stop_after_trap = 1; 74019370Spst 74198944Sobrien if (addr == (CORE_ADDR) -1) 74219370Spst { 74319370Spst /* If there is a breakpoint at the address we will resume at, 74498944Sobrien step one instruction before inserting breakpoints 74598944Sobrien so that we do not stop right away (and report a second 74646283Sdfr hit at this breakpoint). */ 74719370Spst 74846283Sdfr if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) 74919370Spst oneproc = 1; 75019370Spst 75146283Sdfr#ifndef STEP_SKIPS_DELAY 75246283Sdfr#define STEP_SKIPS_DELAY(pc) (0) 75346283Sdfr#define STEP_SKIPS_DELAY_P (0) 75446283Sdfr#endif 75519370Spst /* Check breakpoint_here_p first, because breakpoint_here_p is fast 75698944Sobrien (it just checks internal GDB data structures) and STEP_SKIPS_DELAY 75798944Sobrien is slow (it needs to read memory from the target). */ 75846283Sdfr if (STEP_SKIPS_DELAY_P 75946283Sdfr && breakpoint_here_p (read_pc () + 4) 76019370Spst && STEP_SKIPS_DELAY (read_pc ())) 76119370Spst oneproc = 1; 76219370Spst } 76319370Spst else 76446283Sdfr { 76546283Sdfr write_pc (addr); 76646283Sdfr } 76746283Sdfr 76846283Sdfr /* In a multi-threaded task we may select another thread 76946283Sdfr and then continue or step. 77019370Spst 77146283Sdfr But if the old thread was stopped at a breakpoint, it 77246283Sdfr will immediately cause another breakpoint stop without 77346283Sdfr any execution (i.e. it will report a breakpoint hit 77446283Sdfr incorrectly). So we must step over it first. 77519370Spst 776130803Smarcel prepare_to_proceed checks the current thread against the thread 77746283Sdfr that reported the most recent event. If a step-over is required 77846283Sdfr it returns TRUE and sets the current thread to the old thread. */ 779130803Smarcel if (prepare_to_proceed () && breakpoint_here_p (read_pc ())) 780130803Smarcel oneproc = 1; 78146283Sdfr 78219370Spst#ifdef HP_OS_BUG 78319370Spst if (trap_expected_after_continue) 78419370Spst { 78519370Spst /* If (step == 0), a trap will be automatically generated after 78698944Sobrien the first instruction is executed. Force step one 78798944Sobrien instruction to clear this condition. This should not occur 78898944Sobrien if step is nonzero, but it is harmless in that case. */ 78919370Spst oneproc = 1; 79019370Spst trap_expected_after_continue = 0; 79119370Spst } 79219370Spst#endif /* HP_OS_BUG */ 79319370Spst 79419370Spst if (oneproc) 79519370Spst /* We will get a trace trap after one instruction. 79619370Spst Continue it automatically and insert breakpoints then. */ 79719370Spst trap_expected = 1; 79819370Spst else 79919370Spst { 800130803Smarcel insert_breakpoints (); 801130803Smarcel /* If we get here there was no call to error() in 802130803Smarcel insert breakpoints -- so they were inserted. */ 80319370Spst breakpoints_inserted = 1; 80419370Spst } 80519370Spst 80619370Spst if (siggnal != TARGET_SIGNAL_DEFAULT) 80719370Spst stop_signal = siggnal; 80819370Spst /* If this signal should not be seen by program, 80919370Spst give it zero. Used for debugging signals. */ 81019370Spst else if (!signal_program[stop_signal]) 81119370Spst stop_signal = TARGET_SIGNAL_0; 81219370Spst 81319370Spst annotate_starting (); 81419370Spst 81519370Spst /* Make sure that output from GDB appears before output from the 81619370Spst inferior. */ 81719370Spst gdb_flush (gdb_stdout); 81819370Spst 819130803Smarcel /* Refresh prev_pc value just prior to resuming. This used to be 820130803Smarcel done in stop_stepping, however, setting prev_pc there did not handle 821130803Smarcel scenarios such as inferior function calls or returning from 822130803Smarcel a function via the return command. In those cases, the prev_pc 823130803Smarcel value was not set properly for subsequent commands. The prev_pc value 824130803Smarcel is used to initialize the starting line number in the ecs. With an 825130803Smarcel invalid value, the gdb next command ends up stopping at the position 826130803Smarcel represented by the next line table entry past our start position. 827130803Smarcel On platforms that generate one line table entry per line, this 828130803Smarcel is not a problem. However, on the ia64, the compiler generates 829130803Smarcel extraneous line table entries that do not increase the line number. 830130803Smarcel When we issue the gdb next command on the ia64 after an inferior call 831130803Smarcel or a return command, we often end up a few instructions forward, still 832130803Smarcel within the original line we started. 833130803Smarcel 834130803Smarcel An attempt was made to have init_execution_control_state () refresh 835130803Smarcel the prev_pc value before calculating the line number. This approach 836130803Smarcel did not work because on platforms that use ptrace, the pc register 837130803Smarcel cannot be read unless the inferior is stopped. At that point, we 838130803Smarcel are not guaranteed the inferior is stopped and so the read_pc () 839130803Smarcel call can fail. Setting the prev_pc value here ensures the value is 840130803Smarcel updated correctly when the inferior is stopped. */ 841130803Smarcel prev_pc = read_pc (); 842130803Smarcel 84319370Spst /* Resume inferior. */ 84419370Spst resume (oneproc || step || bpstat_should_step (), stop_signal); 84519370Spst 84619370Spst /* Wait for it to stop (if not standalone) 84719370Spst and in any case decode why it stopped, and act accordingly. */ 84898944Sobrien /* Do this only if we are not using the event loop, or if the target 84998944Sobrien does not support asynchronous execution. */ 85098944Sobrien if (!event_loop_p || !target_can_async_p ()) 85198944Sobrien { 85298944Sobrien wait_for_inferior (); 85398944Sobrien normal_stop (); 85498944Sobrien } 85519370Spst} 85646283Sdfr 85719370Spst 85819370Spst/* Start remote-debugging of a machine over a serial link. */ 85919370Spst 86019370Spstvoid 86198944Sobrienstart_remote (void) 86219370Spst{ 86319370Spst init_thread_list (); 86419370Spst init_wait_for_inferior (); 865130803Smarcel stop_soon = STOP_QUIETLY; 86619370Spst trap_expected = 0; 86798944Sobrien 86898944Sobrien /* Always go on waiting for the target, regardless of the mode. */ 86998944Sobrien /* FIXME: cagney/1999-09-23: At present it isn't possible to 87098944Sobrien indicate to wait_for_inferior that a target should timeout if 87198944Sobrien nothing is returned (instead of just blocking). Because of this, 87298944Sobrien targets expecting an immediate response need to, internally, set 87398944Sobrien things up so that the target_wait() is forced to eventually 87498944Sobrien timeout. */ 87598944Sobrien /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to 87698944Sobrien differentiate to its caller what the state of the target is after 87798944Sobrien the initial open has been performed. Here we're assuming that 87898944Sobrien the target has stopped. It should be possible to eventually have 87998944Sobrien target_open() return to the caller an indication that the target 88098944Sobrien is currently running and GDB state should be set to the same as 88198944Sobrien for an async run. */ 88219370Spst wait_for_inferior (); 88319370Spst normal_stop (); 88419370Spst} 88519370Spst 88619370Spst/* Initialize static vars when a new inferior begins. */ 88719370Spst 88819370Spstvoid 88998944Sobrieninit_wait_for_inferior (void) 89019370Spst{ 89119370Spst /* These are meaningless until the first time through wait_for_inferior. */ 89219370Spst prev_pc = 0; 89319370Spst 89419370Spst#ifdef HP_OS_BUG 89519370Spst trap_expected_after_continue = 0; 89619370Spst#endif 89719370Spst breakpoints_inserted = 0; 89846283Sdfr breakpoint_init_inferior (inf_starting); 89919370Spst 90019370Spst /* Don't confuse first call to proceed(). */ 90119370Spst stop_signal = TARGET_SIGNAL_0; 90246283Sdfr 90346283Sdfr /* The first resume is not following a fork/vfork/exec. */ 90446283Sdfr pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ 90546283Sdfr 90646283Sdfr /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */ 90746283Sdfr number_of_threads_in_syscalls = 0; 90846283Sdfr 90946283Sdfr clear_proceed_status (); 910130803Smarcel 911130803Smarcel stepping_past_singlestep_breakpoint = 0; 91219370Spst} 91319370Spst 91419370Spststatic void 91598944Sobriendelete_breakpoint_current_contents (void *arg) 91619370Spst{ 91746283Sdfr struct breakpoint **breakpointp = (struct breakpoint **) arg; 91819370Spst if (*breakpointp != NULL) 91946283Sdfr { 92046283Sdfr delete_breakpoint (*breakpointp); 92146283Sdfr *breakpointp = NULL; 92246283Sdfr } 92319370Spst} 92419370Spst 92598944Sobrien/* This enum encodes possible reasons for doing a target_wait, so that 92698944Sobrien wfi can call target_wait in one place. (Ultimately the call will be 92798944Sobrien moved out of the infinite loop entirely.) */ 92898944Sobrien 92998944Sobrienenum infwait_states 93098944Sobrien{ 93198944Sobrien infwait_normal_state, 93298944Sobrien infwait_thread_hop_state, 93398944Sobrien infwait_nullified_state, 93498944Sobrien infwait_nonstep_watch_state 93598944Sobrien}; 93698944Sobrien 93798944Sobrien/* Why did the inferior stop? Used to print the appropriate messages 93898944Sobrien to the interface from within handle_inferior_event(). */ 93998944Sobrienenum inferior_stop_reason 94098944Sobrien{ 94198944Sobrien /* We don't know why. */ 94298944Sobrien STOP_UNKNOWN, 94398944Sobrien /* Step, next, nexti, stepi finished. */ 94498944Sobrien END_STEPPING_RANGE, 94598944Sobrien /* Found breakpoint. */ 94698944Sobrien BREAKPOINT_HIT, 94798944Sobrien /* Inferior terminated by signal. */ 94898944Sobrien SIGNAL_EXITED, 94998944Sobrien /* Inferior exited. */ 95098944Sobrien EXITED, 95198944Sobrien /* Inferior received signal, and user asked to be notified. */ 95298944Sobrien SIGNAL_RECEIVED 95398944Sobrien}; 95498944Sobrien 95598944Sobrien/* This structure contains what used to be local variables in 95698944Sobrien wait_for_inferior. Probably many of them can return to being 95798944Sobrien locals in handle_inferior_event. */ 95898944Sobrien 95998944Sobrienstruct execution_control_state 960130803Smarcel{ 961130803Smarcel struct target_waitstatus ws; 962130803Smarcel struct target_waitstatus *wp; 963130803Smarcel int another_trap; 964130803Smarcel int random_signal; 965130803Smarcel CORE_ADDR stop_func_start; 966130803Smarcel CORE_ADDR stop_func_end; 967130803Smarcel char *stop_func_name; 968130803Smarcel struct symtab_and_line sal; 969130803Smarcel int remove_breakpoints_on_following_step; 970130803Smarcel int current_line; 971130803Smarcel struct symtab *current_symtab; 972130803Smarcel int handling_longjmp; /* FIXME */ 973130803Smarcel ptid_t ptid; 974130803Smarcel ptid_t saved_inferior_ptid; 975130803Smarcel int update_step_sp; 976130803Smarcel int stepping_through_solib_after_catch; 977130803Smarcel bpstat stepping_through_solib_catchpoints; 978130803Smarcel int enable_hw_watchpoints_after_wait; 979130803Smarcel int stepping_through_sigtramp; 980130803Smarcel int new_thread_event; 981130803Smarcel struct target_waitstatus tmpstatus; 982130803Smarcel enum infwait_states infwait_state; 983130803Smarcel ptid_t waiton_ptid; 984130803Smarcel int wait_some_more; 985130803Smarcel}; 98698944Sobrien 987130803Smarcelvoid init_execution_control_state (struct execution_control_state *ecs); 98898944Sobrien 989130803Smarcelstatic void handle_step_into_function (struct execution_control_state *ecs); 990130803Smarcelvoid handle_inferior_event (struct execution_control_state *ecs); 99198944Sobrien 99298944Sobrienstatic void check_sigtramp2 (struct execution_control_state *ecs); 99398944Sobrienstatic void step_into_function (struct execution_control_state *ecs); 99498944Sobrienstatic void step_over_function (struct execution_control_state *ecs); 99598944Sobrienstatic void stop_stepping (struct execution_control_state *ecs); 99698944Sobrienstatic void prepare_to_wait (struct execution_control_state *ecs); 99798944Sobrienstatic void keep_going (struct execution_control_state *ecs); 998130803Smarcelstatic void print_stop_reason (enum inferior_stop_reason stop_reason, 999130803Smarcel int stop_info); 100098944Sobrien 100119370Spst/* Wait for control to return from inferior to debugger. 100219370Spst If inferior gets a signal, we may decide to start it up again 100319370Spst instead of returning. That is why there is a loop in this function. 100419370Spst When this function actually returns it means the inferior 100519370Spst should be left stopped and GDB should read more commands. */ 100619370Spst 100719370Spstvoid 100898944Sobrienwait_for_inferior (void) 100919370Spst{ 101019370Spst struct cleanup *old_cleanups; 101198944Sobrien struct execution_control_state ecss; 101298944Sobrien struct execution_control_state *ecs; 101319370Spst 101498944Sobrien old_cleanups = make_cleanup (delete_step_resume_breakpoint, 101519370Spst &step_resume_breakpoint); 101619370Spst make_cleanup (delete_breakpoint_current_contents, 101719370Spst &through_sigtramp_breakpoint); 101819370Spst 101998944Sobrien /* wfi still stays in a loop, so it's OK just to take the address of 102098944Sobrien a local to get the ecs pointer. */ 102198944Sobrien ecs = &ecss; 102219370Spst 102398944Sobrien /* Fill in with reasonable starting values. */ 102498944Sobrien init_execution_control_state (ecs); 102598944Sobrien 102646283Sdfr /* We'll update this if & when we switch to a new thread. */ 102798944Sobrien previous_inferior_ptid = inferior_ptid; 102846283Sdfr 102998944Sobrien overlay_cache_invalid = 1; 103098944Sobrien 103198944Sobrien /* We have to invalidate the registers BEFORE calling target_wait 103298944Sobrien because they can be loaded from the target while in target_wait. 103398944Sobrien This makes remote debugging a bit more efficient for those 103498944Sobrien targets that provide critical registers as part of their normal 103598944Sobrien status mechanism. */ 103698944Sobrien 103798944Sobrien registers_changed (); 103898944Sobrien 103919370Spst while (1) 104019370Spst { 104198944Sobrien if (target_wait_hook) 104298944Sobrien ecs->ptid = target_wait_hook (ecs->waiton_ptid, ecs->wp); 104398944Sobrien else 104498944Sobrien ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp); 104546283Sdfr 104698944Sobrien /* Now figure out what to do with the result of the result. */ 104798944Sobrien handle_inferior_event (ecs); 104898944Sobrien 104998944Sobrien if (!ecs->wait_some_more) 105098944Sobrien break; 105198944Sobrien } 105298944Sobrien do_cleanups (old_cleanups); 105398944Sobrien} 105498944Sobrien 105598944Sobrien/* Asynchronous version of wait_for_inferior. It is called by the 105698944Sobrien event loop whenever a change of state is detected on the file 105798944Sobrien descriptor corresponding to the target. It can be called more than 105898944Sobrien once to complete a single execution command. In such cases we need 105998944Sobrien to keep the state in a global variable ASYNC_ECSS. If it is the 106098944Sobrien last time that this function is called for a single execution 106198944Sobrien command, then report to the user that the inferior has stopped, and 106298944Sobrien do the necessary cleanups. */ 106398944Sobrien 106498944Sobrienstruct execution_control_state async_ecss; 106598944Sobrienstruct execution_control_state *async_ecs; 106698944Sobrien 106798944Sobrienvoid 106898944Sobrienfetch_inferior_event (void *client_data) 106998944Sobrien{ 107098944Sobrien static struct cleanup *old_cleanups; 107198944Sobrien 107298944Sobrien async_ecs = &async_ecss; 107398944Sobrien 107498944Sobrien if (!async_ecs->wait_some_more) 107598944Sobrien { 1076130803Smarcel old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint, 107798944Sobrien &step_resume_breakpoint); 107898944Sobrien make_exec_cleanup (delete_breakpoint_current_contents, 107998944Sobrien &through_sigtramp_breakpoint); 108098944Sobrien 108198944Sobrien /* Fill in with reasonable starting values. */ 108298944Sobrien init_execution_control_state (async_ecs); 108398944Sobrien 108498944Sobrien /* We'll update this if & when we switch to a new thread. */ 108598944Sobrien previous_inferior_ptid = inferior_ptid; 108698944Sobrien 108746283Sdfr overlay_cache_invalid = 1; 108846283Sdfr 108998944Sobrien /* We have to invalidate the registers BEFORE calling target_wait 109098944Sobrien because they can be loaded from the target while in target_wait. 109198944Sobrien This makes remote debugging a bit more efficient for those 109298944Sobrien targets that provide critical registers as part of their normal 109398944Sobrien status mechanism. */ 109419370Spst 109519370Spst registers_changed (); 109698944Sobrien } 109719370Spst 109898944Sobrien if (target_wait_hook) 1099130803Smarcel async_ecs->ptid = 1100130803Smarcel target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp); 110198944Sobrien else 110298944Sobrien async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp); 110398944Sobrien 110498944Sobrien /* Now figure out what to do with the result of the result. */ 110598944Sobrien handle_inferior_event (async_ecs); 110698944Sobrien 110798944Sobrien if (!async_ecs->wait_some_more) 110898944Sobrien { 110998944Sobrien /* Do only the cleanups that have been added by this 1110130803Smarcel function. Let the continuations for the commands do the rest, 1111130803Smarcel if there are any. */ 111298944Sobrien do_exec_cleanups (old_cleanups); 111398944Sobrien normal_stop (); 111498944Sobrien if (step_multi && stop_step) 111598944Sobrien inferior_event_handler (INF_EXEC_CONTINUE, NULL); 111619370Spst else 111798944Sobrien inferior_event_handler (INF_EXEC_COMPLETE, NULL); 111898944Sobrien } 111998944Sobrien} 112019370Spst 112198944Sobrien/* Prepare an execution control state for looping through a 112298944Sobrien wait_for_inferior-type loop. */ 112346283Sdfr 112498944Sobrienvoid 112598944Sobrieninit_execution_control_state (struct execution_control_state *ecs) 112698944Sobrien{ 112798944Sobrien /* ecs->another_trap? */ 112898944Sobrien ecs->random_signal = 0; 112998944Sobrien ecs->remove_breakpoints_on_following_step = 0; 113098944Sobrien ecs->handling_longjmp = 0; /* FIXME */ 113198944Sobrien ecs->update_step_sp = 0; 113298944Sobrien ecs->stepping_through_solib_after_catch = 0; 113398944Sobrien ecs->stepping_through_solib_catchpoints = NULL; 113498944Sobrien ecs->enable_hw_watchpoints_after_wait = 0; 113598944Sobrien ecs->stepping_through_sigtramp = 0; 113698944Sobrien ecs->sal = find_pc_line (prev_pc, 0); 113798944Sobrien ecs->current_line = ecs->sal.line; 113898944Sobrien ecs->current_symtab = ecs->sal.symtab; 113998944Sobrien ecs->infwait_state = infwait_normal_state; 114098944Sobrien ecs->waiton_ptid = pid_to_ptid (-1); 114198944Sobrien ecs->wp = &(ecs->ws); 114298944Sobrien} 114346283Sdfr 114498944Sobrien/* Call this function before setting step_resume_breakpoint, as a 114598944Sobrien sanity check. There should never be more than one step-resume 114698944Sobrien breakpoint per thread, so we should never be setting a new 114798944Sobrien step_resume_breakpoint when one is already active. */ 114898944Sobrienstatic void 114998944Sobriencheck_for_old_step_resume_breakpoint (void) 115098944Sobrien{ 115198944Sobrien if (step_resume_breakpoint) 1152130803Smarcel warning 1153130803Smarcel ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint"); 115498944Sobrien} 115546283Sdfr 115698944Sobrien/* Return the cached copy of the last pid/waitstatus returned by 115798944Sobrien target_wait()/target_wait_hook(). The data is actually cached by 115898944Sobrien handle_inferior_event(), which gets called immediately after 115998944Sobrien target_wait()/target_wait_hook(). */ 116019370Spst 116198944Sobrienvoid 1162130803Smarcelget_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) 116398944Sobrien{ 116498944Sobrien *ptidp = target_last_wait_ptid; 116598944Sobrien *status = target_last_waitstatus; 116698944Sobrien} 116746283Sdfr 116898944Sobrien/* Switch thread contexts, maintaining "infrun state". */ 116946283Sdfr 117098944Sobrienstatic void 117198944Sobriencontext_switch (struct execution_control_state *ecs) 117298944Sobrien{ 117398944Sobrien /* Caution: it may happen that the new thread (or the old one!) 117498944Sobrien is not in the thread list. In this case we must not attempt 117598944Sobrien to "switch context", or we run the risk that our context may 117698944Sobrien be lost. This may happen as a result of the target module 117798944Sobrien mishandling thread creation. */ 117819370Spst 117998944Sobrien if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid)) 1180130803Smarcel { /* Perform infrun state context switch: */ 118198944Sobrien /* Save infrun state for the old thread. */ 1182130803Smarcel save_infrun_state (inferior_ptid, prev_pc, 118398944Sobrien trap_expected, step_resume_breakpoint, 1184130803Smarcel through_sigtramp_breakpoint, step_range_start, 1185130803Smarcel step_range_end, &step_frame_id, 118698944Sobrien ecs->handling_longjmp, ecs->another_trap, 118798944Sobrien ecs->stepping_through_solib_after_catch, 118898944Sobrien ecs->stepping_through_solib_catchpoints, 118998944Sobrien ecs->stepping_through_sigtramp, 1190130803Smarcel ecs->current_line, ecs->current_symtab, step_sp); 119119370Spst 119298944Sobrien /* Load infrun state for the new thread. */ 1193130803Smarcel load_infrun_state (ecs->ptid, &prev_pc, 119498944Sobrien &trap_expected, &step_resume_breakpoint, 1195130803Smarcel &through_sigtramp_breakpoint, &step_range_start, 1196130803Smarcel &step_range_end, &step_frame_id, 119798944Sobrien &ecs->handling_longjmp, &ecs->another_trap, 119898944Sobrien &ecs->stepping_through_solib_after_catch, 119998944Sobrien &ecs->stepping_through_solib_catchpoints, 1200130803Smarcel &ecs->stepping_through_sigtramp, 1201130803Smarcel &ecs->current_line, &ecs->current_symtab, &step_sp); 120298944Sobrien } 120398944Sobrien inferior_ptid = ecs->ptid; 120498944Sobrien} 120546283Sdfr 1206130803Smarcel/* Wrapper for PC_IN_SIGTRAMP that takes care of the need to find the 1207130803Smarcel function's name. 120819370Spst 1209130803Smarcel In a classic example of "left hand VS right hand", "infrun.c" was 1210130803Smarcel trying to improve GDB's performance by caching the result of calls 1211130803Smarcel to calls to find_pc_partial_funtion, while at the same time 1212130803Smarcel find_pc_partial_function was also trying to ramp up performance by 1213130803Smarcel caching its most recent return value. The below makes the the 1214130803Smarcel function find_pc_partial_function solely responsibile for 1215130803Smarcel performance issues (the local cache that relied on a global 1216130803Smarcel variable - arrrggg - deleted). 121719370Spst 1218130803Smarcel Using the testsuite and gcov, it was found that dropping the local 1219130803Smarcel "infrun.c" cache and instead relying on find_pc_partial_function 1220130803Smarcel increased the number of calls to 12000 (from 10000), but the number 1221130803Smarcel of times find_pc_partial_function's cache missed (this is what 1222130803Smarcel matters) was only increased by only 4 (to 3569). (A quick back of 1223130803Smarcel envelope caculation suggests that the extra 2000 function calls 1224130803Smarcel @1000 extra instructions per call make the 1 MIP VAX testsuite run 1225130803Smarcel take two extra seconds, oops :-) 1226130803Smarcel 1227130803Smarcel Long term, this function can be eliminated, replaced by the code: 1228130803Smarcel get_frame_type(current_frame()) == SIGTRAMP_FRAME (for new 1229130803Smarcel architectures this is very cheap). */ 1230130803Smarcel 1231130803Smarcelstatic int 1232130803Smarcelpc_in_sigtramp (CORE_ADDR pc) 123398944Sobrien{ 1234130803Smarcel char *name; 1235130803Smarcel find_pc_partial_function (pc, &name, NULL, NULL); 1236130803Smarcel return PC_IN_SIGTRAMP (pc, name); 1237130803Smarcel} 123819370Spst 1239130803Smarcel/* Handle the inferior event in the cases when we just stepped 1240130803Smarcel into a function. */ 124146283Sdfr 1242130803Smarcelstatic void 1243130803Smarcelhandle_step_into_function (struct execution_control_state *ecs) 1244130803Smarcel{ 1245130803Smarcel CORE_ADDR real_stop_pc; 124698944Sobrien 1247130803Smarcel if ((step_over_calls == STEP_OVER_NONE) 1248130803Smarcel || ((step_range_end == 1) 1249130803Smarcel && in_prologue (prev_pc, ecs->stop_func_start))) 1250130803Smarcel { 1251130803Smarcel /* I presume that step_over_calls is only 0 when we're 1252130803Smarcel supposed to be stepping at the assembly language level 1253130803Smarcel ("stepi"). Just stop. */ 1254130803Smarcel /* Also, maybe we just did a "nexti" inside a prolog, 1255130803Smarcel so we thought it was a subroutine call but it was not. 1256130803Smarcel Stop as well. FENN */ 1257130803Smarcel stop_step = 1; 1258130803Smarcel print_stop_reason (END_STEPPING_RANGE, 0); 1259130803Smarcel stop_stepping (ecs); 1260130803Smarcel return; 1261130803Smarcel } 126298944Sobrien 1263130803Smarcel if (step_over_calls == STEP_OVER_ALL || IGNORE_HELPER_CALL (stop_pc)) 1264130803Smarcel { 1265130803Smarcel /* We're doing a "next". */ 126698944Sobrien 1267130803Smarcel if (pc_in_sigtramp (stop_pc) 1268130803Smarcel && frame_id_inner (step_frame_id, 1269130803Smarcel frame_id_build (read_sp (), 0))) 1270130803Smarcel /* We stepped out of a signal handler, and into its 1271130803Smarcel calling trampoline. This is misdetected as a 1272130803Smarcel subroutine call, but stepping over the signal 1273130803Smarcel trampoline isn't such a bad idea. In order to do that, 1274130803Smarcel we have to ignore the value in step_frame_id, since 1275130803Smarcel that doesn't represent the frame that'll reach when we 1276130803Smarcel return from the signal trampoline. Otherwise we'll 1277130803Smarcel probably continue to the end of the program. */ 1278130803Smarcel step_frame_id = null_frame_id; 127998944Sobrien 1280130803Smarcel step_over_function (ecs); 1281130803Smarcel keep_going (ecs); 1282130803Smarcel return; 1283130803Smarcel } 128498944Sobrien 1285130803Smarcel /* If we are in a function call trampoline (a stub between 1286130803Smarcel the calling routine and the real function), locate the real 1287130803Smarcel function. That's what tells us (a) whether we want to step 1288130803Smarcel into it at all, and (b) what prologue we want to run to 1289130803Smarcel the end of, if we do step into it. */ 1290130803Smarcel real_stop_pc = skip_language_trampoline (stop_pc); 1291130803Smarcel if (real_stop_pc == 0) 1292130803Smarcel real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc); 1293130803Smarcel if (real_stop_pc != 0) 1294130803Smarcel ecs->stop_func_start = real_stop_pc; 129598944Sobrien 1296130803Smarcel /* If we have line number information for the function we 1297130803Smarcel are thinking of stepping into, step into it. 129898944Sobrien 1299130803Smarcel If there are several symtabs at that PC (e.g. with include 1300130803Smarcel files), just want to know whether *any* of them have line 1301130803Smarcel numbers. find_pc_line handles this. */ 1302130803Smarcel { 1303130803Smarcel struct symtab_and_line tmp_sal; 130498944Sobrien 1305130803Smarcel tmp_sal = find_pc_line (ecs->stop_func_start, 0); 1306130803Smarcel if (tmp_sal.line != 0) 130798944Sobrien { 1308130803Smarcel step_into_function (ecs); 1309130803Smarcel return; 1310130803Smarcel } 1311130803Smarcel } 131298944Sobrien 1313130803Smarcel /* If we have no line number and the step-stop-if-no-debug 1314130803Smarcel is set, we stop the step so that the user has a chance to 1315130803Smarcel switch in assembly mode. */ 1316130803Smarcel if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug) 1317130803Smarcel { 1318130803Smarcel stop_step = 1; 1319130803Smarcel print_stop_reason (END_STEPPING_RANGE, 0); 1320130803Smarcel stop_stepping (ecs); 1321130803Smarcel return; 1322130803Smarcel } 132398944Sobrien 1324130803Smarcel step_over_function (ecs); 1325130803Smarcel keep_going (ecs); 1326130803Smarcel return; 1327130803Smarcel} 132846283Sdfr 1329130803Smarcelstatic void 1330130803Smarceladjust_pc_after_break (struct execution_control_state *ecs) 1331130803Smarcel{ 1332130803Smarcel CORE_ADDR stop_pc; 133346283Sdfr 1334130803Smarcel /* If this target does not decrement the PC after breakpoints, then 1335130803Smarcel we have nothing to do. */ 1336130803Smarcel if (DECR_PC_AFTER_BREAK == 0) 1337130803Smarcel return; 133846283Sdfr 1339130803Smarcel /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If 1340130803Smarcel we aren't, just return. 134198944Sobrien 1342130803Smarcel We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not 1343130803Smarcel affected by DECR_PC_AFTER_BREAK. Other waitkinds which are implemented 1344130803Smarcel by software breakpoints should be handled through the normal breakpoint 1345130803Smarcel layer. 1346130803Smarcel 1347130803Smarcel NOTE drow/2004-01-31: On some targets, breakpoints may generate 1348130803Smarcel different signals (SIGILL or SIGEMT for instance), but it is less 1349130803Smarcel clear where the PC is pointing afterwards. It may not match 1350130803Smarcel DECR_PC_AFTER_BREAK. I don't know any specific target that generates 1351130803Smarcel these signals at breakpoints (the code has been in GDB since at least 1352130803Smarcel 1992) so I can not guess how to handle them here. 1353130803Smarcel 1354130803Smarcel In earlier versions of GDB, a target with HAVE_NONSTEPPABLE_WATCHPOINTS 1355130803Smarcel would have the PC after hitting a watchpoint affected by 1356130803Smarcel DECR_PC_AFTER_BREAK. I haven't found any target with both of these set 1357130803Smarcel in GDB history, and it seems unlikely to be correct, so 1358130803Smarcel HAVE_NONSTEPPABLE_WATCHPOINTS is not checked here. */ 135919370Spst 1360130803Smarcel if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) 1361130803Smarcel return; 136246283Sdfr 1363130803Smarcel if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP) 1364130803Smarcel return; 136546283Sdfr 1366130803Smarcel /* Find the location where (if we've hit a breakpoint) the breakpoint would 1367130803Smarcel be. */ 1368130803Smarcel stop_pc = read_pc_pid (ecs->ptid) - DECR_PC_AFTER_BREAK; 136919370Spst 1370130803Smarcel /* If we're software-single-stepping, then assume this is a breakpoint. 1371130803Smarcel NOTE drow/2004-01-17: This doesn't check that the PC matches, or that 1372130803Smarcel we're even in the right thread. The software-single-step code needs 1373130803Smarcel some modernization. 137419370Spst 1375130803Smarcel If we're not software-single-stepping, then we first check that there 1376130803Smarcel is an enabled software breakpoint at this address. If there is, and 1377130803Smarcel we weren't using hardware-single-step, then we've hit the breakpoint. 137819370Spst 1379130803Smarcel If we were using hardware-single-step, we check prev_pc; if we just 1380130803Smarcel stepped over an inserted software breakpoint, then we should decrement 1381130803Smarcel the PC and eventually report hitting the breakpoint. The prev_pc check 1382130803Smarcel prevents us from decrementing the PC if we just stepped over a jump 1383130803Smarcel instruction and landed on the instruction after a breakpoint. 138419370Spst 1385130803Smarcel The last bit checks that we didn't hit a breakpoint in a signal handler 1386130803Smarcel without an intervening stop in sigtramp, which is detected by a new 1387130803Smarcel stack pointer value below any usual function calling stack adjustments. 138819370Spst 1389130803Smarcel NOTE drow/2004-01-17: I'm not sure that this is necessary. The check 1390130803Smarcel predates checking for software single step at the same time. Also, 1391130803Smarcel if we've moved into a signal handler we should have seen the 1392130803Smarcel signal. */ 139319370Spst 1394130803Smarcel if ((SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) 1395130803Smarcel || (software_breakpoint_inserted_here_p (stop_pc) 1396130803Smarcel && !(currently_stepping (ecs) 1397130803Smarcel && prev_pc != stop_pc 1398133748Sdavidxu#if 1 1399133748Sdavidxu && !(step_range_end)))) 1400133748Sdavidxu#else 1401130803Smarcel && !(step_range_end && INNER_THAN (read_sp (), (step_sp - 16)))))) 1402133748Sdavidxu#endif 1403130803Smarcel write_pc_pid (stop_pc, ecs->ptid); 1404130803Smarcel} 140519370Spst 1406130803Smarcel/* Given an execution control state that has been freshly filled in 1407130803Smarcel by an event from the inferior, figure out what it means and take 1408130803Smarcel appropriate action. */ 140919370Spst 1410130803Smarcelvoid 1411130803Smarcelhandle_inferior_event (struct execution_control_state *ecs) 1412130803Smarcel{ 1413130803Smarcel /* NOTE: cagney/2003-03-28: If you're looking at this code and 1414130803Smarcel thinking that the variable stepped_after_stopped_by_watchpoint 1415130803Smarcel isn't used, then you're wrong! The macro STOPPED_BY_WATCHPOINT, 1416130803Smarcel defined in the file "config/pa/nm-hppah.h", accesses the variable 1417130803Smarcel indirectly. Mutter something rude about the HP merge. */ 1418130803Smarcel int stepped_after_stopped_by_watchpoint; 1419130803Smarcel int sw_single_step_trap_p = 0; 142046283Sdfr 1421130803Smarcel /* Cache the last pid/waitstatus. */ 1422130803Smarcel target_last_wait_ptid = ecs->ptid; 1423130803Smarcel target_last_waitstatus = *ecs->wp; 142446283Sdfr 1425130803Smarcel adjust_pc_after_break (ecs); 142646283Sdfr 1427130803Smarcel switch (ecs->infwait_state) 1428130803Smarcel { 1429130803Smarcel case infwait_thread_hop_state: 1430130803Smarcel /* Cancel the waiton_ptid. */ 1431130803Smarcel ecs->waiton_ptid = pid_to_ptid (-1); 1432130803Smarcel /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event 1433130803Smarcel is serviced in this loop, below. */ 1434130803Smarcel if (ecs->enable_hw_watchpoints_after_wait) 1435130803Smarcel { 1436130803Smarcel TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); 1437130803Smarcel ecs->enable_hw_watchpoints_after_wait = 0; 1438130803Smarcel } 1439130803Smarcel stepped_after_stopped_by_watchpoint = 0; 1440130803Smarcel break; 144146283Sdfr 1442130803Smarcel case infwait_normal_state: 1443130803Smarcel /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event 1444130803Smarcel is serviced in this loop, below. */ 1445130803Smarcel if (ecs->enable_hw_watchpoints_after_wait) 1446130803Smarcel { 1447130803Smarcel TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); 1448130803Smarcel ecs->enable_hw_watchpoints_after_wait = 0; 1449130803Smarcel } 1450130803Smarcel stepped_after_stopped_by_watchpoint = 0; 1451130803Smarcel break; 145246283Sdfr 1453130803Smarcel case infwait_nullified_state: 1454130803Smarcel stepped_after_stopped_by_watchpoint = 0; 1455130803Smarcel break; 145646283Sdfr 1457130803Smarcel case infwait_nonstep_watch_state: 1458130803Smarcel insert_breakpoints (); 145946283Sdfr 1460130803Smarcel /* FIXME-maybe: is this cleaner than setting a flag? Does it 1461130803Smarcel handle things like signals arriving and other things happening 1462130803Smarcel in combination correctly? */ 1463130803Smarcel stepped_after_stopped_by_watchpoint = 1; 1464130803Smarcel break; 146546283Sdfr 1466130803Smarcel default: 1467130803Smarcel internal_error (__FILE__, __LINE__, "bad switch"); 1468130803Smarcel } 1469130803Smarcel ecs->infwait_state = infwait_normal_state; 147046283Sdfr 1471130803Smarcel flush_cached_frames (); 147246283Sdfr 1473130803Smarcel /* If it's a new process, add it to the thread database */ 147446283Sdfr 1475130803Smarcel ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) 1476130803Smarcel && !in_thread_list (ecs->ptid)); 147746283Sdfr 1478130803Smarcel if (ecs->ws.kind != TARGET_WAITKIND_EXITED 1479130803Smarcel && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) 1480130803Smarcel { 1481130803Smarcel add_thread (ecs->ptid); 148246283Sdfr 1483130803Smarcel ui_out_text (uiout, "[New "); 1484130803Smarcel ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid)); 1485130803Smarcel ui_out_text (uiout, "]\n"); 148646283Sdfr 1487130803Smarcel#if 0 1488130803Smarcel /* NOTE: This block is ONLY meant to be invoked in case of a 1489130803Smarcel "thread creation event"! If it is invoked for any other 1490130803Smarcel sort of event (such as a new thread landing on a breakpoint), 1491130803Smarcel the event will be discarded, which is almost certainly 1492130803Smarcel a bad thing! 149346283Sdfr 1494130803Smarcel To avoid this, the low-level module (eg. target_wait) 1495130803Smarcel should call in_thread_list and add_thread, so that the 1496130803Smarcel new thread is known by the time we get here. */ 149746283Sdfr 1498130803Smarcel /* We may want to consider not doing a resume here in order 1499130803Smarcel to give the user a chance to play with the new thread. 1500130803Smarcel It might be good to make that a user-settable option. */ 150146283Sdfr 1502130803Smarcel /* At this point, all threads are stopped (happens 1503130803Smarcel automatically in either the OS or the native code). 1504130803Smarcel Therefore we need to continue all threads in order to 1505130803Smarcel make progress. */ 150646283Sdfr 1507130803Smarcel target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); 1508130803Smarcel prepare_to_wait (ecs); 1509130803Smarcel return; 1510130803Smarcel#endif 1511130803Smarcel } 151246283Sdfr 1513130803Smarcel switch (ecs->ws.kind) 1514130803Smarcel { 1515130803Smarcel case TARGET_WAITKIND_LOADED: 1516130803Smarcel /* Ignore gracefully during startup of the inferior, as it 1517130803Smarcel might be the shell which has just loaded some objects, 1518130803Smarcel otherwise add the symbols for the newly loaded objects. */ 1519130803Smarcel#ifdef SOLIB_ADD 1520130803Smarcel if (stop_soon == NO_STOP_QUIETLY) 1521130803Smarcel { 1522130803Smarcel /* Remove breakpoints, SOLIB_ADD might adjust 1523130803Smarcel breakpoint addresses via breakpoint_re_set. */ 1524130803Smarcel if (breakpoints_inserted) 1525130803Smarcel remove_breakpoints (); 152646283Sdfr 1527130803Smarcel /* Check for any newly added shared libraries if we're 1528130803Smarcel supposed to be adding them automatically. Switch 1529130803Smarcel terminal for any messages produced by 1530130803Smarcel breakpoint_re_set. */ 1531130803Smarcel target_terminal_ours_for_output (); 1532130803Smarcel /* NOTE: cagney/2003-11-25: Make certain that the target 1533130803Smarcel stack's section table is kept up-to-date. Architectures, 1534130803Smarcel (e.g., PPC64), use the section table to perform 1535130803Smarcel operations such as address => section name and hence 1536130803Smarcel require the table to contain all sections (including 1537130803Smarcel those found in shared libraries). */ 1538130803Smarcel /* NOTE: cagney/2003-11-25: Pass current_target and not 1539130803Smarcel exec_ops to SOLIB_ADD. This is because current GDB is 1540130803Smarcel only tooled to propagate section_table changes out from 1541130803Smarcel the "current_target" (see target_resize_to_sections), and 1542130803Smarcel not up from the exec stratum. This, of course, isn't 1543130803Smarcel right. "infrun.c" should only interact with the 1544130803Smarcel exec/process stratum, instead relying on the target stack 1545130803Smarcel to propagate relevant changes (stop, section table 1546130803Smarcel changed, ...) up to other layers. */ 1547130803Smarcel SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); 1548130803Smarcel target_terminal_inferior (); 154946283Sdfr 1550130803Smarcel /* Reinsert breakpoints and continue. */ 1551130803Smarcel if (breakpoints_inserted) 1552130803Smarcel insert_breakpoints (); 1553130803Smarcel } 1554130803Smarcel#endif 1555130803Smarcel resume (0, TARGET_SIGNAL_0); 1556130803Smarcel prepare_to_wait (ecs); 1557130803Smarcel return; 155846283Sdfr 1559130803Smarcel case TARGET_WAITKIND_SPURIOUS: 1560130803Smarcel resume (0, TARGET_SIGNAL_0); 1561130803Smarcel prepare_to_wait (ecs); 1562130803Smarcel return; 156346283Sdfr 1564130803Smarcel case TARGET_WAITKIND_EXITED: 1565130803Smarcel target_terminal_ours (); /* Must do this before mourn anyway */ 1566130803Smarcel print_stop_reason (EXITED, ecs->ws.value.integer); 156719370Spst 1568130803Smarcel /* Record the exit code in the convenience variable $_exitcode, so 1569130803Smarcel that the user can inspect this again later. */ 1570130803Smarcel set_internalvar (lookup_internalvar ("_exitcode"), 1571130803Smarcel value_from_longest (builtin_type_int, 1572130803Smarcel (LONGEST) ecs->ws.value.integer)); 1573130803Smarcel gdb_flush (gdb_stdout); 1574130803Smarcel target_mourn_inferior (); 1575130803Smarcel singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ 1576130803Smarcel stop_print_frame = 0; 1577130803Smarcel stop_stepping (ecs); 1578130803Smarcel return; 157919370Spst 1580130803Smarcel case TARGET_WAITKIND_SIGNALLED: 1581130803Smarcel stop_print_frame = 0; 1582130803Smarcel stop_signal = ecs->ws.value.sig; 1583130803Smarcel target_terminal_ours (); /* Must do this before mourn anyway */ 158446283Sdfr 1585130803Smarcel /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't 1586130803Smarcel reach here unless the inferior is dead. However, for years 1587130803Smarcel target_kill() was called here, which hints that fatal signals aren't 1588130803Smarcel really fatal on some systems. If that's true, then some changes 1589130803Smarcel may be needed. */ 1590130803Smarcel target_mourn_inferior (); 159119370Spst 1592130803Smarcel print_stop_reason (SIGNAL_EXITED, stop_signal); 1593130803Smarcel singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ 1594130803Smarcel stop_stepping (ecs); 1595130803Smarcel return; 159619370Spst 1597130803Smarcel /* The following are the only cases in which we keep going; 1598130803Smarcel the above cases end in a continue or goto. */ 1599130803Smarcel case TARGET_WAITKIND_FORKED: 1600130803Smarcel case TARGET_WAITKIND_VFORKED: 1601130803Smarcel stop_signal = TARGET_SIGNAL_TRAP; 1602130803Smarcel pending_follow.kind = ecs->ws.kind; 160319370Spst 1604130803Smarcel pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); 1605130803Smarcel pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; 160619370Spst 1607130803Smarcel stop_pc = read_pc (); 160846283Sdfr 1609130803Smarcel stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); 161046283Sdfr 1611130803Smarcel ecs->random_signal = !bpstat_explains_signal (stop_bpstat); 161219370Spst 1613130803Smarcel /* If no catchpoint triggered for this, then keep going. */ 1614130803Smarcel if (ecs->random_signal) 1615130803Smarcel { 1616130803Smarcel stop_signal = TARGET_SIGNAL_0; 1617130803Smarcel keep_going (ecs); 1618130803Smarcel return; 1619130803Smarcel } 1620130803Smarcel goto process_event_stop_test; 162119370Spst 1622130803Smarcel case TARGET_WAITKIND_EXECD: 1623130803Smarcel stop_signal = TARGET_SIGNAL_TRAP; 162419370Spst 1625130803Smarcel /* NOTE drow/2002-12-05: This code should be pushed down into the 1626130803Smarcel target_wait function. Until then following vfork on HP/UX 10.20 1627130803Smarcel is probably broken by this. Of course, it's broken anyway. */ 1628130803Smarcel /* Is this a target which reports multiple exec events per actual 1629130803Smarcel call to exec()? (HP-UX using ptrace does, for example.) If so, 1630130803Smarcel ignore all but the last one. Just resume the exec'r, and wait 1631130803Smarcel for the next exec event. */ 1632130803Smarcel if (inferior_ignoring_leading_exec_events) 1633130803Smarcel { 1634130803Smarcel inferior_ignoring_leading_exec_events--; 1635130803Smarcel if (pending_follow.kind == TARGET_WAITKIND_VFORKED) 1636130803Smarcel ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event. 1637130803Smarcel parent_pid); 1638130803Smarcel target_resume (ecs->ptid, 0, TARGET_SIGNAL_0); 1639130803Smarcel prepare_to_wait (ecs); 1640130803Smarcel return; 1641130803Smarcel } 1642130803Smarcel inferior_ignoring_leading_exec_events = 1643130803Smarcel target_reported_exec_events_per_exec_call () - 1; 164446283Sdfr 1645130803Smarcel pending_follow.execd_pathname = 1646130803Smarcel savestring (ecs->ws.value.execd_pathname, 1647130803Smarcel strlen (ecs->ws.value.execd_pathname)); 164819370Spst 1649130803Smarcel /* This causes the eventpoints and symbol table to be reset. Must 1650130803Smarcel do this now, before trying to determine whether to stop. */ 1651130803Smarcel follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); 1652130803Smarcel xfree (pending_follow.execd_pathname); 165319370Spst 1654130803Smarcel stop_pc = read_pc_pid (ecs->ptid); 1655130803Smarcel ecs->saved_inferior_ptid = inferior_ptid; 1656130803Smarcel inferior_ptid = ecs->ptid; 165719370Spst 1658130803Smarcel stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); 165919370Spst 1660130803Smarcel ecs->random_signal = !bpstat_explains_signal (stop_bpstat); 1661130803Smarcel inferior_ptid = ecs->saved_inferior_ptid; 166219370Spst 1663130803Smarcel /* If no catchpoint triggered for this, then keep going. */ 1664130803Smarcel if (ecs->random_signal) 1665130803Smarcel { 1666130803Smarcel stop_signal = TARGET_SIGNAL_0; 1667130803Smarcel keep_going (ecs); 1668130803Smarcel return; 1669130803Smarcel } 1670130803Smarcel goto process_event_stop_test; 167119370Spst 1672130803Smarcel /* These syscall events are returned on HP-UX, as part of its 1673130803Smarcel implementation of page-protection-based "hardware" watchpoints. 1674130803Smarcel HP-UX has unfortunate interactions between page-protections and 1675130803Smarcel some system calls. Our solution is to disable hardware watches 1676130803Smarcel when a system call is entered, and reenable them when the syscall 1677130803Smarcel completes. The downside of this is that we may miss the precise 1678130803Smarcel point at which a watched piece of memory is modified. "Oh well." 167919370Spst 1680130803Smarcel Note that we may have multiple threads running, which may each 1681130803Smarcel enter syscalls at roughly the same time. Since we don't have a 1682130803Smarcel good notion currently of whether a watched piece of memory is 1683130803Smarcel thread-private, we'd best not have any page-protections active 1684130803Smarcel when any thread is in a syscall. Thus, we only want to reenable 1685130803Smarcel hardware watches when no threads are in a syscall. 168646283Sdfr 1687130803Smarcel Also, be careful not to try to gather much state about a thread 1688130803Smarcel that's in a syscall. It's frequently a losing proposition. */ 1689130803Smarcel case TARGET_WAITKIND_SYSCALL_ENTRY: 1690130803Smarcel number_of_threads_in_syscalls++; 1691130803Smarcel if (number_of_threads_in_syscalls == 1) 1692130803Smarcel { 1693130803Smarcel TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); 1694130803Smarcel } 1695130803Smarcel resume (0, TARGET_SIGNAL_0); 1696130803Smarcel prepare_to_wait (ecs); 1697130803Smarcel return; 169819370Spst 1699130803Smarcel /* Before examining the threads further, step this thread to 1700130803Smarcel get it entirely out of the syscall. (We get notice of the 1701130803Smarcel event when the thread is just on the verge of exiting a 1702130803Smarcel syscall. Stepping one instruction seems to get it back 1703130803Smarcel into user code.) 170446283Sdfr 1705130803Smarcel Note that although the logical place to reenable h/w watches 1706130803Smarcel is here, we cannot. We cannot reenable them before stepping 1707130803Smarcel the thread (this causes the next wait on the thread to hang). 170846283Sdfr 1709130803Smarcel Nor can we enable them after stepping until we've done a wait. 1710130803Smarcel Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait 1711130803Smarcel here, which will be serviced immediately after the target 1712130803Smarcel is waited on. */ 1713130803Smarcel case TARGET_WAITKIND_SYSCALL_RETURN: 1714130803Smarcel target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); 171519370Spst 1716130803Smarcel if (number_of_threads_in_syscalls > 0) 1717130803Smarcel { 1718130803Smarcel number_of_threads_in_syscalls--; 1719130803Smarcel ecs->enable_hw_watchpoints_after_wait = 1720130803Smarcel (number_of_threads_in_syscalls == 0); 1721130803Smarcel } 1722130803Smarcel prepare_to_wait (ecs); 1723130803Smarcel return; 172446283Sdfr 1725130803Smarcel case TARGET_WAITKIND_STOPPED: 1726130803Smarcel stop_signal = ecs->ws.value.sig; 1727130803Smarcel break; 172819370Spst 1729130803Smarcel /* We had an event in the inferior, but we are not interested 1730130803Smarcel in handling it at this level. The lower layers have already 1731130803Smarcel done what needs to be done, if anything. 1732130803Smarcel 1733130803Smarcel One of the possible circumstances for this is when the 1734130803Smarcel inferior produces output for the console. The inferior has 1735130803Smarcel not stopped, and we are ignoring the event. Another possible 1736130803Smarcel circumstance is any event which the lower level knows will be 1737130803Smarcel reported multiple times without an intervening resume. */ 1738130803Smarcel case TARGET_WAITKIND_IGNORE: 1739130803Smarcel prepare_to_wait (ecs); 1740130803Smarcel return; 1741130803Smarcel } 174246283Sdfr 1743130803Smarcel /* We may want to consider not doing a resume here in order to give 1744130803Smarcel the user a chance to play with the new thread. It might be good 1745130803Smarcel to make that a user-settable option. */ 174646283Sdfr 1747130803Smarcel /* At this point, all threads are stopped (happens automatically in 1748130803Smarcel either the OS or the native code). Therefore we need to continue 1749130803Smarcel all threads in order to make progress. */ 1750130803Smarcel if (ecs->new_thread_event) 1751130803Smarcel { 1752130803Smarcel target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); 1753130803Smarcel prepare_to_wait (ecs); 1754130803Smarcel return; 1755130803Smarcel } 175619370Spst 1757130803Smarcel stop_pc = read_pc_pid (ecs->ptid); 175819370Spst 1759130803Smarcel if (stepping_past_singlestep_breakpoint) 1760130803Smarcel { 1761130803Smarcel gdb_assert (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p); 1762130803Smarcel gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid)); 1763130803Smarcel gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid)); 176419370Spst 1765130803Smarcel stepping_past_singlestep_breakpoint = 0; 176619370Spst 1767130803Smarcel /* We've either finished single-stepping past the single-step 1768130803Smarcel breakpoint, or stopped for some other reason. It would be nice if 1769130803Smarcel we could tell, but we can't reliably. */ 1770130803Smarcel if (stop_signal == TARGET_SIGNAL_TRAP) 1771130803Smarcel { 1772130803Smarcel /* Pull the single step breakpoints out of the target. */ 1773130803Smarcel SOFTWARE_SINGLE_STEP (0, 0); 1774130803Smarcel singlestep_breakpoints_inserted_p = 0; 177519370Spst 1776130803Smarcel ecs->random_signal = 0; 177719370Spst 1778130803Smarcel ecs->ptid = saved_singlestep_ptid; 1779130803Smarcel context_switch (ecs); 1780130803Smarcel if (context_hook) 1781130803Smarcel context_hook (pid_to_thread_id (ecs->ptid)); 178246283Sdfr 1783130803Smarcel resume (1, TARGET_SIGNAL_0); 1784130803Smarcel prepare_to_wait (ecs); 1785130803Smarcel return; 1786130803Smarcel } 1787130803Smarcel } 178819370Spst 1789130803Smarcel stepping_past_singlestep_breakpoint = 0; 179019370Spst 1791130803Smarcel /* See if a thread hit a thread-specific breakpoint that was meant for 1792130803Smarcel another thread. If so, then step that thread past the breakpoint, 1793130803Smarcel and continue it. */ 179446283Sdfr 1795130803Smarcel if (stop_signal == TARGET_SIGNAL_TRAP) 1796130803Smarcel { 1797130803Smarcel int thread_hop_needed = 0; 179846283Sdfr 1799130803Smarcel /* Check if a regular breakpoint has been hit before checking 1800130803Smarcel for a potential single step breakpoint. Otherwise, GDB will 1801130803Smarcel not see this breakpoint hit when stepping onto breakpoints. */ 1802130803Smarcel if (breakpoints_inserted && breakpoint_here_p (stop_pc)) 1803130803Smarcel { 1804130803Smarcel ecs->random_signal = 0; 1805130803Smarcel if (!breakpoint_thread_match (stop_pc, ecs->ptid)) 1806130803Smarcel thread_hop_needed = 1; 1807130803Smarcel } 1808130803Smarcel else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) 1809130803Smarcel { 1810130803Smarcel ecs->random_signal = 0; 1811130803Smarcel /* The call to in_thread_list is necessary because PTIDs sometimes 1812130803Smarcel change when we go from single-threaded to multi-threaded. If 1813130803Smarcel the singlestep_ptid is still in the list, assume that it is 1814130803Smarcel really different from ecs->ptid. */ 1815130803Smarcel if (!ptid_equal (singlestep_ptid, ecs->ptid) 1816130803Smarcel && in_thread_list (singlestep_ptid)) 1817130803Smarcel { 1818130803Smarcel thread_hop_needed = 1; 1819130803Smarcel stepping_past_singlestep_breakpoint = 1; 1820130803Smarcel saved_singlestep_ptid = singlestep_ptid; 1821130803Smarcel } 1822130803Smarcel } 182346283Sdfr 1824130803Smarcel if (thread_hop_needed) 1825130803Smarcel { 1826130803Smarcel int remove_status; 182719370Spst 1828130803Smarcel /* Saw a breakpoint, but it was hit by the wrong thread. 1829130803Smarcel Just continue. */ 183019370Spst 1831130803Smarcel if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) 1832130803Smarcel { 1833130803Smarcel /* Pull the single step breakpoints out of the target. */ 1834130803Smarcel SOFTWARE_SINGLE_STEP (0, 0); 1835130803Smarcel singlestep_breakpoints_inserted_p = 0; 1836130803Smarcel } 183746283Sdfr 1838130803Smarcel remove_status = remove_breakpoints (); 1839130803Smarcel /* Did we fail to remove breakpoints? If so, try 1840130803Smarcel to set the PC past the bp. (There's at least 1841130803Smarcel one situation in which we can fail to remove 1842130803Smarcel the bp's: On HP-UX's that use ttrace, we can't 1843130803Smarcel change the address space of a vforking child 1844130803Smarcel process until the child exits (well, okay, not 1845130803Smarcel then either :-) or execs. */ 1846130803Smarcel if (remove_status != 0) 1847130803Smarcel { 1848130803Smarcel /* FIXME! This is obviously non-portable! */ 1849130803Smarcel write_pc_pid (stop_pc + 4, ecs->ptid); 1850130803Smarcel /* We need to restart all the threads now, 1851130803Smarcel * unles we're running in scheduler-locked mode. 1852130803Smarcel * Use currently_stepping to determine whether to 1853130803Smarcel * step or continue. 1854130803Smarcel */ 1855130803Smarcel /* FIXME MVS: is there any reason not to call resume()? */ 1856130803Smarcel if (scheduler_mode == schedlock_on) 1857130803Smarcel target_resume (ecs->ptid, 1858130803Smarcel currently_stepping (ecs), TARGET_SIGNAL_0); 1859130803Smarcel else 1860130803Smarcel target_resume (RESUME_ALL, 1861130803Smarcel currently_stepping (ecs), TARGET_SIGNAL_0); 1862130803Smarcel prepare_to_wait (ecs); 1863130803Smarcel return; 1864130803Smarcel } 1865130803Smarcel else 1866130803Smarcel { /* Single step */ 1867130803Smarcel breakpoints_inserted = 0; 1868130803Smarcel if (!ptid_equal (inferior_ptid, ecs->ptid)) 1869130803Smarcel context_switch (ecs); 1870130803Smarcel ecs->waiton_ptid = ecs->ptid; 1871130803Smarcel ecs->wp = &(ecs->ws); 1872130803Smarcel ecs->another_trap = 1; 187346283Sdfr 1874130803Smarcel ecs->infwait_state = infwait_thread_hop_state; 1875130803Smarcel keep_going (ecs); 1876130803Smarcel registers_changed (); 1877130803Smarcel return; 1878130803Smarcel } 1879130803Smarcel } 1880130803Smarcel else if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) 1881130803Smarcel { 1882130803Smarcel sw_single_step_trap_p = 1; 1883130803Smarcel ecs->random_signal = 0; 1884130803Smarcel } 1885130803Smarcel } 1886130803Smarcel else 1887130803Smarcel ecs->random_signal = 1; 188846283Sdfr 1889130803Smarcel /* See if something interesting happened to the non-current thread. If 1890130803Smarcel so, then switch to that thread, and eventually give control back to 1891130803Smarcel the user. 189219370Spst 1893130803Smarcel Note that if there's any kind of pending follow (i.e., of a fork, 1894130803Smarcel vfork or exec), we don't want to do this now. Rather, we'll let 1895130803Smarcel the next resume handle it. */ 1896130803Smarcel if (!ptid_equal (ecs->ptid, inferior_ptid) && 1897130803Smarcel (pending_follow.kind == TARGET_WAITKIND_SPURIOUS)) 1898130803Smarcel { 1899130803Smarcel int printed = 0; 190046283Sdfr 1901130803Smarcel /* If it's a random signal for a non-current thread, notify user 1902130803Smarcel if he's expressed an interest. */ 1903130803Smarcel if (ecs->random_signal && signal_print[stop_signal]) 1904130803Smarcel { 1905130803Smarcel/* ??rehrauer: I don't understand the rationale for this code. If the 1906130803Smarcel inferior will stop as a result of this signal, then the act of handling 1907130803Smarcel the stop ought to print a message that's couches the stoppage in user 1908130803Smarcel terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior 1909130803Smarcel won't stop as a result of the signal -- i.e., if the signal is merely 1910130803Smarcel a side-effect of something GDB's doing "under the covers" for the 1911130803Smarcel user, such as stepping threads over a breakpoint they shouldn't stop 1912130803Smarcel for -- then the message seems to be a serious annoyance at best. 191346283Sdfr 1914130803Smarcel For now, remove the message altogether. */ 1915130803Smarcel#if 0 1916130803Smarcel printed = 1; 1917130803Smarcel target_terminal_ours_for_output (); 1918130803Smarcel printf_filtered ("\nProgram received signal %s, %s.\n", 1919130803Smarcel target_signal_to_name (stop_signal), 1920130803Smarcel target_signal_to_string (stop_signal)); 1921130803Smarcel gdb_flush (gdb_stdout); 1922130803Smarcel#endif 1923130803Smarcel } 192446283Sdfr 1925130803Smarcel /* If it's not SIGTRAP and not a signal we want to stop for, then 1926130803Smarcel continue the thread. */ 192719370Spst 1928130803Smarcel if (stop_signal != TARGET_SIGNAL_TRAP && !signal_stop[stop_signal]) 1929130803Smarcel { 1930130803Smarcel if (printed) 1931130803Smarcel target_terminal_inferior (); 193246283Sdfr 1933130803Smarcel /* Clear the signal if it should not be passed. */ 1934130803Smarcel if (signal_program[stop_signal] == 0) 1935130803Smarcel stop_signal = TARGET_SIGNAL_0; 193646283Sdfr 1937130803Smarcel target_resume (ecs->ptid, 0, stop_signal); 1938130803Smarcel prepare_to_wait (ecs); 1939130803Smarcel return; 1940130803Smarcel } 194119370Spst 1942130803Smarcel /* It's a SIGTRAP or a signal we're interested in. Switch threads, 1943130803Smarcel and fall into the rest of wait_for_inferior(). */ 194419370Spst 1945130803Smarcel context_switch (ecs); 194646283Sdfr 1947130803Smarcel if (context_hook) 1948130803Smarcel context_hook (pid_to_thread_id (ecs->ptid)); 194946283Sdfr 1950130803Smarcel flush_cached_frames (); 1951130803Smarcel } 195219370Spst 1953130803Smarcel if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) 1954130803Smarcel { 1955130803Smarcel /* Pull the single step breakpoints out of the target. */ 1956130803Smarcel SOFTWARE_SINGLE_STEP (0, 0); 1957130803Smarcel singlestep_breakpoints_inserted_p = 0; 1958130803Smarcel } 195919370Spst 1960130803Smarcel /* If PC is pointing at a nullified instruction, then step beyond 1961130803Smarcel it so that the user won't be confused when GDB appears to be ready 1962130803Smarcel to execute it. */ 196319370Spst 1964130803Smarcel /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */ 1965130803Smarcel if (INSTRUCTION_NULLIFIED) 196698944Sobrien { 1967130803Smarcel registers_changed (); 1968130803Smarcel target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); 196998944Sobrien 1970130803Smarcel /* We may have received a signal that we want to pass to 1971130803Smarcel the inferior; therefore, we must not clobber the waitstatus 1972130803Smarcel in WS. */ 197398944Sobrien 1974130803Smarcel ecs->infwait_state = infwait_nullified_state; 1975130803Smarcel ecs->waiton_ptid = ecs->ptid; 1976130803Smarcel ecs->wp = &(ecs->tmpstatus); 1977130803Smarcel prepare_to_wait (ecs); 1978130803Smarcel return; 1979130803Smarcel } 198019370Spst 1981130803Smarcel /* It may not be necessary to disable the watchpoint to stop over 1982130803Smarcel it. For example, the PA can (with some kernel cooperation) 1983130803Smarcel single step over a watchpoint without disabling the watchpoint. */ 1984130803Smarcel if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) 1985130803Smarcel { 1986130803Smarcel resume (1, 0); 1987130803Smarcel prepare_to_wait (ecs); 1988130803Smarcel return; 1989130803Smarcel } 199019370Spst 1991130803Smarcel /* It is far more common to need to disable a watchpoint to step 1992130803Smarcel the inferior over it. FIXME. What else might a debug 1993130803Smarcel register or page protection watchpoint scheme need here? */ 1994130803Smarcel if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) 1995130803Smarcel { 1996130803Smarcel /* At this point, we are stopped at an instruction which has 1997130803Smarcel attempted to write to a piece of memory under control of 1998130803Smarcel a watchpoint. The instruction hasn't actually executed 1999130803Smarcel yet. If we were to evaluate the watchpoint expression 2000130803Smarcel now, we would get the old value, and therefore no change 2001130803Smarcel would seem to have occurred. 200219370Spst 2003130803Smarcel In order to make watchpoints work `right', we really need 2004130803Smarcel to complete the memory write, and then evaluate the 2005130803Smarcel watchpoint expression. The following code does that by 2006130803Smarcel removing the watchpoint (actually, all watchpoints and 2007130803Smarcel breakpoints), single-stepping the target, re-inserting 2008130803Smarcel watchpoints, and then falling through to let normal 2009130803Smarcel single-step processing handle proceed. Since this 2010130803Smarcel includes evaluating watchpoints, things will come to a 2011130803Smarcel stop in the correct manner. */ 201219370Spst 2013130803Smarcel remove_breakpoints (); 2014130803Smarcel registers_changed (); 2015130803Smarcel target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */ 201619370Spst 2017130803Smarcel ecs->waiton_ptid = ecs->ptid; 2018130803Smarcel ecs->wp = &(ecs->ws); 2019130803Smarcel ecs->infwait_state = infwait_nonstep_watch_state; 2020130803Smarcel prepare_to_wait (ecs); 2021130803Smarcel return; 2022130803Smarcel } 202319370Spst 2024130803Smarcel /* It may be possible to simply continue after a watchpoint. */ 2025130803Smarcel if (HAVE_CONTINUABLE_WATCHPOINT) 2026130803Smarcel STOPPED_BY_WATCHPOINT (ecs->ws); 202719370Spst 2028130803Smarcel ecs->stop_func_start = 0; 2029130803Smarcel ecs->stop_func_end = 0; 2030130803Smarcel ecs->stop_func_name = 0; 2031130803Smarcel /* Don't care about return value; stop_func_start and stop_func_name 2032130803Smarcel will both be 0 if it doesn't work. */ 2033130803Smarcel find_pc_partial_function (stop_pc, &ecs->stop_func_name, 2034130803Smarcel &ecs->stop_func_start, &ecs->stop_func_end); 2035130803Smarcel ecs->stop_func_start += FUNCTION_START_OFFSET; 2036130803Smarcel ecs->another_trap = 0; 2037130803Smarcel bpstat_clear (&stop_bpstat); 2038130803Smarcel stop_step = 0; 2039130803Smarcel stop_stack_dummy = 0; 2040130803Smarcel stop_print_frame = 1; 2041130803Smarcel ecs->random_signal = 0; 2042130803Smarcel stopped_by_random_signal = 0; 2043130803Smarcel breakpoints_failed = 0; 204419370Spst 2045130803Smarcel /* Look at the cause of the stop, and decide what to do. 2046130803Smarcel The alternatives are: 2047130803Smarcel 1) break; to really stop and return to the debugger, 2048130803Smarcel 2) drop through to start up again 2049130803Smarcel (set ecs->another_trap to 1 to single step once) 2050130803Smarcel 3) set ecs->random_signal to 1, and the decision between 1 and 2 2051130803Smarcel will be made according to the signal handling tables. */ 2052130803Smarcel 2053130803Smarcel /* First, distinguish signals caused by the debugger from signals 2054130803Smarcel that have to do with the program's own actions. Note that 2055130803Smarcel breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending 2056130803Smarcel on the operating system version. Here we detect when a SIGILL or 2057130803Smarcel SIGEMT is really a breakpoint and change it to SIGTRAP. We do 2058130803Smarcel something similar for SIGSEGV, since a SIGSEGV will be generated 2059130803Smarcel when we're trying to execute a breakpoint instruction on a 2060130803Smarcel non-executable stack. This happens for call dummy breakpoints 2061130803Smarcel for architectures like SPARC that place call dummies on the 2062130803Smarcel stack. */ 2063130803Smarcel 2064130803Smarcel if (stop_signal == TARGET_SIGNAL_TRAP 2065130803Smarcel || (breakpoints_inserted && 2066130803Smarcel (stop_signal == TARGET_SIGNAL_ILL 2067130803Smarcel || stop_signal == TARGET_SIGNAL_SEGV 2068130803Smarcel || stop_signal == TARGET_SIGNAL_EMT)) 2069130803Smarcel || stop_soon == STOP_QUIETLY 2070130803Smarcel || stop_soon == STOP_QUIETLY_NO_SIGSTOP) 2071130803Smarcel { 2072130803Smarcel if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) 2073130803Smarcel { 2074130803Smarcel stop_print_frame = 0; 207598944Sobrien stop_stepping (ecs); 207698944Sobrien return; 2077130803Smarcel } 207819370Spst 2079130803Smarcel /* This is originated from start_remote(), start_inferior() and 2080130803Smarcel shared libraries hook functions. */ 2081130803Smarcel if (stop_soon == STOP_QUIETLY) 2082130803Smarcel { 2083130803Smarcel stop_stepping (ecs); 2084130803Smarcel return; 2085130803Smarcel } 208619370Spst 2087130803Smarcel /* This originates from attach_command(). We need to overwrite 2088130803Smarcel the stop_signal here, because some kernels don't ignore a 2089130803Smarcel SIGSTOP in a subsequent ptrace(PTRACE_SONT,SOGSTOP) call. 2090130803Smarcel See more comments in inferior.h. */ 2091130803Smarcel if (stop_soon == STOP_QUIETLY_NO_SIGSTOP) 2092130803Smarcel { 209398944Sobrien stop_stepping (ecs); 2094130803Smarcel if (stop_signal == TARGET_SIGNAL_STOP) 2095130803Smarcel stop_signal = TARGET_SIGNAL_0; 209698944Sobrien return; 2097130803Smarcel } 209846283Sdfr 2099130803Smarcel /* Don't even think about breakpoints 2100130803Smarcel if just proceeded over a breakpoint. 210146283Sdfr 2102130803Smarcel However, if we are trying to proceed over a breakpoint 2103130803Smarcel and end up in sigtramp, then through_sigtramp_breakpoint 2104130803Smarcel will be set and we should check whether we've hit the 2105130803Smarcel step breakpoint. */ 2106130803Smarcel if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected 2107130803Smarcel && through_sigtramp_breakpoint == NULL) 2108130803Smarcel bpstat_clear (&stop_bpstat); 2109130803Smarcel else 2110130803Smarcel { 2111130803Smarcel /* See if there is a breakpoint at the current PC. */ 2112130803Smarcel stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid); 211319370Spst 2114130803Smarcel /* Following in case break condition called a 2115130803Smarcel function. */ 2116130803Smarcel stop_print_frame = 1; 2117130803Smarcel } 211819370Spst 2119130803Smarcel /* NOTE: cagney/2003-03-29: These two checks for a random signal 2120130803Smarcel at one stage in the past included checks for an inferior 2121130803Smarcel function call's call dummy's return breakpoint. The original 2122130803Smarcel comment, that went with the test, read: 212319370Spst 2124130803Smarcel ``End of a stack dummy. Some systems (e.g. Sony news) give 2125130803Smarcel another signal besides SIGTRAP, so check here as well as 2126130803Smarcel above.'' 212719370Spst 2128130803Smarcel If someone ever tries to get get call dummys on a 2129130803Smarcel non-executable stack to work (where the target would stop 2130130803Smarcel with something like a SIGSEGV), then those tests might need 2131130803Smarcel to be re-instated. Given, however, that the tests were only 2132130803Smarcel enabled when momentary breakpoints were not being used, I 2133130803Smarcel suspect that it won't be the case. 213419370Spst 2135130803Smarcel NOTE: kettenis/2004-02-05: Indeed such checks don't seem to 2136130803Smarcel be necessary for call dummies on a non-executable stack on 2137130803Smarcel SPARC. */ 213819370Spst 2139130803Smarcel if (stop_signal == TARGET_SIGNAL_TRAP) 2140130803Smarcel ecs->random_signal 2141130803Smarcel = !(bpstat_explains_signal (stop_bpstat) 2142130803Smarcel || trap_expected 2143130803Smarcel || (step_range_end && step_resume_breakpoint == NULL)); 2144130803Smarcel else 2145130803Smarcel { 2146130803Smarcel ecs->random_signal = !bpstat_explains_signal (stop_bpstat); 2147130803Smarcel if (!ecs->random_signal) 2148130803Smarcel stop_signal = TARGET_SIGNAL_TRAP; 2149130803Smarcel } 2150130803Smarcel } 215146283Sdfr 2152130803Smarcel /* When we reach this point, we've pretty much decided 2153130803Smarcel that the reason for stopping must've been a random 2154130803Smarcel (unexpected) signal. */ 215546283Sdfr 2156130803Smarcel else 2157130803Smarcel ecs->random_signal = 1; 215846283Sdfr 2159130803Smarcelprocess_event_stop_test: 2160130803Smarcel /* For the program's own signals, act according to 2161130803Smarcel the signal handling tables. */ 216246283Sdfr 2163130803Smarcel if (ecs->random_signal) 2164130803Smarcel { 2165130803Smarcel /* Signal not for debugging purposes. */ 2166130803Smarcel int printed = 0; 216746283Sdfr 2168130803Smarcel stopped_by_random_signal = 1; 216919370Spst 2170130803Smarcel if (signal_print[stop_signal]) 2171130803Smarcel { 2172130803Smarcel printed = 1; 2173130803Smarcel target_terminal_ours_for_output (); 2174130803Smarcel print_stop_reason (SIGNAL_RECEIVED, stop_signal); 2175130803Smarcel } 2176130803Smarcel if (signal_stop[stop_signal]) 2177130803Smarcel { 2178130803Smarcel stop_stepping (ecs); 2179130803Smarcel return; 2180130803Smarcel } 2181130803Smarcel /* If not going to stop, give terminal back 2182130803Smarcel if we took it away. */ 2183130803Smarcel else if (printed) 2184130803Smarcel target_terminal_inferior (); 218519370Spst 2186130803Smarcel /* Clear the signal if it should not be passed. */ 2187130803Smarcel if (signal_program[stop_signal] == 0) 2188130803Smarcel stop_signal = TARGET_SIGNAL_0; 218919370Spst 2190130803Smarcel /* I'm not sure whether this needs to be check_sigtramp2 or 2191130803Smarcel whether it could/should be keep_going. 219219370Spst 2193130803Smarcel This used to jump to step_over_function if we are stepping, 2194130803Smarcel which is wrong. 2195130803Smarcel 2196130803Smarcel Suppose the user does a `next' over a function call, and while 2197130803Smarcel that call is in progress, the inferior receives a signal for 2198130803Smarcel which GDB does not stop (i.e., signal_stop[SIG] is false). In 2199130803Smarcel that case, when we reach this point, there is already a 2200130803Smarcel step-resume breakpoint established, right where it should be: 2201130803Smarcel immediately after the function call the user is "next"-ing 2202130803Smarcel over. If we call step_over_function now, two bad things 2203130803Smarcel happen: 2204130803Smarcel 2205130803Smarcel - we'll create a new breakpoint, at wherever the current 2206130803Smarcel frame's return address happens to be. That could be 2207130803Smarcel anywhere, depending on what function call happens to be on 2208130803Smarcel the top of the stack at that point. Point is, it's probably 2209130803Smarcel not where we need it. 2210130803Smarcel 2211130803Smarcel - the existing step-resume breakpoint (which is at the correct 2212130803Smarcel address) will get orphaned: step_resume_breakpoint will point 2213130803Smarcel to the new breakpoint, and the old step-resume breakpoint 2214130803Smarcel will never be cleaned up. 2215130803Smarcel 2216130803Smarcel The old behavior was meant to help HP-UX single-step out of 2217130803Smarcel sigtramps. It would place the new breakpoint at prev_pc, which 2218130803Smarcel was certainly wrong. I don't know the details there, so fixing 2219130803Smarcel this probably breaks that. As with anything else, it's up to 2220130803Smarcel the HP-UX maintainer to furnish a fix that doesn't break other 2221130803Smarcel platforms. --JimB, 20 May 1999 */ 2222130803Smarcel check_sigtramp2 (ecs); 2223130803Smarcel keep_going (ecs); 2224130803Smarcel return; 222598944Sobrien } 222698944Sobrien 2227130803Smarcel /* Handle cases caused by hitting a breakpoint. */ 2228130803Smarcel { 2229130803Smarcel CORE_ADDR jmp_buf_pc; 2230130803Smarcel struct bpstat_what what; 223198944Sobrien 2232130803Smarcel what = bpstat_what (stop_bpstat); 2233130803Smarcel 2234130803Smarcel if (what.call_dummy) 223598944Sobrien { 2236130803Smarcel stop_stack_dummy = 1; 2237130803Smarcel#ifdef HP_OS_BUG 2238130803Smarcel trap_expected_after_continue = 1; 2239130803Smarcel#endif 2240130803Smarcel } 2241130803Smarcel 2242130803Smarcel switch (what.main_action) 2243130803Smarcel { 2244130803Smarcel case BPSTAT_WHAT_SET_LONGJMP_RESUME: 2245130803Smarcel /* If we hit the breakpoint at longjmp, disable it for the 2246130803Smarcel duration of this command. Then, install a temporary 2247130803Smarcel breakpoint at the target of the jmp_buf. */ 2248130803Smarcel disable_longjmp_breakpoint (); 2249130803Smarcel remove_breakpoints (); 2250130803Smarcel breakpoints_inserted = 0; 2251130803Smarcel if (!GET_LONGJMP_TARGET_P () || !GET_LONGJMP_TARGET (&jmp_buf_pc)) 225298944Sobrien { 225398944Sobrien keep_going (ecs); 225498944Sobrien return; 225598944Sobrien } 225646283Sdfr 2257130803Smarcel /* Need to blow away step-resume breakpoint, as it 2258130803Smarcel interferes with us */ 2259130803Smarcel if (step_resume_breakpoint != NULL) 2260130803Smarcel { 2261130803Smarcel delete_step_resume_breakpoint (&step_resume_breakpoint); 2262130803Smarcel } 2263130803Smarcel /* Not sure whether we need to blow this away too, but probably 2264130803Smarcel it is like the step-resume breakpoint. */ 2265130803Smarcel if (through_sigtramp_breakpoint != NULL) 2266130803Smarcel { 2267130803Smarcel delete_breakpoint (through_sigtramp_breakpoint); 2268130803Smarcel through_sigtramp_breakpoint = NULL; 2269130803Smarcel } 227019370Spst 2271130803Smarcel#if 0 2272130803Smarcel /* FIXME - Need to implement nested temporary breakpoints */ 2273130803Smarcel if (step_over_calls > 0) 2274130803Smarcel set_longjmp_resume_breakpoint (jmp_buf_pc, get_current_frame ()); 2275130803Smarcel else 2276130803Smarcel#endif /* 0 */ 2277130803Smarcel set_longjmp_resume_breakpoint (jmp_buf_pc, null_frame_id); 2278130803Smarcel ecs->handling_longjmp = 1; /* FIXME */ 2279130803Smarcel keep_going (ecs); 2280130803Smarcel return; 228119370Spst 2282130803Smarcel case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: 2283130803Smarcel case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: 2284130803Smarcel remove_breakpoints (); 2285130803Smarcel breakpoints_inserted = 0; 2286130803Smarcel#if 0 2287130803Smarcel /* FIXME - Need to implement nested temporary breakpoints */ 2288130803Smarcel if (step_over_calls 2289130803Smarcel && (frame_id_inner (get_frame_id (get_current_frame ()), 2290130803Smarcel step_frame_id))) 229198944Sobrien { 2292130803Smarcel ecs->another_trap = 1; 2293130803Smarcel keep_going (ecs); 229498944Sobrien return; 229598944Sobrien } 2296130803Smarcel#endif /* 0 */ 2297130803Smarcel disable_longjmp_breakpoint (); 2298130803Smarcel ecs->handling_longjmp = 0; /* FIXME */ 2299130803Smarcel if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) 2300130803Smarcel break; 2301130803Smarcel /* else fallthrough */ 230219370Spst 2303130803Smarcel case BPSTAT_WHAT_SINGLE: 2304130803Smarcel if (breakpoints_inserted) 2305130803Smarcel { 2306130803Smarcel remove_breakpoints (); 2307130803Smarcel } 2308130803Smarcel breakpoints_inserted = 0; 2309130803Smarcel ecs->another_trap = 1; 2310130803Smarcel /* Still need to check other stuff, at least the case 2311130803Smarcel where we are stepping and step out of the right range. */ 2312130803Smarcel break; 2313130803Smarcel 2314130803Smarcel case BPSTAT_WHAT_STOP_NOISY: 2315130803Smarcel stop_print_frame = 1; 2316130803Smarcel 2317130803Smarcel /* We are about to nuke the step_resume_breakpoint and 2318130803Smarcel through_sigtramp_breakpoint via the cleanup chain, so 2319130803Smarcel no need to worry about it here. */ 2320130803Smarcel 2321130803Smarcel stop_stepping (ecs); 232298944Sobrien return; 232319370Spst 2324130803Smarcel case BPSTAT_WHAT_STOP_SILENT: 2325130803Smarcel stop_print_frame = 0; 232646283Sdfr 2327130803Smarcel /* We are about to nuke the step_resume_breakpoint and 2328130803Smarcel through_sigtramp_breakpoint via the cleanup chain, so 2329130803Smarcel no need to worry about it here. */ 2330130803Smarcel 2331130803Smarcel stop_stepping (ecs); 233298944Sobrien return; 233319370Spst 2334130803Smarcel case BPSTAT_WHAT_STEP_RESUME: 2335130803Smarcel /* This proably demands a more elegant solution, but, yeah 2336130803Smarcel right... 233719370Spst 2338130803Smarcel This function's use of the simple variable 2339130803Smarcel step_resume_breakpoint doesn't seem to accomodate 2340130803Smarcel simultaneously active step-resume bp's, although the 2341130803Smarcel breakpoint list certainly can. 234219370Spst 2343130803Smarcel If we reach here and step_resume_breakpoint is already 2344130803Smarcel NULL, then apparently we have multiple active 2345130803Smarcel step-resume bp's. We'll just delete the breakpoint we 2346130803Smarcel stopped at, and carry on. 2347130803Smarcel 2348130803Smarcel Correction: what the code currently does is delete a 2349130803Smarcel step-resume bp, but it makes no effort to ensure that 2350130803Smarcel the one deleted is the one currently stopped at. MVS */ 2351130803Smarcel 2352130803Smarcel if (step_resume_breakpoint == NULL) 235319370Spst { 235498944Sobrien step_resume_breakpoint = 2355130803Smarcel bpstat_find_step_resume_breakpoint (stop_bpstat); 235619370Spst } 2357130803Smarcel delete_step_resume_breakpoint (&step_resume_breakpoint); 2358130803Smarcel break; 235919370Spst 2360130803Smarcel case BPSTAT_WHAT_THROUGH_SIGTRAMP: 2361130803Smarcel if (through_sigtramp_breakpoint) 2362130803Smarcel delete_breakpoint (through_sigtramp_breakpoint); 2363130803Smarcel through_sigtramp_breakpoint = NULL; 236446283Sdfr 2365130803Smarcel /* If were waiting for a trap, hitting the step_resume_break 2366130803Smarcel doesn't count as getting it. */ 2367130803Smarcel if (trap_expected) 2368130803Smarcel ecs->another_trap = 1; 2369130803Smarcel break; 237019370Spst 2371130803Smarcel case BPSTAT_WHAT_CHECK_SHLIBS: 2372130803Smarcel case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: 2373130803Smarcel#ifdef SOLIB_ADD 2374130803Smarcel { 2375130803Smarcel /* Remove breakpoints, we eventually want to step over the 2376130803Smarcel shlib event breakpoint, and SOLIB_ADD might adjust 2377130803Smarcel breakpoint addresses via breakpoint_re_set. */ 2378130803Smarcel if (breakpoints_inserted) 2379130803Smarcel remove_breakpoints (); 2380130803Smarcel breakpoints_inserted = 0; 238119370Spst 2382130803Smarcel /* Check for any newly added shared libraries if we're 2383130803Smarcel supposed to be adding them automatically. Switch 2384130803Smarcel terminal for any messages produced by 2385130803Smarcel breakpoint_re_set. */ 2386130803Smarcel target_terminal_ours_for_output (); 2387130803Smarcel /* NOTE: cagney/2003-11-25: Make certain that the target 2388130803Smarcel stack's section table is kept up-to-date. Architectures, 2389130803Smarcel (e.g., PPC64), use the section table to perform 2390130803Smarcel operations such as address => section name and hence 2391130803Smarcel require the table to contain all sections (including 2392130803Smarcel those found in shared libraries). */ 2393130803Smarcel /* NOTE: cagney/2003-11-25: Pass current_target and not 2394130803Smarcel exec_ops to SOLIB_ADD. This is because current GDB is 2395130803Smarcel only tooled to propagate section_table changes out from 2396130803Smarcel the "current_target" (see target_resize_to_sections), and 2397130803Smarcel not up from the exec stratum. This, of course, isn't 2398130803Smarcel right. "infrun.c" should only interact with the 2399130803Smarcel exec/process stratum, instead relying on the target stack 2400130803Smarcel to propagate relevant changes (stop, section table 2401130803Smarcel changed, ...) up to other layers. */ 2402130803Smarcel SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); 2403130803Smarcel target_terminal_inferior (); 240419370Spst 2405130803Smarcel /* Try to reenable shared library breakpoints, additional 2406130803Smarcel code segments in shared libraries might be mapped in now. */ 2407130803Smarcel re_enable_breakpoints_in_shlibs (); 240819370Spst 2409130803Smarcel /* If requested, stop when the dynamic linker notifies 2410130803Smarcel gdb of events. This allows the user to get control 2411130803Smarcel and place breakpoints in initializer routines for 2412130803Smarcel dynamically loaded objects (among other things). */ 2413130803Smarcel if (stop_on_solib_events || stop_stack_dummy) 2414130803Smarcel { 2415130803Smarcel stop_stepping (ecs); 2416130803Smarcel return; 2417130803Smarcel } 241819370Spst 2419130803Smarcel /* If we stopped due to an explicit catchpoint, then the 2420130803Smarcel (see above) call to SOLIB_ADD pulled in any symbols 2421130803Smarcel from a newly-loaded library, if appropriate. 2422130803Smarcel 2423130803Smarcel We do want the inferior to stop, but not where it is 2424130803Smarcel now, which is in the dynamic linker callback. Rather, 2425130803Smarcel we would like it stop in the user's program, just after 2426130803Smarcel the call that caused this catchpoint to trigger. That 2427130803Smarcel gives the user a more useful vantage from which to 2428130803Smarcel examine their program's state. */ 2429130803Smarcel else if (what.main_action == 2430130803Smarcel BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) 243198944Sobrien { 2432130803Smarcel /* ??rehrauer: If I could figure out how to get the 2433130803Smarcel right return PC from here, we could just set a temp 2434130803Smarcel breakpoint and resume. I'm not sure we can without 2435130803Smarcel cracking open the dld's shared libraries and sniffing 2436130803Smarcel their unwind tables and text/data ranges, and that's 2437130803Smarcel not a terribly portable notion. 243819370Spst 2439130803Smarcel Until that time, we must step the inferior out of the 2440130803Smarcel dld callback, and also out of the dld itself (and any 2441130803Smarcel code or stubs in libdld.sl, such as "shl_load" and 2442130803Smarcel friends) until we reach non-dld code. At that point, 2443130803Smarcel we can stop stepping. */ 2444130803Smarcel bpstat_get_triggered_catchpoints (stop_bpstat, 2445130803Smarcel &ecs-> 2446130803Smarcel stepping_through_solib_catchpoints); 2447130803Smarcel ecs->stepping_through_solib_after_catch = 1; 244819370Spst 2449130803Smarcel /* Be sure to lift all breakpoints, so the inferior does 2450130803Smarcel actually step past this point... */ 2451130803Smarcel ecs->another_trap = 1; 2452130803Smarcel break; 245398944Sobrien } 245498944Sobrien else 245598944Sobrien { 2456130803Smarcel /* We want to step over this breakpoint, then keep going. */ 2457130803Smarcel ecs->another_trap = 1; 2458130803Smarcel break; 245998944Sobrien } 246098944Sobrien } 2461130803Smarcel#endif 2462130803Smarcel break; 246319370Spst 2464130803Smarcel case BPSTAT_WHAT_LAST: 2465130803Smarcel /* Not a real code, but listed here to shut up gcc -Wall. */ 246619370Spst 2467130803Smarcel case BPSTAT_WHAT_KEEP_CHECKING: 2468130803Smarcel break; 246998944Sobrien } 2470130803Smarcel } 247119370Spst 2472130803Smarcel /* We come here if we hit a breakpoint but should not 2473130803Smarcel stop for it. Possibly we also were stepping 2474130803Smarcel and should stop for that. So fall through and 2475130803Smarcel test for stepping. But, if not stepping, 2476130803Smarcel do not stop. */ 247719370Spst 2478130803Smarcel /* Are we stepping to get the inferior out of the dynamic 2479130803Smarcel linker's hook (and possibly the dld itself) after catching 2480130803Smarcel a shlib event? */ 2481130803Smarcel if (ecs->stepping_through_solib_after_catch) 2482130803Smarcel { 2483130803Smarcel#if defined(SOLIB_ADD) 2484130803Smarcel /* Have we reached our destination? If not, keep going. */ 2485130803Smarcel if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) 2486130803Smarcel { 2487130803Smarcel ecs->another_trap = 1; 2488130803Smarcel keep_going (ecs); 2489130803Smarcel return; 2490130803Smarcel } 2491130803Smarcel#endif 2492130803Smarcel /* Else, stop and report the catchpoint(s) whose triggering 2493130803Smarcel caused us to begin stepping. */ 2494130803Smarcel ecs->stepping_through_solib_after_catch = 0; 2495130803Smarcel bpstat_clear (&stop_bpstat); 2496130803Smarcel stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); 2497130803Smarcel bpstat_clear (&ecs->stepping_through_solib_catchpoints); 2498130803Smarcel stop_print_frame = 1; 2499130803Smarcel stop_stepping (ecs); 2500130803Smarcel return; 2501130803Smarcel } 250219370Spst 2503130803Smarcel if (step_resume_breakpoint) 2504130803Smarcel { 2505130803Smarcel /* Having a step-resume breakpoint overrides anything 2506130803Smarcel else having to do with stepping commands until 2507130803Smarcel that breakpoint is reached. */ 2508130803Smarcel /* I'm not sure whether this needs to be check_sigtramp2 or 2509130803Smarcel whether it could/should be keep_going. */ 2510130803Smarcel check_sigtramp2 (ecs); 2511130803Smarcel keep_going (ecs); 2512130803Smarcel return; 2513130803Smarcel } 251419370Spst 2515130803Smarcel if (step_range_end == 0) 2516130803Smarcel { 2517130803Smarcel /* Likewise if we aren't even stepping. */ 2518130803Smarcel /* I'm not sure whether this needs to be check_sigtramp2 or 2519130803Smarcel whether it could/should be keep_going. */ 2520130803Smarcel check_sigtramp2 (ecs); 2521130803Smarcel keep_going (ecs); 2522130803Smarcel return; 2523130803Smarcel } 252419370Spst 2525130803Smarcel /* If stepping through a line, keep going if still within it. 252619370Spst 2527130803Smarcel Note that step_range_end is the address of the first instruction 2528130803Smarcel beyond the step range, and NOT the address of the last instruction 2529130803Smarcel within it! */ 2530130803Smarcel if (stop_pc >= step_range_start && stop_pc < step_range_end) 2531130803Smarcel { 2532130803Smarcel /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal. 2533130803Smarcel So definately need to check for sigtramp here. */ 2534130803Smarcel check_sigtramp2 (ecs); 2535130803Smarcel keep_going (ecs); 2536130803Smarcel return; 2537130803Smarcel } 253819370Spst 2539130803Smarcel /* We stepped out of the stepping range. */ 254019370Spst 2541130803Smarcel /* If we are stepping at the source level and entered the runtime 2542130803Smarcel loader dynamic symbol resolution code, we keep on single stepping 2543130803Smarcel until we exit the run time loader code and reach the callee's 2544130803Smarcel address. */ 2545130803Smarcel if (step_over_calls == STEP_OVER_UNDEBUGGABLE 2546130803Smarcel && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc)) 2547130803Smarcel { 2548130803Smarcel CORE_ADDR pc_after_resolver = 2549130803Smarcel gdbarch_skip_solib_resolver (current_gdbarch, stop_pc); 2550130803Smarcel 2551130803Smarcel if (pc_after_resolver) 255298944Sobrien { 2553130803Smarcel /* Set up a step-resume breakpoint at the address 2554130803Smarcel indicated by SKIP_SOLIB_RESOLVER. */ 2555130803Smarcel struct symtab_and_line sr_sal; 2556130803Smarcel init_sal (&sr_sal); 2557130803Smarcel sr_sal.pc = pc_after_resolver; 255819370Spst 2559130803Smarcel check_for_old_step_resume_breakpoint (); 2560130803Smarcel step_resume_breakpoint = 2561130803Smarcel set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume); 2562130803Smarcel if (breakpoints_inserted) 2563130803Smarcel insert_breakpoints (); 256498944Sobrien } 256519370Spst 2566130803Smarcel keep_going (ecs); 2567130803Smarcel return; 2568130803Smarcel } 256919370Spst 2570130803Smarcel /* We can't update step_sp every time through the loop, because 2571130803Smarcel reading the stack pointer would slow down stepping too much. 2572130803Smarcel But we can update it every time we leave the step range. */ 2573130803Smarcel ecs->update_step_sp = 1; 257419370Spst 2575130803Smarcel /* Did we just take a signal? */ 2576130803Smarcel if (pc_in_sigtramp (stop_pc) 2577130803Smarcel && !pc_in_sigtramp (prev_pc) 2578130803Smarcel && INNER_THAN (read_sp (), step_sp)) 2579130803Smarcel { 2580130803Smarcel /* We've just taken a signal; go until we are back to 2581130803Smarcel the point where we took it and one more. */ 258219370Spst 2583130803Smarcel /* Note: The test above succeeds not only when we stepped 2584130803Smarcel into a signal handler, but also when we step past the last 2585130803Smarcel statement of a signal handler and end up in the return stub 2586130803Smarcel of the signal handler trampoline. To distinguish between 2587130803Smarcel these two cases, check that the frame is INNER_THAN the 2588130803Smarcel previous one below. pai/1997-09-11 */ 258919370Spst 259019370Spst 259198944Sobrien { 2592130803Smarcel struct frame_id current_frame = get_frame_id (get_current_frame ()); 259319370Spst 2594130803Smarcel if (frame_id_inner (current_frame, step_frame_id)) 2595130803Smarcel { 2596130803Smarcel /* We have just taken a signal; go until we are back to 2597130803Smarcel the point where we took it and one more. */ 259819370Spst 2599130803Smarcel /* This code is needed at least in the following case: 2600130803Smarcel The user types "next" and then a signal arrives (before 2601130803Smarcel the "next" is done). */ 260219370Spst 2603130803Smarcel /* Note that if we are stopped at a breakpoint, then we need 2604130803Smarcel the step_resume breakpoint to override any breakpoints at 2605130803Smarcel the same location, so that we will still step over the 2606130803Smarcel breakpoint even though the signal happened. */ 260798944Sobrien struct symtab_and_line sr_sal; 260819370Spst 2609130803Smarcel init_sal (&sr_sal); 2610130803Smarcel sr_sal.symtab = NULL; 2611130803Smarcel sr_sal.line = 0; 2612130803Smarcel sr_sal.pc = prev_pc; 2613130803Smarcel /* We could probably be setting the frame to 2614130803Smarcel step_frame_id; I don't think anyone thought to try it. */ 261598944Sobrien check_for_old_step_resume_breakpoint (); 261698944Sobrien step_resume_breakpoint = 2617130803Smarcel set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume); 261898944Sobrien if (breakpoints_inserted) 261998944Sobrien insert_breakpoints (); 2620130803Smarcel } 2621130803Smarcel else 2622130803Smarcel { 2623130803Smarcel /* We just stepped out of a signal handler and into 2624130803Smarcel its calling trampoline. 262546283Sdfr 2626130803Smarcel Normally, we'd call step_over_function from 2627130803Smarcel here, but for some reason GDB can't unwind the 2628130803Smarcel stack correctly to find the real PC for the point 2629130803Smarcel user code where the signal trampoline will return 2630130803Smarcel -- FRAME_SAVED_PC fails, at least on HP-UX 10.20. 2631130803Smarcel But signal trampolines are pretty small stubs of 2632130803Smarcel code, anyway, so it's OK instead to just 2633130803Smarcel single-step out. Note: assuming such trampolines 2634130803Smarcel don't exhibit recursion on any platform... */ 2635130803Smarcel find_pc_partial_function (stop_pc, &ecs->stop_func_name, 2636130803Smarcel &ecs->stop_func_start, 2637130803Smarcel &ecs->stop_func_end); 2638130803Smarcel /* Readjust stepping range */ 2639130803Smarcel step_range_start = ecs->stop_func_start; 2640130803Smarcel step_range_end = ecs->stop_func_end; 2641130803Smarcel ecs->stepping_through_sigtramp = 1; 264298944Sobrien } 264398944Sobrien } 264419370Spst 264519370Spst 2646130803Smarcel /* If this is stepi or nexti, make sure that the stepping range 2647130803Smarcel gets us past that instruction. */ 2648130803Smarcel if (step_range_end == 1) 2649130803Smarcel /* FIXME: Does this run afoul of the code below which, if 2650130803Smarcel we step into the middle of a line, resets the stepping 2651130803Smarcel range? */ 2652130803Smarcel step_range_end = (step_range_start = prev_pc) + 1; 265319370Spst 2654130803Smarcel ecs->remove_breakpoints_on_following_step = 1; 2655130803Smarcel keep_going (ecs); 2656130803Smarcel return; 2657130803Smarcel } 265819370Spst 2659130803Smarcel if (((stop_pc == ecs->stop_func_start /* Quick test */ 2660130803Smarcel || in_prologue (stop_pc, ecs->stop_func_start)) 2661130803Smarcel && !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) 2662130803Smarcel || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name) 2663130803Smarcel || ecs->stop_func_name == 0) 2664130803Smarcel { 2665130803Smarcel /* It's a subroutine call. */ 2666130803Smarcel handle_step_into_function (ecs); 2667130803Smarcel return; 2668130803Smarcel } 266946283Sdfr 2670130803Smarcel /* We've wandered out of the step range. */ 267146283Sdfr 2672130803Smarcel ecs->sal = find_pc_line (stop_pc, 0); 2673130803Smarcel 2674130803Smarcel if (step_range_end == 1) 267598944Sobrien { 2676130803Smarcel /* It is stepi or nexti. We always want to stop stepping after 2677130803Smarcel one instruction. */ 2678130803Smarcel stop_step = 1; 2679130803Smarcel print_stop_reason (END_STEPPING_RANGE, 0); 2680130803Smarcel stop_stepping (ecs); 2681130803Smarcel return; 268298944Sobrien } 268346283Sdfr 2684130803Smarcel /* If we're in the return path from a shared library trampoline, 2685130803Smarcel we want to proceed through the trampoline when stepping. */ 2686130803Smarcel if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) 2687130803Smarcel { 2688130803Smarcel /* Determine where this trampoline returns. */ 2689130803Smarcel CORE_ADDR real_stop_pc = SKIP_TRAMPOLINE_CODE (stop_pc); 269019370Spst 2691130803Smarcel /* Only proceed through if we know where it's going. */ 2692130803Smarcel if (real_stop_pc) 2693130803Smarcel { 2694130803Smarcel /* And put the step-breakpoint there and go until there. */ 2695130803Smarcel struct symtab_and_line sr_sal; 2696130803Smarcel 2697130803Smarcel init_sal (&sr_sal); /* initialize to zeroes */ 2698130803Smarcel sr_sal.pc = real_stop_pc; 2699130803Smarcel sr_sal.section = find_pc_overlay (sr_sal.pc); 2700130803Smarcel /* Do not specify what the fp should be when we stop 2701130803Smarcel since on some machines the prologue 2702130803Smarcel is where the new fp value is established. */ 2703130803Smarcel check_for_old_step_resume_breakpoint (); 2704130803Smarcel step_resume_breakpoint = 2705130803Smarcel set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume); 2706130803Smarcel if (breakpoints_inserted) 2707130803Smarcel insert_breakpoints (); 2708130803Smarcel 2709130803Smarcel /* Restart without fiddling with the step ranges or 2710130803Smarcel other state. */ 2711130803Smarcel keep_going (ecs); 2712130803Smarcel return; 2713130803Smarcel } 2714130803Smarcel } 2715130803Smarcel 2716130803Smarcel if (ecs->sal.line == 0) 2717130803Smarcel { 2718130803Smarcel /* We have no line number information. That means to stop 2719130803Smarcel stepping (does this always happen right after one instruction, 2720130803Smarcel when we do "s" in a function with no line numbers, 2721130803Smarcel or can this happen as a result of a return or longjmp?). */ 2722130803Smarcel stop_step = 1; 2723130803Smarcel print_stop_reason (END_STEPPING_RANGE, 0); 2724130803Smarcel stop_stepping (ecs); 2725130803Smarcel return; 2726130803Smarcel } 2727130803Smarcel 2728130803Smarcel if ((stop_pc == ecs->sal.pc) 2729130803Smarcel && (ecs->current_line != ecs->sal.line 2730130803Smarcel || ecs->current_symtab != ecs->sal.symtab)) 2731130803Smarcel { 2732130803Smarcel /* We are at the start of a different line. So stop. Note that 2733130803Smarcel we don't stop if we step into the middle of a different line. 2734130803Smarcel That is said to make things like for (;;) statements work 2735130803Smarcel better. */ 2736130803Smarcel stop_step = 1; 2737130803Smarcel print_stop_reason (END_STEPPING_RANGE, 0); 2738130803Smarcel stop_stepping (ecs); 2739130803Smarcel return; 2740130803Smarcel } 2741130803Smarcel 2742130803Smarcel /* We aren't done stepping. 2743130803Smarcel 2744130803Smarcel Optimize by setting the stepping range to the line. 2745130803Smarcel (We might not be in the original line, but if we entered a 2746130803Smarcel new line in mid-statement, we continue stepping. This makes 2747130803Smarcel things like for(;;) statements work better.) */ 2748130803Smarcel 2749130803Smarcel if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end) 2750130803Smarcel { 2751130803Smarcel /* If this is the last line of the function, don't keep stepping 2752130803Smarcel (it would probably step us out of the function). 2753130803Smarcel This is particularly necessary for a one-line function, 2754130803Smarcel in which after skipping the prologue we better stop even though 2755130803Smarcel we will be in mid-line. */ 2756130803Smarcel stop_step = 1; 2757130803Smarcel print_stop_reason (END_STEPPING_RANGE, 0); 2758130803Smarcel stop_stepping (ecs); 2759130803Smarcel return; 2760130803Smarcel } 2761130803Smarcel step_range_start = ecs->sal.pc; 2762130803Smarcel step_range_end = ecs->sal.end; 2763130803Smarcel step_frame_id = get_frame_id (get_current_frame ()); 2764130803Smarcel ecs->current_line = ecs->sal.line; 2765130803Smarcel ecs->current_symtab = ecs->sal.symtab; 2766130803Smarcel 2767130803Smarcel /* In the case where we just stepped out of a function into the 2768130803Smarcel middle of a line of the caller, continue stepping, but 2769130803Smarcel step_frame_id must be modified to current frame */ 2770130803Smarcel#if 0 2771130803Smarcel /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too 2772130803Smarcel generous. It will trigger on things like a step into a frameless 2773130803Smarcel stackless leaf function. I think the logic should instead look 2774130803Smarcel at the unwound frame ID has that should give a more robust 2775130803Smarcel indication of what happened. */ 2776130803Smarcel if (step-ID == current-ID) 2777130803Smarcel still stepping in same function; 2778130803Smarcel else if (step-ID == unwind (current-ID)) 2779130803Smarcel stepped into a function; 2780130803Smarcel else 2781130803Smarcel stepped out of a function; 2782130803Smarcel /* Of course this assumes that the frame ID unwind code is robust 2783130803Smarcel and we're willing to introduce frame unwind logic into this 2784130803Smarcel function. Fortunately, those days are nearly upon us. */ 2785130803Smarcel#endif 2786130803Smarcel { 2787130803Smarcel struct frame_id current_frame = get_frame_id (get_current_frame ()); 2788130803Smarcel if (!(frame_id_inner (current_frame, step_frame_id))) 2789130803Smarcel step_frame_id = current_frame; 2790130803Smarcel } 2791130803Smarcel 2792130803Smarcel keep_going (ecs); 279398944Sobrien} 279419370Spst 279598944Sobrien/* Are we in the middle of stepping? */ 279619370Spst 279798944Sobrienstatic int 279898944Sobriencurrently_stepping (struct execution_control_state *ecs) 279998944Sobrien{ 280098944Sobrien return ((through_sigtramp_breakpoint == NULL 280198944Sobrien && !ecs->handling_longjmp 280298944Sobrien && ((step_range_end && step_resume_breakpoint == NULL) 280398944Sobrien || trap_expected)) 280498944Sobrien || ecs->stepping_through_solib_after_catch 280598944Sobrien || bpstat_should_step ()); 280698944Sobrien} 280719370Spst 280898944Sobrienstatic void 280998944Sobriencheck_sigtramp2 (struct execution_control_state *ecs) 281098944Sobrien{ 281198944Sobrien if (trap_expected 2812130803Smarcel && pc_in_sigtramp (stop_pc) 2813130803Smarcel && !pc_in_sigtramp (prev_pc) 281498944Sobrien && INNER_THAN (read_sp (), step_sp)) 281598944Sobrien { 281698944Sobrien /* What has happened here is that we have just stepped the 2817130803Smarcel inferior with a signal (because it is a signal which 2818130803Smarcel shouldn't make us stop), thus stepping into sigtramp. 281919370Spst 2820130803Smarcel So we need to set a step_resume_break_address breakpoint and 2821130803Smarcel continue until we hit it, and then step. FIXME: This should 2822130803Smarcel be more enduring than a step_resume breakpoint; we should 2823130803Smarcel know that we will later need to keep going rather than 2824130803Smarcel re-hitting the breakpoint here (see the testsuite, 2825130803Smarcel gdb.base/signals.exp where it says "exceedingly difficult"). */ 282619370Spst 282798944Sobrien struct symtab_and_line sr_sal; 282846283Sdfr 2829130803Smarcel init_sal (&sr_sal); /* initialize to zeroes */ 283098944Sobrien sr_sal.pc = prev_pc; 283198944Sobrien sr_sal.section = find_pc_overlay (sr_sal.pc); 283298944Sobrien /* We perhaps could set the frame if we kept track of what the 2833130803Smarcel frame corresponding to prev_pc was. But we don't, so don't. */ 283498944Sobrien through_sigtramp_breakpoint = 2835130803Smarcel set_momentary_breakpoint (sr_sal, null_frame_id, bp_through_sigtramp); 283698944Sobrien if (breakpoints_inserted) 283798944Sobrien insert_breakpoints (); 283846283Sdfr 283998944Sobrien ecs->remove_breakpoints_on_following_step = 1; 284098944Sobrien ecs->another_trap = 1; 284198944Sobrien } 284298944Sobrien} 284319370Spst 284498944Sobrien/* Subroutine call with source code we should not step over. Do step 284598944Sobrien to the first line of code in it. */ 284619370Spst 284798944Sobrienstatic void 284898944Sobrienstep_into_function (struct execution_control_state *ecs) 284998944Sobrien{ 285098944Sobrien struct symtab *s; 285198944Sobrien struct symtab_and_line sr_sal; 285219370Spst 285398944Sobrien s = find_pc_symtab (stop_pc); 285498944Sobrien if (s && s->language != language_asm) 285598944Sobrien ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start); 285619370Spst 285798944Sobrien ecs->sal = find_pc_line (ecs->stop_func_start, 0); 285898944Sobrien /* Use the step_resume_break to step until the end of the prologue, 285998944Sobrien even if that involves jumps (as it seems to on the vax under 286098944Sobrien 4.2). */ 286198944Sobrien /* If the prologue ends in the middle of a source line, continue to 286298944Sobrien the end of that source line (if it is still within the function). 286398944Sobrien Otherwise, just go to end of prologue. */ 286498944Sobrien if (ecs->sal.end 286598944Sobrien && ecs->sal.pc != ecs->stop_func_start 286698944Sobrien && ecs->sal.end < ecs->stop_func_end) 286798944Sobrien ecs->stop_func_start = ecs->sal.end; 286819370Spst 2869130803Smarcel /* Architectures which require breakpoint adjustment might not be able 2870130803Smarcel to place a breakpoint at the computed address. If so, the test 2871130803Smarcel ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust 2872130803Smarcel ecs->stop_func_start to an address at which a breakpoint may be 2873130803Smarcel legitimately placed. 2874130803Smarcel 2875130803Smarcel Note: kevinb/2004-01-19: On FR-V, if this adjustment is not 2876130803Smarcel made, GDB will enter an infinite loop when stepping through 2877130803Smarcel optimized code consisting of VLIW instructions which contain 2878130803Smarcel subinstructions corresponding to different source lines. On 2879130803Smarcel FR-V, it's not permitted to place a breakpoint on any but the 2880130803Smarcel first subinstruction of a VLIW instruction. When a breakpoint is 2881130803Smarcel set, GDB will adjust the breakpoint address to the beginning of 2882130803Smarcel the VLIW instruction. Thus, we need to make the corresponding 2883130803Smarcel adjustment here when computing the stop address. */ 2884130803Smarcel 2885130803Smarcel if (gdbarch_adjust_breakpoint_address_p (current_gdbarch)) 2886130803Smarcel { 2887130803Smarcel ecs->stop_func_start 2888130803Smarcel = gdbarch_adjust_breakpoint_address (current_gdbarch, 2889130803Smarcel ecs->stop_func_start); 2890130803Smarcel } 2891130803Smarcel 289298944Sobrien if (ecs->stop_func_start == stop_pc) 289398944Sobrien { 289498944Sobrien /* We are already there: stop now. */ 289598944Sobrien stop_step = 1; 2896130803Smarcel print_stop_reason (END_STEPPING_RANGE, 0); 289798944Sobrien stop_stepping (ecs); 289898944Sobrien return; 289998944Sobrien } 290098944Sobrien else 290198944Sobrien { 290298944Sobrien /* Put the step-breakpoint there and go until there. */ 2903130803Smarcel init_sal (&sr_sal); /* initialize to zeroes */ 290498944Sobrien sr_sal.pc = ecs->stop_func_start; 290598944Sobrien sr_sal.section = find_pc_overlay (ecs->stop_func_start); 290698944Sobrien /* Do not specify what the fp should be when we stop since on 2907130803Smarcel some machines the prologue is where the new fp value is 2908130803Smarcel established. */ 290998944Sobrien check_for_old_step_resume_breakpoint (); 291098944Sobrien step_resume_breakpoint = 2911130803Smarcel set_momentary_breakpoint (sr_sal, null_frame_id, bp_step_resume); 291298944Sobrien if (breakpoints_inserted) 291398944Sobrien insert_breakpoints (); 291419370Spst 291598944Sobrien /* And make sure stepping stops right away then. */ 291698944Sobrien step_range_end = step_range_start; 291798944Sobrien } 291898944Sobrien keep_going (ecs); 291998944Sobrien} 292019370Spst 292198944Sobrien/* We've just entered a callee, and we wish to resume until it returns 292298944Sobrien to the caller. Setting a step_resume breakpoint on the return 292398944Sobrien address will catch a return from the callee. 292498944Sobrien 292598944Sobrien However, if the callee is recursing, we want to be careful not to 292698944Sobrien catch returns of those recursive calls, but only of THIS instance 292798944Sobrien of the call. 292846283Sdfr 292998944Sobrien To do this, we set the step_resume bp's frame to our current 2930130803Smarcel caller's frame (step_frame_id, which is set by the "next" or 293198944Sobrien "until" command, before execution begins). */ 293246283Sdfr 293398944Sobrienstatic void 293498944Sobrienstep_over_function (struct execution_control_state *ecs) 293598944Sobrien{ 293698944Sobrien struct symtab_and_line sr_sal; 293719370Spst 2938130803Smarcel init_sal (&sr_sal); /* initialize to zeros */ 2939130803Smarcel 2940130803Smarcel /* NOTE: cagney/2003-04-06: 2941130803Smarcel 2942130803Smarcel At this point the equality get_frame_pc() == get_frame_func() 2943130803Smarcel should hold. This may make it possible for this code to tell the 2944130803Smarcel frame where it's function is, instead of the reverse. This would 2945130803Smarcel avoid the need to search for the frame's function, which can get 2946130803Smarcel very messy when there is no debug info available (look at the 2947130803Smarcel heuristic find pc start code found in targets like the MIPS). */ 2948130803Smarcel 2949130803Smarcel /* NOTE: cagney/2003-04-06: 2950130803Smarcel 2951130803Smarcel The intent of DEPRECATED_SAVED_PC_AFTER_CALL was to: 2952130803Smarcel 2953130803Smarcel - provide a very light weight equivalent to frame_unwind_pc() 2954130803Smarcel (nee FRAME_SAVED_PC) that avoids the prologue analyzer 2955130803Smarcel 2956130803Smarcel - avoid handling the case where the PC hasn't been saved in the 2957130803Smarcel prologue analyzer 2958130803Smarcel 2959130803Smarcel Unfortunately, not five lines further down, is a call to 2960130803Smarcel get_frame_id() and that is guarenteed to trigger the prologue 2961130803Smarcel analyzer. 2962130803Smarcel 2963130803Smarcel The `correct fix' is for the prologe analyzer to handle the case 2964130803Smarcel where the prologue is incomplete (PC in prologue) and, 2965130803Smarcel consequently, the return pc has not yet been saved. It should be 2966130803Smarcel noted that the prologue analyzer needs to handle this case 2967130803Smarcel anyway: frameless leaf functions that don't save the return PC; 2968130803Smarcel single stepping through a prologue. 2969130803Smarcel 2970130803Smarcel The d10v handles all this by bailing out of the prologue analsis 2971130803Smarcel when it reaches the current instruction. */ 2972130803Smarcel 2973130803Smarcel if (DEPRECATED_SAVED_PC_AFTER_CALL_P ()) 2974130803Smarcel sr_sal.pc = ADDR_BITS_REMOVE (DEPRECATED_SAVED_PC_AFTER_CALL (get_current_frame ())); 2975130803Smarcel else 2976130803Smarcel sr_sal.pc = ADDR_BITS_REMOVE (frame_pc_unwind (get_current_frame ())); 297798944Sobrien sr_sal.section = find_pc_overlay (sr_sal.pc); 297819370Spst 297998944Sobrien check_for_old_step_resume_breakpoint (); 298098944Sobrien step_resume_breakpoint = 2981130803Smarcel set_momentary_breakpoint (sr_sal, get_frame_id (get_current_frame ()), 2982130803Smarcel bp_step_resume); 298319370Spst 2984130803Smarcel if (frame_id_p (step_frame_id) 2985130803Smarcel && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc)) 2986130803Smarcel step_resume_breakpoint->frame_id = step_frame_id; 298719370Spst 298898944Sobrien if (breakpoints_inserted) 298998944Sobrien insert_breakpoints (); 299098944Sobrien} 299198944Sobrien 299298944Sobrienstatic void 299398944Sobrienstop_stepping (struct execution_control_state *ecs) 299498944Sobrien{ 299598944Sobrien /* Let callers know we don't want to wait for the inferior anymore. */ 299698944Sobrien ecs->wait_some_more = 0; 299719370Spst} 299846283Sdfr 299998944Sobrien/* This function handles various cases where we need to continue 300098944Sobrien waiting for the inferior. */ 300198944Sobrien/* (Used to be the keep_going: label in the old wait_for_inferior) */ 300298944Sobrien 300398944Sobrienstatic void 300498944Sobrienkeep_going (struct execution_control_state *ecs) 300546283Sdfr{ 300698944Sobrien /* Save the pc before execution, to compare with pc after stop. */ 3007130803Smarcel prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ 300898944Sobrien 300998944Sobrien if (ecs->update_step_sp) 301098944Sobrien step_sp = read_sp (); 301198944Sobrien ecs->update_step_sp = 0; 301298944Sobrien 301398944Sobrien /* If we did not do break;, it means we should keep running the 301498944Sobrien inferior and not return to debugger. */ 301598944Sobrien 301698944Sobrien if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) 301746283Sdfr { 301898944Sobrien /* We took a signal (which we are supposed to pass through to 3019130803Smarcel the inferior, else we'd have done a break above) and we 3020130803Smarcel haven't yet gotten our trap. Simply continue. */ 302198944Sobrien resume (currently_stepping (ecs), stop_signal); 302246283Sdfr } 302398944Sobrien else 302498944Sobrien { 302598944Sobrien /* Either the trap was not expected, but we are continuing 3026130803Smarcel anyway (the user asked that this signal be passed to the 3027130803Smarcel child) 3028130803Smarcel -- or -- 3029130803Smarcel The signal was SIGTRAP, e.g. it was our signal, but we 3030130803Smarcel decided we should resume from it. 303146283Sdfr 3032130803Smarcel We're going to run this baby now! 303398944Sobrien 3034130803Smarcel Insert breakpoints now, unless we are trying to one-proceed 3035130803Smarcel past a breakpoint. */ 303698944Sobrien /* If we've just finished a special step resume and we don't 3037130803Smarcel want to hit a breakpoint, pull em out. */ 303898944Sobrien if (step_resume_breakpoint == NULL 303998944Sobrien && through_sigtramp_breakpoint == NULL 304098944Sobrien && ecs->remove_breakpoints_on_following_step) 304198944Sobrien { 304298944Sobrien ecs->remove_breakpoints_on_following_step = 0; 304398944Sobrien remove_breakpoints (); 304498944Sobrien breakpoints_inserted = 0; 304598944Sobrien } 304698944Sobrien else if (!breakpoints_inserted && 304798944Sobrien (through_sigtramp_breakpoint != NULL || !ecs->another_trap)) 304898944Sobrien { 304998944Sobrien breakpoints_failed = insert_breakpoints (); 305098944Sobrien if (breakpoints_failed) 305198944Sobrien { 305298944Sobrien stop_stepping (ecs); 305398944Sobrien return; 305498944Sobrien } 305598944Sobrien breakpoints_inserted = 1; 305698944Sobrien } 305798944Sobrien 305898944Sobrien trap_expected = ecs->another_trap; 305998944Sobrien 306098944Sobrien /* Do not deliver SIGNAL_TRAP (except when the user explicitly 3061130803Smarcel specifies that such a signal should be delivered to the 3062130803Smarcel target program). 306398944Sobrien 3064130803Smarcel Typically, this would occure when a user is debugging a 3065130803Smarcel target monitor on a simulator: the target monitor sets a 3066130803Smarcel breakpoint; the simulator encounters this break-point and 3067130803Smarcel halts the simulation handing control to GDB; GDB, noteing 3068130803Smarcel that the break-point isn't valid, returns control back to the 3069130803Smarcel simulator; the simulator then delivers the hardware 3070130803Smarcel equivalent of a SIGNAL_TRAP to the program being debugged. */ 307198944Sobrien 3072130803Smarcel if (stop_signal == TARGET_SIGNAL_TRAP && !signal_program[stop_signal]) 307398944Sobrien stop_signal = TARGET_SIGNAL_0; 307498944Sobrien 307598944Sobrien 307698944Sobrien resume (currently_stepping (ecs), stop_signal); 307798944Sobrien } 307898944Sobrien 3079130803Smarcel prepare_to_wait (ecs); 308046283Sdfr} 308146283Sdfr 308298944Sobrien/* This function normally comes after a resume, before 308398944Sobrien handle_inferior_event exits. It takes care of any last bits of 308498944Sobrien housekeeping, and sets the all-important wait_some_more flag. */ 308546283Sdfr 308698944Sobrienstatic void 308798944Sobrienprepare_to_wait (struct execution_control_state *ecs) 308898944Sobrien{ 308998944Sobrien if (ecs->infwait_state == infwait_normal_state) 309098944Sobrien { 309198944Sobrien overlay_cache_invalid = 1; 309246283Sdfr 309398944Sobrien /* We have to invalidate the registers BEFORE calling 3094130803Smarcel target_wait because they can be loaded from the target while 3095130803Smarcel in target_wait. This makes remote debugging a bit more 3096130803Smarcel efficient for those targets that provide critical registers 3097130803Smarcel as part of their normal status mechanism. */ 309898944Sobrien 309998944Sobrien registers_changed (); 310098944Sobrien ecs->waiton_ptid = pid_to_ptid (-1); 310198944Sobrien ecs->wp = &(ecs->ws); 310298944Sobrien } 310398944Sobrien /* This is the old end of the while loop. Let everybody know we 310498944Sobrien want to wait for the inferior some more and get called again 310598944Sobrien soon. */ 310698944Sobrien ecs->wait_some_more = 1; 310798944Sobrien} 310898944Sobrien 310998944Sobrien/* Print why the inferior has stopped. We always print something when 311098944Sobrien the inferior exits, or receives a signal. The rest of the cases are 311198944Sobrien dealt with later on in normal_stop() and print_it_typical(). Ideally 311298944Sobrien there should be a call to this function from handle_inferior_event() 311398944Sobrien each time stop_stepping() is called.*/ 311498944Sobrienstatic void 311598944Sobrienprint_stop_reason (enum inferior_stop_reason stop_reason, int stop_info) 311646283Sdfr{ 311798944Sobrien switch (stop_reason) 311846283Sdfr { 311998944Sobrien case STOP_UNKNOWN: 312098944Sobrien /* We don't deal with these cases from handle_inferior_event() 312198944Sobrien yet. */ 312298944Sobrien break; 312398944Sobrien case END_STEPPING_RANGE: 312498944Sobrien /* We are done with a step/next/si/ni command. */ 312598944Sobrien /* For now print nothing. */ 312698944Sobrien /* Print a message only if not in the middle of doing a "step n" 3127130803Smarcel operation for n > 1 */ 312898944Sobrien if (!step_multi || !stop_step) 312998944Sobrien if (ui_out_is_mi_like_p (uiout)) 313098944Sobrien ui_out_field_string (uiout, "reason", "end-stepping-range"); 313198944Sobrien break; 313298944Sobrien case BREAKPOINT_HIT: 313398944Sobrien /* We found a breakpoint. */ 313498944Sobrien /* For now print nothing. */ 313598944Sobrien break; 313698944Sobrien case SIGNAL_EXITED: 313798944Sobrien /* The inferior was terminated by a signal. */ 313898944Sobrien annotate_signalled (); 313998944Sobrien if (ui_out_is_mi_like_p (uiout)) 314098944Sobrien ui_out_field_string (uiout, "reason", "exited-signalled"); 314198944Sobrien ui_out_text (uiout, "\nProgram terminated with signal "); 314298944Sobrien annotate_signal_name (); 3143130803Smarcel ui_out_field_string (uiout, "signal-name", 3144130803Smarcel target_signal_to_name (stop_info)); 314598944Sobrien annotate_signal_name_end (); 314698944Sobrien ui_out_text (uiout, ", "); 314798944Sobrien annotate_signal_string (); 3148130803Smarcel ui_out_field_string (uiout, "signal-meaning", 3149130803Smarcel target_signal_to_string (stop_info)); 315098944Sobrien annotate_signal_string_end (); 315198944Sobrien ui_out_text (uiout, ".\n"); 315298944Sobrien ui_out_text (uiout, "The program no longer exists.\n"); 315398944Sobrien break; 315498944Sobrien case EXITED: 315598944Sobrien /* The inferior program is finished. */ 315698944Sobrien annotate_exited (stop_info); 315798944Sobrien if (stop_info) 315846283Sdfr { 315998944Sobrien if (ui_out_is_mi_like_p (uiout)) 316098944Sobrien ui_out_field_string (uiout, "reason", "exited"); 316198944Sobrien ui_out_text (uiout, "\nProgram exited with code "); 3162130803Smarcel ui_out_field_fmt (uiout, "exit-code", "0%o", 3163130803Smarcel (unsigned int) stop_info); 316498944Sobrien ui_out_text (uiout, ".\n"); 316546283Sdfr } 316698944Sobrien else 316798944Sobrien { 316898944Sobrien if (ui_out_is_mi_like_p (uiout)) 316998944Sobrien ui_out_field_string (uiout, "reason", "exited-normally"); 317098944Sobrien ui_out_text (uiout, "\nProgram exited normally.\n"); 317198944Sobrien } 317298944Sobrien break; 317398944Sobrien case SIGNAL_RECEIVED: 317498944Sobrien /* Signal received. The signal table tells us to print about 317598944Sobrien it. */ 317698944Sobrien annotate_signal (); 317798944Sobrien ui_out_text (uiout, "\nProgram received signal "); 317898944Sobrien annotate_signal_name (); 317998944Sobrien if (ui_out_is_mi_like_p (uiout)) 318098944Sobrien ui_out_field_string (uiout, "reason", "signal-received"); 3181130803Smarcel ui_out_field_string (uiout, "signal-name", 3182130803Smarcel target_signal_to_name (stop_info)); 318398944Sobrien annotate_signal_name_end (); 318498944Sobrien ui_out_text (uiout, ", "); 318598944Sobrien annotate_signal_string (); 3186130803Smarcel ui_out_field_string (uiout, "signal-meaning", 3187130803Smarcel target_signal_to_string (stop_info)); 318898944Sobrien annotate_signal_string_end (); 318998944Sobrien ui_out_text (uiout, ".\n"); 319098944Sobrien break; 319198944Sobrien default: 319298944Sobrien internal_error (__FILE__, __LINE__, 319398944Sobrien "print_stop_reason: unrecognized enum value"); 319498944Sobrien break; 319546283Sdfr } 319646283Sdfr} 319719370Spst 319846283Sdfr 319919370Spst/* Here to return control to GDB when the inferior stops for real. 320019370Spst Print appropriate messages, remove breakpoints, give terminal our modes. 320119370Spst 320219370Spst STOP_PRINT_FRAME nonzero means print the executing frame 320319370Spst (pc, function, args, file, line number and line text). 320419370Spst BREAKPOINTS_FAILED nonzero means stop was due to error 320519370Spst attempting to insert breakpoints. */ 320619370Spst 320719370Spstvoid 320898944Sobriennormal_stop (void) 320919370Spst{ 3210130803Smarcel struct target_waitstatus last; 3211130803Smarcel ptid_t last_ptid; 3212130803Smarcel 3213130803Smarcel get_last_target_status (&last_ptid, &last); 3214130803Smarcel 321546283Sdfr /* As with the notification of thread events, we want to delay 321646283Sdfr notifying the user that we've switched thread context until 321746283Sdfr the inferior actually stops. 321846283Sdfr 3219130803Smarcel There's no point in saying anything if the inferior has exited. 3220130803Smarcel Note that SIGNALLED here means "exited with a signal", not 3221130803Smarcel "received a signal". */ 3222130803Smarcel if (!ptid_equal (previous_inferior_ptid, inferior_ptid) 3223130803Smarcel && target_has_execution 3224130803Smarcel && last.kind != TARGET_WAITKIND_SIGNALLED 3225130803Smarcel && last.kind != TARGET_WAITKIND_EXITED) 322646283Sdfr { 322746283Sdfr target_terminal_ours_for_output (); 322898944Sobrien printf_filtered ("[Switching to %s]\n", 322998944Sobrien target_pid_or_tid_to_str (inferior_ptid)); 323098944Sobrien previous_inferior_ptid = inferior_ptid; 323146283Sdfr } 323246283Sdfr 3233130803Smarcel /* NOTE drow/2004-01-17: Is this still necessary? */ 323419370Spst /* Make sure that the current_frame's pc is correct. This 323519370Spst is a correction for setting up the frame info before doing 323619370Spst DECR_PC_AFTER_BREAK */ 3237130803Smarcel if (target_has_execution) 3238130803Smarcel /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to 3239130803Smarcel DECR_PC_AFTER_BREAK, the program counter can change. Ask the 3240130803Smarcel frame code to check for this and sort out any resultant mess. 3241130803Smarcel DECR_PC_AFTER_BREAK needs to just go away. */ 3242130803Smarcel deprecated_update_frame_pc_hack (get_current_frame (), read_pc ()); 324346283Sdfr 324419370Spst if (target_has_execution && breakpoints_inserted) 324546283Sdfr { 324646283Sdfr if (remove_breakpoints ()) 324746283Sdfr { 324846283Sdfr target_terminal_ours_for_output (); 324946283Sdfr printf_filtered ("Cannot remove breakpoints because "); 325046283Sdfr printf_filtered ("program is no longer writable.\n"); 325146283Sdfr printf_filtered ("It might be running in another process.\n"); 325246283Sdfr printf_filtered ("Further execution is probably impossible.\n"); 325346283Sdfr } 325446283Sdfr } 325519370Spst breakpoints_inserted = 0; 325619370Spst 325719370Spst /* Delete the breakpoint we stopped at, if it wants to be deleted. 325819370Spst Delete any breakpoint that is to be deleted at the next stop. */ 325919370Spst 326019370Spst breakpoint_auto_delete (stop_bpstat); 326119370Spst 326219370Spst /* If an auto-display called a function and that got a signal, 326319370Spst delete that auto-display to avoid an infinite recursion. */ 326419370Spst 326519370Spst if (stopped_by_random_signal) 326619370Spst disable_current_display (); 326719370Spst 326846283Sdfr /* Don't print a message if in the middle of doing a "step n" 326946283Sdfr operation for n > 1 */ 327019370Spst if (step_multi && stop_step) 327119370Spst goto done; 327219370Spst 327319370Spst target_terminal_ours (); 327419370Spst 3275130803Smarcel /* Look up the hook_stop and run it (CLI internally handles problem 3276130803Smarcel of stop_command's pre-hook not existing). */ 3277130803Smarcel if (stop_command) 3278130803Smarcel catch_errors (hook_stop_stub, stop_command, 3279130803Smarcel "Error while running hook_stop:\n", RETURN_MASK_ALL); 328019370Spst 328119370Spst if (!target_has_stack) 328246283Sdfr { 328319370Spst 328446283Sdfr goto done; 328546283Sdfr } 328646283Sdfr 328746283Sdfr /* Select innermost stack frame - i.e., current frame is frame 0, 328846283Sdfr and current location is based on that. 328946283Sdfr Don't do this on return from a stack dummy routine, 329046283Sdfr or if the program has exited. */ 329146283Sdfr 329219370Spst if (!stop_stack_dummy) 329319370Spst { 3294130803Smarcel select_frame (get_current_frame ()); 329519370Spst 329646283Sdfr /* Print current location without a level number, if 329798944Sobrien we have changed functions or hit a breakpoint. 329898944Sobrien Print source line if we have one. 329998944Sobrien bpstat_print() contains the logic deciding in detail 330098944Sobrien what to print, based on the event(s) that just occurred. */ 330146283Sdfr 3302130803Smarcel if (stop_print_frame && deprecated_selected_frame) 330319370Spst { 330446283Sdfr int bpstat_ret; 330546283Sdfr int source_flag; 330698944Sobrien int do_frame_printing = 1; 330719370Spst 330846283Sdfr bpstat_ret = bpstat_print (stop_bpstat); 330998944Sobrien switch (bpstat_ret) 331098944Sobrien { 331198944Sobrien case PRINT_UNKNOWN: 3312130803Smarcel /* FIXME: cagney/2002-12-01: Given that a frame ID does 3313130803Smarcel (or should) carry around the function and does (or 3314130803Smarcel should) use that when doing a frame comparison. */ 331598944Sobrien if (stop_step 3316130803Smarcel && frame_id_eq (step_frame_id, 3317130803Smarcel get_frame_id (get_current_frame ())) 331898944Sobrien && step_start_function == find_pc_function (stop_pc)) 3319130803Smarcel source_flag = SRC_LINE; /* finished step, just print source line */ 332098944Sobrien else 3321130803Smarcel source_flag = SRC_AND_LOC; /* print location and source line */ 332298944Sobrien break; 332398944Sobrien case PRINT_SRC_AND_LOC: 3324130803Smarcel source_flag = SRC_AND_LOC; /* print location and source line */ 332598944Sobrien break; 332698944Sobrien case PRINT_SRC_ONLY: 332798944Sobrien source_flag = SRC_LINE; 332898944Sobrien break; 332998944Sobrien case PRINT_NOTHING: 3330130803Smarcel source_flag = SRC_LINE; /* something bogus */ 333198944Sobrien do_frame_printing = 0; 333298944Sobrien break; 333398944Sobrien default: 3334130803Smarcel internal_error (__FILE__, __LINE__, "Unknown value."); 333598944Sobrien } 333698944Sobrien /* For mi, have the same behavior every time we stop: 3337130803Smarcel print everything but the source line. */ 333898944Sobrien if (ui_out_is_mi_like_p (uiout)) 333998944Sobrien source_flag = LOC_AND_ADDRESS; 334019370Spst 334198944Sobrien if (ui_out_is_mi_like_p (uiout)) 334298944Sobrien ui_out_field_int (uiout, "thread-id", 3343130803Smarcel pid_to_thread_id (inferior_ptid)); 334446283Sdfr /* The behavior of this routine with respect to the source 334546283Sdfr flag is: 334698944Sobrien SRC_LINE: Print only source line 334798944Sobrien LOCATION: Print only location 334898944Sobrien SRC_AND_LOC: Print location and source line */ 334998944Sobrien if (do_frame_printing) 3350130803Smarcel print_stack_frame (deprecated_selected_frame, -1, source_flag); 335146283Sdfr 335219370Spst /* Display the auto-display expressions. */ 335319370Spst do_displays (); 335419370Spst } 335519370Spst } 335619370Spst 335719370Spst /* Save the function value return registers, if we care. 335819370Spst We might be about to restore their previous contents. */ 335919370Spst if (proceed_to_finish) 3360130803Smarcel /* NB: The copy goes through to the target picking up the value of 3361130803Smarcel all the registers. */ 3362130803Smarcel regcache_cpy (stop_registers, current_regcache); 336319370Spst 336419370Spst if (stop_stack_dummy) 336519370Spst { 3366130803Smarcel /* Pop the empty frame that contains the stack dummy. POP_FRAME 3367130803Smarcel ends with a setting of the current frame, so we can use that 3368130803Smarcel next. */ 3369130803Smarcel frame_pop (get_current_frame ()); 337046283Sdfr /* Set stop_pc to what it was before we called the function. 337198944Sobrien Can't rely on restore_inferior_status because that only gets 337298944Sobrien called if we don't stop in the called function. */ 337346283Sdfr stop_pc = read_pc (); 3374130803Smarcel select_frame (get_current_frame ()); 337519370Spst } 337646283Sdfr 337746283Sdfrdone: 337819370Spst annotate_stopped (); 3379130803Smarcel observer_notify_normal_stop (); 338019370Spst} 338119370Spst 338219370Spststatic int 338398944Sobrienhook_stop_stub (void *cmd) 338419370Spst{ 3385130803Smarcel execute_cmd_pre_hook ((struct cmd_list_element *) cmd); 338619370Spst return (0); 338719370Spst} 338819370Spst 338998944Sobrienint 339098944Sobriensignal_stop_state (int signo) 339119370Spst{ 339219370Spst return signal_stop[signo]; 339319370Spst} 339419370Spst 339598944Sobrienint 339698944Sobriensignal_print_state (int signo) 339719370Spst{ 339819370Spst return signal_print[signo]; 339919370Spst} 340019370Spst 340198944Sobrienint 340298944Sobriensignal_pass_state (int signo) 340319370Spst{ 340419370Spst return signal_program[signo]; 340519370Spst} 340619370Spst 3407130803Smarcelint 3408130803Smarcelsignal_stop_update (int signo, int state) 340998944Sobrien{ 341098944Sobrien int ret = signal_stop[signo]; 341198944Sobrien signal_stop[signo] = state; 341298944Sobrien return ret; 341398944Sobrien} 341498944Sobrien 3415130803Smarcelint 3416130803Smarcelsignal_print_update (int signo, int state) 341798944Sobrien{ 341898944Sobrien int ret = signal_print[signo]; 341998944Sobrien signal_print[signo] = state; 342098944Sobrien return ret; 342198944Sobrien} 342298944Sobrien 3423130803Smarcelint 3424130803Smarcelsignal_pass_update (int signo, int state) 342598944Sobrien{ 342698944Sobrien int ret = signal_program[signo]; 342798944Sobrien signal_program[signo] = state; 342898944Sobrien return ret; 342998944Sobrien} 343098944Sobrien 343119370Spststatic void 343298944Sobriensig_print_header (void) 343319370Spst{ 343419370Spst printf_filtered ("\ 343519370SpstSignal Stop\tPrint\tPass to program\tDescription\n"); 343619370Spst} 343719370Spst 343819370Spststatic void 343998944Sobriensig_print_info (enum target_signal oursig) 344019370Spst{ 344119370Spst char *name = target_signal_to_name (oursig); 344246283Sdfr int name_padding = 13 - strlen (name); 344398944Sobrien 344446283Sdfr if (name_padding <= 0) 344546283Sdfr name_padding = 0; 344646283Sdfr 344719370Spst printf_filtered ("%s", name); 3448130803Smarcel printf_filtered ("%*.*s ", name_padding, name_padding, " "); 344919370Spst printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); 345019370Spst printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); 345119370Spst printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); 345219370Spst printf_filtered ("%s\n", target_signal_to_string (oursig)); 345319370Spst} 345419370Spst 345519370Spst/* Specify how various signals in the inferior should be handled. */ 345619370Spst 345719370Spststatic void 345898944Sobrienhandle_command (char *args, int from_tty) 345919370Spst{ 346019370Spst char **argv; 346119370Spst int digits, wordlen; 346219370Spst int sigfirst, signum, siglast; 346319370Spst enum target_signal oursig; 346419370Spst int allsigs; 346519370Spst int nsigs; 346619370Spst unsigned char *sigs; 346719370Spst struct cleanup *old_chain; 346819370Spst 346919370Spst if (args == NULL) 347019370Spst { 347119370Spst error_no_arg ("signal to handle"); 347219370Spst } 347319370Spst 347419370Spst /* Allocate and zero an array of flags for which signals to handle. */ 347519370Spst 347646283Sdfr nsigs = (int) TARGET_SIGNAL_LAST; 347719370Spst sigs = (unsigned char *) alloca (nsigs); 347819370Spst memset (sigs, 0, nsigs); 347919370Spst 348019370Spst /* Break the command line up into args. */ 348119370Spst 348219370Spst argv = buildargv (args); 348319370Spst if (argv == NULL) 348419370Spst { 348519370Spst nomem (0); 348619370Spst } 348798944Sobrien old_chain = make_cleanup_freeargv (argv); 348819370Spst 348919370Spst /* Walk through the args, looking for signal oursigs, signal names, and 349019370Spst actions. Signal numbers and signal names may be interspersed with 349119370Spst actions, with the actions being performed for all signals cumulatively 349219370Spst specified. Signal ranges can be specified as <LOW>-<HIGH>. */ 349319370Spst 349419370Spst while (*argv != NULL) 349519370Spst { 349619370Spst wordlen = strlen (*argv); 349746283Sdfr for (digits = 0; isdigit ((*argv)[digits]); digits++) 349846283Sdfr {; 349946283Sdfr } 350019370Spst allsigs = 0; 350119370Spst sigfirst = siglast = -1; 350219370Spst 350319370Spst if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) 350419370Spst { 350519370Spst /* Apply action to all signals except those used by the 350619370Spst debugger. Silently skip those. */ 350719370Spst allsigs = 1; 350819370Spst sigfirst = 0; 350919370Spst siglast = nsigs - 1; 351019370Spst } 351119370Spst else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) 351219370Spst { 351319370Spst SET_SIGS (nsigs, sigs, signal_stop); 351419370Spst SET_SIGS (nsigs, sigs, signal_print); 351519370Spst } 351619370Spst else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) 351719370Spst { 351819370Spst UNSET_SIGS (nsigs, sigs, signal_program); 351919370Spst } 352019370Spst else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) 352119370Spst { 352219370Spst SET_SIGS (nsigs, sigs, signal_print); 352319370Spst } 352419370Spst else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) 352519370Spst { 352619370Spst SET_SIGS (nsigs, sigs, signal_program); 352719370Spst } 352819370Spst else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) 352919370Spst { 353019370Spst UNSET_SIGS (nsigs, sigs, signal_stop); 353119370Spst } 353219370Spst else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) 353319370Spst { 353419370Spst SET_SIGS (nsigs, sigs, signal_program); 353519370Spst } 353619370Spst else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) 353719370Spst { 353819370Spst UNSET_SIGS (nsigs, sigs, signal_print); 353919370Spst UNSET_SIGS (nsigs, sigs, signal_stop); 354019370Spst } 354119370Spst else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) 354219370Spst { 354319370Spst UNSET_SIGS (nsigs, sigs, signal_program); 354419370Spst } 354519370Spst else if (digits > 0) 354619370Spst { 354746283Sdfr /* It is numeric. The numeric signal refers to our own 354846283Sdfr internal signal numbering from target.h, not to host/target 354946283Sdfr signal number. This is a feature; users really should be 355046283Sdfr using symbolic names anyway, and the common ones like 355146283Sdfr SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ 355219370Spst 355346283Sdfr sigfirst = siglast = (int) 355446283Sdfr target_signal_from_command (atoi (*argv)); 355519370Spst if ((*argv)[digits] == '-') 355619370Spst { 355746283Sdfr siglast = (int) 355846283Sdfr target_signal_from_command (atoi ((*argv) + digits + 1)); 355919370Spst } 356019370Spst if (sigfirst > siglast) 356119370Spst { 356219370Spst /* Bet he didn't figure we'd think of this case... */ 356319370Spst signum = sigfirst; 356419370Spst sigfirst = siglast; 356519370Spst siglast = signum; 356619370Spst } 356719370Spst } 356819370Spst else 356919370Spst { 357019370Spst oursig = target_signal_from_name (*argv); 357119370Spst if (oursig != TARGET_SIGNAL_UNKNOWN) 357219370Spst { 357346283Sdfr sigfirst = siglast = (int) oursig; 357419370Spst } 357519370Spst else 357619370Spst { 357719370Spst /* Not a number and not a recognized flag word => complain. */ 357819370Spst error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); 357919370Spst } 358019370Spst } 358119370Spst 358219370Spst /* If any signal numbers or symbol names were found, set flags for 358398944Sobrien which signals to apply actions to. */ 358419370Spst 358519370Spst for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) 358619370Spst { 358746283Sdfr switch ((enum target_signal) signum) 358819370Spst { 358946283Sdfr case TARGET_SIGNAL_TRAP: 359046283Sdfr case TARGET_SIGNAL_INT: 359146283Sdfr if (!allsigs && !sigs[signum]) 359246283Sdfr { 359346283Sdfr if (query ("%s is used by the debugger.\n\ 3594130803SmarcelAre you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum))) 359546283Sdfr { 359646283Sdfr sigs[signum] = 1; 359746283Sdfr } 359846283Sdfr else 359946283Sdfr { 360046283Sdfr printf_unfiltered ("Not confirmed, unchanged.\n"); 360146283Sdfr gdb_flush (gdb_stdout); 360246283Sdfr } 360346283Sdfr } 360446283Sdfr break; 360546283Sdfr case TARGET_SIGNAL_0: 360646283Sdfr case TARGET_SIGNAL_DEFAULT: 360746283Sdfr case TARGET_SIGNAL_UNKNOWN: 360846283Sdfr /* Make sure that "all" doesn't print these. */ 360946283Sdfr break; 361046283Sdfr default: 361146283Sdfr sigs[signum] = 1; 361246283Sdfr break; 361319370Spst } 361419370Spst } 361519370Spst 361619370Spst argv++; 361719370Spst } 361819370Spst 361998944Sobrien target_notice_signals (inferior_ptid); 362019370Spst 362119370Spst if (from_tty) 362219370Spst { 362319370Spst /* Show the results. */ 362419370Spst sig_print_header (); 362519370Spst for (signum = 0; signum < nsigs; signum++) 362619370Spst { 362719370Spst if (sigs[signum]) 362819370Spst { 362919370Spst sig_print_info (signum); 363019370Spst } 363119370Spst } 363219370Spst } 363319370Spst 363419370Spst do_cleanups (old_chain); 363519370Spst} 363619370Spst 363746283Sdfrstatic void 363898944Sobrienxdb_handle_command (char *args, int from_tty) 363946283Sdfr{ 364046283Sdfr char **argv; 364146283Sdfr struct cleanup *old_chain; 364246283Sdfr 364346283Sdfr /* Break the command line up into args. */ 364446283Sdfr 364546283Sdfr argv = buildargv (args); 364646283Sdfr if (argv == NULL) 364746283Sdfr { 364846283Sdfr nomem (0); 364946283Sdfr } 365098944Sobrien old_chain = make_cleanup_freeargv (argv); 365146283Sdfr if (argv[1] != (char *) NULL) 365246283Sdfr { 365346283Sdfr char *argBuf; 365446283Sdfr int bufLen; 365546283Sdfr 365646283Sdfr bufLen = strlen (argv[0]) + 20; 365746283Sdfr argBuf = (char *) xmalloc (bufLen); 365846283Sdfr if (argBuf) 365946283Sdfr { 366046283Sdfr int validFlag = 1; 366146283Sdfr enum target_signal oursig; 366246283Sdfr 366346283Sdfr oursig = target_signal_from_name (argv[0]); 366446283Sdfr memset (argBuf, 0, bufLen); 366546283Sdfr if (strcmp (argv[1], "Q") == 0) 366646283Sdfr sprintf (argBuf, "%s %s", argv[0], "noprint"); 366746283Sdfr else 366846283Sdfr { 366946283Sdfr if (strcmp (argv[1], "s") == 0) 367046283Sdfr { 367146283Sdfr if (!signal_stop[oursig]) 367246283Sdfr sprintf (argBuf, "%s %s", argv[0], "stop"); 367346283Sdfr else 367446283Sdfr sprintf (argBuf, "%s %s", argv[0], "nostop"); 367546283Sdfr } 367646283Sdfr else if (strcmp (argv[1], "i") == 0) 367746283Sdfr { 367846283Sdfr if (!signal_program[oursig]) 367946283Sdfr sprintf (argBuf, "%s %s", argv[0], "pass"); 368046283Sdfr else 368146283Sdfr sprintf (argBuf, "%s %s", argv[0], "nopass"); 368246283Sdfr } 368346283Sdfr else if (strcmp (argv[1], "r") == 0) 368446283Sdfr { 368546283Sdfr if (!signal_print[oursig]) 368646283Sdfr sprintf (argBuf, "%s %s", argv[0], "print"); 368746283Sdfr else 368846283Sdfr sprintf (argBuf, "%s %s", argv[0], "noprint"); 368946283Sdfr } 369046283Sdfr else 369146283Sdfr validFlag = 0; 369246283Sdfr } 369346283Sdfr if (validFlag) 369446283Sdfr handle_command (argBuf, from_tty); 369546283Sdfr else 369646283Sdfr printf_filtered ("Invalid signal handling flag.\n"); 369746283Sdfr if (argBuf) 369898944Sobrien xfree (argBuf); 369946283Sdfr } 370046283Sdfr } 370146283Sdfr do_cleanups (old_chain); 370246283Sdfr} 370346283Sdfr 370419370Spst/* Print current contents of the tables set by the handle command. 370519370Spst It is possible we should just be printing signals actually used 370619370Spst by the current target (but for things to work right when switching 370719370Spst targets, all signals should be in the signal tables). */ 370819370Spst 370919370Spststatic void 371098944Sobriensignals_info (char *signum_exp, int from_tty) 371119370Spst{ 371219370Spst enum target_signal oursig; 371319370Spst sig_print_header (); 371419370Spst 371519370Spst if (signum_exp) 371619370Spst { 371719370Spst /* First see if this is a symbol name. */ 371819370Spst oursig = target_signal_from_name (signum_exp); 371919370Spst if (oursig == TARGET_SIGNAL_UNKNOWN) 372019370Spst { 372119370Spst /* No, try numeric. */ 372219370Spst oursig = 372398944Sobrien target_signal_from_command (parse_and_eval_long (signum_exp)); 372419370Spst } 372519370Spst sig_print_info (oursig); 372619370Spst return; 372719370Spst } 372819370Spst 372919370Spst printf_filtered ("\n"); 373019370Spst /* These ugly casts brought to you by the native VAX compiler. */ 373119370Spst for (oursig = TARGET_SIGNAL_FIRST; 373246283Sdfr (int) oursig < (int) TARGET_SIGNAL_LAST; 373346283Sdfr oursig = (enum target_signal) ((int) oursig + 1)) 373419370Spst { 373519370Spst QUIT; 373619370Spst 373719370Spst if (oursig != TARGET_SIGNAL_UNKNOWN 3738130803Smarcel && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0) 373919370Spst sig_print_info (oursig); 374019370Spst } 374119370Spst 374219370Spst printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); 374319370Spst} 374419370Spst 374598944Sobrienstruct inferior_status 374698944Sobrien{ 374798944Sobrien enum target_signal stop_signal; 374898944Sobrien CORE_ADDR stop_pc; 374998944Sobrien bpstat stop_bpstat; 375098944Sobrien int stop_step; 375198944Sobrien int stop_stack_dummy; 375298944Sobrien int stopped_by_random_signal; 375398944Sobrien int trap_expected; 375498944Sobrien CORE_ADDR step_range_start; 375598944Sobrien CORE_ADDR step_range_end; 3756130803Smarcel struct frame_id step_frame_id; 375798944Sobrien enum step_over_calls_kind step_over_calls; 375898944Sobrien CORE_ADDR step_resume_break_address; 375998944Sobrien int stop_after_trap; 3760130803Smarcel int stop_soon; 3761130803Smarcel struct regcache *stop_registers; 376298944Sobrien 376398944Sobrien /* These are here because if call_function_by_hand has written some 376498944Sobrien registers and then decides to call error(), we better not have changed 376598944Sobrien any registers. */ 3766130803Smarcel struct regcache *registers; 376798944Sobrien 3768130803Smarcel /* A frame unique identifier. */ 3769130803Smarcel struct frame_id selected_frame_id; 3770130803Smarcel 377198944Sobrien int breakpoint_proceeded; 377298944Sobrien int restore_stack_info; 377398944Sobrien int proceed_to_finish; 377498944Sobrien}; 377598944Sobrien 377698944Sobrienvoid 377798944Sobrienwrite_inferior_status_register (struct inferior_status *inf_status, int regno, 377898944Sobrien LONGEST val) 377998944Sobrien{ 3780130803Smarcel int size = DEPRECATED_REGISTER_RAW_SIZE (regno); 378198944Sobrien void *buf = alloca (size); 378298944Sobrien store_signed_integer (buf, size, val); 3783130803Smarcel regcache_raw_write (inf_status->registers, regno, buf); 378498944Sobrien} 378598944Sobrien 378619370Spst/* Save all of the information associated with the inferior<==>gdb 378719370Spst connection. INF_STATUS is a pointer to a "struct inferior_status" 378819370Spst (defined in inferior.h). */ 378919370Spst 379098944Sobrienstruct inferior_status * 379198944Sobriensave_inferior_status (int restore_stack_info) 379219370Spst{ 3793130803Smarcel struct inferior_status *inf_status = XMALLOC (struct inferior_status); 379498944Sobrien 379519370Spst inf_status->stop_signal = stop_signal; 379619370Spst inf_status->stop_pc = stop_pc; 379719370Spst inf_status->stop_step = stop_step; 379819370Spst inf_status->stop_stack_dummy = stop_stack_dummy; 379919370Spst inf_status->stopped_by_random_signal = stopped_by_random_signal; 380019370Spst inf_status->trap_expected = trap_expected; 380119370Spst inf_status->step_range_start = step_range_start; 380219370Spst inf_status->step_range_end = step_range_end; 3803130803Smarcel inf_status->step_frame_id = step_frame_id; 380419370Spst inf_status->step_over_calls = step_over_calls; 380519370Spst inf_status->stop_after_trap = stop_after_trap; 3806130803Smarcel inf_status->stop_soon = stop_soon; 380746283Sdfr /* Save original bpstat chain here; replace it with copy of chain. 380819370Spst If caller's caller is walking the chain, they'll be happier if we 380998944Sobrien hand them back the original chain when restore_inferior_status is 381098944Sobrien called. */ 381119370Spst inf_status->stop_bpstat = stop_bpstat; 381219370Spst stop_bpstat = bpstat_copy (stop_bpstat); 381319370Spst inf_status->breakpoint_proceeded = breakpoint_proceeded; 381419370Spst inf_status->restore_stack_info = restore_stack_info; 381519370Spst inf_status->proceed_to_finish = proceed_to_finish; 381646283Sdfr 3817130803Smarcel inf_status->stop_registers = regcache_dup_no_passthrough (stop_registers); 381819370Spst 3819130803Smarcel inf_status->registers = regcache_dup (current_regcache); 382019370Spst 3821130803Smarcel inf_status->selected_frame_id = get_frame_id (deprecated_selected_frame); 382298944Sobrien return inf_status; 382319370Spst} 382419370Spst 382519370Spststatic int 382698944Sobrienrestore_selected_frame (void *args) 382719370Spst{ 3828130803Smarcel struct frame_id *fid = (struct frame_id *) args; 382919370Spst struct frame_info *frame; 383019370Spst 3831130803Smarcel frame = frame_find_by_id (*fid); 383219370Spst 3833130803Smarcel /* If inf_status->selected_frame_id is NULL, there was no previously 3834130803Smarcel selected frame. */ 3835130803Smarcel if (frame == NULL) 383619370Spst { 383719370Spst warning ("Unable to restore previously selected frame.\n"); 383819370Spst return 0; 383919370Spst } 384046283Sdfr 3841130803Smarcel select_frame (frame); 384246283Sdfr 384346283Sdfr return (1); 384419370Spst} 384519370Spst 384619370Spstvoid 384798944Sobrienrestore_inferior_status (struct inferior_status *inf_status) 384819370Spst{ 384919370Spst stop_signal = inf_status->stop_signal; 385019370Spst stop_pc = inf_status->stop_pc; 385119370Spst stop_step = inf_status->stop_step; 385219370Spst stop_stack_dummy = inf_status->stop_stack_dummy; 385319370Spst stopped_by_random_signal = inf_status->stopped_by_random_signal; 385419370Spst trap_expected = inf_status->trap_expected; 385519370Spst step_range_start = inf_status->step_range_start; 385619370Spst step_range_end = inf_status->step_range_end; 3857130803Smarcel step_frame_id = inf_status->step_frame_id; 385819370Spst step_over_calls = inf_status->step_over_calls; 385919370Spst stop_after_trap = inf_status->stop_after_trap; 3860130803Smarcel stop_soon = inf_status->stop_soon; 386119370Spst bpstat_clear (&stop_bpstat); 386219370Spst stop_bpstat = inf_status->stop_bpstat; 386319370Spst breakpoint_proceeded = inf_status->breakpoint_proceeded; 386419370Spst proceed_to_finish = inf_status->proceed_to_finish; 386519370Spst 3866130803Smarcel /* FIXME: Is the restore of stop_registers always needed. */ 3867130803Smarcel regcache_xfree (stop_registers); 3868130803Smarcel stop_registers = inf_status->stop_registers; 386919370Spst 387019370Spst /* The inferior can be gone if the user types "print exit(0)" 387119370Spst (and perhaps other times). */ 387219370Spst if (target_has_execution) 3873130803Smarcel /* NB: The register write goes through to the target. */ 3874130803Smarcel regcache_cpy (current_regcache, inf_status->registers); 3875130803Smarcel regcache_xfree (inf_status->registers); 387619370Spst 387719370Spst /* FIXME: If we are being called after stopping in a function which 387819370Spst is called from gdb, we should not be trying to restore the 387919370Spst selected frame; it just prints a spurious error message (The 388019370Spst message is useful, however, in detecting bugs in gdb (like if gdb 388119370Spst clobbers the stack)). In fact, should we be restoring the 388219370Spst inferior status at all in that case? . */ 388319370Spst 388419370Spst if (target_has_stack && inf_status->restore_stack_info) 388519370Spst { 388619370Spst /* The point of catch_errors is that if the stack is clobbered, 3887130803Smarcel walking the stack might encounter a garbage pointer and 3888130803Smarcel error() trying to dereference it. */ 3889130803Smarcel if (catch_errors 3890130803Smarcel (restore_selected_frame, &inf_status->selected_frame_id, 3891130803Smarcel "Unable to restore previously selected frame:\n", 3892130803Smarcel RETURN_MASK_ERROR) == 0) 389319370Spst /* Error in restoring the selected frame. Select the innermost 389419370Spst frame. */ 3895130803Smarcel select_frame (get_current_frame ()); 389646283Sdfr 389719370Spst } 389898944Sobrien 3899130803Smarcel xfree (inf_status); 390019370Spst} 390119370Spst 390298944Sobrienstatic void 390398944Sobriendo_restore_inferior_status_cleanup (void *sts) 390498944Sobrien{ 390598944Sobrien restore_inferior_status (sts); 390698944Sobrien} 390746283Sdfr 390898944Sobrienstruct cleanup * 390998944Sobrienmake_cleanup_restore_inferior_status (struct inferior_status *inf_status) 391098944Sobrien{ 391198944Sobrien return make_cleanup (do_restore_inferior_status_cleanup, inf_status); 391298944Sobrien} 391398944Sobrien 391446283Sdfrvoid 391598944Sobriendiscard_inferior_status (struct inferior_status *inf_status) 391646283Sdfr{ 391798944Sobrien /* See save_inferior_status for info on stop_bpstat. */ 391898944Sobrien bpstat_clear (&inf_status->stop_bpstat); 3919130803Smarcel regcache_xfree (inf_status->registers); 3920130803Smarcel regcache_xfree (inf_status->stop_registers); 3921130803Smarcel xfree (inf_status); 392298944Sobrien} 392346283Sdfr 3924130803Smarcelint 3925130803Smarcelinferior_has_forked (int pid, int *child_pid) 3926130803Smarcel{ 3927130803Smarcel struct target_waitstatus last; 3928130803Smarcel ptid_t last_ptid; 3929130803Smarcel 3930130803Smarcel get_last_target_status (&last_ptid, &last); 3931130803Smarcel 3932130803Smarcel if (last.kind != TARGET_WAITKIND_FORKED) 3933130803Smarcel return 0; 3934130803Smarcel 3935130803Smarcel if (ptid_get_pid (last_ptid) != pid) 3936130803Smarcel return 0; 3937130803Smarcel 3938130803Smarcel *child_pid = last.value.related_pid; 3939130803Smarcel return 1; 3940130803Smarcel} 3941130803Smarcel 3942130803Smarcelint 3943130803Smarcelinferior_has_vforked (int pid, int *child_pid) 3944130803Smarcel{ 3945130803Smarcel struct target_waitstatus last; 3946130803Smarcel ptid_t last_ptid; 3947130803Smarcel 3948130803Smarcel get_last_target_status (&last_ptid, &last); 3949130803Smarcel 3950130803Smarcel if (last.kind != TARGET_WAITKIND_VFORKED) 3951130803Smarcel return 0; 3952130803Smarcel 3953130803Smarcel if (ptid_get_pid (last_ptid) != pid) 3954130803Smarcel return 0; 3955130803Smarcel 3956130803Smarcel *child_pid = last.value.related_pid; 3957130803Smarcel return 1; 3958130803Smarcel} 3959130803Smarcel 3960130803Smarcelint 3961130803Smarcelinferior_has_execd (int pid, char **execd_pathname) 3962130803Smarcel{ 3963130803Smarcel struct target_waitstatus last; 3964130803Smarcel ptid_t last_ptid; 3965130803Smarcel 3966130803Smarcel get_last_target_status (&last_ptid, &last); 3967130803Smarcel 3968130803Smarcel if (last.kind != TARGET_WAITKIND_EXECD) 3969130803Smarcel return 0; 3970130803Smarcel 3971130803Smarcel if (ptid_get_pid (last_ptid) != pid) 3972130803Smarcel return 0; 3973130803Smarcel 3974130803Smarcel *execd_pathname = xstrdup (last.value.execd_pathname); 3975130803Smarcel return 1; 3976130803Smarcel} 3977130803Smarcel 397898944Sobrien/* Oft used ptids */ 397998944Sobrienptid_t null_ptid; 398098944Sobrienptid_t minus_one_ptid; 398198944Sobrien 398298944Sobrien/* Create a ptid given the necessary PID, LWP, and TID components. */ 3983130803Smarcel 398498944Sobrienptid_t 398598944Sobrienptid_build (int pid, long lwp, long tid) 398698944Sobrien{ 398798944Sobrien ptid_t ptid; 398898944Sobrien 398998944Sobrien ptid.pid = pid; 399098944Sobrien ptid.lwp = lwp; 399198944Sobrien ptid.tid = tid; 399298944Sobrien return ptid; 399346283Sdfr} 399498944Sobrien 399598944Sobrien/* Create a ptid from just a pid. */ 399698944Sobrien 399798944Sobrienptid_t 399898944Sobrienpid_to_ptid (int pid) 399998944Sobrien{ 400098944Sobrien return ptid_build (pid, 0, 0); 400198944Sobrien} 400298944Sobrien 400398944Sobrien/* Fetch the pid (process id) component from a ptid. */ 400498944Sobrien 400598944Sobrienint 400698944Sobrienptid_get_pid (ptid_t ptid) 400798944Sobrien{ 400898944Sobrien return ptid.pid; 400998944Sobrien} 401098944Sobrien 401198944Sobrien/* Fetch the lwp (lightweight process) component from a ptid. */ 401298944Sobrien 401398944Sobrienlong 401498944Sobrienptid_get_lwp (ptid_t ptid) 401598944Sobrien{ 401698944Sobrien return ptid.lwp; 401798944Sobrien} 401898944Sobrien 401998944Sobrien/* Fetch the tid (thread id) component from a ptid. */ 402098944Sobrien 402198944Sobrienlong 402298944Sobrienptid_get_tid (ptid_t ptid) 402398944Sobrien{ 402498944Sobrien return ptid.tid; 402598944Sobrien} 402698944Sobrien 402798944Sobrien/* ptid_equal() is used to test equality of two ptids. */ 402898944Sobrien 402998944Sobrienint 403098944Sobrienptid_equal (ptid_t ptid1, ptid_t ptid2) 403198944Sobrien{ 403298944Sobrien return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp 4033130803Smarcel && ptid1.tid == ptid2.tid); 403498944Sobrien} 403598944Sobrien 403698944Sobrien/* restore_inferior_ptid() will be used by the cleanup machinery 403798944Sobrien to restore the inferior_ptid value saved in a call to 403898944Sobrien save_inferior_ptid(). */ 403998944Sobrien 404098944Sobrienstatic void 404198944Sobrienrestore_inferior_ptid (void *arg) 404298944Sobrien{ 404398944Sobrien ptid_t *saved_ptid_ptr = arg; 404498944Sobrien inferior_ptid = *saved_ptid_ptr; 404598944Sobrien xfree (arg); 404698944Sobrien} 404798944Sobrien 404898944Sobrien/* Save the value of inferior_ptid so that it may be restored by a 404998944Sobrien later call to do_cleanups(). Returns the struct cleanup pointer 405098944Sobrien needed for later doing the cleanup. */ 405198944Sobrien 405298944Sobrienstruct cleanup * 405398944Sobriensave_inferior_ptid (void) 405498944Sobrien{ 405598944Sobrien ptid_t *saved_ptid_ptr; 405698944Sobrien 405798944Sobrien saved_ptid_ptr = xmalloc (sizeof (ptid_t)); 405898944Sobrien *saved_ptid_ptr = inferior_ptid; 405998944Sobrien return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); 406098944Sobrien} 4061130803Smarcel 406298944Sobrien 406398944Sobrienstatic void 406498944Sobrienbuild_infrun (void) 406598944Sobrien{ 4066130803Smarcel stop_registers = regcache_xmalloc (current_gdbarch); 406798944Sobrien} 406846283Sdfr 406919370Spstvoid 407098944Sobrien_initialize_infrun (void) 407119370Spst{ 4072130803Smarcel int i; 4073130803Smarcel int numsigs; 407446283Sdfr struct cmd_list_element *c; 407519370Spst 4076130803Smarcel DEPRECATED_REGISTER_GDBARCH_SWAP (stop_registers); 4077130803Smarcel deprecated_register_gdbarch_swap (NULL, 0, build_infrun); 407898944Sobrien 407919370Spst add_info ("signals", signals_info, 408019370Spst "What debugger does when program gets various signals.\n\ 408119370SpstSpecify a signal as argument to print info on that signal only."); 408219370Spst add_info_alias ("handle", "signals", 0); 408319370Spst 408419370Spst add_com ("handle", class_run, handle_command, 408519370Spst concat ("Specify how to handle a signal.\n\ 408619370SpstArgs are signals and actions to apply to those signals.\n\ 408719370SpstSymbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ 408819370Spstfrom 1-15 are allowed for compatibility with old versions of GDB.\n\ 408919370SpstNumeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ 409019370SpstThe special arg \"all\" is recognized to mean all signals except those\n\ 4091130803Smarcelused by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ 409219370Spst\"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ 409319370SpstStop means reenter debugger if this signal happens (implies print).\n\ 409419370SpstPrint means print a message if this signal happens.\n\ 409519370SpstPass means let program see this signal; otherwise program doesn't know.\n\ 409619370SpstIgnore is a synonym for nopass and noignore is a synonym for pass.\n\ 409719370SpstPass and Stop may be combined.", NULL)); 409846283Sdfr if (xdb_commands) 409946283Sdfr { 410046283Sdfr add_com ("lz", class_info, signals_info, 410146283Sdfr "What debugger does when program gets various signals.\n\ 410246283SdfrSpecify a signal as argument to print info on that signal only."); 410346283Sdfr add_com ("z", class_run, xdb_handle_command, 410446283Sdfr concat ("Specify how to handle a signal.\n\ 410546283SdfrArgs are signals and actions to apply to those signals.\n\ 410646283SdfrSymbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ 410746283Sdfrfrom 1-15 are allowed for compatibility with old versions of GDB.\n\ 410846283SdfrNumeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ 410946283SdfrThe special arg \"all\" is recognized to mean all signals except those\n\ 4110130803Smarcelused by the debugger, typically SIGTRAP and SIGINT.\n", "Recognized actions include \"s\" (toggles between stop and nostop), \n\ 411146283Sdfr\"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ 411246283Sdfrnopass), \"Q\" (noprint)\n\ 411346283SdfrStop means reenter debugger if this signal happens (implies print).\n\ 411446283SdfrPrint means print a message if this signal happens.\n\ 411546283SdfrPass means let program see this signal; otherwise program doesn't know.\n\ 411646283SdfrIgnore is a synonym for nopass and noignore is a synonym for pass.\n\ 411746283SdfrPass and Stop may be combined.", NULL)); 411846283Sdfr } 411919370Spst 412046283Sdfr if (!dbx_commands) 4121130803Smarcel stop_command = 4122130803Smarcel add_cmd ("stop", class_obscure, not_just_help_class_command, "There is no `stop' command, but you can set a hook on `stop'.\n\ 412319370SpstThis allows you to set a list of commands to be run each time execution\n\ 412419370Spstof the program stops.", &cmdlist); 412519370Spst 412646283Sdfr numsigs = (int) TARGET_SIGNAL_LAST; 4127130803Smarcel signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); 412819370Spst signal_print = (unsigned char *) 412919370Spst xmalloc (sizeof (signal_print[0]) * numsigs); 413019370Spst signal_program = (unsigned char *) 413119370Spst xmalloc (sizeof (signal_program[0]) * numsigs); 413219370Spst for (i = 0; i < numsigs; i++) 413319370Spst { 413419370Spst signal_stop[i] = 1; 413519370Spst signal_print[i] = 1; 413619370Spst signal_program[i] = 1; 413719370Spst } 413819370Spst 413919370Spst /* Signals caused by debugger's own actions 414019370Spst should not be given to the program afterwards. */ 414119370Spst signal_program[TARGET_SIGNAL_TRAP] = 0; 414219370Spst signal_program[TARGET_SIGNAL_INT] = 0; 414319370Spst 414419370Spst /* Signals that are not errors should not normally enter the debugger. */ 414519370Spst signal_stop[TARGET_SIGNAL_ALRM] = 0; 414619370Spst signal_print[TARGET_SIGNAL_ALRM] = 0; 414719370Spst signal_stop[TARGET_SIGNAL_VTALRM] = 0; 414819370Spst signal_print[TARGET_SIGNAL_VTALRM] = 0; 414919370Spst signal_stop[TARGET_SIGNAL_PROF] = 0; 415019370Spst signal_print[TARGET_SIGNAL_PROF] = 0; 415119370Spst signal_stop[TARGET_SIGNAL_CHLD] = 0; 415219370Spst signal_print[TARGET_SIGNAL_CHLD] = 0; 415319370Spst signal_stop[TARGET_SIGNAL_IO] = 0; 415419370Spst signal_print[TARGET_SIGNAL_IO] = 0; 415519370Spst signal_stop[TARGET_SIGNAL_POLL] = 0; 415619370Spst signal_print[TARGET_SIGNAL_POLL] = 0; 415719370Spst signal_stop[TARGET_SIGNAL_URG] = 0; 415819370Spst signal_print[TARGET_SIGNAL_URG] = 0; 415946283Sdfr signal_stop[TARGET_SIGNAL_WINCH] = 0; 416046283Sdfr signal_print[TARGET_SIGNAL_WINCH] = 0; 416119370Spst 416298944Sobrien /* These signals are used internally by user-level thread 416398944Sobrien implementations. (See signal(5) on Solaris.) Like the above 416498944Sobrien signals, a healthy program receives and handles them as part of 416598944Sobrien its normal operation. */ 416698944Sobrien signal_stop[TARGET_SIGNAL_LWP] = 0; 416798944Sobrien signal_print[TARGET_SIGNAL_LWP] = 0; 416898944Sobrien signal_stop[TARGET_SIGNAL_WAITING] = 0; 416998944Sobrien signal_print[TARGET_SIGNAL_WAITING] = 0; 417098944Sobrien signal_stop[TARGET_SIGNAL_CANCEL] = 0; 417198944Sobrien signal_print[TARGET_SIGNAL_CANCEL] = 0; 417298944Sobrien 417319370Spst#ifdef SOLIB_ADD 417419370Spst add_show_from_set 417519370Spst (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger, 417646283Sdfr (char *) &stop_on_solib_events, 417719370Spst "Set stopping for shared library events.\n\ 417819370SpstIf nonzero, gdb will give control to the user when the dynamic linker\n\ 417919370Spstnotifies gdb of shared library events. The most common event of interest\n\ 4180130803Smarcelto the user would be loading/unloading of a new library.\n", &setlist), &showlist); 418119370Spst#endif 418246283Sdfr 418346283Sdfr c = add_set_enum_cmd ("follow-fork-mode", 418446283Sdfr class_run, 4185130803Smarcel follow_fork_mode_kind_names, &follow_fork_mode_string, 418646283Sdfr "Set debugger response to a program call of fork \ 418746283Sdfror vfork.\n\ 418846283SdfrA fork or vfork creates a new process. follow-fork-mode can be:\n\ 418946283Sdfr parent - the original process is debugged after a fork\n\ 419046283Sdfr child - the new process is debugged after a fork\n\ 4191130803SmarcelThe unfollowed process will continue to run.\n\ 4192130803SmarcelBy default, the debugger will follow the parent process.", &setlist); 419346283Sdfr add_show_from_set (c, &showlist); 419446283Sdfr 4195130803Smarcel c = add_set_enum_cmd ("scheduler-locking", class_run, scheduler_enums, /* array of string names */ 419698944Sobrien &scheduler_mode, /* current mode */ 419746283Sdfr "Set mode for locking scheduler during execution.\n\ 419846283Sdfroff == no locking (threads may preempt at any time)\n\ 419946283Sdfron == full locking (no thread except the current thread may run)\n\ 420046283Sdfrstep == scheduler locked during every single-step operation.\n\ 420146283Sdfr In this mode, no other thread may run during a step command.\n\ 4202130803Smarcel Other threads may run while stepping over a function call ('next').", &setlist); 420346283Sdfr 420498944Sobrien set_cmd_sfunc (c, set_schedlock_func); /* traps on target vector */ 420546283Sdfr add_show_from_set (c, &showlist); 420698944Sobrien 420798944Sobrien c = add_set_cmd ("step-mode", class_run, 4208130803Smarcel var_boolean, (char *) &step_stop_if_no_debug, 4209130803Smarcel "Set mode of the step operation. When set, doing a step over a\n\ 421098944Sobrienfunction without debug line information will stop at the first\n\ 421198944Sobrieninstruction of that function. Otherwise, the function is skipped and\n\ 4212130803Smarcelthe step command stops at a different source line.", &setlist); 421398944Sobrien add_show_from_set (c, &showlist); 421498944Sobrien 421598944Sobrien /* ptid initializations */ 421698944Sobrien null_ptid = ptid_build (0, 0, 0); 421798944Sobrien minus_one_ptid = ptid_build (-1, 0, 0); 421898944Sobrien inferior_ptid = null_ptid; 421998944Sobrien target_last_wait_ptid = minus_one_ptid; 422019370Spst} 4221