1 //===-- NativeThreadLinux.h ----------------------------------- -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_NativeThreadLinux_H_
10 #define liblldb_NativeThreadLinux_H_
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"
17 #include "llvm/ADT/StringRef.h"
24 namespace lldb_private
{
25 namespace process_linux
{
27 class NativeProcessLinux
;
29 class NativeThreadLinux
: public NativeThreadProtocol
{
30 friend class NativeProcessLinux
;
33 NativeThreadLinux(NativeProcessLinux
&process
, lldb::tid_t tid
);
35 // NativeThreadProtocol Interface
36 std::string
GetName() override
;
38 lldb::StateType
GetState() override
;
40 bool GetStopReason(ThreadStopInfo
&stop_info
,
41 std::string
&description
) override
;
43 NativeRegisterContextLinux
&GetRegisterContext() override
{
44 return *m_reg_context_up
;
47 Status
SetWatchpoint(lldb::addr_t addr
, size_t size
, uint32_t watch_flags
,
48 bool hardware
) override
;
50 Status
RemoveWatchpoint(lldb::addr_t addr
) override
;
52 Status
SetHardwareBreakpoint(lldb::addr_t addr
, size_t size
) override
;
54 Status
RemoveHardwareBreakpoint(lldb::addr_t addr
) override
;
56 NativeProcessLinux
&GetProcess();
58 const NativeProcessLinux
&GetProcess() const;
60 llvm::Expected
<std::unique_ptr
<llvm::MemoryBuffer
>>
61 GetSiginfo() const override
;
64 // Interface for friend classes
66 /// Resumes the thread. If \p signo is anything but
67 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
68 Status
Resume(uint32_t signo
);
70 /// Single steps the thread. If \p signo is anything but
71 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
72 Status
SingleStep(uint32_t signo
);
74 void SetStoppedBySignal(uint32_t signo
, const siginfo_t
*info
= nullptr);
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
);
81 void SetStoppedByExec();
83 void SetStoppedByBreakpoint();
85 void SetStoppedByWatchpoint(uint32_t wp_index
);
87 bool IsStoppedAtBreakpoint();
89 bool IsStoppedAtWatchpoint();
91 void SetStoppedByTrace();
93 void SetStoppedByFork(bool is_vfork
, lldb::pid_t child_pid
);
95 void SetStoppedByVForkDone();
97 void SetStoppedWithNoReason();
99 void SetStoppedByProcessorTrace(llvm::StringRef description
);
103 Status
RequestStop();
106 void MaybeLogStateChange(lldb::StateType new_state
);
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 able
113 void AnnotateSyncTagCheckFault(lldb::addr_t fault_addr
);
116 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
;
125 } // namespace process_linux
126 } // namespace lldb_private
128 #endif // #ifndef liblldb_NativeThreadLinux_H_