1af245d11STodd Fiala //===-- NativeThreadLinux.h ----------------------------------- -*- C++ -*-===// 2af245d11STodd Fiala // 3af245d11STodd Fiala // The LLVM Compiler Infrastructure 4af245d11STodd Fiala // 5af245d11STodd Fiala // This file is distributed under the University of Illinois Open Source 6af245d11STodd Fiala // License. See LICENSE.TXT for details. 7af245d11STodd Fiala // 8af245d11STodd Fiala //===----------------------------------------------------------------------===// 9af245d11STodd Fiala 10af245d11STodd Fiala #ifndef liblldb_NativeThreadLinux_H_ 11af245d11STodd Fiala #define liblldb_NativeThreadLinux_H_ 12af245d11STodd Fiala 132fe1d0abSChaoren Lin #include "lldb/Host/common/NativeThreadProtocol.h" 14*b9c1b51eSKate Stone #include "lldb/lldb-private-forward.h" 15af245d11STodd Fiala 16605b51b8SPavel Labath #include <sched.h> 17605b51b8SPavel Labath 1818fe6404SChaoren Lin #include <map> 190e1d729bSPavel Labath #include <memory> 207572caf4SRichard Smith #include <string> 2118fe6404SChaoren Lin 22db264a6dSTamas Berghammer namespace lldb_private { 23db264a6dSTamas Berghammer namespace process_linux { 24db264a6dSTamas Berghammer 25af245d11STodd Fiala class NativeProcessLinux; 26af245d11STodd Fiala 27*b9c1b51eSKate Stone class NativeThreadLinux : public NativeThreadProtocol { 28af245d11STodd Fiala friend class NativeProcessLinux; 29af245d11STodd Fiala 30af245d11STodd Fiala public: 31af245d11STodd Fiala NativeThreadLinux(NativeProcessLinux *process, lldb::tid_t tid); 32af245d11STodd Fiala 33af245d11STodd Fiala // --------------------------------------------------------------------- 34af245d11STodd Fiala // NativeThreadProtocol Interface 35af245d11STodd Fiala // --------------------------------------------------------------------- 36*b9c1b51eSKate Stone std::string GetName() override; 37af245d11STodd Fiala 38*b9c1b51eSKate Stone lldb::StateType GetState() override; 39af245d11STodd Fiala 40*b9c1b51eSKate Stone bool GetStopReason(ThreadStopInfo &stop_info, 41*b9c1b51eSKate Stone std::string &description) override; 42af245d11STodd Fiala 43*b9c1b51eSKate Stone NativeRegisterContextSP GetRegisterContext() override; 44af245d11STodd Fiala 45*b9c1b51eSKate Stone Error SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags, 46*b9c1b51eSKate Stone bool hardware) override; 47af245d11STodd Fiala 48*b9c1b51eSKate Stone Error RemoveWatchpoint(lldb::addr_t addr) override; 49af245d11STodd Fiala 50af245d11STodd Fiala private: 51af245d11STodd Fiala // --------------------------------------------------------------------- 52af245d11STodd Fiala // Interface for friend classes 53af245d11STodd Fiala // --------------------------------------------------------------------- 54af245d11STodd Fiala 55605b51b8SPavel Labath /// Resumes the thread. If @p signo is anything but 56605b51b8SPavel Labath /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 57*b9c1b51eSKate Stone Error Resume(uint32_t signo); 58605b51b8SPavel Labath 59605b51b8SPavel Labath /// Single steps the thread. If @p signo is anything but 60605b51b8SPavel Labath /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 61*b9c1b51eSKate Stone Error SingleStep(uint32_t signo); 62af245d11STodd Fiala 63*b9c1b51eSKate Stone void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); 64af245d11STodd Fiala 65511e5cdcSTodd Fiala /// Return true if the thread is stopped. 66511e5cdcSTodd Fiala /// If stopped by a signal, indicate the signo in the signo argument. 67511e5cdcSTodd Fiala /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. 68*b9c1b51eSKate Stone bool IsStopped(int *signo); 69511e5cdcSTodd Fiala 70*b9c1b51eSKate Stone void SetStoppedByExec(); 71a9882ceeSTodd Fiala 72*b9c1b51eSKate Stone void SetStoppedByBreakpoint(); 73af245d11STodd Fiala 74*b9c1b51eSKate Stone void SetStoppedByWatchpoint(uint32_t wp_index); 7518fe6404SChaoren Lin 76*b9c1b51eSKate Stone bool IsStoppedAtBreakpoint(); 77af245d11STodd Fiala 78*b9c1b51eSKate Stone bool IsStoppedAtWatchpoint(); 7918fe6404SChaoren Lin 80*b9c1b51eSKate Stone void SetStoppedByTrace(); 8128e57429SChaoren Lin 82*b9c1b51eSKate Stone void SetStoppedWithNoReason(); 83af245d11STodd Fiala 84*b9c1b51eSKate Stone void SetExited(); 85af245d11STodd Fiala 86*b9c1b51eSKate Stone Error RequestStop(); 878c8ff7afSPavel Labath 88af245d11STodd Fiala // --------------------------------------------------------------------- 89af245d11STodd Fiala // Private interface 90af245d11STodd Fiala // --------------------------------------------------------------------- 91*b9c1b51eSKate Stone void MaybeLogStateChange(lldb::StateType new_state); 92af245d11STodd Fiala 93*b9c1b51eSKate Stone NativeProcessLinux &GetProcess(); 94605b51b8SPavel Labath 95*b9c1b51eSKate Stone void SetStopped(); 96605b51b8SPavel Labath 97*b9c1b51eSKate Stone inline void MaybePrepareSingleStepWorkaround(); 98605b51b8SPavel Labath 99*b9c1b51eSKate Stone inline void MaybeCleanupSingleStepWorkaround(); 100605b51b8SPavel Labath 101af245d11STodd Fiala // --------------------------------------------------------------------- 102af245d11STodd Fiala // Member Variables 103af245d11STodd Fiala // --------------------------------------------------------------------- 104af245d11STodd Fiala lldb::StateType m_state; 105af245d11STodd Fiala ThreadStopInfo m_stop_info; 106af245d11STodd Fiala NativeRegisterContextSP m_reg_context_sp; 10728e57429SChaoren Lin std::string m_stop_description; 10818fe6404SChaoren Lin using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; 10918fe6404SChaoren Lin WatchpointIndexMap m_watchpoint_index_map; 110605b51b8SPavel Labath cpu_set_t m_original_cpu_set; // For single-step workaround. 111af245d11STodd Fiala }; 112db264a6dSTamas Berghammer 1130e1d729bSPavel Labath typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP; 114db264a6dSTamas Berghammer } // namespace process_linux 115db264a6dSTamas Berghammer } // namespace lldb_private 116af245d11STodd Fiala 117af245d11STodd Fiala #endif // #ifndef liblldb_NativeThreadLinux_H_ 118