1 //===-- NativeThreadLinux.h ----------------------------------- -*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef liblldb_NativeThreadLinux_H_ 10 #define liblldb_NativeThreadLinux_H_ 11 12 #include "Plugins/Process/Linux/NativeRegisterContextLinux.h" 13 #include "Plugins/Process/Linux/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 // NativeThreadProtocol Interface 34 std::string GetName() override; 35 36 lldb::StateType GetState() override; 37 38 bool GetStopReason(ThreadStopInfo &stop_info, 39 std::string &description) override; 40 41 NativeRegisterContextLinux &GetRegisterContext() override { 42 return *m_reg_context_up; 43 } 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 // Interface for friend classes 56 57 /// Resumes the thread. If \p signo is anything but 58 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 59 Status Resume(uint32_t signo); 60 61 /// Single steps the thread. If \p signo is anything but 62 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 63 Status SingleStep(uint32_t signo); 64 65 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); 66 67 /// Return true if the thread is stopped. 68 /// If stopped by a signal, indicate the signo in the signo argument. 69 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. 70 bool IsStopped(int *signo); 71 72 void SetStoppedByExec(); 73 74 void SetStoppedByBreakpoint(); 75 76 void SetStoppedByWatchpoint(uint32_t wp_index); 77 78 bool IsStoppedAtBreakpoint(); 79 80 bool IsStoppedAtWatchpoint(); 81 82 void SetStoppedByTrace(); 83 84 void SetStoppedWithNoReason(); 85 86 void SetExited(); 87 88 Status RequestStop(); 89 90 // Private interface 91 void MaybeLogStateChange(lldb::StateType new_state); 92 93 NativeProcessLinux &GetProcess(); 94 95 void SetStopped(); 96 97 // Member Variables 98 lldb::StateType m_state; 99 ThreadStopInfo m_stop_info; 100 std::unique_ptr<NativeRegisterContextLinux> m_reg_context_up; 101 std::string m_stop_description; 102 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; 103 WatchpointIndexMap m_watchpoint_index_map; 104 WatchpointIndexMap m_hw_break_index_map; 105 std::unique_ptr<SingleStepWorkaround> m_step_workaround; 106 }; 107 } // namespace process_linux 108 } // namespace lldb_private 109 110 #endif // #ifndef liblldb_NativeThreadLinux_H_ 111