From: Jim Ingham Date: Sat, 28 Sep 2019 00:53:45 +0000 (+0000) Subject: Give an error when StepUsingScriptedThreadPlan is passed a bad classname. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=93c98346e98a50e481efda95c9b095bf2b1c8a73;p=platform%2Fupstream%2Fllvm.git Give an error when StepUsingScriptedThreadPlan is passed a bad classname. Differential Revision: https://reviews.llvm.org/D68173 llvm-svn: 373135 --- diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreter.h b/lldb/include/lldb/Interpreter/ScriptInterpreter.h index 44c7554..9c68ffb 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreter.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreter.h @@ -208,6 +208,7 @@ public: virtual StructuredData::ObjectSP CreateScriptedThreadPlan(const char *class_name, + std::string &error_str, lldb::ThreadPlanSP thread_plan_sp) { return StructuredData::ObjectSP(); } diff --git a/lldb/include/lldb/Target/ThreadPlanPython.h b/lldb/include/lldb/Target/ThreadPlanPython.h index 3825bf6..58eb33e 100644 --- a/lldb/include/lldb/Target/ThreadPlanPython.h +++ b/lldb/include/lldb/Target/ThreadPlanPython.h @@ -55,6 +55,7 @@ protected: private: std::string m_class_name; + std::string m_error_str; StructuredData::ObjectSP m_implementation_sp; bool m_did_push; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/step_scripted/TestStepScripted.py b/lldb/packages/Python/lldbsuite/test/functionalities/step_scripted/TestStepScripted.py index a111ede..ce5f33f 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/step_scripted/TestStepScripted.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/step_scripted/TestStepScripted.py @@ -26,10 +26,13 @@ class StepScriptedTestCase(TestBase): def setUp(self): TestBase.setUp(self) + self.main_source_file = lldb.SBFileSpec("main.c") self.runCmd("command script import Steps.py") def step_out_with_scripted_plan(self, name): - (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, "Set a breakpoint here", self.main_source_file) + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + "Set a breakpoint here", + self.main_source_file) frame = thread.GetFrameAtIndex(0) self.assertEqual("foo", frame.GetFunctionName()) @@ -39,3 +42,21 @@ class StepScriptedTestCase(TestBase): frame = thread.GetFrameAtIndex(0) self.assertEqual("main", frame.GetFunctionName()) + + def test_misspelled_plan_name(self): + """Test that we get a useful error if we misspell the plan class name""" + self.build() + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + "Set a breakpoint here", + self.main_source_file) + stop_id = process.GetStopID() + # Pass a non-existent class for the plan class: + err = thread.StepUsingScriptedThreadPlan("NoSuchModule.NoSuchPlan") + + # Make sure we got a good error: + self.assertTrue(err.Fail(), "We got a failure state") + msg = err.GetCString() + self.assertTrue("NoSuchModule.NoSuchPlan" in msg, "Mentioned missing class") + + # Make sure we didn't let the process run: + self.assertEqual(stop_id, process.GetStopID(), "Process didn't run") diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index 8509899..8a99daa 100644 --- a/lldb/scripts/Python/python-wrapper.swig +++ b/lldb/scripts/Python/python-wrapper.swig @@ -250,6 +250,7 @@ LLDBSwigPythonCreateScriptedThreadPlan ( const char *python_class_name, const char *session_dictionary_name, + std::string &error_string, const lldb::ThreadPlanSP& thread_plan_sp ) { @@ -267,8 +268,11 @@ LLDBSwigPythonCreateScriptedThreadPlan auto dict = PythonModule::MainModule().ResolveName(session_dictionary_name); auto pfunc = PythonObject::ResolveNameWithDictionary(python_class_name, dict); - if (!pfunc.IsAllocated()) + if (!pfunc.IsAllocated()) { + error_string.append("could not find script class: "); + error_string.append(python_class_name); return nullptr; + } PythonObject tp_arg(PyRefType::Owned, SBTypeToSWIGWrapper(tp_value)); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 4019a57..4438a9b 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -97,6 +97,7 @@ LLDBSwigPythonCreateCommandObject(const char *python_class_name, extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan( const char *python_class_name, const char *session_dictionary_name, + std::string &error_string, const lldb::ThreadPlanSP &thread_plan_sp); extern "C" bool LLDBSWIGPythonCallThreadPlan(void *implementor, @@ -1844,12 +1845,13 @@ StructuredData::DictionarySP ScriptInterpreterPythonImpl::OSPlugin_CreateThread( } StructuredData::ObjectSP ScriptInterpreterPythonImpl::CreateScriptedThreadPlan( - const char *class_name, lldb::ThreadPlanSP thread_plan_sp) { + const char *class_name, std::string &error_str, + lldb::ThreadPlanSP thread_plan_sp) { if (class_name == nullptr || class_name[0] == '\0') return StructuredData::ObjectSP(); if (!thread_plan_sp.get()) - return StructuredData::ObjectSP(); + return {}; Debugger &debugger = thread_plan_sp->GetTarget().GetDebugger(); ScriptInterpreter *script_interpreter = debugger.GetScriptInterpreter(); @@ -1857,17 +1859,18 @@ StructuredData::ObjectSP ScriptInterpreterPythonImpl::CreateScriptedThreadPlan( static_cast(script_interpreter); if (!script_interpreter) - return StructuredData::ObjectSP(); + return {}; void *ret_val; { Locker py_lock(this, Locker::AcquireLock | Locker::InitSession | Locker::NoSTDIN); - ret_val = LLDBSwigPythonCreateScriptedThreadPlan( class_name, python_interpreter->m_dictionary_name.c_str(), - thread_plan_sp); + error_str, thread_plan_sp); + if (!ret_val) + return {}; } return StructuredData::ObjectSP(new StructuredPythonObject(ret_val)); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h index e81c3b0..9cf3205 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -78,6 +78,7 @@ public: StructuredData::ObjectSP CreateScriptedThreadPlan(const char *class_name, + std::string &error_str, lldb::ThreadPlanSP thread_plan) override; bool ScriptedThreadPlanExplainsStop(StructuredData::ObjectSP implementor_sp, diff --git a/lldb/source/Target/ThreadPlanPython.cpp b/lldb/source/Target/ThreadPlanPython.cpp index cc0f55b..ff57e0a 100644 --- a/lldb/source/Target/ThreadPlanPython.cpp +++ b/lldb/source/Target/ThreadPlanPython.cpp @@ -45,7 +45,9 @@ bool ThreadPlanPython::ValidatePlan(Stream *error) { if (!m_implementation_sp) { if (error) - error->Printf("Python thread plan does not have an implementation"); + error->Printf("Error constructing Python ThreadPlan: %s", + m_error_str.empty() ? "" + : m_error_str.c_str()); return false; } @@ -63,7 +65,7 @@ void ThreadPlanPython::DidPush() { .GetScriptInterpreter(); if (script_interp) { m_implementation_sp = script_interp->CreateScriptedThreadPlan( - m_class_name.c_str(), this->shared_from_this()); + m_class_name.c_str(), m_error_str, this->shared_from_this()); } } } diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp index f6b617d..3ccda8c 100644 --- a/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp +++ b/lldb/unittests/ScriptInterpreter/Python/PythonTestSuite.cpp @@ -95,6 +95,7 @@ LLDBSwigPythonCreateCommandObject(const char *python_class_name, extern "C" void *LLDBSwigPythonCreateScriptedThreadPlan( const char *python_class_name, const char *session_dictionary_name, + std::string &error_string, const lldb::ThreadPlanSP &thread_plan_sp) { return nullptr; }