1 //===-- ThreadPlan.cpp ------------------------------------------*- 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 #include "lldb/lldb-python.h"
12 #include "lldb/Target/ThreadPlan.h"
16 // Other libraries and framework includes
18 #include "lldb/Core/Debugger.h"
19 #include "lldb/Core/Log.h"
20 #include "lldb/Core/State.h"
21 #include "lldb/Interpreter/CommandInterpreter.h"
22 #include "lldb/Interpreter/ScriptInterpreter.h"
23 #include "lldb/Interpreter/ScriptInterpreterPython.h"
24 #include "lldb/Target/RegisterContext.h"
25 #include "lldb/Target/Thread.h"
26 #include "lldb/Target/ThreadPlan.h"
27 #include "lldb/Target/ThreadPlanPython.h"
28 #include "lldb/Target/Process.h"
29 #include "lldb/Target/Target.h"
32 using namespace lldb_private;
34 //----------------------------------------------------------------------
36 //----------------------------------------------------------------------
38 ThreadPlanPython::ThreadPlanPython (Thread &thread, const char *class_name) :
39 ThreadPlan (ThreadPlan::eKindPython,
40 "Python based Thread Plan",
44 m_class_name (class_name)
46 SetIsMasterPlan (true);
47 SetOkayToDiscard (true);
51 ThreadPlanPython::~ThreadPlanPython ()
53 // FIXME, do I need to decrement the ref count on this implementation object to make it go away?
57 ThreadPlanPython::ValidatePlan (Stream *error)
59 // I have to postpone setting up the implementation till after the constructor because I need to call
60 // shared_from_this, which you can't do in the constructor. So I'll do it here.
61 if (m_implementation_sp)
68 ThreadPlanPython::DidPush()
70 // We set up the script side in DidPush, so that it can push other plans in the constructor,
71 // and doesn't have to care about the details of DidPush.
73 if (!m_class_name.empty())
75 ScriptInterpreter *script_interp = m_thread.GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
78 m_implementation_sp = script_interp->CreateScriptedThreadPlan (m_class_name.c_str(), this->shared_from_this());
84 ThreadPlanPython::ShouldStop (Event *event_ptr)
86 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
88 log->Printf ("%s called on Python Thread Plan: %s )",
89 __PRETTY_FUNCTION__, m_class_name.c_str());
91 bool should_stop = true;
92 if (m_implementation_sp)
94 ScriptInterpreter *script_interp = m_thread.GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
98 should_stop = script_interp->ScriptedThreadPlanShouldStop (m_implementation_sp, event_ptr, script_error);
100 SetPlanComplete(false);
107 ThreadPlanPython::DoPlanExplainsStop (Event *event_ptr)
109 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
111 log->Printf ("%s called on Python Thread Plan: %s )",
112 __PRETTY_FUNCTION__, m_class_name.c_str());
114 bool explains_stop = true;
115 if (m_implementation_sp)
117 ScriptInterpreter *script_interp = m_thread.GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
121 explains_stop = script_interp->ScriptedThreadPlanExplainsStop (m_implementation_sp, event_ptr, script_error);
123 SetPlanComplete(false);
126 return explains_stop;
130 ThreadPlanPython::MischiefManaged ()
132 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
134 log->Printf ("%s called on Python Thread Plan: %s )",
135 __PRETTY_FUNCTION__, m_class_name.c_str());
136 bool mischief_managed = true;
137 if (m_implementation_sp)
139 // I don't really need mischief_managed, since it's simpler to just call SetPlanComplete in should_stop.
140 mischief_managed = IsPlanComplete();
141 if (mischief_managed)
142 m_implementation_sp.reset();
144 return mischief_managed;
148 ThreadPlanPython::GetPlanRunState ()
150 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
152 log->Printf ("%s called on Python Thread Plan: %s )",
154 m_class_name.c_str());
155 lldb::StateType run_state = eStateRunning;
156 if (m_implementation_sp)
158 ScriptInterpreter *script_interp = m_thread.GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
162 run_state = script_interp->ScriptedThreadPlanGetRunState (m_implementation_sp, script_error);
168 // The ones below are not currently exported to Python.
171 ThreadPlanPython::StopOthers ()
173 // For now Python plans run all threads, but we should add some controls for this.
178 ThreadPlanPython::GetDescription (Stream *s,
179 lldb::DescriptionLevel level)
181 s->Printf ("Python thread plan implemented by class %s.", m_class_name.c_str());
185 ThreadPlanPython::WillStop ()
187 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
189 log->Printf ("%s called on Python Thread Plan: %s )",
190 __PRETTY_FUNCTION__, m_class_name.c_str());