129 lines · c
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-exception6//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 24namespace lldb_private {25namespace process_linux {26 27class NativeProcessLinux;28 29class NativeThreadLinux : public NativeThreadProtocol {30 friend class NativeProcessLinux;31 32public:33 NativeThreadLinux(NativeProcessLinux &process, lldb::tid_t tid);34 35 // NativeThreadProtocol Interface36 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 const NativeProcessLinux &GetProcess() const;59 60 llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>61 GetSiginfo() const override;62 63private:64 // Interface for friend classes65 66 /// Resumes the thread. If \p signo is anything but67 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.68 Status Resume(uint32_t signo);69 70 /// Single steps the thread. If \p signo is anything but71 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.72 Status SingleStep(uint32_t signo);73 74 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);75 76 /// Return true if the thread is stopped.77 /// If stopped by a signal, indicate the signo in the signo argument.78 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.79 bool IsStopped(int *signo);80 81 void SetStoppedByExec();82 83 void SetStoppedByBreakpoint();84 85 void SetStoppedByWatchpoint(uint32_t wp_index);86 87 bool IsStoppedAtBreakpoint();88 89 bool IsStoppedAtWatchpoint();90 91 void SetStoppedByTrace();92 93 void SetStoppedByFork(bool is_vfork, lldb::pid_t child_pid);94 95 void SetStoppedByVForkDone();96 97 void SetStoppedWithNoReason();98 99 void SetStoppedByProcessorTrace(llvm::StringRef description);100 101 void SetExited();102 103 Status RequestStop();104 105 // Private interface106 void MaybeLogStateChange(lldb::StateType new_state);107 108 void SetStopped();109 110 /// Extend m_stop_description with logical and allocation tag values.111 /// If there is an error along the way just add the information we were able112 /// to get.113 void AnnotateSyncTagCheckFault(lldb::addr_t fault_addr);114 115 // Member Variables116 lldb::StateType m_state;117 ThreadStopInfo m_stop_info;118 std::unique_ptr<NativeRegisterContextLinux> m_reg_context_up;119 std::string m_stop_description;120 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;121 WatchpointIndexMap m_watchpoint_index_map;122 WatchpointIndexMap m_hw_break_index_map;123 std::unique_ptr<SingleStepWorkaround> m_step_workaround;124};125} // namespace process_linux126} // namespace lldb_private127 128#endif // #ifndef liblldb_NativeThreadLinux_H_129