[Lldb-commits] [lldb] afaeb6a - Fix crash in SBStructuredData::GetDescription() when there's no StructuredDataPlugin.
Jim Ingham via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 30 11:49:05 PDT 2020
Author: Jim Ingham
Date: 2020-09-30T11:48:54-07:00
New Revision: afaeb6af79a4278249ef9114755e5685d0b35984
URL: https://github.com/llvm/llvm-project/commit/afaeb6af79a4278249ef9114755e5685d0b35984
DIFF: https://github.com/llvm/llvm-project/commit/afaeb6af79a4278249ef9114755e5685d0b35984.diff
LOG: Fix crash in SBStructuredData::GetDescription() when there's no StructuredDataPlugin.
Also, use the StructuredData::Dump method to print the StructuredData if there
is no plugin, rather than just returning an error.
Differential Revision: https://reviews.llvm.org/D88266
Added:
Modified:
lldb/include/lldb/Core/StructuredDataImpl.h
lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/StructuredDataImpl.h b/lldb/include/lldb/Core/StructuredDataImpl.h
index 9aea645a3ea6..929ce21fb2f9 100644
--- a/lldb/include/lldb/Core/StructuredDataImpl.h
+++ b/lldb/include/lldb/Core/StructuredDataImpl.h
@@ -68,14 +68,18 @@ class StructuredDataImpl {
return error;
}
- // Grab the plugin.
- auto plugin_sp = lldb::StructuredDataPluginSP(m_plugin_wp);
+ // Grab the plugin
+ lldb::StructuredDataPluginSP plugin_sp = m_plugin_wp.lock();
+
+ // If there's no plugin, call underlying data's dump method:
if (!plugin_sp) {
- error.SetErrorString("Cannot pretty print structured data: "
- "plugin doesn't exist.");
+ if (!m_data_sp) {
+ error.SetErrorString("No data to describe.");
+ return error;
+ }
+ m_data_sp->Dump(stream, true);
return error;
}
-
// Get the data's description.
return plugin_sp->GetDescription(m_data_sp, stream);
}
diff --git a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
index f5efdfa8b37f..a1a318517bed 100644
--- a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
+++ b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py
@@ -35,6 +35,13 @@ def structured_data_api_test(self):
# Tests for invalid data type
self.invalid_struct_test(example)
+ # Test that GetDescription works:
+ s.Clear()
+ error = example.GetDescription(s)
+ self.assertTrue(error.Success(), "GetDescription works")
+ if not "key_float" in s.GetData():
+ self.fail("FAILED: could not find key_float in description output")
+
dict_struct = lldb.SBStructuredData()
dict_struct = example.GetValueForKey("key_dict")
More information about the lldb-commits
mailing list