1af245d11STodd Fiala //===-- NativeThreadLinux.h ----------------------------------- -*- C++ -*-===//
2af245d11STodd Fiala //
3af245d11STodd Fiala //                     The LLVM Compiler Infrastructure
4af245d11STodd Fiala //
5af245d11STodd Fiala // This file is distributed under the University of Illinois Open Source
6af245d11STodd Fiala // License. See LICENSE.TXT for details.
7af245d11STodd Fiala //
8af245d11STodd Fiala //===----------------------------------------------------------------------===//
9af245d11STodd Fiala 
10af245d11STodd Fiala #ifndef liblldb_NativeThreadLinux_H_
11af245d11STodd Fiala #define liblldb_NativeThreadLinux_H_
12af245d11STodd Fiala 
13*8abd34f0SPavel Labath #include "SingleStepCheck.h"
142fe1d0abSChaoren Lin #include "lldb/Host/common/NativeThreadProtocol.h"
15b9c1b51eSKate Stone #include "lldb/lldb-private-forward.h"
16af245d11STodd Fiala 
1718fe6404SChaoren Lin #include <map>
180e1d729bSPavel Labath #include <memory>
197572caf4SRichard Smith #include <string>
2018fe6404SChaoren Lin 
21db264a6dSTamas Berghammer namespace lldb_private {
22db264a6dSTamas Berghammer namespace process_linux {
23db264a6dSTamas Berghammer 
24af245d11STodd Fiala class NativeProcessLinux;
25af245d11STodd Fiala 
26b9c1b51eSKate Stone class NativeThreadLinux : public NativeThreadProtocol {
27af245d11STodd Fiala   friend class NativeProcessLinux;
28af245d11STodd Fiala 
29af245d11STodd Fiala public:
30af245d11STodd Fiala   NativeThreadLinux(NativeProcessLinux *process, lldb::tid_t tid);
31af245d11STodd Fiala 
32af245d11STodd Fiala   // ---------------------------------------------------------------------
33af245d11STodd Fiala   // NativeThreadProtocol Interface
34af245d11STodd Fiala   // ---------------------------------------------------------------------
35b9c1b51eSKate Stone   std::string GetName() override;
36af245d11STodd Fiala 
37b9c1b51eSKate Stone   lldb::StateType GetState() override;
38af245d11STodd Fiala 
39b9c1b51eSKate Stone   bool GetStopReason(ThreadStopInfo &stop_info,
40b9c1b51eSKate Stone                      std::string &description) override;
41af245d11STodd Fiala 
42b9c1b51eSKate Stone   NativeRegisterContextSP GetRegisterContext() override;
43af245d11STodd Fiala 
44b9c1b51eSKate Stone   Error SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
45b9c1b51eSKate Stone                       bool hardware) override;
46af245d11STodd Fiala 
47b9c1b51eSKate Stone   Error RemoveWatchpoint(lldb::addr_t addr) override;
48af245d11STodd Fiala 
49af245d11STodd Fiala private:
50af245d11STodd Fiala   // ---------------------------------------------------------------------
51af245d11STodd Fiala   // Interface for friend classes
52af245d11STodd Fiala   // ---------------------------------------------------------------------
53af245d11STodd Fiala 
54605b51b8SPavel Labath   /// Resumes the thread.  If @p signo is anything but
55605b51b8SPavel Labath   /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
56b9c1b51eSKate Stone   Error Resume(uint32_t signo);
57605b51b8SPavel Labath 
58605b51b8SPavel Labath   /// Single steps the thread.  If @p signo is anything but
59605b51b8SPavel Labath   /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
60b9c1b51eSKate Stone   Error SingleStep(uint32_t signo);
61af245d11STodd Fiala 
62b9c1b51eSKate Stone   void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
63af245d11STodd Fiala 
64511e5cdcSTodd Fiala   /// Return true if the thread is stopped.
65511e5cdcSTodd Fiala   /// If stopped by a signal, indicate the signo in the signo argument.
66511e5cdcSTodd Fiala   /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
67b9c1b51eSKate Stone   bool IsStopped(int *signo);
68511e5cdcSTodd Fiala 
69b9c1b51eSKate Stone   void SetStoppedByExec();
70a9882ceeSTodd Fiala 
71b9c1b51eSKate Stone   void SetStoppedByBreakpoint();
72af245d11STodd Fiala 
73b9c1b51eSKate Stone   void SetStoppedByWatchpoint(uint32_t wp_index);
7418fe6404SChaoren Lin 
75b9c1b51eSKate Stone   bool IsStoppedAtBreakpoint();
76af245d11STodd Fiala 
77b9c1b51eSKate Stone   bool IsStoppedAtWatchpoint();
7818fe6404SChaoren Lin 
79b9c1b51eSKate Stone   void SetStoppedByTrace();
8028e57429SChaoren Lin 
81b9c1b51eSKate Stone   void SetStoppedWithNoReason();
82af245d11STodd Fiala 
83b9c1b51eSKate Stone   void SetExited();
84af245d11STodd Fiala 
85b9c1b51eSKate Stone   Error RequestStop();
868c8ff7afSPavel Labath 
87af245d11STodd Fiala   // ---------------------------------------------------------------------
88af245d11STodd Fiala   // Private interface
89af245d11STodd Fiala   // ---------------------------------------------------------------------
90b9c1b51eSKate Stone   void MaybeLogStateChange(lldb::StateType new_state);
91af245d11STodd Fiala 
92b9c1b51eSKate Stone   NativeProcessLinux &GetProcess();
93605b51b8SPavel Labath 
94b9c1b51eSKate Stone   void SetStopped();
95605b51b8SPavel Labath 
96af245d11STodd Fiala   // ---------------------------------------------------------------------
97af245d11STodd Fiala   // Member Variables
98af245d11STodd Fiala   // ---------------------------------------------------------------------
99af245d11STodd Fiala   lldb::StateType m_state;
100af245d11STodd Fiala   ThreadStopInfo m_stop_info;
101af245d11STodd Fiala   NativeRegisterContextSP m_reg_context_sp;
10228e57429SChaoren Lin   std::string m_stop_description;
10318fe6404SChaoren Lin   using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
10418fe6404SChaoren Lin   WatchpointIndexMap m_watchpoint_index_map;
105*8abd34f0SPavel Labath   llvm::Optional<SingleStepWorkaround> m_step_workaround;
106af245d11STodd Fiala };
107db264a6dSTamas Berghammer 
1080e1d729bSPavel Labath typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP;
109db264a6dSTamas Berghammer } // namespace process_linux
110db264a6dSTamas Berghammer } // namespace lldb_private
111af245d11STodd Fiala 
112af245d11STodd Fiala #endif // #ifndef liblldb_NativeThreadLinux_H_
113