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 
13af245d11STodd Fiala #include "lldb/lldb-private-forward.h"
142fe1d0abSChaoren Lin #include "lldb/Host/common/NativeThreadProtocol.h"
15af245d11STodd Fiala 
16*605b51b8SPavel Labath #include <sched.h>
17*605b51b8SPavel Labath 
1818fe6404SChaoren Lin #include <map>
190e1d729bSPavel Labath #include <memory>
207572caf4SRichard Smith #include <string>
2118fe6404SChaoren Lin 
22db264a6dSTamas Berghammer namespace lldb_private {
23db264a6dSTamas Berghammer namespace process_linux {
24db264a6dSTamas Berghammer 
25af245d11STodd Fiala     class NativeProcessLinux;
26af245d11STodd Fiala 
27af245d11STodd Fiala     class NativeThreadLinux : public NativeThreadProtocol
28af245d11STodd Fiala     {
29af245d11STodd Fiala         friend class NativeProcessLinux;
30af245d11STodd Fiala 
31af245d11STodd Fiala     public:
32af245d11STodd Fiala         NativeThreadLinux (NativeProcessLinux *process, lldb::tid_t tid);
33af245d11STodd Fiala 
34af245d11STodd Fiala         // ---------------------------------------------------------------------
35af245d11STodd Fiala         // NativeThreadProtocol Interface
36af245d11STodd Fiala         // ---------------------------------------------------------------------
377206c6d1STodd Fiala         std::string
38af245d11STodd Fiala         GetName() override;
39af245d11STodd Fiala 
40af245d11STodd Fiala         lldb::StateType
41af245d11STodd Fiala         GetState () override;
42af245d11STodd Fiala 
43af245d11STodd Fiala         bool
4428e57429SChaoren Lin         GetStopReason (ThreadStopInfo &stop_info, std::string& description) override;
45af245d11STodd Fiala 
46af245d11STodd Fiala         NativeRegisterContextSP
47af245d11STodd Fiala         GetRegisterContext () override;
48af245d11STodd Fiala 
49af245d11STodd Fiala         Error
50af245d11STodd Fiala         SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override;
51af245d11STodd Fiala 
52af245d11STodd Fiala         Error
53af245d11STodd Fiala         RemoveWatchpoint (lldb::addr_t addr) override;
54af245d11STodd Fiala 
55af245d11STodd Fiala     private:
56af245d11STodd Fiala         // ---------------------------------------------------------------------
57af245d11STodd Fiala         // Interface for friend classes
58af245d11STodd Fiala         // ---------------------------------------------------------------------
59af245d11STodd Fiala 
60*605b51b8SPavel Labath         /// Resumes the thread.  If @p signo is anything but
61*605b51b8SPavel Labath         /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
62*605b51b8SPavel Labath         Error
63*605b51b8SPavel Labath         Resume(uint32_t signo);
64*605b51b8SPavel Labath 
65*605b51b8SPavel Labath         /// Single steps the thread.  If @p signo is anything but
66*605b51b8SPavel Labath         /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
67*605b51b8SPavel Labath         Error
68*605b51b8SPavel Labath         SingleStep(uint32_t signo);
69af245d11STodd Fiala 
70af245d11STodd Fiala         void
71c4e25c96SPavel Labath         SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
72af245d11STodd Fiala 
73511e5cdcSTodd Fiala         /// Return true if the thread is stopped.
74511e5cdcSTodd Fiala         /// If stopped by a signal, indicate the signo in the signo argument.
75511e5cdcSTodd Fiala         /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
76511e5cdcSTodd Fiala         bool
77511e5cdcSTodd Fiala         IsStopped (int *signo);
78511e5cdcSTodd Fiala 
79af245d11STodd Fiala         void
80a9882ceeSTodd Fiala         SetStoppedByExec ();
81a9882ceeSTodd Fiala 
82a9882ceeSTodd Fiala         void
83af245d11STodd Fiala         SetStoppedByBreakpoint ();
84af245d11STodd Fiala 
8518fe6404SChaoren Lin         void
86c16f5dcaSChaoren Lin         SetStoppedByWatchpoint (uint32_t wp_index);
8718fe6404SChaoren Lin 
88af245d11STodd Fiala         bool
89af245d11STodd Fiala         IsStoppedAtBreakpoint ();
90af245d11STodd Fiala 
9118fe6404SChaoren Lin         bool
9218fe6404SChaoren Lin         IsStoppedAtWatchpoint ();
9318fe6404SChaoren Lin 
94af245d11STodd Fiala         void
9528e57429SChaoren Lin         SetStoppedByTrace ();
9628e57429SChaoren Lin 
9728e57429SChaoren Lin         void
9805569f67SPavel Labath         SetStoppedWithNoReason ();
99af245d11STodd Fiala 
100af245d11STodd Fiala         void
101af245d11STodd Fiala         SetExited ();
102af245d11STodd Fiala 
1038c8ff7afSPavel Labath         Error
1048c8ff7afSPavel Labath         RequestStop ();
1058c8ff7afSPavel Labath 
106af245d11STodd Fiala         // ---------------------------------------------------------------------
107af245d11STodd Fiala         // Private interface
108af245d11STodd Fiala         // ---------------------------------------------------------------------
109af245d11STodd Fiala         void
110af245d11STodd Fiala         MaybeLogStateChange (lldb::StateType new_state);
111af245d11STodd Fiala 
112*605b51b8SPavel Labath         NativeProcessLinux &
113*605b51b8SPavel Labath         GetProcess();
114*605b51b8SPavel Labath 
115*605b51b8SPavel Labath         void
116*605b51b8SPavel Labath         SetStopped();
117*605b51b8SPavel Labath 
118*605b51b8SPavel Labath         inline void
119*605b51b8SPavel Labath         MaybePrepareSingleStepWorkaround();
120*605b51b8SPavel Labath 
121*605b51b8SPavel Labath         inline void
122*605b51b8SPavel Labath         MaybeCleanupSingleStepWorkaround();
123*605b51b8SPavel Labath 
124af245d11STodd Fiala         // ---------------------------------------------------------------------
125af245d11STodd Fiala         // Member Variables
126af245d11STodd Fiala         // ---------------------------------------------------------------------
127af245d11STodd Fiala         lldb::StateType m_state;
128af245d11STodd Fiala         ThreadStopInfo m_stop_info;
129af245d11STodd Fiala         NativeRegisterContextSP m_reg_context_sp;
13028e57429SChaoren Lin         std::string m_stop_description;
13118fe6404SChaoren Lin         using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
13218fe6404SChaoren Lin         WatchpointIndexMap m_watchpoint_index_map;
133*605b51b8SPavel Labath         cpu_set_t m_original_cpu_set; // For single-step workaround.
134af245d11STodd Fiala     };
135db264a6dSTamas Berghammer 
1360e1d729bSPavel Labath     typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP;
137db264a6dSTamas Berghammer } // namespace process_linux
138db264a6dSTamas Berghammer } // namespace lldb_private
139af245d11STodd Fiala 
140af245d11STodd Fiala #endif // #ifndef liblldb_NativeThreadLinux_H_
141