1 //===-- NativeThreadLinux.h ----------------------------------- -*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_NativeThreadLinux_H_ 11 #define liblldb_NativeThreadLinux_H_ 12 13 #include "SingleStepCheck.h" 14 #include "lldb/Host/common/NativeThreadProtocol.h" 15 #include "lldb/lldb-private-forward.h" 16 17 #include <map> 18 #include <memory> 19 #include <string> 20 21 namespace lldb_private { 22 namespace process_linux { 23 24 class NativeProcessLinux; 25 26 class NativeThreadLinux : public NativeThreadProtocol { 27 friend class NativeProcessLinux; 28 29 public: 30 NativeThreadLinux(NativeProcessLinux *process, lldb::tid_t tid); 31 32 // --------------------------------------------------------------------- 33 // NativeThreadProtocol Interface 34 // --------------------------------------------------------------------- 35 std::string GetName() override; 36 37 lldb::StateType GetState() override; 38 39 bool GetStopReason(ThreadStopInfo &stop_info, 40 std::string &description) override; 41 42 NativeRegisterContextSP GetRegisterContext() override; 43 44 Error SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags, 45 bool hardware) override; 46 47 Error RemoveWatchpoint(lldb::addr_t addr) override; 48 49 private: 50 // --------------------------------------------------------------------- 51 // Interface for friend classes 52 // --------------------------------------------------------------------- 53 54 /// Resumes the thread. If @p signo is anything but 55 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 56 Error Resume(uint32_t signo); 57 58 /// Single steps the thread. If @p signo is anything but 59 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 60 Error SingleStep(uint32_t signo); 61 62 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); 63 64 /// Return true if the thread is stopped. 65 /// If stopped by a signal, indicate the signo in the signo argument. 66 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. 67 bool IsStopped(int *signo); 68 69 void SetStoppedByExec(); 70 71 void SetStoppedByBreakpoint(); 72 73 void SetStoppedByWatchpoint(uint32_t wp_index); 74 75 bool IsStoppedAtBreakpoint(); 76 77 bool IsStoppedAtWatchpoint(); 78 79 void SetStoppedByTrace(); 80 81 void SetStoppedWithNoReason(); 82 83 void SetExited(); 84 85 Error RequestStop(); 86 87 // --------------------------------------------------------------------- 88 // Private interface 89 // --------------------------------------------------------------------- 90 void MaybeLogStateChange(lldb::StateType new_state); 91 92 NativeProcessLinux &GetProcess(); 93 94 void SetStopped(); 95 96 // --------------------------------------------------------------------- 97 // Member Variables 98 // --------------------------------------------------------------------- 99 lldb::StateType m_state; 100 ThreadStopInfo m_stop_info; 101 NativeRegisterContextSP m_reg_context_sp; 102 std::string m_stop_description; 103 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; 104 WatchpointIndexMap m_watchpoint_index_map; 105 llvm::Optional<SingleStepWorkaround> m_step_workaround; 106 }; 107 108 typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP; 109 } // namespace process_linux 110 } // namespace lldb_private 111 112 #endif // #ifndef liblldb_NativeThreadLinux_H_ 113