Skip to content

Commit 034eaed

Browse files
authored
[lldb][DataFormatters] Adjust retrieval of unordered_map element type (#140256)
A user ran into an issue where the libc++ `std::unordered_map` formatter fails because it can't deduce the `element_type`. That happens because the `node_type` is a forwad declaration. And, in fact, dsymutil stripped the definition for `std::__1::__hash_node<...>` for a particular instantiation. While I'm still unclear whether this is a dsymutil bug, this patch works around said issue by getting the element type from the `__table_` member. Drive-by: - Set the `m_element_type` in `Update`, which is where the other members are initialized I don't have a reduced example of this unfortunately. But the crux of the issue is that `std::__1::__hash_node<...>` only has a forward declaration in the dsym. Then trying to call `GetTypeTemplateArgument` on that `CompilerType` fails. And even if the definition was present in the dsym it seems like we're stopped in a context where the CU only had a forward declaration DIE for that type and the `node_type` never ends up being completed with the definition that lives in another CU. rdar://150813798
1 parent 32a1b6a commit 034eaed

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lldb/source/Plugins/Language/CPlusPlus/LibCxxUnorderedMap.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LibcxxStdUnorderedMapSyntheticFrontEnd
4444

4545
private:
4646
CompilerType GetNodeType();
47-
CompilerType GetElementType(CompilerType node_type);
47+
CompilerType GetElementType(CompilerType table_type);
4848
llvm::Expected<size_t> CalculateNumChildrenImpl(ValueObject &table);
4949

5050
CompilerType m_element_type;
@@ -98,8 +98,8 @@ static bool isUnorderedMap(ConstString type_name) {
9898
}
9999

100100
CompilerType lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
101-
GetElementType(CompilerType node_type) {
102-
CompilerType element_type = node_type.GetTypeTemplateArgument(0);
101+
GetElementType(CompilerType table_type) {
102+
auto element_type = table_type.GetTypedefedType().GetTypeTemplateArgument(0);
103103

104104
// This synthetic provider is used for both unordered_(multi)map and
105105
// unordered_(multi)set. For unordered_map, the element type has an
@@ -114,7 +114,7 @@ CompilerType lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::
114114
element_type.GetFieldAtIndex(0, name, nullptr, nullptr, nullptr);
115115
CompilerType actual_type = field_type.GetTypedefedType();
116116
if (isStdTemplate(actual_type.GetTypeName(), "pair"))
117-
element_type = actual_type;
117+
return actual_type;
118118
}
119119

120120
return element_type;
@@ -161,13 +161,6 @@ lldb::ValueObjectSP lldb_private::formatters::
161161
ValueObjectSP value_sp = node_sp->GetChildMemberWithName("__value_");
162162
ValueObjectSP hash_sp = node_sp->GetChildMemberWithName("__hash_");
163163
if (!hash_sp || !value_sp) {
164-
if (!m_element_type) {
165-
m_node_type = GetNodeType();
166-
if (!m_node_type)
167-
return nullptr;
168-
169-
m_element_type = GetElementType(m_node_type);
170-
}
171164
node_sp = m_next_element->Cast(m_node_type.GetPointerType())
172165
->Dereference(error);
173166
if (!node_sp || error.Fail())
@@ -271,6 +264,14 @@ lldb_private::formatters::LibcxxStdUnorderedMapSyntheticFrontEnd::Update() {
271264
if (!table_sp)
272265
return lldb::ChildCacheState::eRefetch;
273266

267+
m_node_type = GetNodeType();
268+
if (!m_node_type)
269+
return lldb::ChildCacheState::eRefetch;
270+
271+
m_element_type = GetElementType(table_sp->GetCompilerType());
272+
if (!m_element_type)
273+
return lldb::ChildCacheState::eRefetch;
274+
274275
ValueObjectSP tree_sp = GetTreePointer(*table_sp);
275276
if (!tree_sp)
276277
return lldb::ChildCacheState::eRefetch;

0 commit comments

Comments
 (0)