[Lldb-commits] [lldb] 9093f3c - Report a useful error when someone passes an incorrect python class name.
Jim Ingham via lldb-commits
lldb-commits at lists.llvm.org
Tue Feb 14 13:47:30 PST 2023
Author: Jim Ingham
Date: 2023-02-14T13:47:14-08:00
New Revision: 9093f3c39b8fa8ef836c627e1db329cd7349e9bb
URL: https://github.com/llvm/llvm-project/commit/9093f3c39b8fa8ef836c627e1db329cd7349e9bb
DIFF: https://github.com/llvm/llvm-project/commit/9093f3c39b8fa8ef836c627e1db329cd7349e9bb.diff
LOG: Report a useful error when someone passes an incorrect python class name.
Added:
Modified:
lldb/source/Commands/CommandObjectCommands.cpp
lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
lldb/test/API/commands/command/script/TestCommandScript.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectCommands.cpp b/lldb/source/Commands/CommandObjectCommands.cpp
index f06dec8328c9d..254e226772dfa 100644
--- a/lldb/source/Commands/CommandObjectCommands.cpp
+++ b/lldb/source/Commands/CommandObjectCommands.cpp
@@ -1600,7 +1600,8 @@ class CommandObjectCommandsScriptAdd : public CommandObjectParsed,
auto cmd_obj_sp = interpreter->CreateScriptCommandObject(
m_options.m_class_name.c_str());
if (!cmd_obj_sp) {
- result.AppendError("cannot create helper object");
+ result.AppendErrorWithFormatv("cannot create helper object for: "
+ "'{0}'", m_options.m_class_name);
return false;
}
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 3c0aa29071968..1a2307424750d 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -1949,8 +1949,11 @@ ScriptInterpreterPythonImpl::CreateScriptCommandObject(const char *class_name) {
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
index 756cb4a3632f8..7e8206ca96a48 100644
--- a/lldb/test/API/commands/command/script/TestCommandScript.py
+++ b/lldb/test/API/commands/command/script/TestCommandScript.py
@@ -164,6 +164,10 @@ def cleanup():
# 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!)
More information about the lldb-commits
mailing list