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 Error SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override; 50 51 Error RemoveHardwareBreakpoint(lldb::addr_t addr) override; 52 53 private: 54 // --------------------------------------------------------------------- 55 // Interface for friend classes 56 // --------------------------------------------------------------------- 57 58 /// Resumes the thread. If @p signo is anything but 59 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 60 Error Resume(uint32_t signo); 61 62 /// Single steps the thread. If @p signo is anything but 63 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 64 Error SingleStep(uint32_t signo); 65 66 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); 67 68 /// Return true if the thread is stopped. 69 /// If stopped by a signal, indicate the signo in the signo argument. 70 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. 71 bool IsStopped(int *signo); 72 73 void SetStoppedByExec(); 74 75 void SetStoppedByBreakpoint(); 76 77 void SetStoppedByWatchpoint(uint32_t wp_index); 78 79 bool IsStoppedAtBreakpoint(); 80 81 bool IsStoppedAtWatchpoint(); 82 83 void SetStoppedByTrace(); 84 85 void SetStoppedWithNoReason(); 86 87 void SetExited(); 88 89 Error RequestStop(); 90 91 // --------------------------------------------------------------------- 92 // Private interface 93 // --------------------------------------------------------------------- 94 void MaybeLogStateChange(lldb::StateType new_state); 95 96 NativeProcessLinux &GetProcess(); 97 98 void SetStopped(); 99 100 // --------------------------------------------------------------------- 101 // Member Variables 102 // --------------------------------------------------------------------- 103 lldb::StateType m_state; 104 ThreadStopInfo m_stop_info; 105 NativeRegisterContextSP m_reg_context_sp; 106 std::string m_stop_description; 107 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; 108 WatchpointIndexMap m_watchpoint_index_map; 109 WatchpointIndexMap m_hw_break_index_map; 110 std::unique_ptr<SingleStepWorkaround> m_step_workaround; 111 }; 112 113 typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP; 114 } // namespace process_linux 115 } // namespace lldb_private 116 117 #endif // #ifndef liblldb_NativeThreadLinux_H_ 118