15796c8dcSSimon Schubert /* Multi-process/thread control defs for GDB, the GNU debugger. 25796c8dcSSimon Schubert Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1997, 1998, 1999, 3*cf7f2e2dSJohn Marino 2000, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. 45796c8dcSSimon Schubert Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This file is part of GDB. 85796c8dcSSimon Schubert 95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 125796c8dcSSimon Schubert (at your option) any later version. 135796c8dcSSimon Schubert 145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 175796c8dcSSimon Schubert GNU General Public License for more details. 185796c8dcSSimon Schubert 195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert #ifndef GDBTHREAD_H 235796c8dcSSimon Schubert #define GDBTHREAD_H 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert struct symtab; 265796c8dcSSimon Schubert 275796c8dcSSimon Schubert #include "breakpoint.h" 285796c8dcSSimon Schubert #include "frame.h" 295796c8dcSSimon Schubert #include "ui-out.h" 305796c8dcSSimon Schubert #include "inferior.h" 315796c8dcSSimon Schubert 325796c8dcSSimon Schubert struct thread_info 335796c8dcSSimon Schubert { 345796c8dcSSimon Schubert struct thread_info *next; 355796c8dcSSimon Schubert ptid_t ptid; /* "Actual process id"; 365796c8dcSSimon Schubert In fact, this may be overloaded with 375796c8dcSSimon Schubert kernel thread id, etc. */ 385796c8dcSSimon Schubert int num; /* Convenient handle (GDB thread id) */ 395796c8dcSSimon Schubert 405796c8dcSSimon Schubert /* Non-zero means the thread is executing. Note: this is different 415796c8dcSSimon Schubert from saying that there is an active target and we are stopped at 425796c8dcSSimon Schubert a breakpoint, for instance. This is a real indicator whether the 435796c8dcSSimon Schubert thread is off and running. */ 445796c8dcSSimon Schubert /* This field is internal to thread.c. Never access it directly, 455796c8dcSSimon Schubert use is_executing instead. */ 465796c8dcSSimon Schubert int executing_; 475796c8dcSSimon Schubert 485796c8dcSSimon Schubert /* Frontend view of the thread state. Note that the RUNNING/STOPPED 495796c8dcSSimon Schubert states are different from EXECUTING. When the thread is stopped 505796c8dcSSimon Schubert internally while handling an internal event, like a software 515796c8dcSSimon Schubert single-step breakpoint, EXECUTING will be false, but running will 525796c8dcSSimon Schubert still be true. As a possible future extension, this could turn 535796c8dcSSimon Schubert into enum { stopped, exited, stepping, finishing, until(ling), 545796c8dcSSimon Schubert running ... } */ 555796c8dcSSimon Schubert /* This field is internal to thread.c. Never access it directly, 565796c8dcSSimon Schubert use is_running instead. */ 575796c8dcSSimon Schubert int state_; 585796c8dcSSimon Schubert 595796c8dcSSimon Schubert /* If this is > 0, then it means there's code out there that relies 605796c8dcSSimon Schubert on this thread being listed. Don't delete it from the lists even 615796c8dcSSimon Schubert if we detect it exiting. */ 625796c8dcSSimon Schubert int refcount; 635796c8dcSSimon Schubert 645796c8dcSSimon Schubert /* User/external stepping state. */ 655796c8dcSSimon Schubert 665796c8dcSSimon Schubert /* Step-resume or longjmp-resume breakpoint. */ 675796c8dcSSimon Schubert struct breakpoint *step_resume_breakpoint; 685796c8dcSSimon Schubert 695796c8dcSSimon Schubert /* Range to single step within. 705796c8dcSSimon Schubert 715796c8dcSSimon Schubert If this is nonzero, respond to a single-step signal by continuing 725796c8dcSSimon Schubert to step if the pc is in this range. 735796c8dcSSimon Schubert 745796c8dcSSimon Schubert If step_range_start and step_range_end are both 1, it means to 755796c8dcSSimon Schubert step for a single instruction (FIXME: it might clean up 765796c8dcSSimon Schubert wait_for_inferior in a minor way if this were changed to the 775796c8dcSSimon Schubert address of the instruction and that address plus one. But maybe 785796c8dcSSimon Schubert not.). */ 795796c8dcSSimon Schubert CORE_ADDR step_range_start; /* Inclusive */ 805796c8dcSSimon Schubert CORE_ADDR step_range_end; /* Exclusive */ 815796c8dcSSimon Schubert 825796c8dcSSimon Schubert /* Stack frame address as of when stepping command was issued. 835796c8dcSSimon Schubert This is how we know when we step into a subroutine call, and how 845796c8dcSSimon Schubert to set the frame for the breakpoint used to step out. */ 855796c8dcSSimon Schubert struct frame_id step_frame_id; 865796c8dcSSimon Schubert 875796c8dcSSimon Schubert /* Similarly, the frame ID of the underlying stack frame (skipping 885796c8dcSSimon Schubert any inlined frames). */ 895796c8dcSSimon Schubert struct frame_id step_stack_frame_id; 905796c8dcSSimon Schubert 915796c8dcSSimon Schubert int current_line; 925796c8dcSSimon Schubert struct symtab *current_symtab; 935796c8dcSSimon Schubert 945796c8dcSSimon Schubert /* Internal stepping state. */ 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert /* Record the pc of the thread the last time it stopped. This is 975796c8dcSSimon Schubert maintained by proceed and keep_going, and used in 985796c8dcSSimon Schubert adjust_pc_after_break to distinguish a hardware single-step 995796c8dcSSimon Schubert SIGTRAP from a breakpoint SIGTRAP. */ 1005796c8dcSSimon Schubert CORE_ADDR prev_pc; 1015796c8dcSSimon Schubert 1025796c8dcSSimon Schubert /* Nonzero if we are presently stepping over a breakpoint. 1035796c8dcSSimon Schubert 1045796c8dcSSimon Schubert If we hit a breakpoint or watchpoint, and then continue, we need 1055796c8dcSSimon Schubert to single step the current thread with breakpoints disabled, to 1065796c8dcSSimon Schubert avoid hitting the same breakpoint or watchpoint again. And we 1075796c8dcSSimon Schubert should step just a single thread and keep other threads stopped, 1085796c8dcSSimon Schubert so that other threads don't miss breakpoints while they are 1095796c8dcSSimon Schubert removed. 1105796c8dcSSimon Schubert 1115796c8dcSSimon Schubert So, this variable simultaneously means that we need to single 1125796c8dcSSimon Schubert step the current thread, keep other threads stopped, and that 1135796c8dcSSimon Schubert breakpoints should be removed while we step. 1145796c8dcSSimon Schubert 1155796c8dcSSimon Schubert This variable is set either: 1165796c8dcSSimon Schubert - in proceed, when we resume inferior on user's explicit request 1175796c8dcSSimon Schubert - in keep_going, if handle_inferior_event decides we need to 1185796c8dcSSimon Schubert step over breakpoint. 1195796c8dcSSimon Schubert 1205796c8dcSSimon Schubert The variable is cleared in normal_stop. The proceed calls 1215796c8dcSSimon Schubert wait_for_inferior, which calls handle_inferior_event in a loop, 1225796c8dcSSimon Schubert and until wait_for_inferior exits, this variable is changed only 1235796c8dcSSimon Schubert by keep_going. */ 1245796c8dcSSimon Schubert int trap_expected; 1255796c8dcSSimon Schubert 1265796c8dcSSimon Schubert /* Should we step over breakpoint next time keep_going is called? */ 1275796c8dcSSimon Schubert int stepping_over_breakpoint; 1285796c8dcSSimon Schubert 1295796c8dcSSimon Schubert /* Set to TRUE if we should finish single-stepping over a breakpoint 1305796c8dcSSimon Schubert after hitting the current step-resume breakpoint. */ 1315796c8dcSSimon Schubert int step_after_step_resume_breakpoint; 1325796c8dcSSimon Schubert 1335796c8dcSSimon Schubert /* This is set TRUE when a catchpoint of a shared library event 1345796c8dcSSimon Schubert triggers. Since we don't wish to leave the inferior in the 1355796c8dcSSimon Schubert solib hook when we report the event, we step the inferior 1365796c8dcSSimon Schubert back to user code before stopping and reporting the event. */ 1375796c8dcSSimon Schubert int stepping_through_solib_after_catch; 1385796c8dcSSimon Schubert 1395796c8dcSSimon Schubert /* When stepping_through_solib_after_catch is TRUE, this is a 1405796c8dcSSimon Schubert list of the catchpoints that should be reported as triggering 1415796c8dcSSimon Schubert when we finally do stop stepping. */ 1425796c8dcSSimon Schubert bpstat stepping_through_solib_catchpoints; 1435796c8dcSSimon Schubert 1445796c8dcSSimon Schubert /* Per-thread command support. */ 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert /* Pointer to what is left to do for an execution command after the 1475796c8dcSSimon Schubert target stops. Used only in asynchronous mode, by targets that 1485796c8dcSSimon Schubert support async execution. Several execution commands use it. */ 1495796c8dcSSimon Schubert struct continuation *continuations; 1505796c8dcSSimon Schubert 1515796c8dcSSimon Schubert /* Similar to the above, but used when a single execution command 1525796c8dcSSimon Schubert requires several resume/stop iterations. Used by the step 1535796c8dcSSimon Schubert command. */ 1545796c8dcSSimon Schubert struct continuation *intermediate_continuations; 1555796c8dcSSimon Schubert 1565796c8dcSSimon Schubert /* Nonzero if the thread is being proceeded for a "finish" command 1575796c8dcSSimon Schubert or a similar situation when stop_registers should be saved. */ 1585796c8dcSSimon Schubert int proceed_to_finish; 1595796c8dcSSimon Schubert 1605796c8dcSSimon Schubert /* Nonzero if the thread is being proceeded for an inferior function 1615796c8dcSSimon Schubert call. */ 1625796c8dcSSimon Schubert int in_infcall; 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert enum step_over_calls_kind step_over_calls; 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert /* Nonzero if stopped due to a step command. */ 1675796c8dcSSimon Schubert int stop_step; 1685796c8dcSSimon Schubert 1695796c8dcSSimon Schubert /* If stepping, nonzero means step count is > 1 so don't print frame 1705796c8dcSSimon Schubert next time inferior stops if it stops due to stepping. */ 1715796c8dcSSimon Schubert int step_multi; 1725796c8dcSSimon Schubert 1735796c8dcSSimon Schubert /* This is used to remember when a fork or vfork event was caught by 1745796c8dcSSimon Schubert a catchpoint, and thus the event is to be followed at the next 1755796c8dcSSimon Schubert resume of the thread, and not immediately. */ 1765796c8dcSSimon Schubert struct target_waitstatus pending_follow; 1775796c8dcSSimon Schubert 1785796c8dcSSimon Schubert /* Last signal that the inferior received (why it stopped). */ 1795796c8dcSSimon Schubert enum target_signal stop_signal; 1805796c8dcSSimon Schubert 1815796c8dcSSimon Schubert /* Chain containing status of breakpoint(s) the thread stopped 1825796c8dcSSimon Schubert at. */ 1835796c8dcSSimon Schubert bpstat stop_bpstat; 1845796c8dcSSimon Schubert 1855796c8dcSSimon Schubert /* True if this thread has been explicitly requested to stop. */ 1865796c8dcSSimon Schubert int stop_requested; 1875796c8dcSSimon Schubert 1885796c8dcSSimon Schubert /* Private data used by the target vector implementation. */ 1895796c8dcSSimon Schubert struct private_thread_info *private; 190*cf7f2e2dSJohn Marino 191*cf7f2e2dSJohn Marino /* Function that is called to free PRIVATE. If this is NULL, then 192*cf7f2e2dSJohn Marino xfree will be called on PRIVATE. */ 193*cf7f2e2dSJohn Marino void (*private_dtor) (struct private_thread_info *); 1945796c8dcSSimon Schubert }; 1955796c8dcSSimon Schubert 1965796c8dcSSimon Schubert /* Create an empty thread list, or empty the existing one. */ 1975796c8dcSSimon Schubert extern void init_thread_list (void); 1985796c8dcSSimon Schubert 1995796c8dcSSimon Schubert /* Add a thread to the thread list, print a message 2005796c8dcSSimon Schubert that a new thread is found, and return the pointer to 2015796c8dcSSimon Schubert the new thread. Caller my use this pointer to 2025796c8dcSSimon Schubert initialize the private thread data. */ 2035796c8dcSSimon Schubert extern struct thread_info *add_thread (ptid_t ptid); 2045796c8dcSSimon Schubert 2055796c8dcSSimon Schubert /* Same as add_thread, but does not print a message 2065796c8dcSSimon Schubert about new thread. */ 2075796c8dcSSimon Schubert extern struct thread_info *add_thread_silent (ptid_t ptid); 2085796c8dcSSimon Schubert 2095796c8dcSSimon Schubert /* Same as add_thread, and sets the private info. */ 2105796c8dcSSimon Schubert extern struct thread_info *add_thread_with_info (ptid_t ptid, 2115796c8dcSSimon Schubert struct private_thread_info *); 2125796c8dcSSimon Schubert 2135796c8dcSSimon Schubert /* Delete an existing thread list entry. */ 2145796c8dcSSimon Schubert extern void delete_thread (ptid_t); 2155796c8dcSSimon Schubert 2165796c8dcSSimon Schubert /* Delete an existing thread list entry, and be quiet about it. Used 2175796c8dcSSimon Schubert after the process this thread having belonged to having already 2185796c8dcSSimon Schubert exited, for example. */ 2195796c8dcSSimon Schubert extern void delete_thread_silent (ptid_t); 2205796c8dcSSimon Schubert 2215796c8dcSSimon Schubert /* Delete a step_resume_breakpoint from the thread database. */ 2225796c8dcSSimon Schubert extern void delete_step_resume_breakpoint (struct thread_info *); 2235796c8dcSSimon Schubert 2245796c8dcSSimon Schubert /* Translate the integer thread id (GDB's homegrown id, not the system's) 2255796c8dcSSimon Schubert into a "pid" (which may be overloaded with extra thread information). */ 2265796c8dcSSimon Schubert extern ptid_t thread_id_to_pid (int); 2275796c8dcSSimon Schubert 2285796c8dcSSimon Schubert /* Translate a 'pid' (which may be overloaded with extra thread information) 2295796c8dcSSimon Schubert into the integer thread id (GDB's homegrown id, not the system's). */ 2305796c8dcSSimon Schubert extern int pid_to_thread_id (ptid_t ptid); 2315796c8dcSSimon Schubert 2325796c8dcSSimon Schubert /* Boolean test for an already-known pid (which may be overloaded with 2335796c8dcSSimon Schubert extra thread information). */ 2345796c8dcSSimon Schubert extern int in_thread_list (ptid_t ptid); 2355796c8dcSSimon Schubert 2365796c8dcSSimon Schubert /* Boolean test for an already-known thread id (GDB's homegrown id, 2375796c8dcSSimon Schubert not the system's). */ 2385796c8dcSSimon Schubert extern int valid_thread_id (int thread); 2395796c8dcSSimon Schubert 2405796c8dcSSimon Schubert /* Search function to lookup a thread by 'pid'. */ 2415796c8dcSSimon Schubert extern struct thread_info *find_thread_ptid (ptid_t ptid); 2425796c8dcSSimon Schubert 2435796c8dcSSimon Schubert /* Find thread by GDB user-visible thread number. */ 2445796c8dcSSimon Schubert struct thread_info *find_thread_id (int num); 2455796c8dcSSimon Schubert 2465796c8dcSSimon Schubert /* Finds the first thread of the inferior given by PID. If PID is -1, 2475796c8dcSSimon Schubert returns the first thread in the list. */ 2485796c8dcSSimon Schubert struct thread_info *first_thread_of_process (int pid); 2495796c8dcSSimon Schubert 2505796c8dcSSimon Schubert /* Returns any thread of process PID. */ 2515796c8dcSSimon Schubert extern struct thread_info *any_thread_of_process (int pid); 2525796c8dcSSimon Schubert 253*cf7f2e2dSJohn Marino /* Returns any non-exited thread of process PID, giving preference for 254*cf7f2e2dSJohn Marino already stopped threads. */ 255*cf7f2e2dSJohn Marino extern struct thread_info *any_live_thread_of_process (int pid); 256*cf7f2e2dSJohn Marino 2575796c8dcSSimon Schubert /* Change the ptid of thread OLD_PTID to NEW_PTID. */ 2585796c8dcSSimon Schubert void thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid); 2595796c8dcSSimon Schubert 2605796c8dcSSimon Schubert /* Iterator function to call a user-provided callback function 2615796c8dcSSimon Schubert once for each known thread. */ 2625796c8dcSSimon Schubert typedef int (*thread_callback_func) (struct thread_info *, void *); 2635796c8dcSSimon Schubert extern struct thread_info *iterate_over_threads (thread_callback_func, void *); 2645796c8dcSSimon Schubert 2655796c8dcSSimon Schubert extern int thread_count (void); 2665796c8dcSSimon Schubert 2675796c8dcSSimon Schubert /* Switch from one thread to another. */ 2685796c8dcSSimon Schubert extern void switch_to_thread (ptid_t ptid); 2695796c8dcSSimon Schubert 2705796c8dcSSimon Schubert /* Marks thread PTID is running, or stopped. 2715796c8dcSSimon Schubert If PIDGET (PTID) is -1, marks all threads. */ 2725796c8dcSSimon Schubert extern void set_running (ptid_t ptid, int running); 2735796c8dcSSimon Schubert 2745796c8dcSSimon Schubert /* Marks or clears thread(s) PTID as having been requested to stop. 2755796c8dcSSimon Schubert If PTID is MINUS_ONE_PTID, applies to all threads. If 2765796c8dcSSimon Schubert ptid_is_pid(PTID) is true, applies to all threads of the process 2775796c8dcSSimon Schubert pointed at by PTID. If STOP, then the THREAD_STOP_REQUESTED 2785796c8dcSSimon Schubert observer is called with PTID as argument. */ 2795796c8dcSSimon Schubert extern void set_stop_requested (ptid_t ptid, int stop); 2805796c8dcSSimon Schubert 2815796c8dcSSimon Schubert /* NOTE: Since the thread state is not a boolean, most times, you do 2825796c8dcSSimon Schubert not want to check it with negation. If you really want to check if 2835796c8dcSSimon Schubert the thread is stopped, 2845796c8dcSSimon Schubert 2855796c8dcSSimon Schubert use (good): 2865796c8dcSSimon Schubert 2875796c8dcSSimon Schubert if (is_stopped (ptid)) 2885796c8dcSSimon Schubert 2895796c8dcSSimon Schubert instead of (bad): 2905796c8dcSSimon Schubert 2915796c8dcSSimon Schubert if (!is_running (ptid)) 2925796c8dcSSimon Schubert 2935796c8dcSSimon Schubert The latter also returns true on exited threads, most likelly not 2945796c8dcSSimon Schubert what you want. */ 2955796c8dcSSimon Schubert 2965796c8dcSSimon Schubert /* Reports if in the frontend's perpective, thread PTID is running. */ 2975796c8dcSSimon Schubert extern int is_running (ptid_t ptid); 2985796c8dcSSimon Schubert 2995796c8dcSSimon Schubert /* Is this thread listed, but known to have exited? We keep it listed 3005796c8dcSSimon Schubert (but not visible) until it's safe to delete. */ 3015796c8dcSSimon Schubert extern int is_exited (ptid_t ptid); 3025796c8dcSSimon Schubert 3035796c8dcSSimon Schubert /* In the frontend's perpective, is this thread stopped? */ 3045796c8dcSSimon Schubert extern int is_stopped (ptid_t ptid); 3055796c8dcSSimon Schubert 3065796c8dcSSimon Schubert /* In the frontend's perpective is there any thread running? */ 3075796c8dcSSimon Schubert extern int any_running (void); 3085796c8dcSSimon Schubert 3095796c8dcSSimon Schubert /* Marks thread PTID as executing, or not. If PIDGET (PTID) is -1, 3105796c8dcSSimon Schubert marks all threads. 3115796c8dcSSimon Schubert 3125796c8dcSSimon Schubert Note that this is different from the running state. See the 3135796c8dcSSimon Schubert description of state_ and executing_ fields of struct 3145796c8dcSSimon Schubert thread_info. */ 3155796c8dcSSimon Schubert extern void set_executing (ptid_t ptid, int executing); 3165796c8dcSSimon Schubert 3175796c8dcSSimon Schubert /* Reports if thread PTID is executing. */ 3185796c8dcSSimon Schubert extern int is_executing (ptid_t ptid); 3195796c8dcSSimon Schubert 3205796c8dcSSimon Schubert /* Merge the executing property of thread PTID over to its thread 3215796c8dcSSimon Schubert state property (frontend running/stopped view). 3225796c8dcSSimon Schubert 3235796c8dcSSimon Schubert "not executing" -> "stopped" 3245796c8dcSSimon Schubert "executing" -> "running" 3255796c8dcSSimon Schubert "exited" -> "exited" 3265796c8dcSSimon Schubert 3275796c8dcSSimon Schubert If PIDGET (PTID) is -1, go over all threads. 3285796c8dcSSimon Schubert 3295796c8dcSSimon Schubert Notifications are only emitted if the thread state did change. */ 3305796c8dcSSimon Schubert extern void finish_thread_state (ptid_t ptid); 3315796c8dcSSimon Schubert 3325796c8dcSSimon Schubert /* Same as FINISH_THREAD_STATE, but with an interface suitable to be 3335796c8dcSSimon Schubert registered as a cleanup. PTID_P points to the ptid_t that is 3345796c8dcSSimon Schubert passed to FINISH_THREAD_STATE. */ 3355796c8dcSSimon Schubert extern void finish_thread_state_cleanup (void *ptid_p); 3365796c8dcSSimon Schubert 3375796c8dcSSimon Schubert /* Commands with a prefix of `thread'. */ 3385796c8dcSSimon Schubert extern struct cmd_list_element *thread_cmd_list; 3395796c8dcSSimon Schubert 3405796c8dcSSimon Schubert /* Print notices on thread events (attach, detach, etc.), set with 3415796c8dcSSimon Schubert `set print thread-events'. */ 3425796c8dcSSimon Schubert extern int print_thread_events; 3435796c8dcSSimon Schubert 3445796c8dcSSimon Schubert extern void print_thread_info (struct ui_out *uiout, int thread, 3455796c8dcSSimon Schubert int pid); 3465796c8dcSSimon Schubert 3475796c8dcSSimon Schubert extern struct cleanup *make_cleanup_restore_current_thread (void); 3485796c8dcSSimon Schubert 3495796c8dcSSimon Schubert /* Returns a pointer into the thread_info corresponding to 3505796c8dcSSimon Schubert INFERIOR_PTID. INFERIOR_PTID *must* be in the thread list. */ 3515796c8dcSSimon Schubert extern struct thread_info* inferior_thread (void); 3525796c8dcSSimon Schubert 353*cf7f2e2dSJohn Marino extern void update_thread_list (void); 354*cf7f2e2dSJohn Marino 3555796c8dcSSimon Schubert #endif /* GDBTHREAD_H */ 356