1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
//===-- DWARFDIETest.cpp ----------------------------------------------=---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
#include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
#include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h"
#include "Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h"
#include "TestingSupport/Symbol/YAMLModuleTester.h"
#include "llvm/ADT/STLExtras.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::plugin::dwarf;
using StringRef = llvm::StringRef;
static void
check_num_matches(DebugNamesDWARFIndex &index, int expected_num_matches,
llvm::ArrayRef<DWARFDeclContext::Entry> ctx_entries) {
DWARFDeclContext ctx(ctx_entries);
int num_matches = 0;
index.GetFullyQualifiedType(ctx, [&](DWARFDIE die) {
num_matches++;
return true;
});
ASSERT_EQ(num_matches, expected_num_matches);
}
static DWARFDeclContext::Entry make_entry(const char *c) {
return DWARFDeclContext::Entry(dwarf::DW_TAG_class_type, c);
}
TEST(DWARFDebugNamesIndexTest, FullyQualifiedQueryWithIDXParent) {
const char *yamldata = R"(
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_386
DWARF:
debug_str:
- '1'
- '2'
- '3'
debug_abbrev:
- Table:
# We intentionally don't nest types in debug_info: if the nesting is not
# inferred from debug_names, we want the test to fail.
- Code: 0x1
Tag: DW_TAG_compile_unit
Children: DW_CHILDREN_yes
- Code: 0x2
Tag: DW_TAG_class_type
Children: DW_CHILDREN_no
Attributes:
- Attribute: DW_AT_name
Form: DW_FORM_strp
debug_info:
- Version: 4
AddrSize: 8
Entries:
- AbbrCode: 0x1
- AbbrCode: 0x2
Values:
- Value: 0x0 # Name "1"
- AbbrCode: 0x2
Values:
- Value: 0x2 # Name "2"
- AbbrCode: 0x2
Values:
- Value: 0x4 # Name "3"
- AbbrCode: 0x0
debug_names:
Abbreviations:
- Code: 0x11
Tag: DW_TAG_class_type
Indices:
- Idx: DW_IDX_parent
Form: DW_FORM_flag_present
- Idx: DW_IDX_die_offset
Form: DW_FORM_ref4
- Code: 0x22
Tag: DW_TAG_class_type
Indices:
- Idx: DW_IDX_parent
Form: DW_FORM_ref4
- Idx: DW_IDX_die_offset
Form: DW_FORM_ref4
Entries:
- Name: 0x0 # strp to Name1
Code: 0x11
Values:
- 0xc # Die offset to entry named "1"
- Name: 0x2 # strp to Name2
Code: 0x22
Values:
- 0x0 # Parent = First entry ("1")
- 0x11 # Die offset to entry named "1:2"
- Name: 0x4 # strp to Name3
Code: 0x22
Values:
- 0x6 # Parent = Second entry ("1::2")
- 0x16 # Die offset to entry named "1::2::3"
- Name: 0x4 # strp to Name3
Code: 0x11
Values:
- 0x16 # Die offset to entry named "3"
)";
YAMLModuleTester t(yamldata);
auto *symbol_file =
llvm::cast<SymbolFileDWARF>(t.GetModule()->GetSymbolFile());
auto *index = static_cast<DebugNamesDWARFIndex *>(symbol_file->getIndex());
ASSERT_NE(index, nullptr);
check_num_matches(*index, 1, {make_entry("1")});
check_num_matches(*index, 1, {make_entry("2"), make_entry("1")});
check_num_matches(*index, 1,
{make_entry("3"), make_entry("2"), make_entry("1")});
check_num_matches(*index, 0, {make_entry("2")});
check_num_matches(*index, 1, {make_entry("3")});
}
TEST(DWARFDebugNamesIndexTest, FullyQualifiedQueryWithoutIDXParent) {
const char *yamldata = R"(
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_386
DWARF:
debug_str:
- '1'
- '2'
debug_abbrev:
- Table:
- Code: 0x1
Tag: DW_TAG_compile_unit
Children: DW_CHILDREN_yes
- Code: 0x2
Tag: DW_TAG_class_type
Children: DW_CHILDREN_yes
Attributes:
- Attribute: DW_AT_name
Form: DW_FORM_strp
- Code: 0x3
Tag: DW_TAG_class_type
Children: DW_CHILDREN_no
Attributes:
- Attribute: DW_AT_name
Form: DW_FORM_strp
debug_info:
- Version: 4
AddrSize: 8
Entries:
- AbbrCode: 0x1
- AbbrCode: 0x2
Values:
- Value: 0x0 # Name "1"
- AbbrCode: 0x3
Values:
- Value: 0x2 # Name "2"
- AbbrCode: 0x0
- AbbrCode: 0x3
Values:
- Value: 0x2 # Name "2"
- AbbrCode: 0x0
debug_names:
Abbreviations:
- Code: 0x1
Tag: DW_TAG_class_type
Indices:
- Idx: DW_IDX_die_offset
Form: DW_FORM_ref4
Entries:
- Name: 0x0 # strp to Name1
Code: 0x1
Values:
- 0xc # Die offset to entry named "1"
- Name: 0x2 # strp to Name2
Code: 0x1
Values:
- 0x11 # Die offset to entry named "1::2"
- Name: 0x2 # strp to Name2
Code: 0x1
Values:
- 0x17 # Die offset to entry named "2"
)";
YAMLModuleTester t(yamldata);
auto *symbol_file =
llvm::cast<SymbolFileDWARF>(t.GetModule()->GetSymbolFile());
auto *index = static_cast<DebugNamesDWARFIndex *>(symbol_file->getIndex());
ASSERT_NE(index, nullptr);
check_num_matches(*index, 1, {make_entry("1")});
check_num_matches(*index, 1, {make_entry("2"), make_entry("1")});
check_num_matches(*index, 1, {make_entry("2")});
}
|