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 "llvm/ADT/StringRef.h" 18 19 #include <csignal> 20 #include <map> 21 #include <memory> 22 #include <string> 23 24 namespace lldb_private { 25 namespace process_linux { 26 27 class NativeProcessLinux; 28 29 class NativeThreadLinux : public NativeThreadProtocol { 30 friend class NativeProcessLinux; 31 32 public: 33 NativeThreadLinux(NativeProcessLinux &process, lldb::tid_t tid); 34 35 // NativeThreadProtocol Interface 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 NativeRegisterContextLinux &GetRegisterContext() override { 44 return *m_reg_context_up; 45 } 46 47 Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags, 48 bool hardware) override; 49 50 Status RemoveWatchpoint(lldb::addr_t addr) override; 51 52 Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override; 53 54 Status RemoveHardwareBreakpoint(lldb::addr_t addr) override; 55 56 NativeProcessLinux &GetProcess(); 57 58 private: 59 // Interface for friend classes 60 61 /// Resumes the thread. If \p signo is anything but 62 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 63 Status Resume(uint32_t signo); 64 65 /// Single steps the thread. If \p signo is anything but 66 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 67 Status SingleStep(uint32_t signo); 68 69 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); 70 71 /// Return true if the thread is stopped. 72 /// If stopped by a signal, indicate the signo in the signo argument. 73 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. 74 bool IsStopped(int *signo); 75 76 void SetStoppedByExec(); 77 78 void SetStoppedByBreakpoint(); 79 80 void SetStoppedByWatchpoint(uint32_t wp_index); 81 82 bool IsStoppedAtBreakpoint(); 83 84 bool IsStoppedAtWatchpoint(); 85 86 void SetStoppedByTrace(); 87 88 void SetStoppedByFork(bool is_vfork, lldb::pid_t child_pid); 89 90 void SetStoppedByVForkDone(); 91 92 void SetStoppedWithNoReason(); 93 94 void SetStoppedByProcessorTrace(llvm::StringRef description); 95 96 void SetExited(); 97 98 Status RequestStop(); 99 100 // Private interface 101 void MaybeLogStateChange(lldb::StateType new_state); 102 103 void SetStopped(); 104 105 /// Extend m_stop_description with logical and allocation tag values. 106 /// If there is an error along the way just add the information we were able 107 /// to get. 108 void AnnotateSyncTagCheckFault(const siginfo_t *info); 109 110 // Member Variables 111 lldb::StateType m_state; 112 ThreadStopInfo m_stop_info; 113 std::unique_ptr<NativeRegisterContextLinux> m_reg_context_up; 114 std::string m_stop_description; 115 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; 116 WatchpointIndexMap m_watchpoint_index_map; 117 WatchpointIndexMap m_hw_break_index_map; 118 std::unique_ptr<SingleStepWorkaround> m_step_workaround; 119 }; 120 } // namespace process_linux 121 } // namespace lldb_private 122 123 #endif // #ifndef liblldb_NativeThreadLinux_H_ 124