1 //===-- DWARFDIETest.cpp ----------------------------------------------=---===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
10 #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
11 #include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h"
12 #include "Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h"
13 #include "TestingSupport/Symbol/YAMLModuleTester.h"
14 #include "llvm/ADT/STLExtras.h"
15 #include "gmock/gmock.h"
16 #include "gtest/gtest.h"
19 using namespace lldb_private
;
20 using namespace lldb_private::plugin::dwarf
;
21 using StringRef
= llvm::StringRef
;
24 check_num_matches(DebugNamesDWARFIndex
&index
, int expected_num_matches
,
25 llvm::ArrayRef
<DWARFDeclContext::Entry
> ctx_entries
) {
26 DWARFDeclContext
ctx(ctx_entries
);
29 index
.GetFullyQualifiedType(ctx
, [&](DWARFDIE die
) {
33 ASSERT_EQ(num_matches
, expected_num_matches
);
36 static DWARFDeclContext::Entry
make_entry(const char *c
) {
37 return DWARFDeclContext::Entry(dwarf::DW_TAG_class_type
, c
);
40 TEST(DWARFDebugNamesIndexTest
, FullyQualifiedQueryWithIDXParent
) {
41 const char *yamldata
= R
"(
55 # We intentionally don't nest types in debug_info: if the nesting is not
56 # inferred from debug_names, we want the test to fail.
58 Tag: DW_TAG_compile_unit
59 Children: DW_CHILDREN_yes
61 Tag: DW_TAG_class_type
62 Children: DW_CHILDREN_no
64 - Attribute: DW_AT_name
73 - Value: 0x0 # Name "1"
76 - Value: 0x2 # Name "2"
79 - Value: 0x4 # Name "3"
84 Tag: DW_TAG_class_type
87 Form: DW_FORM_flag_present
88 - Idx: DW_IDX_die_offset
91 Tag: DW_TAG_class_type
95 - Idx: DW_IDX_die_offset
98 - Name: 0x0 # strp to Name1
101 - 0xc # Die offset to entry named "1"
102 - Name: 0x2 # strp to Name2
105 - 0x0 # Parent = First entry ("1")
106 - 0x11 # Die offset to entry named "1:2"
107 - Name: 0x4 # strp to Name3
110 - 0x6 # Parent = Second entry ("1::2")
111 - 0x16 # Die offset to entry named "1::2::3"
112 - Name: 0x4 # strp to Name3
115 - 0x16 # Die offset to entry named "3"
118 YAMLModuleTester
t(yamldata
);
120 llvm::cast
<SymbolFileDWARF
>(t
.GetModule()->GetSymbolFile());
121 auto *index
= static_cast<DebugNamesDWARFIndex
*>(symbol_file
->getIndex());
122 ASSERT_NE(index
, nullptr);
124 check_num_matches(*index
, 1, {make_entry("1")});
125 check_num_matches(*index
, 1, {make_entry("2"), make_entry("1")});
126 check_num_matches(*index
, 1,
127 {make_entry("3"), make_entry("2"), make_entry("1")});
128 check_num_matches(*index
, 0, {make_entry("2")});
129 check_num_matches(*index
, 1, {make_entry("3")});
132 TEST(DWARFDebugNamesIndexTest
, FullyQualifiedQueryWithoutIDXParent
) {
133 const char *yamldata
= R
"(
147 Tag: DW_TAG_compile_unit
148 Children: DW_CHILDREN_yes
150 Tag: DW_TAG_class_type
151 Children: DW_CHILDREN_yes
153 - Attribute: DW_AT_name
156 Tag: DW_TAG_class_type
157 Children: DW_CHILDREN_no
159 - Attribute: DW_AT_name
168 - Value: 0x0 # Name "1"
171 - Value: 0x2 # Name "2"
175 - Value: 0x2 # Name "2"
180 Tag: DW_TAG_class_type
182 - Idx: DW_IDX_die_offset
185 - Name: 0x0 # strp to Name1
188 - 0xc # Die offset to entry named "1"
189 - Name: 0x2 # strp to Name2
192 - 0x11 # Die offset to entry named "1::2"
193 - Name: 0x2 # strp to Name2
196 - 0x17 # Die offset to entry named "2"
199 YAMLModuleTester
t(yamldata
);
201 llvm::cast
<SymbolFileDWARF
>(t
.GetModule()->GetSymbolFile());
202 auto *index
= static_cast<DebugNamesDWARFIndex
*>(symbol_file
->getIndex());
203 ASSERT_NE(index
, nullptr);
205 check_num_matches(*index
, 1, {make_entry("1")});
206 check_num_matches(*index
, 1, {make_entry("2"), make_entry("1")});
207 check_num_matches(*index
, 1, {make_entry("2")});