1 //===-- Debug.h -------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Debug_h_
11 #define liblldb_Debug_h_
17 // Other libraries and framework includes
19 #include "lldb/lldb-private.h"
21 namespace lldb_private {
23 //------------------------------------------------------------------
24 // Tells a thread what it needs to do when the process is resumed.
25 //------------------------------------------------------------------
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
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
49 ResumeActionList (lldb::StateType default_action, int signal) :
53 SetDefaultThreadActionIfNeeded (default_action, signal);
56 ResumeActionList (const ResumeAction *actions, size_t num_actions) :
60 if (actions && num_actions)
62 m_actions.assign (actions, actions + num_actions);
63 m_signal_handled.assign (num_actions, false);
67 ~ResumeActionList() = default;
72 return m_actions.empty();
76 Append (const ResumeAction &action)
78 m_actions.push_back (action);
79 m_signal_handled.push_back (false);
83 AppendAction (lldb::tid_t tid,
84 lldb::StateType state,
87 ResumeAction action = { tid, state, signal };
94 AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateRunning);
100 AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateStopped);
106 AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateStepping);
110 GetActionForThread (lldb::tid_t tid, bool default_ok) const
112 const size_t num_actions = m_actions.size();
113 for (size_t i=0; i<num_actions; ++i)
115 if (m_actions[i].tid == tid)
116 return &m_actions[i];
118 if (default_ok && tid != LLDB_INVALID_THREAD_ID)
119 return GetActionForThread (LLDB_INVALID_THREAD_ID, false);
124 NumActionsWithState (lldb::StateType state) const
127 const size_t num_actions = m_actions.size();
128 for (size_t i=0; i<num_actions; ++i)
130 if (m_actions[i].state == state)
137 SetDefaultThreadActionIfNeeded (lldb::StateType action, int signal)
139 if (GetActionForThread (LLDB_INVALID_THREAD_ID, true) == nullptr)
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
151 SetSignalHandledForThread (lldb::tid_t tid) const
153 if (tid != LLDB_INVALID_THREAD_ID)
155 const size_t num_actions = m_actions.size();
156 for (size_t i=0; i<num_actions; ++i)
158 if (m_actions[i].tid == tid)
159 m_signal_handled[i] = true;
167 return m_actions.data();
173 return m_actions.size();
180 m_signal_handled.clear();
184 std::vector<ResumeAction> m_actions;
185 mutable std::vector<bool> m_signal_handled;
188 struct ThreadStopInfo
190 lldb::StopReason reason;
199 // eStopReasonException
204 lldb::addr_t data[2];
210 #endif // liblldb_Debug_h_