18dffb485Schristos /* Internal interfaces for the GNU/Linux specific target code for gdbserver. 2*f1c2b495Schristos Copyright (C) 2002-2024 Free Software Foundation, Inc. 38dffb485Schristos 48dffb485Schristos This file is part of GDB. 58dffb485Schristos 68dffb485Schristos This program is free software; you can redistribute it and/or modify 78dffb485Schristos it under the terms of the GNU General Public License as published by 88dffb485Schristos the Free Software Foundation; either version 3 of the License, or 98dffb485Schristos (at your option) any later version. 108dffb485Schristos 118dffb485Schristos This program is distributed in the hope that it will be useful, 128dffb485Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 138dffb485Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148dffb485Schristos GNU General Public License for more details. 158dffb485Schristos 168dffb485Schristos You should have received a copy of the GNU General Public License 178dffb485Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 188dffb485Schristos 198dffb485Schristos #ifndef GDBSERVER_LINUX_LOW_H 208dffb485Schristos #define GDBSERVER_LINUX_LOW_H 218dffb485Schristos 228dffb485Schristos #include "nat/linux-nat.h" 238dffb485Schristos #include "nat/gdb_thread_db.h" 248dffb485Schristos #include <signal.h> 258dffb485Schristos 268dffb485Schristos #include "gdbthread.h" 278dffb485Schristos #include "gdb_proc_service.h" 288dffb485Schristos 298dffb485Schristos /* Included for ptrace type definitions. */ 308dffb485Schristos #include "nat/linux-ptrace.h" 31*f1c2b495Schristos #include "target/waitstatus.h" 328dffb485Schristos #include "tracepoint.h" 338dffb485Schristos 348dffb485Schristos #include <list> 358dffb485Schristos 368dffb485Schristos #define PTRACE_XFER_TYPE long 378dffb485Schristos 388dffb485Schristos #ifdef HAVE_LINUX_REGSETS 398dffb485Schristos typedef void (*regset_fill_func) (struct regcache *, void *); 408dffb485Schristos typedef void (*regset_store_func) (struct regcache *, const void *); 418dffb485Schristos enum regset_type { 428dffb485Schristos GENERAL_REGS, 438dffb485Schristos FP_REGS, 448dffb485Schristos EXTENDED_REGS, 458dffb485Schristos OPTIONAL_REGS, /* Do not error if the regset cannot be accessed. */ 468dffb485Schristos }; 478dffb485Schristos 488dffb485Schristos /* The arch's regsets array initializer must be terminated with a NULL 498dffb485Schristos regset. */ 508dffb485Schristos #define NULL_REGSET \ 518dffb485Schristos { 0, 0, 0, -1, (enum regset_type) -1, NULL, NULL } 528dffb485Schristos 538dffb485Schristos struct regset_info 548dffb485Schristos { 558dffb485Schristos int get_request, set_request; 568dffb485Schristos /* If NT_TYPE isn't 0, it will be passed to ptrace as the 3rd 578dffb485Schristos argument and the 4th argument should be "const struct iovec *". */ 588dffb485Schristos int nt_type; 598dffb485Schristos int size; 608dffb485Schristos enum regset_type type; 618dffb485Schristos regset_fill_func fill_function; 628dffb485Schristos regset_store_func store_function; 638dffb485Schristos }; 648dffb485Schristos 658dffb485Schristos /* Aggregation of all the supported regsets of a given 668dffb485Schristos architecture/mode. */ 678dffb485Schristos 688dffb485Schristos struct regsets_info 698dffb485Schristos { 708dffb485Schristos /* The regsets array. */ 718dffb485Schristos struct regset_info *regsets; 728dffb485Schristos 738dffb485Schristos /* The number of regsets in the REGSETS array. */ 748dffb485Schristos int num_regsets; 758dffb485Schristos 768dffb485Schristos /* If we get EIO on a regset, do not try it again. Note the set of 778dffb485Schristos supported regsets may depend on processor mode on biarch 788dffb485Schristos machines. This is a (lazily allocated) array holding one boolean 798dffb485Schristos byte (0/1) per regset, with each element corresponding to the 808dffb485Schristos regset in the REGSETS array above at the same offset. */ 818dffb485Schristos char *disabled_regsets; 828dffb485Schristos }; 838dffb485Schristos 848dffb485Schristos #endif 858dffb485Schristos 868dffb485Schristos /* Mapping between the general-purpose registers in `struct user' 878dffb485Schristos format and GDB's register array layout. */ 888dffb485Schristos 898dffb485Schristos struct usrregs_info 908dffb485Schristos { 918dffb485Schristos /* The number of registers accessible. */ 928dffb485Schristos int num_regs; 938dffb485Schristos 948dffb485Schristos /* The registers map. */ 958dffb485Schristos int *regmap; 968dffb485Schristos }; 978dffb485Schristos 988dffb485Schristos /* All info needed to access an architecture/mode's registers. */ 998dffb485Schristos 1008dffb485Schristos struct regs_info 1018dffb485Schristos { 1028dffb485Schristos /* Regset support bitmap: 1 for registers that are transferred as a part 1038dffb485Schristos of a regset, 0 for ones that need to be handled individually. This 1048dffb485Schristos can be NULL if all registers are transferred with regsets or regsets 1058dffb485Schristos are not supported. */ 1068dffb485Schristos unsigned char *regset_bitmap; 1078dffb485Schristos 1088dffb485Schristos /* Info used when accessing registers with PTRACE_PEEKUSER / 1098dffb485Schristos PTRACE_POKEUSER. This can be NULL if all registers are 1108dffb485Schristos transferred with regsets .*/ 1118dffb485Schristos struct usrregs_info *usrregs; 1128dffb485Schristos 1138dffb485Schristos #ifdef HAVE_LINUX_REGSETS 1148dffb485Schristos /* Info used when accessing registers with regsets. */ 1158dffb485Schristos struct regsets_info *regsets_info; 1168dffb485Schristos #endif 1178dffb485Schristos }; 1188dffb485Schristos 1198dffb485Schristos struct process_info_private 1208dffb485Schristos { 1218dffb485Schristos /* Arch-specific additions. */ 1228dffb485Schristos struct arch_process_info *arch_private; 1238dffb485Schristos 1248dffb485Schristos /* libthread_db-specific additions. Not NULL if this process has loaded 1258dffb485Schristos thread_db, and it is active. */ 1268dffb485Schristos struct thread_db *thread_db; 1278dffb485Schristos 1288dffb485Schristos /* &_r_debug. 0 if not yet determined. -1 if no PT_DYNAMIC in Phdrs. */ 1298dffb485Schristos CORE_ADDR r_debug; 1304b169a6bSchristos 1314b169a6bSchristos /* The /proc/pid/mem file used for reading/writing memory. */ 1324b169a6bSchristos int mem_fd; 1338dffb485Schristos }; 1348dffb485Schristos 1358dffb485Schristos struct lwp_info; 1368dffb485Schristos 1378dffb485Schristos /* Target ops definitions for a Linux target. */ 1388dffb485Schristos 1398dffb485Schristos class linux_process_target : public process_stratum_target 1408dffb485Schristos { 1418dffb485Schristos public: 1428dffb485Schristos 1438dffb485Schristos int create_inferior (const char *program, 1448dffb485Schristos const std::vector<char *> &program_args) override; 1458dffb485Schristos 1468dffb485Schristos void post_create_inferior () override; 1478dffb485Schristos 1488dffb485Schristos int attach (unsigned long pid) override; 1498dffb485Schristos 1508dffb485Schristos int kill (process_info *proc) override; 1518dffb485Schristos 1528dffb485Schristos int detach (process_info *proc) override; 1538dffb485Schristos 1548dffb485Schristos void mourn (process_info *proc) override; 1558dffb485Schristos 1568dffb485Schristos void join (int pid) override; 1578dffb485Schristos 1588dffb485Schristos bool thread_alive (ptid_t pid) override; 1598dffb485Schristos 1608dffb485Schristos void resume (thread_resume *resume_info, size_t n) override; 1618dffb485Schristos 1628dffb485Schristos ptid_t wait (ptid_t ptid, target_waitstatus *status, 1634b169a6bSchristos target_wait_flags options) override; 1648dffb485Schristos 1658dffb485Schristos void fetch_registers (regcache *regcache, int regno) override; 1668dffb485Schristos 1678dffb485Schristos void store_registers (regcache *regcache, int regno) override; 1688dffb485Schristos 1698dffb485Schristos int read_memory (CORE_ADDR memaddr, unsigned char *myaddr, 1708dffb485Schristos int len) override; 1718dffb485Schristos 1728dffb485Schristos int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, 1738dffb485Schristos int len) override; 1748dffb485Schristos 1758dffb485Schristos void look_up_symbols () override; 1768dffb485Schristos 1778dffb485Schristos void request_interrupt () override; 1788dffb485Schristos 1798dffb485Schristos bool supports_read_auxv () override; 1808dffb485Schristos 181*f1c2b495Schristos int read_auxv (int pid, CORE_ADDR offset, unsigned char *myaddr, 1828dffb485Schristos unsigned int len) override; 1838dffb485Schristos 1848dffb485Schristos int insert_point (enum raw_bkpt_type type, CORE_ADDR addr, 1858dffb485Schristos int size, raw_breakpoint *bp) override; 1868dffb485Schristos 1878dffb485Schristos int remove_point (enum raw_bkpt_type type, CORE_ADDR addr, 1888dffb485Schristos int size, raw_breakpoint *bp) override; 1898dffb485Schristos 1908dffb485Schristos bool stopped_by_sw_breakpoint () override; 1918dffb485Schristos 1928dffb485Schristos bool supports_stopped_by_sw_breakpoint () override; 1938dffb485Schristos 1948dffb485Schristos bool stopped_by_hw_breakpoint () override; 1958dffb485Schristos 1968dffb485Schristos bool supports_stopped_by_hw_breakpoint () override; 1978dffb485Schristos 1988dffb485Schristos bool supports_hardware_single_step () override; 1998dffb485Schristos 2008dffb485Schristos bool stopped_by_watchpoint () override; 2018dffb485Schristos 2028dffb485Schristos CORE_ADDR stopped_data_address () override; 2038dffb485Schristos 2048dffb485Schristos bool supports_read_offsets () override; 2058dffb485Schristos 2068dffb485Schristos int read_offsets (CORE_ADDR *text, CORE_ADDR *data) override; 2078dffb485Schristos 2088dffb485Schristos bool supports_get_tls_address () override; 2098dffb485Schristos 2108dffb485Schristos int get_tls_address (thread_info *thread, CORE_ADDR offset, 2118dffb485Schristos CORE_ADDR load_module, CORE_ADDR *address) override; 2128dffb485Schristos 2138dffb485Schristos bool supports_qxfer_osdata () override; 2148dffb485Schristos 2158dffb485Schristos int qxfer_osdata (const char *annex, unsigned char *readbuf, 2168dffb485Schristos unsigned const char *writebuf, 2178dffb485Schristos CORE_ADDR offset, int len) override; 2188dffb485Schristos 2198dffb485Schristos bool supports_qxfer_siginfo () override; 2208dffb485Schristos 2218dffb485Schristos int qxfer_siginfo (const char *annex, unsigned char *readbuf, 2228dffb485Schristos unsigned const char *writebuf, 2238dffb485Schristos CORE_ADDR offset, int len) override; 2248dffb485Schristos 2258dffb485Schristos bool supports_non_stop () override; 2268dffb485Schristos 2278dffb485Schristos bool async (bool enable) override; 2288dffb485Schristos 2298dffb485Schristos int start_non_stop (bool enable) override; 2308dffb485Schristos 2318dffb485Schristos bool supports_multi_process () override; 2328dffb485Schristos 2338dffb485Schristos bool supports_fork_events () override; 2348dffb485Schristos 2358dffb485Schristos bool supports_vfork_events () override; 2368dffb485Schristos 237*f1c2b495Schristos gdb_thread_options supported_thread_options () override; 238*f1c2b495Schristos 2398dffb485Schristos bool supports_exec_events () override; 2408dffb485Schristos 2418dffb485Schristos void handle_new_gdb_connection () override; 2428dffb485Schristos 2438dffb485Schristos int handle_monitor_command (char *mon) override; 2448dffb485Schristos 2458dffb485Schristos int core_of_thread (ptid_t ptid) override; 2468dffb485Schristos 2478dffb485Schristos #if defined PT_GETDSBT || defined PTRACE_GETFDPIC 2488dffb485Schristos bool supports_read_loadmap () override; 2498dffb485Schristos 2508dffb485Schristos int read_loadmap (const char *annex, CORE_ADDR offset, 2518dffb485Schristos unsigned char *myaddr, unsigned int len) override; 2528dffb485Schristos #endif 2538dffb485Schristos 2548dffb485Schristos CORE_ADDR read_pc (regcache *regcache) override; 2558dffb485Schristos 2568dffb485Schristos void write_pc (regcache *regcache, CORE_ADDR pc) override; 2578dffb485Schristos 2588dffb485Schristos bool supports_thread_stopped () override; 2598dffb485Schristos 2608dffb485Schristos bool thread_stopped (thread_info *thread) override; 2618dffb485Schristos 262*f1c2b495Schristos bool any_resumed () override; 263*f1c2b495Schristos 2648dffb485Schristos void pause_all (bool freeze) override; 2658dffb485Schristos 2668dffb485Schristos void unpause_all (bool unfreeze) override; 2678dffb485Schristos 2688dffb485Schristos void stabilize_threads () override; 2698dffb485Schristos 2708dffb485Schristos bool supports_disable_randomization () override; 2718dffb485Schristos 2728dffb485Schristos bool supports_qxfer_libraries_svr4 () override; 2738dffb485Schristos 2748dffb485Schristos int qxfer_libraries_svr4 (const char *annex, 2758dffb485Schristos unsigned char *readbuf, 2768dffb485Schristos unsigned const char *writebuf, 2778dffb485Schristos CORE_ADDR offset, int len) override; 2788dffb485Schristos 2798dffb485Schristos bool supports_agent () override; 2808dffb485Schristos 2818dffb485Schristos #ifdef HAVE_LINUX_BTRACE 2824b169a6bSchristos bool supports_btrace () override; 2834b169a6bSchristos 2844b169a6bSchristos btrace_target_info *enable_btrace (thread_info *tp, 2858dffb485Schristos const btrace_config *conf) override; 2868dffb485Schristos 2878dffb485Schristos int disable_btrace (btrace_target_info *tinfo) override; 2888dffb485Schristos 289*f1c2b495Schristos int read_btrace (btrace_target_info *tinfo, std::string *buf, 2908dffb485Schristos enum btrace_read_type type) override; 2918dffb485Schristos 2928dffb485Schristos int read_btrace_conf (const btrace_target_info *tinfo, 293*f1c2b495Schristos std::string *buf) override; 2948dffb485Schristos #endif 2958dffb485Schristos 2968dffb485Schristos bool supports_range_stepping () override; 2978dffb485Schristos 2988dffb485Schristos bool supports_pid_to_exec_file () override; 2998dffb485Schristos 3004b169a6bSchristos const char *pid_to_exec_file (int pid) override; 3018dffb485Schristos 3028dffb485Schristos bool supports_multifs () override; 3038dffb485Schristos 3048dffb485Schristos int multifs_open (int pid, const char *filename, int flags, 3058dffb485Schristos mode_t mode) override; 3068dffb485Schristos 3078dffb485Schristos int multifs_unlink (int pid, const char *filename) override; 3088dffb485Schristos 3098dffb485Schristos ssize_t multifs_readlink (int pid, const char *filename, char *buf, 3108dffb485Schristos size_t bufsiz) override; 3118dffb485Schristos 3128dffb485Schristos const char *thread_name (ptid_t thread) override; 3138dffb485Schristos 3148dffb485Schristos #if USE_THREAD_DB 3158dffb485Schristos bool thread_handle (ptid_t ptid, gdb_byte **handle, 3168dffb485Schristos int *handle_len) override; 3178dffb485Schristos #endif 3188dffb485Schristos 3194b169a6bSchristos thread_info *thread_pending_parent (thread_info *thread) override; 320*f1c2b495Schristos thread_info *thread_pending_child (thread_info *thread, 321*f1c2b495Schristos target_waitkind *kind) override; 3224b169a6bSchristos 3238dffb485Schristos bool supports_catch_syscall () override; 3248dffb485Schristos 3258dffb485Schristos /* Return the information to access registers. This has public 3268dffb485Schristos visibility because proc-service uses it. */ 3278dffb485Schristos virtual const regs_info *get_regs_info () = 0; 3288dffb485Schristos 3298dffb485Schristos private: 3308dffb485Schristos 3318dffb485Schristos /* Handle a GNU/Linux extended wait response. If we see a clone, 3328dffb485Schristos fork, or vfork event, we need to add the new LWP to our list 3338dffb485Schristos (and return 0 so as not to report the trap to higher layers). 3348dffb485Schristos If we see an exec event, we will modify ORIG_EVENT_LWP to point 3358dffb485Schristos to a new LWP representing the new program. */ 3368dffb485Schristos int handle_extended_wait (lwp_info **orig_event_lwp, int wstat); 3378dffb485Schristos 3384b169a6bSchristos /* Do low-level handling of the event, and check if this is an event we want 3394b169a6bSchristos to report. Is so, store it as a pending status in the lwp_info structure 3404b169a6bSchristos corresponding to LWPID. */ 3414b169a6bSchristos void filter_event (int lwpid, int wstat); 3428dffb485Schristos 3438dffb485Schristos /* Wait for an event from child(ren) WAIT_PTID, and return any that 3448dffb485Schristos match FILTER_PTID (leaving others pending). The PTIDs can be: 3458dffb485Schristos minus_one_ptid, to specify any child; a pid PTID, specifying all 3468dffb485Schristos lwps of a thread group; or a PTID representing a single lwp. Store 3478dffb485Schristos the stop status through the status pointer WSTAT. OPTIONS is 3488dffb485Schristos passed to the waitpid call. Return 0 if no event was found and 3498dffb485Schristos OPTIONS contains WNOHANG. Return -1 if no unwaited-for children 3508dffb485Schristos was found. Return the PID of the stopped child otherwise. */ 3518dffb485Schristos int wait_for_event_filtered (ptid_t wait_ptid, ptid_t filter_ptid, 3528dffb485Schristos int *wstatp, int options); 3538dffb485Schristos 3548dffb485Schristos /* Wait for an event from child(ren) PTID. PTIDs can be: 3558dffb485Schristos minus_one_ptid, to specify any child; a pid PTID, specifying all 3568dffb485Schristos lwps of a thread group; or a PTID representing a single lwp. Store 3578dffb485Schristos the stop status through the status pointer WSTAT. OPTIONS is 3588dffb485Schristos passed to the waitpid call. Return 0 if no event was found and 3598dffb485Schristos OPTIONS contains WNOHANG. Return -1 if no unwaited-for children 3608dffb485Schristos was found. Return the PID of the stopped child otherwise. */ 3618dffb485Schristos int wait_for_event (ptid_t ptid, int *wstatp, int options); 3628dffb485Schristos 3638dffb485Schristos /* Wait for all children to stop for the SIGSTOPs we just queued. */ 3648dffb485Schristos void wait_for_sigstop (); 3658dffb485Schristos 3668dffb485Schristos /* Wait for process, returns status. */ 3678dffb485Schristos ptid_t wait_1 (ptid_t ptid, target_waitstatus *ourstatus, 3684b169a6bSchristos target_wait_flags target_options); 3698dffb485Schristos 3708dffb485Schristos /* Stop all lwps that aren't stopped yet, except EXCEPT, if not NULL. 3718dffb485Schristos If SUSPEND, then also increase the suspend count of every LWP, 3728dffb485Schristos except EXCEPT. */ 3738dffb485Schristos void stop_all_lwps (int suspend, lwp_info *except); 3748dffb485Schristos 3758dffb485Schristos /* Stopped LWPs that the client wanted to be running, that don't have 3768dffb485Schristos pending statuses, are set to run again, except for EXCEPT, if not 3778dffb485Schristos NULL. This undoes a stop_all_lwps call. */ 3788dffb485Schristos void unstop_all_lwps (int unsuspend, lwp_info *except); 3798dffb485Schristos 3808dffb485Schristos /* Start a step-over operation on LWP. When LWP stopped at a 3818dffb485Schristos breakpoint, to make progress, we need to remove the breakpoint out 3828dffb485Schristos of the way. If we let other threads run while we do that, they may 3838dffb485Schristos pass by the breakpoint location and miss hitting it. To avoid 3848dffb485Schristos that, a step-over momentarily stops all threads while LWP is 3858dffb485Schristos single-stepped by either hardware or software while the breakpoint 3868dffb485Schristos is temporarily uninserted from the inferior. When the single-step 3878dffb485Schristos finishes, we reinsert the breakpoint, and let all threads that are 3888dffb485Schristos supposed to be running, run again. */ 3898dffb485Schristos void start_step_over (lwp_info *lwp); 3908dffb485Schristos 3918dffb485Schristos /* If there's a step over in progress, wait until all threads stop 3928dffb485Schristos (that is, until the stepping thread finishes its step), and 3938dffb485Schristos unsuspend all lwps. The stepping thread ends with its status 3948dffb485Schristos pending, which is processed later when we get back to processing 3958dffb485Schristos events. */ 3968dffb485Schristos void complete_ongoing_step_over (); 3978dffb485Schristos 3988dffb485Schristos /* Finish a step-over. Reinsert the breakpoint we had uninserted in 3998dffb485Schristos start_step_over, if still there, and delete any single-step 4008dffb485Schristos breakpoints we've set, on non hardware single-step targets. 4018dffb485Schristos Return true if step over finished. */ 4028dffb485Schristos bool finish_step_over (lwp_info *lwp); 4038dffb485Schristos 4048dffb485Schristos /* When we finish a step-over, set threads running again. If there's 4058dffb485Schristos another thread that may need a step-over, now's the time to start 4068dffb485Schristos it. Eventually, we'll move all threads past their breakpoints. */ 4078dffb485Schristos void proceed_all_lwps (); 4088dffb485Schristos 4098dffb485Schristos /* The reason we resume in the caller, is because we want to be able 4108dffb485Schristos to pass lwp->status_pending as WSTAT, and we need to clear 4118dffb485Schristos status_pending_p before resuming, otherwise, resume_one_lwp 4128dffb485Schristos refuses to resume. */ 4138dffb485Schristos bool maybe_move_out_of_jump_pad (lwp_info *lwp, int *wstat); 4148dffb485Schristos 4158dffb485Schristos /* Move THREAD out of the jump pad. */ 4168dffb485Schristos void move_out_of_jump_pad (thread_info *thread); 4178dffb485Schristos 4188dffb485Schristos /* Call low_arch_setup on THREAD. */ 4198dffb485Schristos void arch_setup_thread (thread_info *thread); 4208dffb485Schristos 4218dffb485Schristos #ifdef HAVE_LINUX_USRREGS 4228dffb485Schristos /* Fetch one register. */ 4238dffb485Schristos void fetch_register (const usrregs_info *usrregs, regcache *regcache, 4248dffb485Schristos int regno); 4258dffb485Schristos 4268dffb485Schristos /* Store one register. */ 4278dffb485Schristos void store_register (const usrregs_info *usrregs, regcache *regcache, 4288dffb485Schristos int regno); 4298dffb485Schristos #endif 4308dffb485Schristos 4318dffb485Schristos /* Fetch all registers, or just one, from the child process. 4328dffb485Schristos If REGNO is -1, do this for all registers, skipping any that are 4338dffb485Schristos assumed to have been retrieved by regsets_fetch_inferior_registers, 4348dffb485Schristos unless ALL is non-zero. 4358dffb485Schristos Otherwise, REGNO specifies which register (so we can save time). */ 4368dffb485Schristos void usr_fetch_inferior_registers (const regs_info *regs_info, 4378dffb485Schristos regcache *regcache, int regno, int all); 4388dffb485Schristos 4398dffb485Schristos /* Store our register values back into the inferior. 4408dffb485Schristos If REGNO is -1, do this for all registers, skipping any that are 4418dffb485Schristos assumed to have been saved by regsets_store_inferior_registers, 4428dffb485Schristos unless ALL is non-zero. 4438dffb485Schristos Otherwise, REGNO specifies which register (so we can save time). */ 4448dffb485Schristos void usr_store_inferior_registers (const regs_info *regs_info, 4458dffb485Schristos regcache *regcache, int regno, int all); 4468dffb485Schristos 4478dffb485Schristos /* Return the PC as read from the regcache of LWP, without any 4488dffb485Schristos adjustment. */ 4498dffb485Schristos CORE_ADDR get_pc (lwp_info *lwp); 4508dffb485Schristos 4518dffb485Schristos /* Called when the LWP stopped for a signal/trap. If it stopped for a 4528dffb485Schristos trap check what caused it (breakpoint, watchpoint, trace, etc.), 4538dffb485Schristos and save the result in the LWP's stop_reason field. If it stopped 4548dffb485Schristos for a breakpoint, decrement the PC if necessary on the lwp's 4558dffb485Schristos architecture. Returns true if we now have the LWP's stop PC. */ 4568dffb485Schristos bool save_stop_reason (lwp_info *lwp); 4578dffb485Schristos 4588dffb485Schristos /* Resume execution of LWP. If STEP is nonzero, single-step it. If 4598dffb485Schristos SIGNAL is nonzero, give it that signal. */ 4608dffb485Schristos void resume_one_lwp_throw (lwp_info *lwp, int step, int signal, 4618dffb485Schristos siginfo_t *info); 4628dffb485Schristos 4638dffb485Schristos /* Like resume_one_lwp_throw, but no error is thrown if the LWP 4648dffb485Schristos disappears while we try to resume it. */ 4658dffb485Schristos void resume_one_lwp (lwp_info *lwp, int step, int signal, siginfo_t *info); 4668dffb485Schristos 4678dffb485Schristos /* This function is called once per thread. We check the thread's 4688dffb485Schristos last resume request, which will tell us whether to resume, step, or 4698dffb485Schristos leave the thread stopped. Any signal the client requested to be 4708dffb485Schristos delivered has already been enqueued at this point. 4718dffb485Schristos 4728dffb485Schristos If any thread that GDB wants running is stopped at an internal 4738dffb485Schristos breakpoint that needs stepping over, we start a step-over operation 4748dffb485Schristos on that particular thread, and leave all others stopped. */ 4758dffb485Schristos void proceed_one_lwp (thread_info *thread, lwp_info *except); 4768dffb485Schristos 4778dffb485Schristos /* This function is called once per thread. We check the thread's 4788dffb485Schristos resume request, which will tell us whether to resume, step, or 4798dffb485Schristos leave the thread stopped; and what signal, if any, it should be 4808dffb485Schristos sent. 4818dffb485Schristos 4828dffb485Schristos For threads which we aren't explicitly told otherwise, we preserve 4838dffb485Schristos the stepping flag; this is used for stepping over gdbserver-placed 4848dffb485Schristos breakpoints. 4858dffb485Schristos 4868dffb485Schristos If pending_flags was set in any thread, we queue any needed 4878dffb485Schristos signals, since we won't actually resume. We already have a pending 4888dffb485Schristos event to report, so we don't need to preserve any step requests; 4898dffb485Schristos they should be re-issued if necessary. */ 4908dffb485Schristos void resume_one_thread (thread_info *thread, bool leave_all_stopped); 4918dffb485Schristos 4928dffb485Schristos /* Return true if this lwp has an interesting status pending. */ 4938dffb485Schristos bool status_pending_p_callback (thread_info *thread, ptid_t ptid); 4948dffb485Schristos 4958dffb485Schristos /* Resume LWPs that are currently stopped without any pending status 4968dffb485Schristos to report, but are resumed from the core's perspective. */ 4978dffb485Schristos void resume_stopped_resumed_lwps (thread_info *thread); 4988dffb485Schristos 4998dffb485Schristos /* Unsuspend THREAD, except EXCEPT, and proceed. */ 5008dffb485Schristos void unsuspend_and_proceed_one_lwp (thread_info *thread, lwp_info *except); 5018dffb485Schristos 5028dffb485Schristos /* Return true if this lwp still has an interesting status pending. 5038dffb485Schristos If not (e.g., it had stopped for a breakpoint that is gone), return 5048dffb485Schristos false. */ 5058dffb485Schristos bool thread_still_has_status_pending (thread_info *thread); 5068dffb485Schristos 5078dffb485Schristos /* Return true if this lwp is to-be-resumed and has an interesting 5088dffb485Schristos status pending. */ 5098dffb485Schristos bool resume_status_pending (thread_info *thread); 5108dffb485Schristos 5118dffb485Schristos /* Return true if this lwp that GDB wants running is stopped at an 5128dffb485Schristos internal breakpoint that we need to step over. It assumes that 5138dffb485Schristos any required STOP_PC adjustment has already been propagated to 5148dffb485Schristos the inferior's regcache. */ 5158dffb485Schristos bool thread_needs_step_over (thread_info *thread); 5168dffb485Schristos 5178dffb485Schristos /* Single step via hardware or software single step. 5188dffb485Schristos Return 1 if hardware single stepping, 0 if software single stepping 5198dffb485Schristos or can't single step. */ 5208dffb485Schristos int single_step (lwp_info* lwp); 5218dffb485Schristos 5228dffb485Schristos /* Return true if THREAD is doing hardware single step. */ 5238dffb485Schristos bool maybe_hw_step (thread_info *thread); 5248dffb485Schristos 5258dffb485Schristos /* Install breakpoints for software single stepping. */ 5268dffb485Schristos void install_software_single_step_breakpoints (lwp_info *lwp); 5278dffb485Schristos 5288dffb485Schristos /* Fetch the possibly triggered data watchpoint info and store it in 5298dffb485Schristos CHILD. 5308dffb485Schristos 5318dffb485Schristos On some archs, like x86, that use debug registers to set 5328dffb485Schristos watchpoints, it's possible that the way to know which watched 5338dffb485Schristos address trapped, is to check the register that is used to select 5348dffb485Schristos which address to watch. Problem is, between setting the watchpoint 5358dffb485Schristos and reading back which data address trapped, the user may change 5368dffb485Schristos the set of watchpoints, and, as a consequence, GDB changes the 5378dffb485Schristos debug registers in the inferior. To avoid reading back a stale 5388dffb485Schristos stopped-data-address when that happens, we cache in LP the fact 5398dffb485Schristos that a watchpoint trapped, and the corresponding data address, as 5408dffb485Schristos soon as we see CHILD stop with a SIGTRAP. If GDB changes the debug 5418dffb485Schristos registers meanwhile, we have the cached data we can rely on. */ 5428dffb485Schristos bool check_stopped_by_watchpoint (lwp_info *child); 5438dffb485Schristos 5448dffb485Schristos /* Convert a native/host siginfo object, into/from the siginfo in the 5458dffb485Schristos layout of the inferiors' architecture. */ 5468dffb485Schristos void siginfo_fixup (siginfo_t *siginfo, gdb_byte *inf_siginfo, 5478dffb485Schristos int direction); 5488dffb485Schristos 5498dffb485Schristos /* Add a process to the common process list, and set its private 5508dffb485Schristos data. */ 5518dffb485Schristos process_info *add_linux_process (int pid, int attached); 5528dffb485Schristos 5534b169a6bSchristos /* Same as add_linux_process, but don't open the /proc/PID/mem file 5544b169a6bSchristos yet. */ 5554b169a6bSchristos process_info *add_linux_process_no_mem_file (int pid, int attached); 5564b169a6bSchristos 5574b169a6bSchristos /* Free resources associated to PROC and remove it. */ 5584b169a6bSchristos void remove_linux_process (process_info *proc); 5594b169a6bSchristos 5608dffb485Schristos /* Add a new thread. */ 5618dffb485Schristos lwp_info *add_lwp (ptid_t ptid); 5628dffb485Schristos 5638dffb485Schristos /* Delete a thread. */ 5648dffb485Schristos void delete_lwp (lwp_info *lwp); 5658dffb485Schristos 5668dffb485Schristos public: /* Make this public because it's used from outside. */ 5678dffb485Schristos /* Attach to an inferior process. Returns 0 on success, ERRNO on 5688dffb485Schristos error. */ 5698dffb485Schristos int attach_lwp (ptid_t ptid); 5708dffb485Schristos 5718dffb485Schristos private: /* Back to private. */ 5728dffb485Schristos /* Detach from LWP. */ 5738dffb485Schristos void detach_one_lwp (lwp_info *lwp); 5748dffb485Schristos 5758dffb485Schristos /* Detect zombie thread group leaders, and "exit" them. We can't 5768dffb485Schristos reap their exits until all other threads in the group have 577*f1c2b495Schristos exited. Returns true if we left any new event pending, false 578*f1c2b495Schristos otherwise. */ 579*f1c2b495Schristos bool check_zombie_leaders (); 5808dffb485Schristos 581*f1c2b495Schristos /* Convenience function that is called when we're about to return an 582*f1c2b495Schristos event to the core. If the event is an exit or signalled event, 583*f1c2b495Schristos then this decides whether to report it as process-wide event, as 584*f1c2b495Schristos a thread exit event, or to suppress it. All other event kinds 585*f1c2b495Schristos are passed through unmodified. */ 5868dffb485Schristos ptid_t filter_exit_event (lwp_info *event_child, 5878dffb485Schristos target_waitstatus *ourstatus); 5888dffb485Schristos 5898dffb485Schristos /* Returns true if THREAD is stopped in a jump pad, and we can't 5908dffb485Schristos move it out, because we need to report the stop event to GDB. For 5918dffb485Schristos example, if the user puts a breakpoint in the jump pad, it's 5928dffb485Schristos because she wants to debug it. */ 5938dffb485Schristos bool stuck_in_jump_pad (thread_info *thread); 5948dffb485Schristos 5958dffb485Schristos /* Convenience wrapper. Returns information about LWP's fast tracepoint 5968dffb485Schristos collection status. */ 5978dffb485Schristos fast_tpoint_collect_result linux_fast_tracepoint_collecting 5988dffb485Schristos (lwp_info *lwp, fast_tpoint_collect_status *status); 5998dffb485Schristos 6008dffb485Schristos /* This function should only be called if LWP got a SYSCALL_SIGTRAP. 6018dffb485Schristos Fill *SYSNO with the syscall nr trapped. */ 6028dffb485Schristos void get_syscall_trapinfo (lwp_info *lwp, int *sysno); 6038dffb485Schristos 6048dffb485Schristos /* Returns true if GDB is interested in the event_child syscall. 6058dffb485Schristos Only to be called when stopped reason is SYSCALL_SIGTRAP. */ 6068dffb485Schristos bool gdb_catch_this_syscall (lwp_info *event_child); 6078dffb485Schristos 6088dffb485Schristos protected: 6098dffb485Schristos /* The architecture-specific "low" methods are listed below. */ 6108dffb485Schristos 6118dffb485Schristos /* Architecture-specific setup for the current thread. */ 6128dffb485Schristos virtual void low_arch_setup () = 0; 6138dffb485Schristos 6148dffb485Schristos /* Return false if we can fetch/store the register, true if we cannot 6158dffb485Schristos fetch/store the register. */ 6168dffb485Schristos virtual bool low_cannot_fetch_register (int regno) = 0; 6178dffb485Schristos 6188dffb485Schristos virtual bool low_cannot_store_register (int regno) = 0; 6198dffb485Schristos 6208dffb485Schristos /* Hook to fetch a register in some non-standard way. Used for 6218dffb485Schristos example by backends that have read-only registers with hardcoded 6228dffb485Schristos values (e.g., IA64's gr0/fr0/fr1). Returns true if register 6238dffb485Schristos REGNO was supplied, false if not, and we should fallback to the 6248dffb485Schristos standard ptrace methods. */ 6258dffb485Schristos virtual bool low_fetch_register (regcache *regcache, int regno); 6268dffb485Schristos 6278dffb485Schristos /* Return true if breakpoints are supported. Such targets must 6288dffb485Schristos implement the GET_PC and SET_PC methods. */ 6298dffb485Schristos virtual bool low_supports_breakpoints (); 6308dffb485Schristos 6318dffb485Schristos virtual CORE_ADDR low_get_pc (regcache *regcache); 6328dffb485Schristos 6338dffb485Schristos virtual void low_set_pc (regcache *regcache, CORE_ADDR newpc); 6348dffb485Schristos 6358dffb485Schristos /* Find the next possible PCs after the current instruction executes. 6368dffb485Schristos Targets that override this method should also override 6378dffb485Schristos 'supports_software_single_step' to return true. */ 6388dffb485Schristos virtual std::vector<CORE_ADDR> low_get_next_pcs (regcache *regcache); 6398dffb485Schristos 6408dffb485Schristos /* Return true if there is a breakpoint at PC. */ 6418dffb485Schristos virtual bool low_breakpoint_at (CORE_ADDR pc) = 0; 6428dffb485Schristos 6438dffb485Schristos /* Breakpoint and watchpoint related functions. See target.h for 6448dffb485Schristos comments. */ 6458dffb485Schristos virtual int low_insert_point (raw_bkpt_type type, CORE_ADDR addr, 6468dffb485Schristos int size, raw_breakpoint *bp); 6478dffb485Schristos 6488dffb485Schristos virtual int low_remove_point (raw_bkpt_type type, CORE_ADDR addr, 6498dffb485Schristos int size, raw_breakpoint *bp); 6508dffb485Schristos 6518dffb485Schristos virtual bool low_stopped_by_watchpoint (); 6528dffb485Schristos 6538dffb485Schristos virtual CORE_ADDR low_stopped_data_address (); 6548dffb485Schristos 6558dffb485Schristos /* Hooks to reformat register data for PEEKUSR/POKEUSR (in particular 6568dffb485Schristos for registers smaller than an xfer unit). */ 6578dffb485Schristos virtual void low_collect_ptrace_register (regcache *regcache, int regno, 6588dffb485Schristos char *buf); 6598dffb485Schristos 6608dffb485Schristos virtual void low_supply_ptrace_register (regcache *regcache, int regno, 6618dffb485Schristos const char *buf); 6628dffb485Schristos 6638dffb485Schristos /* Hook to convert from target format to ptrace format and back. 6648dffb485Schristos Returns true if any conversion was done; false otherwise. 6658dffb485Schristos If DIRECTION is 1, then copy from INF to NATIVE. 6668dffb485Schristos If DIRECTION is 0, copy from NATIVE to INF. */ 6678dffb485Schristos virtual bool low_siginfo_fixup (siginfo_t *native, gdb_byte *inf, 6688dffb485Schristos int direction); 6698dffb485Schristos 6708dffb485Schristos /* Hook to call when a new process is created or attached to. 6718dffb485Schristos If extra per-process architecture-specific data is needed, 6728dffb485Schristos allocate it here. */ 6738dffb485Schristos virtual arch_process_info *low_new_process (); 6748dffb485Schristos 6758dffb485Schristos /* Hook to call when a process is being deleted. If extra per-process 6768dffb485Schristos architecture-specific data is needed, delete it here. */ 6778dffb485Schristos virtual void low_delete_process (arch_process_info *info); 6788dffb485Schristos 6798dffb485Schristos /* Hook to call when a new thread is detected. 6808dffb485Schristos If extra per-thread architecture-specific data is needed, 6818dffb485Schristos allocate it here. */ 6828dffb485Schristos virtual void low_new_thread (lwp_info *); 6838dffb485Schristos 6848dffb485Schristos /* Hook to call when a thread is being deleted. If extra per-thread 6858dffb485Schristos architecture-specific data is needed, delete it here. */ 6868dffb485Schristos virtual void low_delete_thread (arch_lwp_info *); 6878dffb485Schristos 6888dffb485Schristos /* Hook to call, if any, when a new fork is attached. */ 6898dffb485Schristos virtual void low_new_fork (process_info *parent, process_info *child); 6908dffb485Schristos 6918dffb485Schristos /* Hook to call prior to resuming a thread. */ 6928dffb485Schristos virtual void low_prepare_to_resume (lwp_info *lwp); 6938dffb485Schristos 6948dffb485Schristos /* Fill ADDRP with the thread area address of LWPID. Returns 0 on 6958dffb485Schristos success, -1 on failure. */ 6968dffb485Schristos virtual int low_get_thread_area (int lwpid, CORE_ADDR *addrp); 6978dffb485Schristos 6988dffb485Schristos /* Returns true if the low target supports range stepping. */ 6998dffb485Schristos virtual bool low_supports_range_stepping (); 7008dffb485Schristos 7018dffb485Schristos /* Return true if the target supports catch syscall. Such targets 7028dffb485Schristos override the low_get_syscall_trapinfo method below. */ 7038dffb485Schristos virtual bool low_supports_catch_syscall (); 7048dffb485Schristos 7058dffb485Schristos /* Fill *SYSNO with the syscall nr trapped. Only to be called when 7068dffb485Schristos inferior is stopped due to SYSCALL_SIGTRAP. */ 7078dffb485Schristos virtual void low_get_syscall_trapinfo (regcache *regcache, int *sysno); 7088dffb485Schristos 7098dffb485Schristos /* How many bytes the PC should be decremented after a break. */ 7108dffb485Schristos virtual int low_decr_pc_after_break (); 7118dffb485Schristos }; 7128dffb485Schristos 7138dffb485Schristos extern linux_process_target *the_linux_target; 7148dffb485Schristos 7158dffb485Schristos #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr))) 7168dffb485Schristos #define get_lwp_thread(lwp) ((lwp)->thread) 7178dffb485Schristos 7188dffb485Schristos /* Information about a signal that is to be delivered to a thread. */ 7198dffb485Schristos 7208dffb485Schristos struct pending_signal 7218dffb485Schristos { 7228dffb485Schristos pending_signal (int signal) 7238dffb485Schristos : signal {signal} 7248dffb485Schristos {}; 7258dffb485Schristos 7268dffb485Schristos int signal; 7278dffb485Schristos siginfo_t info; 7288dffb485Schristos }; 7298dffb485Schristos 7308dffb485Schristos /* This struct is recorded in the target_data field of struct thread_info. 7318dffb485Schristos 7328dffb485Schristos On linux ``all_threads'' is keyed by the LWP ID, which we use as the 7338dffb485Schristos GDB protocol representation of the thread ID. Threads also have 7348dffb485Schristos a "process ID" (poorly named) which is (presently) the same as the 7358dffb485Schristos LWP ID. 7368dffb485Schristos 7378dffb485Schristos There is also ``all_processes'' is keyed by the "overall process ID", 7388dffb485Schristos which GNU/Linux calls tgid, "thread group ID". */ 7398dffb485Schristos 7408dffb485Schristos struct lwp_info 7418dffb485Schristos { 742*f1c2b495Schristos /* If this LWP is a fork/vfork/clone child that wasn't reported to 743*f1c2b495Schristos GDB yet, return its parent, else nullptr. */ 7444b169a6bSchristos lwp_info *pending_parent () const 7454b169a6bSchristos { 746*f1c2b495Schristos if (this->relative == nullptr) 7474b169a6bSchristos return nullptr; 7484b169a6bSchristos 749*f1c2b495Schristos gdb_assert (this->relative->relative == this); 7504b169a6bSchristos 751*f1c2b495Schristos /* In a parent/child relationship, the parent has a status pending and 7524b169a6bSchristos the child does not, and a thread can only be in one such relationship 7534b169a6bSchristos at most. So we can recognize who is the parent based on which one has 7544b169a6bSchristos a pending status. */ 7554b169a6bSchristos gdb_assert (!!this->status_pending_p 756*f1c2b495Schristos != !!this->relative->status_pending_p); 7574b169a6bSchristos 758*f1c2b495Schristos if (!this->relative->status_pending_p) 7594b169a6bSchristos return nullptr; 7604b169a6bSchristos 7614b169a6bSchristos const target_waitstatus &ws 762*f1c2b495Schristos = this->relative->waitstatus; 7634b169a6bSchristos gdb_assert (ws.kind () == TARGET_WAITKIND_FORKED 764*f1c2b495Schristos || ws.kind () == TARGET_WAITKIND_VFORKED 765*f1c2b495Schristos || ws.kind () == TARGET_WAITKIND_THREAD_CLONED); 7664b169a6bSchristos 767*f1c2b495Schristos return this->relative; } 7684b169a6bSchristos 769*f1c2b495Schristos /* If this LWP is the parent of a fork/vfork/clone child we haven't 770*f1c2b495Schristos reported to GDB yet, return that child and fill in KIND with the 771*f1c2b495Schristos matching waitkind, otherwise nullptr. */ 772*f1c2b495Schristos lwp_info *pending_child (target_waitkind *kind) const 7734b169a6bSchristos { 774*f1c2b495Schristos if (this->relative == nullptr) 7754b169a6bSchristos return nullptr; 7764b169a6bSchristos 777*f1c2b495Schristos gdb_assert (this->relative->relative == this); 7784b169a6bSchristos 779*f1c2b495Schristos /* In a parent/child relationship, the parent has a status pending and 7804b169a6bSchristos the child does not, and a thread can only be in one such relationship 7814b169a6bSchristos at most. So we can recognize who is the parent based on which one has 7824b169a6bSchristos a pending status. */ 7834b169a6bSchristos gdb_assert (!!this->status_pending_p 784*f1c2b495Schristos != !!this->relative->status_pending_p); 7854b169a6bSchristos 7864b169a6bSchristos if (!this->status_pending_p) 7874b169a6bSchristos return nullptr; 7884b169a6bSchristos 7894b169a6bSchristos const target_waitstatus &ws = this->waitstatus; 7904b169a6bSchristos gdb_assert (ws.kind () == TARGET_WAITKIND_FORKED 791*f1c2b495Schristos || ws.kind () == TARGET_WAITKIND_VFORKED 792*f1c2b495Schristos || ws.kind () == TARGET_WAITKIND_THREAD_CLONED); 7934b169a6bSchristos 794*f1c2b495Schristos *kind = ws.kind (); 795*f1c2b495Schristos return this->relative; 7964b169a6bSchristos } 7974b169a6bSchristos 7988dffb485Schristos /* Backlink to the parent object. */ 7994b169a6bSchristos struct thread_info *thread = nullptr; 8008dffb485Schristos 8018dffb485Schristos /* If this flag is set, the next SIGSTOP will be ignored (the 8028dffb485Schristos process will be immediately resumed). This means that either we 8038dffb485Schristos sent the SIGSTOP to it ourselves and got some other pending event 8048dffb485Schristos (so the SIGSTOP is still pending), or that we stopped the 8058dffb485Schristos inferior implicitly via PTRACE_ATTACH and have not waited for it 8068dffb485Schristos yet. */ 8074b169a6bSchristos int stop_expected = 0; 8088dffb485Schristos 8098dffb485Schristos /* When this is true, we shall not try to resume this thread, even 8108dffb485Schristos if last_resume_kind isn't resume_stop. */ 8114b169a6bSchristos int suspended = 0; 8128dffb485Schristos 8138dffb485Schristos /* If this flag is set, the lwp is known to be stopped right now (stop 8148dffb485Schristos event already received in a wait()). */ 8154b169a6bSchristos int stopped = 0; 8168dffb485Schristos 8178dffb485Schristos /* Signal whether we are in a SYSCALL_ENTRY or 8188dffb485Schristos in a SYSCALL_RETURN event. 8198dffb485Schristos Values: 8208dffb485Schristos - TARGET_WAITKIND_SYSCALL_ENTRY 8218dffb485Schristos - TARGET_WAITKIND_SYSCALL_RETURN */ 8224b169a6bSchristos enum target_waitkind syscall_state = TARGET_WAITKIND_SYSCALL_ENTRY; 8238dffb485Schristos 8248dffb485Schristos /* When stopped is set, the last wait status recorded for this lwp. */ 8254b169a6bSchristos int last_status = 0; 8268dffb485Schristos 8278dffb485Schristos /* If WAITSTATUS->KIND != TARGET_WAITKIND_IGNORE, the waitstatus for 8288dffb485Schristos this LWP's last event, to pass to GDB without any further 8298dffb485Schristos processing. This is used to store extended ptrace event 8308dffb485Schristos information or exit status until it can be reported to GDB. */ 8318dffb485Schristos struct target_waitstatus waitstatus; 8328dffb485Schristos 833*f1c2b495Schristos /* A pointer to the fork/vfork/clone child/parent relative (like 834*f1c2b495Schristos people, LWPs have relatives). Valid only while the parent 835*f1c2b495Schristos fork/vfork/clone event is not reported to higher layers. Used to 836*f1c2b495Schristos avoid wildcard vCont actions resuming a fork/vfork/clone child 837*f1c2b495Schristos before GDB is notified about the parent's fork/vfork/clone 838*f1c2b495Schristos event. */ 839*f1c2b495Schristos struct lwp_info *relative = nullptr; 8408dffb485Schristos 8418dffb485Schristos /* When stopped is set, this is where the lwp last stopped, with 8428dffb485Schristos decr_pc_after_break already accounted for. If the LWP is 8438dffb485Schristos running, this is the address at which the lwp was resumed. */ 8444b169a6bSchristos CORE_ADDR stop_pc = 0; 8458dffb485Schristos 8468dffb485Schristos /* If this flag is set, STATUS_PENDING is a waitstatus that has not yet 8478dffb485Schristos been reported. */ 8484b169a6bSchristos int status_pending_p = 0; 8494b169a6bSchristos int status_pending = 0; 8508dffb485Schristos 8518dffb485Schristos /* The reason the LWP last stopped, if we need to track it 8528dffb485Schristos (breakpoint, watchpoint, etc.) */ 8534b169a6bSchristos enum target_stop_reason stop_reason = TARGET_STOPPED_BY_NO_REASON; 8548dffb485Schristos 8558dffb485Schristos /* On architectures where it is possible to know the data address of 8568dffb485Schristos a triggered watchpoint, STOPPED_DATA_ADDRESS is non-zero, and 8578dffb485Schristos contains such data address. Only valid if STOPPED_BY_WATCHPOINT 8588dffb485Schristos is true. */ 8594b169a6bSchristos CORE_ADDR stopped_data_address = 0; 8608dffb485Schristos 8618dffb485Schristos /* If this is non-zero, it is a breakpoint to be reinserted at our next 8628dffb485Schristos stop (SIGTRAP stops only). */ 8634b169a6bSchristos CORE_ADDR bp_reinsert = 0; 8648dffb485Schristos 8658dffb485Schristos /* If this flag is set, the last continue operation at the ptrace 8668dffb485Schristos level on this process was a single-step. */ 8674b169a6bSchristos int stepping = 0; 8688dffb485Schristos 8698dffb485Schristos /* Range to single step within. This is a copy of the step range 8708dffb485Schristos passed along the last resume request. See 'struct 8718dffb485Schristos thread_resume'. */ 8724b169a6bSchristos CORE_ADDR step_range_start = 0; /* Inclusive */ 8734b169a6bSchristos CORE_ADDR step_range_end = 0; /* Exclusive */ 8748dffb485Schristos 8758dffb485Schristos /* If this flag is set, we need to set the event request flags the 8768dffb485Schristos next time we see this LWP stop. */ 8774b169a6bSchristos int must_set_ptrace_flags = 0; 8788dffb485Schristos 8798dffb485Schristos /* A chain of signals that need to be delivered to this process. */ 8808dffb485Schristos std::list<pending_signal> pending_signals; 8818dffb485Schristos 8828dffb485Schristos /* A link used when resuming. It is initialized from the resume request, 8838dffb485Schristos and then processed and cleared in linux_resume_one_lwp. */ 8844b169a6bSchristos struct thread_resume *resume = nullptr; 8858dffb485Schristos 8868dffb485Schristos /* Information bout this lwp's fast tracepoint collection status (is it 8878dffb485Schristos currently stopped in the jump pad, and if so, before or at/after the 8888dffb485Schristos relocated instruction). Normally, we won't care about this, but we will 8898dffb485Schristos if a signal arrives to this lwp while it is collecting. */ 8904b169a6bSchristos fast_tpoint_collect_result collecting_fast_tracepoint 8914b169a6bSchristos = fast_tpoint_collect_result::not_collecting; 8928dffb485Schristos 8938dffb485Schristos /* A chain of signals that need to be reported to GDB. These were 8948dffb485Schristos deferred because the thread was doing a fast tracepoint collect 8958dffb485Schristos when they arrived. */ 8968dffb485Schristos std::list<pending_signal> pending_signals_to_report; 8978dffb485Schristos 8988dffb485Schristos /* When collecting_fast_tracepoint is first found to be 1, we insert 8998dffb485Schristos a exit-jump-pad-quickly breakpoint. This is it. */ 9004b169a6bSchristos struct breakpoint *exit_jump_pad_bkpt = nullptr; 9018dffb485Schristos 9028dffb485Schristos #ifdef USE_THREAD_DB 9034b169a6bSchristos int thread_known = 0; 9048dffb485Schristos /* The thread handle, used for e.g. TLS access. Only valid if 9058dffb485Schristos THREAD_KNOWN is set. */ 9064b169a6bSchristos td_thrhandle_t th {}; 9078dffb485Schristos 9088dffb485Schristos /* The pthread_t handle. */ 9094b169a6bSchristos thread_t thread_handle {}; 9108dffb485Schristos #endif 9118dffb485Schristos 9128dffb485Schristos /* Arch-specific additions. */ 9134b169a6bSchristos struct arch_lwp_info *arch_private = nullptr; 9148dffb485Schristos }; 9158dffb485Schristos 9168dffb485Schristos int linux_pid_exe_is_elf_64_file (int pid, unsigned int *machine); 9178dffb485Schristos 9188dffb485Schristos /* Attach to PTID. Returns 0 on success, non-zero otherwise (an 9198dffb485Schristos errno). */ 9208dffb485Schristos int linux_attach_lwp (ptid_t ptid); 9218dffb485Schristos 9228dffb485Schristos struct lwp_info *find_lwp_pid (ptid_t ptid); 9238dffb485Schristos /* For linux_stop_lwp see nat/linux-nat.h. */ 9248dffb485Schristos 9258dffb485Schristos #ifdef HAVE_LINUX_REGSETS 9268dffb485Schristos void initialize_regsets_info (struct regsets_info *regsets_info); 9278dffb485Schristos #endif 9288dffb485Schristos 9298dffb485Schristos void initialize_low_arch (void); 9308dffb485Schristos 9318dffb485Schristos void linux_set_pc_32bit (struct regcache *regcache, CORE_ADDR pc); 9328dffb485Schristos CORE_ADDR linux_get_pc_32bit (struct regcache *regcache); 9338dffb485Schristos 9348dffb485Schristos void linux_set_pc_64bit (struct regcache *regcache, CORE_ADDR pc); 9358dffb485Schristos CORE_ADDR linux_get_pc_64bit (struct regcache *regcache); 9368dffb485Schristos 9378dffb485Schristos /* From thread-db.c */ 9388dffb485Schristos int thread_db_init (void); 9398dffb485Schristos void thread_db_detach (struct process_info *); 9408dffb485Schristos void thread_db_mourn (struct process_info *); 9418dffb485Schristos int thread_db_handle_monitor_command (char *); 9428dffb485Schristos int thread_db_get_tls_address (struct thread_info *thread, CORE_ADDR offset, 9438dffb485Schristos CORE_ADDR load_module, CORE_ADDR *address); 9448dffb485Schristos int thread_db_look_up_one_symbol (const char *name, CORE_ADDR *addrp); 9458dffb485Schristos 9468dffb485Schristos /* Called from linux-low.c when a clone event is detected. Upon entry, 9478dffb485Schristos both the clone and the parent should be stopped. This function does 9488dffb485Schristos whatever is required have the clone under thread_db's control. */ 9498dffb485Schristos 9508dffb485Schristos void thread_db_notice_clone (struct thread_info *parent_thr, ptid_t child_ptid); 9518dffb485Schristos 9528dffb485Schristos bool thread_db_thread_handle (ptid_t ptid, gdb_byte **handle, int *handle_len); 9538dffb485Schristos 954*f1c2b495Schristos extern enum tribool have_ptrace_getregset; 9558dffb485Schristos 956*f1c2b495Schristos /* Search for the value with type MATCH in the auxv vector, with entries of 957*f1c2b495Schristos length WORDSIZE bytes, of process with pid PID. If found, store the 958*f1c2b495Schristos value in *VALP and return 1. If not found or if there is an error, 959*f1c2b495Schristos return 0. */ 9608dffb485Schristos 961*f1c2b495Schristos int linux_get_auxv (int pid, int wordsize, CORE_ADDR match, CORE_ADDR *valp); 9628dffb485Schristos 9638dffb485Schristos /* Fetch the AT_HWCAP entry from the auxv vector, where entries are length 964*f1c2b495Schristos WORDSIZE, of process with pid PID. If no entry was found, return 0. */ 9658dffb485Schristos 966*f1c2b495Schristos CORE_ADDR linux_get_hwcap (int pid, int wordsize); 9678dffb485Schristos 9688dffb485Schristos /* Fetch the AT_HWCAP2 entry from the auxv vector, where entries are length 969*f1c2b495Schristos WORDSIZE, of process with pid PID. If no entry was found, return 0. */ 9708dffb485Schristos 971*f1c2b495Schristos CORE_ADDR linux_get_hwcap2 (int pid, int wordsize); 9728dffb485Schristos 9738dffb485Schristos #endif /* GDBSERVER_LINUX_LOW_H */ 974