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/Target/ThreadPlan.h"
14 // Other libraries and framework includes
16 #include "lldb/Core/Debugger.h"
17 #include "lldb/Core/Log.h"
18 #include "lldb/Core/State.h"
19 #include "lldb/Interpreter/CommandInterpreter.h"
20 #include "lldb/Interpreter/ScriptInterpreter.h"
21 #include "lldb/Target/RegisterContext.h"
22 #include "lldb/Target/Thread.h"
23 #include "lldb/Target/ThreadPlan.h"
24 #include "lldb/Target/ThreadPlanPython.h"
25 #include "lldb/Target/Process.h"
26 #include "lldb/Target/Target.h"
29 using namespace lldb_private;
31 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
35 ThreadPlanPython::ThreadPlanPython (Thread &thread, const char *class_name) :
36 ThreadPlan (ThreadPlan::eKindPython,
37 "Python based Thread Plan",
41 m_class_name (class_name)
43 SetIsMasterPlan (true);
44 SetOkayToDiscard (true);
48 ThreadPlanPython::~ThreadPlanPython ()
50 // FIXME, do I need to decrement the ref count on this implementation object to make it go away?
54 ThreadPlanPython::ValidatePlan (Stream *error)
56 // I have to postpone setting up the implementation till after the constructor because I need to call
57 // shared_from_this, which you can't do in the constructor. So I'll do it here.
58 if (m_implementation_sp)
65 ThreadPlanPython::DidPush()
67 // We set up the script side in DidPush, so that it can push other plans in the constructor,
68 // and doesn't have to care about the details of DidPush.
70 if (!m_class_name.empty())
72 ScriptInterpreter *script_interp = m_thread.GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
75 m_implementation_sp = script_interp->CreateScriptedThreadPlan (m_class_name.c_str(), this->shared_from_this());
81 ThreadPlanPython::ShouldStop (Event *event_ptr)
83 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
85 log->Printf ("%s called on Python Thread Plan: %s )",
86 __PRETTY_FUNCTION__, m_class_name.c_str());
88 bool should_stop = true;
89 if (m_implementation_sp)
91 ScriptInterpreter *script_interp = m_thread.GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
95 should_stop = script_interp->ScriptedThreadPlanShouldStop (m_implementation_sp, event_ptr, script_error);
97 SetPlanComplete(false);
104 ThreadPlanPython::DoPlanExplainsStop (Event *event_ptr)
106 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
108 log->Printf ("%s called on Python Thread Plan: %s )",
109 __PRETTY_FUNCTION__, m_class_name.c_str());
111 bool explains_stop = true;
112 if (m_implementation_sp)
114 ScriptInterpreter *script_interp = m_thread.GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
118 explains_stop = script_interp->ScriptedThreadPlanExplainsStop (m_implementation_sp, event_ptr, script_error);
120 SetPlanComplete(false);
123 return explains_stop;
127 ThreadPlanPython::MischiefManaged ()
129 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
131 log->Printf ("%s called on Python Thread Plan: %s )",
132 __PRETTY_FUNCTION__, m_class_name.c_str());
133 bool mischief_managed = true;
134 if (m_implementation_sp)
136 // I don't really need mischief_managed, since it's simpler to just call SetPlanComplete in should_stop.
137 mischief_managed = IsPlanComplete();
138 if (mischief_managed)
139 m_implementation_sp.reset();
141 return mischief_managed;
145 ThreadPlanPython::GetPlanRunState ()
147 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
149 log->Printf ("%s called on Python Thread Plan: %s )",
151 m_class_name.c_str());
152 lldb::StateType run_state = eStateRunning;
153 if (m_implementation_sp)
155 ScriptInterpreter *script_interp = m_thread.GetProcess()->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
159 run_state = script_interp->ScriptedThreadPlanGetRunState (m_implementation_sp, script_error);
165 // The ones below are not currently exported to Python.
168 ThreadPlanPython::StopOthers ()
170 // For now Python plans run all threads, but we should add some controls for this.
175 ThreadPlanPython::GetDescription (Stream *s,
176 lldb::DescriptionLevel level)
178 s->Printf ("Python thread plan implemented by class %s.", m_class_name.c_str());
182 ThreadPlanPython::WillStop ()
184 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
186 log->Printf ("%s called on Python Thread Plan: %s )",
187 __PRETTY_FUNCTION__, m_class_name.c_str());