1061da546Spatrick //===-- NativeThreadLinux.h ----------------------------------- -*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9061da546Spatrick #ifndef liblldb_NativeThreadLinux_H_ 10061da546Spatrick #define liblldb_NativeThreadLinux_H_ 11061da546Spatrick 12061da546Spatrick #include "Plugins/Process/Linux/NativeRegisterContextLinux.h" 13061da546Spatrick #include "Plugins/Process/Linux/SingleStepCheck.h" 14061da546Spatrick #include "lldb/Host/common/NativeThreadProtocol.h" 15061da546Spatrick #include "lldb/lldb-private-forward.h" 16061da546Spatrick 17be691f3bSpatrick #include "llvm/ADT/StringRef.h" 18be691f3bSpatrick 19061da546Spatrick #include <csignal> 20061da546Spatrick #include <map> 21061da546Spatrick #include <memory> 22061da546Spatrick #include <string> 23061da546Spatrick 24061da546Spatrick namespace lldb_private { 25061da546Spatrick namespace process_linux { 26061da546Spatrick 27061da546Spatrick class NativeProcessLinux; 28061da546Spatrick 29061da546Spatrick class NativeThreadLinux : public NativeThreadProtocol { 30061da546Spatrick friend class NativeProcessLinux; 31061da546Spatrick 32061da546Spatrick public: 33061da546Spatrick NativeThreadLinux(NativeProcessLinux &process, lldb::tid_t tid); 34061da546Spatrick 35061da546Spatrick // NativeThreadProtocol Interface 36061da546Spatrick std::string GetName() override; 37061da546Spatrick 38061da546Spatrick lldb::StateType GetState() override; 39061da546Spatrick 40061da546Spatrick bool GetStopReason(ThreadStopInfo &stop_info, 41061da546Spatrick std::string &description) override; 42061da546Spatrick GetRegisterContext()43061da546Spatrick NativeRegisterContextLinux &GetRegisterContext() override { 44061da546Spatrick return *m_reg_context_up; 45061da546Spatrick } 46061da546Spatrick 47061da546Spatrick Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags, 48061da546Spatrick bool hardware) override; 49061da546Spatrick 50061da546Spatrick Status RemoveWatchpoint(lldb::addr_t addr) override; 51061da546Spatrick 52061da546Spatrick Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override; 53061da546Spatrick 54061da546Spatrick Status RemoveHardwareBreakpoint(lldb::addr_t addr) override; 55061da546Spatrick 56be691f3bSpatrick NativeProcessLinux &GetProcess(); 57be691f3bSpatrick 58*f6aab3d8Srobert const NativeProcessLinux &GetProcess() const; 59*f6aab3d8Srobert 60*f6aab3d8Srobert llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> 61*f6aab3d8Srobert GetSiginfo() const override; 62*f6aab3d8Srobert 63061da546Spatrick private: 64061da546Spatrick // Interface for friend classes 65061da546Spatrick 66061da546Spatrick /// Resumes the thread. If \p signo is anything but 67061da546Spatrick /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 68061da546Spatrick Status Resume(uint32_t signo); 69061da546Spatrick 70061da546Spatrick /// Single steps the thread. If \p signo is anything but 71061da546Spatrick /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. 72061da546Spatrick Status SingleStep(uint32_t signo); 73061da546Spatrick 74061da546Spatrick void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); 75061da546Spatrick 76061da546Spatrick /// Return true if the thread is stopped. 77061da546Spatrick /// If stopped by a signal, indicate the signo in the signo argument. 78061da546Spatrick /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. 79061da546Spatrick bool IsStopped(int *signo); 80061da546Spatrick 81061da546Spatrick void SetStoppedByExec(); 82061da546Spatrick 83061da546Spatrick void SetStoppedByBreakpoint(); 84061da546Spatrick 85061da546Spatrick void SetStoppedByWatchpoint(uint32_t wp_index); 86061da546Spatrick 87061da546Spatrick bool IsStoppedAtBreakpoint(); 88061da546Spatrick 89061da546Spatrick bool IsStoppedAtWatchpoint(); 90061da546Spatrick 91061da546Spatrick void SetStoppedByTrace(); 92061da546Spatrick 93be691f3bSpatrick void SetStoppedByFork(bool is_vfork, lldb::pid_t child_pid); 94be691f3bSpatrick 95be691f3bSpatrick void SetStoppedByVForkDone(); 96be691f3bSpatrick 97061da546Spatrick void SetStoppedWithNoReason(); 98061da546Spatrick 99be691f3bSpatrick void SetStoppedByProcessorTrace(llvm::StringRef description); 100be691f3bSpatrick 101061da546Spatrick void SetExited(); 102061da546Spatrick 103061da546Spatrick Status RequestStop(); 104061da546Spatrick 105061da546Spatrick // Private interface 106061da546Spatrick void MaybeLogStateChange(lldb::StateType new_state); 107061da546Spatrick 108061da546Spatrick void SetStopped(); 109061da546Spatrick 110be691f3bSpatrick /// Extend m_stop_description with logical and allocation tag values. 111be691f3bSpatrick /// If there is an error along the way just add the information we were able 112be691f3bSpatrick /// to get. 113be691f3bSpatrick void AnnotateSyncTagCheckFault(const siginfo_t *info); 114be691f3bSpatrick 115061da546Spatrick // Member Variables 116061da546Spatrick lldb::StateType m_state; 117061da546Spatrick ThreadStopInfo m_stop_info; 118061da546Spatrick std::unique_ptr<NativeRegisterContextLinux> m_reg_context_up; 119061da546Spatrick std::string m_stop_description; 120061da546Spatrick using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; 121061da546Spatrick WatchpointIndexMap m_watchpoint_index_map; 122061da546Spatrick WatchpointIndexMap m_hw_break_index_map; 123061da546Spatrick std::unique_ptr<SingleStepWorkaround> m_step_workaround; 124061da546Spatrick }; 125061da546Spatrick } // namespace process_linux 126061da546Spatrick } // namespace lldb_private 127061da546Spatrick 128061da546Spatrick #endif // #ifndef liblldb_NativeThreadLinux_H_ 129