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         SetLaunching ();
58 
59         void
60         SetRunning ();
61 
62         void
63         SetStepping ();
64 
65         void
66         SetStoppedBySignal (uint32_t signo);
67 
68         /// Return true if the thread is stopped.
69         /// If stopped by a signal, indicate the signo in the signo argument.
70         /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
71         bool
72         IsStopped (int *signo);
73 
74         void
75         SetStoppedByExec ();
76 
77         void
78         SetStoppedByBreakpoint ();
79 
80         void
81         SetStoppedByWatchpoint (uint32_t wp_index);
82 
83         bool
84         IsStoppedAtBreakpoint ();
85 
86         bool
87         IsStoppedAtWatchpoint ();
88 
89         void
90         SetStoppedByTrace ();
91 
92         void
93         SetCrashedWithException (const siginfo_t& info);
94 
95         void
96         SetSuspended ();
97 
98         void
99         SetExited ();
100 
101         // ---------------------------------------------------------------------
102         // Private interface
103         // ---------------------------------------------------------------------
104         void
105         MaybeLogStateChange (lldb::StateType new_state);
106 
107         // ---------------------------------------------------------------------
108         // Member Variables
109         // ---------------------------------------------------------------------
110         lldb::StateType m_state;
111         ThreadStopInfo m_stop_info;
112         NativeRegisterContextSP m_reg_context_sp;
113         std::string m_stop_description;
114         using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
115         WatchpointIndexMap m_watchpoint_index_map;
116     };
117 
118 } // namespace process_linux
119 } // namespace lldb_private
120 
121 #endif // #ifndef liblldb_NativeThreadLinux_H_
122