1 //===-- NativeThreadLinux.h ----------------------------------- -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_NativeThreadLinux_H_
11 #define liblldb_NativeThreadLinux_H_
12 
13 #include "lldb/lldb-private-forward.h"
14 #include "lldb/Host/common/NativeThreadProtocol.h"
15 
16 #include <map>
17 #include <string>
18 
19 namespace lldb_private {
20 namespace process_linux {
21 
22     class NativeProcessLinux;
23 
24     class NativeThreadLinux : public NativeThreadProtocol
25     {
26         friend class NativeProcessLinux;
27 
28     public:
29         NativeThreadLinux (NativeProcessLinux *process, lldb::tid_t tid);
30 
31         // ---------------------------------------------------------------------
32         // NativeThreadProtocol Interface
33         // ---------------------------------------------------------------------
34         std::string
35         GetName() override;
36 
37         lldb::StateType
38         GetState () override;
39 
40         bool
41         GetStopReason (ThreadStopInfo &stop_info, std::string& description) override;
42 
43         NativeRegisterContextSP
44         GetRegisterContext () override;
45 
46         Error
47         SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override;
48 
49         Error
50         RemoveWatchpoint (lldb::addr_t addr) override;
51 
52     private:
53         // ---------------------------------------------------------------------
54         // Interface for friend classes
55         // ---------------------------------------------------------------------
56         void
57         SetRunning ();
58 
59         void
60         SetStepping ();
61 
62         void
63         SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
64 
65         /// Return true if the thread is stopped.
66         /// If stopped by a signal, indicate the signo in the signo argument.
67         /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
68         bool
69         IsStopped (int *signo);
70 
71         void
72         SetStoppedByExec ();
73 
74         void
75         SetStoppedByBreakpoint ();
76 
77         void
78         SetStoppedByWatchpoint (uint32_t wp_index);
79 
80         bool
81         IsStoppedAtBreakpoint ();
82 
83         bool
84         IsStoppedAtWatchpoint ();
85 
86         void
87         SetStoppedByTrace ();
88 
89         void
90         SetCrashedWithException (const siginfo_t& info);
91 
92         void
93         SetSuspended ();
94 
95         void
96         SetExited ();
97 
98         Error
99         RequestStop ();
100 
101         typedef std::function<Error (lldb::tid_t tid, bool supress_signal)> ResumeThreadFunction;
102         struct ThreadContext
103         {
104             bool stop_requested = false;
105             ResumeThreadFunction request_resume_function;
106         };
107 
108         ThreadContext &
109         GetThreadContext() { return m_thread_context; }
110 
111         // ---------------------------------------------------------------------
112         // Private interface
113         // ---------------------------------------------------------------------
114         void
115         MaybeLogStateChange (lldb::StateType new_state);
116 
117         // ---------------------------------------------------------------------
118         // Member Variables
119         // ---------------------------------------------------------------------
120         lldb::StateType m_state;
121         ThreadStopInfo m_stop_info;
122         NativeRegisterContextSP m_reg_context_sp;
123         std::string m_stop_description;
124         using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
125         WatchpointIndexMap m_watchpoint_index_map;
126         ThreadContext m_thread_context;
127     };
128 
129 } // namespace process_linux
130 } // namespace lldb_private
131 
132 #endif // #ifndef liblldb_NativeThreadLinux_H_
133