@@ -40,42 +40,20 @@ namespace {
4040// _Which = '\x01'
4141// }
4242// }
43- //
44- // ... when using PDB, it looks like this:
45- // (lldb) fr v -R v1
46- // (std::variant<int,double,char>) v1 = {
47- // std::_Variant_base<int,double,char> = {
48- // std::_Variant_storage_<1,int,double,char> = {
49- // _Head = 0
50- // _Tail = {
51- // _Head = 2
52- // _Tail = {
53- // _Head = '\0'
54- // _Tail = {}
55- // }
56- // }
57- // }
58- // _Which = '\x01'
59- // }
60- // }
61-
62- ValueObjectSP GetStorageAtIndex (ValueObject &valobj, size_t index) {
63- // PDB flattens the members on unions to the parent
64- if (valobj.GetCompilerType ().GetNumFields () == 2 )
65- return valobj.GetChildAtIndex (index);
6643
67- // DWARF keeps the union
44+ ValueObjectSP GetStorageMember (ValueObject &valobj, llvm::StringRef name) {
45+ // Find the union
6846 ValueObjectSP union_sp = valobj.GetChildAtIndex (0 );
6947 if (!union_sp)
7048 return nullptr ;
71- return union_sp->GetChildAtIndex (index );
49+ return union_sp->GetChildMemberWithName (name );
7250}
7351
7452ValueObjectSP GetHead (ValueObject &valobj) {
75- return GetStorageAtIndex (valobj, 0 );
53+ return GetStorageMember (valobj, " _Head " );
7654}
7755ValueObjectSP GetTail (ValueObject &valobj) {
78- return GetStorageAtIndex (valobj, 1 );
56+ return GetStorageMember (valobj, " _Tail " );
7957}
8058
8159std::optional<int64_t > GetIndexValue (ValueObject &valobj) {
@@ -87,20 +65,16 @@ std::optional<int64_t> GetIndexValue(ValueObject &valobj) {
8765}
8866
8967ValueObjectSP GetNthStorage (ValueObject &outer, int64_t index) {
90- ValueObjectSP container_sp = outer. GetSP ();
68+ // We need to find the std::_Variant_storage base class.
9169
92- // When using DWARF, we need to find the std::_Variant_storage base class.
93- // There, the top level type doesn't have any fields.
94- if (container_sp->GetCompilerType ().GetNumFields () == 0 ) {
95- // -> std::_SMF_control (typedef to std::_Variant_base)
96- container_sp = container_sp->GetChildAtIndex (0 );
97- if (!container_sp)
98- return nullptr ;
99- // -> std::_Variant_storage
100- container_sp = container_sp->GetChildAtIndex (0 );
101- if (!container_sp)
102- return nullptr ;
103- }
70+ // -> std::_SMF_control (typedef to std::_Variant_base)
71+ ValueObjectSP container_sp = outer.GetSP ()->GetChildAtIndex (0 );
72+ if (!container_sp)
73+ return nullptr ;
74+ // -> std::_Variant_storage
75+ container_sp = container_sp->GetChildAtIndex (0 );
76+ if (!container_sp)
77+ return nullptr ;
10478
10579 for (int64_t i = 0 ; i < index; i++) {
10680 container_sp = GetTail (*container_sp);
@@ -140,20 +114,13 @@ bool formatters::MsvcStlVariantSummaryProvider(
140114 CompilerType storage_type = storage->GetCompilerType ();
141115 if (!storage_type)
142116 return false ;
143- // With DWARF, it's a typedef, with PDB, it's not
117+ // Resolve the typedef
144118 if (storage_type.IsTypedefType ())
145119 storage_type = storage_type.GetTypedefedType ();
146120
147121 CompilerType active_type = storage_type.GetTypeTemplateArgument (1 , true );
148- if (!active_type) {
149- // not enough debug info, try the type of _Head
150- ValueObjectSP head_sp = GetHead (*storage);
151- if (!head_sp)
152- return false ;
153- active_type = head_sp->GetCompilerType ();
154- if (!active_type)
155- return false ;
156- }
122+ if (!active_type)
123+ return false ;
157124
158125 stream << " Active Type = " << active_type.GetDisplayTypeName () << " " ;
159126 return true ;
0 commit comments