Skip to content

Commit afaeb6a

Browse files
committed
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
1 parent ad865d9 commit afaeb6a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lldb/include/lldb/Core/StructuredDataImpl.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ class StructuredDataImpl {
6868
return error;
6969
}
7070

71-
// Grab the plugin.
72-
auto plugin_sp = lldb::StructuredDataPluginSP(m_plugin_wp);
71+
// Grab the plugin
72+
lldb::StructuredDataPluginSP plugin_sp = m_plugin_wp.lock();
73+
74+
// If there's no plugin, call underlying data's dump method:
7375
if (!plugin_sp) {
74-
error.SetErrorString("Cannot pretty print structured data: "
75-
"plugin doesn't exist.");
76+
if (!m_data_sp) {
77+
error.SetErrorString("No data to describe.");
78+
return error;
79+
}
80+
m_data_sp->Dump(stream, true);
7681
return error;
7782
}
78-
7983
// Get the data's description.
8084
return plugin_sp->GetDescription(m_data_sp, stream);
8185
}

lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def structured_data_api_test(self):
3535
# Tests for invalid data type
3636
self.invalid_struct_test(example)
3737

38+
# Test that GetDescription works:
39+
s.Clear()
40+
error = example.GetDescription(s)
41+
self.assertTrue(error.Success(), "GetDescription works")
42+
if not "key_float" in s.GetData():
43+
self.fail("FAILED: could not find key_float in description output")
44+
3845
dict_struct = lldb.SBStructuredData()
3946
dict_struct = example.GetValueForKey("key_dict")
4047

0 commit comments

Comments
 (0)