]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Host/Debug.h
Vendor import of stripped lldb trunk r256633:
[FreeBSD/FreeBSD.git] / include / lldb / Host / Debug.h
1 //===-- Debug.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_Debug_h_
11 #define liblldb_Debug_h_
12
13 // C Includes
14 // C++ Includes
15 #include <vector>
16
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/lldb-private.h"
20
21 namespace lldb_private {
22
23     //------------------------------------------------------------------
24     // Tells a thread what it needs to do when the process is resumed.
25     //------------------------------------------------------------------
26     struct ResumeAction
27     {
28         lldb::tid_t tid;        // The thread ID that this action applies to, LLDB_INVALID_THREAD_ID for the default thread action
29         lldb::StateType state;  // Valid values are eStateStopped/eStateSuspended, eStateRunning, and eStateStepping.
30         int signal;             // When resuming this thread, resume it with this signal if this value is > 0
31     };
32
33     //------------------------------------------------------------------
34     // A class that contains instructions for all threads for
35     // NativeProcessProtocol::Resume(). Each thread can either run, stay
36     // suspended, or step when the process is resumed. We optionally
37     // have the ability to also send a signal to the thread when the
38     // action is run or step.
39     //------------------------------------------------------------------
40     class ResumeActionList
41     {
42     public:
43         ResumeActionList () :
44             m_actions (),
45             m_signal_handled ()
46         {
47         }
48
49         ResumeActionList (lldb::StateType default_action, int signal) :
50             m_actions(),
51             m_signal_handled ()
52         {
53             SetDefaultThreadActionIfNeeded (default_action, signal);
54         }
55
56         ResumeActionList (const ResumeAction *actions, size_t num_actions) :
57             m_actions (),
58             m_signal_handled ()
59         {
60             if (actions && num_actions)
61             {
62                 m_actions.assign (actions, actions + num_actions);
63                 m_signal_handled.assign (num_actions, false);
64             }
65         }
66
67         ~ResumeActionList() = default;
68
69         bool
70         IsEmpty() const
71         {
72             return m_actions.empty();
73         }
74
75         void
76         Append (const ResumeAction &action)
77         {
78             m_actions.push_back (action);
79             m_signal_handled.push_back (false);
80         }
81
82         void
83         AppendAction (lldb::tid_t tid,
84                       lldb::StateType state,
85                       int signal = 0)
86         {
87             ResumeAction action = { tid, state, signal };
88             Append (action);
89         }
90
91         void
92         AppendResumeAll ()
93         {
94             AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateRunning);
95         }
96
97         void
98         AppendSuspendAll ()
99         {
100             AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateStopped);
101         }
102
103         void
104         AppendStepAll ()
105         {
106             AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateStepping);
107         }
108
109         const ResumeAction *
110         GetActionForThread (lldb::tid_t tid, bool default_ok) const
111         {
112             const size_t num_actions = m_actions.size();
113             for (size_t i=0; i<num_actions; ++i)
114             {
115                 if (m_actions[i].tid == tid)
116                     return &m_actions[i];
117             }
118             if (default_ok && tid != LLDB_INVALID_THREAD_ID)
119                 return GetActionForThread (LLDB_INVALID_THREAD_ID, false);
120             return nullptr;
121         }
122
123         size_t
124         NumActionsWithState (lldb::StateType state) const
125         {
126             size_t count = 0;
127             const size_t num_actions = m_actions.size();
128             for (size_t i=0; i<num_actions; ++i)
129             {
130                 if (m_actions[i].state == state)
131                     ++count;
132             }
133             return count;
134         }
135
136         bool
137         SetDefaultThreadActionIfNeeded (lldb::StateType action, int signal)
138         {
139             if (GetActionForThread (LLDB_INVALID_THREAD_ID, true) == nullptr)
140             {
141                 // There isn't a default action so we do need to set it.
142                 ResumeAction default_action = {LLDB_INVALID_THREAD_ID, action, signal };
143                 m_actions.push_back (default_action);
144                 m_signal_handled.push_back (false);
145                 return true; // Return true as we did add the default action
146             }
147             return false;
148         }
149
150         void
151         SetSignalHandledForThread (lldb::tid_t tid) const
152         {
153             if (tid != LLDB_INVALID_THREAD_ID)
154             {
155                 const size_t num_actions = m_actions.size();
156                 for (size_t i=0; i<num_actions; ++i)
157                 {
158                     if (m_actions[i].tid == tid)
159                         m_signal_handled[i] = true;
160                 }
161             }
162         }
163
164         const ResumeAction *
165         GetFirst() const
166         {
167             return m_actions.data();
168         }
169
170         size_t
171         GetSize () const
172         {
173             return m_actions.size();
174         }
175
176         void
177         Clear()
178         {
179             m_actions.clear();
180             m_signal_handled.clear();
181         }
182
183     protected:
184         std::vector<ResumeAction> m_actions;
185         mutable std::vector<bool> m_signal_handled;
186     };
187
188     struct ThreadStopInfo
189     {
190         lldb::StopReason reason;
191         union
192         {
193             // eStopReasonSignal
194             struct
195             {
196                 uint32_t signo;
197             } signal;
198
199             // eStopReasonException
200             struct
201             {
202                 uint64_t type;
203                 uint32_t data_count;
204                 lldb::addr_t data[2];
205             } exception;
206         } details;
207     };
208 }
209
210 #endif // liblldb_Debug_h_