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 "lldb/lldb-private-forward.h" 14 #include "lldb/Host/common/NativeThreadProtocol.h" 15 16 #include <map> 17 #include <string> 18 19 namespace lldb_private { 20 namespace process_linux { 21 22 class NativeProcessLinux; 23 24 class NativeThreadLinux : public NativeThreadProtocol 25 { 26 friend class NativeProcessLinux; 27 28 public: 29 NativeThreadLinux (NativeProcessLinux *process, lldb::tid_t tid); 30 31 // --------------------------------------------------------------------- 32 // NativeThreadProtocol Interface 33 // --------------------------------------------------------------------- 34 std::string 35 GetName() override; 36 37 lldb::StateType 38 GetState () override; 39 40 bool 41 GetStopReason (ThreadStopInfo &stop_info, std::string& description) override; 42 43 NativeRegisterContextSP 44 GetRegisterContext () override; 45 46 Error 47 SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override; 48 49 Error 50 RemoveWatchpoint (lldb::addr_t addr) override; 51 52 private: 53 // --------------------------------------------------------------------- 54 // Interface for friend classes 55 // --------------------------------------------------------------------- 56 void 57 SetRunning (); 58 59 void 60 SetStepping (); 61 62 void 63 SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); 64 65 /// Return true if the thread is stopped. 66 /// If stopped by a signal, indicate the signo in the signo argument. 67 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. 68 bool 69 IsStopped (int *signo); 70 71 void 72 SetStoppedByExec (); 73 74 void 75 SetStoppedByBreakpoint (); 76 77 void 78 SetStoppedByWatchpoint (uint32_t wp_index); 79 80 bool 81 IsStoppedAtBreakpoint (); 82 83 bool 84 IsStoppedAtWatchpoint (); 85 86 void 87 SetStoppedByTrace (); 88 89 void 90 SetStoppedWithNoReason (); 91 92 void 93 SetExited (); 94 95 Error 96 RequestStop (); 97 98 typedef std::function<Error (lldb::tid_t tid, bool supress_signal)> ResumeThreadFunction; 99 struct ThreadContext 100 { 101 bool stop_requested = false; 102 ResumeThreadFunction request_resume_function; 103 }; 104 105 ThreadContext & 106 GetThreadContext() { return m_thread_context; } 107 108 // --------------------------------------------------------------------- 109 // Private interface 110 // --------------------------------------------------------------------- 111 void 112 MaybeLogStateChange (lldb::StateType new_state); 113 114 // --------------------------------------------------------------------- 115 // Member Variables 116 // --------------------------------------------------------------------- 117 lldb::StateType m_state; 118 ThreadStopInfo m_stop_info; 119 NativeRegisterContextSP m_reg_context_sp; 120 std::string m_stop_description; 121 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; 122 WatchpointIndexMap m_watchpoint_index_map; 123 ThreadContext m_thread_context; 124 }; 125 126 } // namespace process_linux 127 } // namespace lldb_private 128 129 #endif // #ifndef liblldb_NativeThreadLinux_H_ 130