diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp --- a/lldb/source/Commands/CommandObjectCommands.cpp +++ b/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; } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/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( diff --git a/lldb/test/API/commands/command/script/TestCommandScript.py b/lldb/test/API/commands/command/script/TestCommandScript.py --- a/lldb/test/API/commands/command/script/TestCommandScript.py +++ b/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!)