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 <csignal> 18 #include <map> 19 #include <memory> 20 #include <string> 21 22 namespace lldb_private { 23 namespace process_linux { 24 25 class NativeProcessLinux; 26 27 class NativeThreadLinux : public NativeThreadProtocol { 28 friend class NativeProcessLinux; 29 30 public: 31 NativeThreadLinux(NativeProcessLinux &process, lldb::tid_t tid); 32 33 // --------------------------------------------------------------------- 34 // NativeThreadProtocol Interface 35 // --------------------------------------------------------------------- 36 std::string GetName() override; 37 38 lldb::StateType GetState() override; 39 40 bool GetStopReason(ThreadStopInfo &stop_info, 41 std::string &description) override; 42 43 NativeRegisterContextSP GetRegisterContext() override; 44 45 Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags, 46 bool hardware) override; 47 48 Status RemoveWatchpoint(lldb::addr_t addr) override; 49 50 Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override; 51 52 Status RemoveHardwareBreakpoint(lldb::addr_t addr) override; 53 54 private: 55 // --------------------------------------------------------------------- 56 // Interface for friend classes 57 // --------------------------------------------------------------------- 58 59 /// Resumes the thread. If @p signo is anything but 60 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 61 Status Resume(uint32_t signo); 62 63 /// Single steps the thread. If @p signo is anything but 64 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 65 Status SingleStep(uint32_t signo); 66 67 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); 68 69 /// Return true if the thread is stopped. 70 /// If stopped by a signal, indicate the signo in the signo argument. 71 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. 72 bool IsStopped(int *signo); 73 74 void SetStoppedByExec(); 75 76 void SetStoppedByBreakpoint(); 77 78 void SetStoppedByWatchpoint(uint32_t wp_index); 79 80 bool IsStoppedAtBreakpoint(); 81 82 bool IsStoppedAtWatchpoint(); 83 84 void SetStoppedByTrace(); 85 86 void SetStoppedWithNoReason(); 87 88 void SetExited(); 89 90 Status RequestStop(); 91 92 // --------------------------------------------------------------------- 93 // Private interface 94 // --------------------------------------------------------------------- 95 void MaybeLogStateChange(lldb::StateType new_state); 96 97 NativeProcessLinux &GetProcess(); 98 99 void SetStopped(); 100 101 // --------------------------------------------------------------------- 102 // Member Variables 103 // --------------------------------------------------------------------- 104 lldb::StateType m_state; 105 ThreadStopInfo m_stop_info; 106 NativeRegisterContextSP m_reg_context_sp; 107 std::string m_stop_description; 108 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; 109 WatchpointIndexMap m_watchpoint_index_map; 110 WatchpointIndexMap m_hw_break_index_map; 111 std::unique_ptr<SingleStepWorkaround> m_step_workaround; 112 }; 113 114 typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP; 115 } // namespace process_linux 116 } // namespace lldb_private 117 118 #endif // #ifndef liblldb_NativeThreadLinux_H_ 119