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 
1618fe6404SChaoren Lin #include <map>
177572caf4SRichard Smith #include <string>
1818fe6404SChaoren Lin 
19db264a6dSTamas Berghammer namespace lldb_private {
20db264a6dSTamas Berghammer namespace process_linux {
21db264a6dSTamas Berghammer 
22af245d11STodd Fiala     class NativeProcessLinux;
23af245d11STodd Fiala 
24af245d11STodd Fiala     class NativeThreadLinux : public NativeThreadProtocol
25af245d11STodd Fiala     {
26af245d11STodd Fiala         friend class NativeProcessLinux;
27af245d11STodd Fiala 
28af245d11STodd Fiala     public:
29af245d11STodd Fiala         NativeThreadLinux (NativeProcessLinux *process, lldb::tid_t tid);
30af245d11STodd Fiala 
31af245d11STodd Fiala         // ---------------------------------------------------------------------
32af245d11STodd Fiala         // NativeThreadProtocol Interface
33af245d11STodd Fiala         // ---------------------------------------------------------------------
347206c6d1STodd Fiala         std::string
35af245d11STodd Fiala         GetName() override;
36af245d11STodd Fiala 
37af245d11STodd Fiala         lldb::StateType
38af245d11STodd Fiala         GetState () override;
39af245d11STodd Fiala 
40af245d11STodd Fiala         bool
4128e57429SChaoren Lin         GetStopReason (ThreadStopInfo &stop_info, std::string& description) override;
42af245d11STodd Fiala 
43af245d11STodd Fiala         NativeRegisterContextSP
44af245d11STodd Fiala         GetRegisterContext () override;
45af245d11STodd Fiala 
46af245d11STodd Fiala         Error
47af245d11STodd Fiala         SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override;
48af245d11STodd Fiala 
49af245d11STodd Fiala         Error
50af245d11STodd Fiala         RemoveWatchpoint (lldb::addr_t addr) override;
51af245d11STodd Fiala 
52af245d11STodd Fiala     private:
53af245d11STodd Fiala         // ---------------------------------------------------------------------
54af245d11STodd Fiala         // Interface for friend classes
55af245d11STodd Fiala         // ---------------------------------------------------------------------
56af245d11STodd Fiala         void
57af245d11STodd Fiala         SetRunning ();
58af245d11STodd Fiala 
59af245d11STodd Fiala         void
60af245d11STodd Fiala         SetStepping ();
61af245d11STodd Fiala 
62af245d11STodd Fiala         void
63af245d11STodd Fiala         SetStoppedBySignal (uint32_t signo);
64af245d11STodd Fiala 
65511e5cdcSTodd Fiala         /// Return true if the thread is stopped.
66511e5cdcSTodd Fiala         /// If stopped by a signal, indicate the signo in the signo argument.
67511e5cdcSTodd Fiala         /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
68511e5cdcSTodd Fiala         bool
69511e5cdcSTodd Fiala         IsStopped (int *signo);
70511e5cdcSTodd Fiala 
71af245d11STodd Fiala         void
72a9882ceeSTodd Fiala         SetStoppedByExec ();
73a9882ceeSTodd Fiala 
74a9882ceeSTodd Fiala         void
75af245d11STodd Fiala         SetStoppedByBreakpoint ();
76af245d11STodd Fiala 
7718fe6404SChaoren Lin         void
78c16f5dcaSChaoren Lin         SetStoppedByWatchpoint (uint32_t wp_index);
7918fe6404SChaoren Lin 
80af245d11STodd Fiala         bool
81af245d11STodd Fiala         IsStoppedAtBreakpoint ();
82af245d11STodd Fiala 
8318fe6404SChaoren Lin         bool
8418fe6404SChaoren Lin         IsStoppedAtWatchpoint ();
8518fe6404SChaoren Lin 
86af245d11STodd Fiala         void
8728e57429SChaoren Lin         SetStoppedByTrace ();
8828e57429SChaoren Lin 
8928e57429SChaoren Lin         void
9028e57429SChaoren Lin         SetCrashedWithException (const siginfo_t& info);
91af245d11STodd Fiala 
92af245d11STodd Fiala         void
93af245d11STodd Fiala         SetSuspended ();
94af245d11STodd Fiala 
95af245d11STodd Fiala         void
96af245d11STodd Fiala         SetExited ();
97af245d11STodd Fiala 
98*8c8ff7afSPavel Labath         Error
99*8c8ff7afSPavel Labath         RequestStop ();
100*8c8ff7afSPavel Labath 
101*8c8ff7afSPavel Labath         typedef std::function<Error (lldb::tid_t tid, bool supress_signal)> ResumeThreadFunction;
102*8c8ff7afSPavel Labath         struct ThreadContext
103*8c8ff7afSPavel Labath         {
104*8c8ff7afSPavel Labath             bool stop_requested = false;
105*8c8ff7afSPavel Labath             ResumeThreadFunction request_resume_function;
106*8c8ff7afSPavel Labath         };
107*8c8ff7afSPavel Labath 
108*8c8ff7afSPavel Labath         ThreadContext &
109*8c8ff7afSPavel Labath         GetThreadContext() { return m_thread_context; }
110*8c8ff7afSPavel Labath 
111af245d11STodd Fiala         // ---------------------------------------------------------------------
112af245d11STodd Fiala         // Private interface
113af245d11STodd Fiala         // ---------------------------------------------------------------------
114af245d11STodd Fiala         void
115af245d11STodd Fiala         MaybeLogStateChange (lldb::StateType new_state);
116af245d11STodd Fiala 
117af245d11STodd Fiala         // ---------------------------------------------------------------------
118af245d11STodd Fiala         // Member Variables
119af245d11STodd Fiala         // ---------------------------------------------------------------------
120af245d11STodd Fiala         lldb::StateType m_state;
121af245d11STodd Fiala         ThreadStopInfo m_stop_info;
122af245d11STodd Fiala         NativeRegisterContextSP m_reg_context_sp;
12328e57429SChaoren Lin         std::string m_stop_description;
12418fe6404SChaoren Lin         using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
12518fe6404SChaoren Lin         WatchpointIndexMap m_watchpoint_index_map;
126*8c8ff7afSPavel Labath         ThreadContext m_thread_context;
127af245d11STodd Fiala     };
128db264a6dSTamas Berghammer 
129db264a6dSTamas Berghammer } // namespace process_linux
130db264a6dSTamas Berghammer } // namespace lldb_private
131af245d11STodd Fiala 
132af245d11STodd Fiala #endif // #ifndef liblldb_NativeThreadLinux_H_
133