[Lldb-commits] [PATCH] D142260: Actually report an error when `command script add` is passed a non-existent class
Jim Ingham via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Fri Jan 20 15:10:36 PST 2023
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142260.490984.patch
Type: text/x-patch
Size: 2150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230120/ad5ff38a/attachment.bin>
More information about the lldb-commits
mailing list