jingham created this revision. jingham added a reviewer: JDevlieghere. Herald added a project: All. jingham requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
Before we were returning a SP with an invalid PythonObject, but the calling code wants an empty shared pointer as an indication of error. Make it so. Also added a test for this error. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D142260 Files: lldb/source/Commands/CommandObjectCommands.cpp lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp lldb/test/API/commands/command/script/TestCommandScript.py Index: lldb/test/API/commands/command/script/TestCommandScript.py =================================================================== --- lldb/test/API/commands/command/script/TestCommandScript.py +++ lldb/test/API/commands/command/script/TestCommandScript.py @@ -164,6 +164,10 @@ # This should not crash. self.runCmd('bug11569', check=False) + # Make sure that a reference to a non-existent class raises an error: + bad_class_name = "LLDBNoSuchModule.LLDBNoSuchClass" + self.expect("command script add wont-work --class {0}".format(bad_class_name), error=True, substrs = [bad_class_name]) + def test_persistence(self): """ Ensure that function arguments meaningfully persist (and do not crash!) Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -1943,8 +1943,11 @@ PythonObject ret_val = LLDBSwigPythonCreateCommandObject( class_name, m_dictionary_name.c_str(), debugger_sp); - return StructuredData::GenericSP( - new StructuredPythonObject(std::move(ret_val))); + if (ret_val.IsValid()) + return StructuredData::GenericSP( + new StructuredPythonObject(std::move(ret_val))); + else + return {}; } bool ScriptInterpreterPythonImpl::GenerateTypeScriptFunction( Index: lldb/source/Commands/CommandObjectCommands.cpp =================================================================== --- lldb/source/Commands/CommandObjectCommands.cpp +++ lldb/source/Commands/CommandObjectCommands.cpp @@ -1600,7 +1600,8 @@ auto cmd_obj_sp = interpreter->CreateScriptCommandObject( m_options.m_class_name.c_str()); if (!cmd_obj_sp) { - result.AppendError("cannot create helper object"); + result.AppendErrorWithFormat("cannot create helper object for class: " + "'%s'", m_options.m_class_name.c_str()); return false; }
Index: lldb/test/API/commands/command/script/TestCommandScript.py =================================================================== --- lldb/test/API/commands/command/script/TestCommandScript.py +++ lldb/test/API/commands/command/script/TestCommandScript.py @@ -164,6 +164,10 @@ # This should not crash. self.runCmd('bug11569', check=False) + # Make sure that a reference to a non-existent class raises an error: + bad_class_name = "LLDBNoSuchModule.LLDBNoSuchClass" + self.expect("command script add wont-work --class {0}".format(bad_class_name), error=True, substrs = [bad_class_name]) + def test_persistence(self): """ Ensure that function arguments meaningfully persist (and do not crash!) Index: lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp =================================================================== --- lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -1943,8 +1943,11 @@ PythonObject ret_val = LLDBSwigPythonCreateCommandObject( class_name, m_dictionary_name.c_str(), debugger_sp); - return StructuredData::GenericSP( - new StructuredPythonObject(std::move(ret_val))); + if (ret_val.IsValid()) + return StructuredData::GenericSP( + new StructuredPythonObject(std::move(ret_val))); + else + return {}; } bool ScriptInterpreterPythonImpl::GenerateTypeScriptFunction( Index: lldb/source/Commands/CommandObjectCommands.cpp =================================================================== --- lldb/source/Commands/CommandObjectCommands.cpp +++ lldb/source/Commands/CommandObjectCommands.cpp @@ -1600,7 +1600,8 @@ auto cmd_obj_sp = interpreter->CreateScriptCommandObject( m_options.m_class_name.c_str()); if (!cmd_obj_sp) { - result.AppendError("cannot create helper object"); + result.AppendErrorWithFormat("cannot create helper object for class: " + "'%s'", m_options.m_class_name.c_str()); return false; }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits