| 1 |
//===-- DWARF64UnitTest.cpp------------------------------------------------===// |
| 2 |
// |
| 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 |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h" |
| 10 |
#include "Plugins/SymbolFile/DWARF/DWARFUnit.h" |
| 11 |
#include "TestingSupport/Symbol/YAMLModuleTester.h" |
| 12 |
|
| 13 |
using namespace lldb_private; |
| 14 |
using namespace lldb_private::dwarf; |
| 15 |
using namespace lldb_private::plugin::dwarf; |
| 16 |
|
| 17 |
TEST(DWARF64UnitTest, DWARF64DebugInfoAndCU) { |
| 18 |
const char *yamldata = R"( |
| 19 |
--- !ELF |
| 20 |
FileHeader: |
| 21 |
Class: ELFCLASS64 |
| 22 |
Data: ELFDATA2LSB |
| 23 |
Type: ET_EXEC |
| 24 |
Machine: EM_PPC64 |
| 25 |
DWARF: |
| 26 |
debug_str: |
| 27 |
- 'clang version 18.1.8 (clang-18.1.8-1)' |
| 28 |
- 'main' |
| 29 |
debug_abbrev: |
| 30 |
- Table: |
| 31 |
- Code: 0x1 |
| 32 |
Tag: DW_TAG_compile_unit |
| 33 |
Children: DW_CHILDREN_yes |
| 34 |
Attributes: |
| 35 |
- Attribute: DW_AT_producer |
| 36 |
Form: DW_FORM_strp |
| 37 |
- Attribute: DW_AT_language |
| 38 |
Form: DW_FORM_data2 |
| 39 |
- Attribute: DW_AT_stmt_list |
| 40 |
Form: DW_FORM_sec_offset |
| 41 |
- Code: 0x02 |
| 42 |
Tag: DW_TAG_subprogram |
| 43 |
Children: DW_CHILDREN_no |
| 44 |
Attributes: |
| 45 |
- Attribute: DW_AT_name |
| 46 |
Form: DW_FORM_strp |
| 47 |
debug_info: |
| 48 |
- Format: DWARF64 |
| 49 |
Version: 4 |
| 50 |
AbbrOffset: 0x0 |
| 51 |
AddrSize: 8 |
| 52 |
Entries: |
| 53 |
- AbbrCode: 0x1 |
| 54 |
Values: |
| 55 |
- Value: 0x0 |
| 56 |
- Value: 0x04 |
| 57 |
- Value: 0x0 |
| 58 |
- AbbrCode: 0x2 |
| 59 |
Values: |
| 60 |
- Value: 0x1 |
| 61 |
- AbbrCode: 0x0 |
| 62 |
)"; |
| 63 |
|
| 64 |
YAMLModuleTester t(yamldata); |
| 65 |
auto *symbol_file = |
| 66 |
llvm::cast<SymbolFileDWARF>(t.GetModule()->GetSymbolFile()); |
| 67 |
DWARFUnit *unit = symbol_file->DebugInfo().GetUnitAtIndex(0); |
| 68 |
ASSERT_TRUE(unit); |
| 69 |
ASSERT_EQ(unit->GetFormParams().Format, DwarfFormat::DWARF64); |
| 70 |
ASSERT_EQ(unit->GetVersion(), 4); |
| 71 |
ASSERT_EQ(unit->GetAddressByteSize(), 8); |
| 72 |
|
| 73 |
DWARFFormValue form_value; |
| 74 |
const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE(); |
| 75 |
ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit); |
| 76 |
ASSERT_EQ(unit->GetProducer(), eProducerClang); |
| 77 |
ASSERT_EQ(unit->GetDWARFLanguageType(), DW_LANG_C_plus_plus); |
| 78 |
auto attrs = cu_entry->GetAttributes(unit, DWARFDebugInfoEntry::Recurse::yes); |
| 79 |
attrs.ExtractFormValueAtIndex(2, form_value); // Validate DW_AT_stmt_list |
| 80 |
ASSERT_EQ(form_value.Unsigned(), 0UL); |
| 81 |
|
| 82 |
DWARFDIE cu_die(unit, cu_entry); |
| 83 |
auto declaration = cu_die.GetFirstChild(); |
| 84 |
ASSERT_TRUE(declaration.IsValid()); |
| 85 |
ASSERT_EQ(declaration.Tag(), DW_TAG_subprogram); |
| 86 |
} |
| 87 |
|
| 88 |
TEST(DWARF64UnitTest, DWARF5StrTable) { |
| 89 |
const char *yamldata = R"( |
| 90 |
--- !ELF |
| 91 |
FileHeader: |
| 92 |
Class: ELFCLASS64 |
| 93 |
Data: ELFDATA2MSB |
| 94 |
Type: ET_EXEC |
| 95 |
Machine: EM_PPC64 |
| 96 |
DWARF: |
| 97 |
debug_str: |
| 98 |
- 'clang version 18.1.8 (clang-18.1.8-1)' |
| 99 |
- 'main.c' |
| 100 |
- 'foo' |
| 101 |
- 'main' |
| 102 |
debug_abbrev: |
| 103 |
- Table: |
| 104 |
- Code: 0x1 |
| 105 |
Tag: DW_TAG_compile_unit |
| 106 |
Children: DW_CHILDREN_yes |
| 107 |
Attributes: |
| 108 |
- Attribute: DW_AT_producer |
| 109 |
Form: DW_FORM_strx1 |
| 110 |
- Attribute: DW_AT_language |
| 111 |
Form: DW_FORM_data2 |
| 112 |
- Attribute: DW_AT_name |
| 113 |
Form: DW_FORM_strx1 |
| 114 |
- Attribute: DW_AT_str_offsets_base |
| 115 |
Form: DW_FORM_sec_offset |
| 116 |
- Code: 0x2 |
| 117 |
Tag: DW_TAG_subprogram |
| 118 |
Children: DW_CHILDREN_no |
| 119 |
Attributes: |
| 120 |
- Attribute: DW_AT_name |
| 121 |
Form: DW_FORM_strx1 |
| 122 |
debug_info: |
| 123 |
- Format: DWARF64 |
| 124 |
Version: 0x05 |
| 125 |
UnitType: DW_UT_compile |
| 126 |
AbbrOffset: 0x0 |
| 127 |
AddrSize: 0x08 |
| 128 |
Entries: |
| 129 |
- AbbrCode: 0x1 |
| 130 |
Values: |
| 131 |
- Value: 0x0 |
| 132 |
- Value: 0x04 |
| 133 |
- Value: 0x1 |
| 134 |
- Value: 0x00000010 |
| 135 |
- AbbrCode: 0x2 |
| 136 |
Values: |
| 137 |
- Value: 0x2 |
| 138 |
- AbbrCode: 0x2 |
| 139 |
Values: |
| 140 |
- Value: 0x3 |
| 141 |
- AbbrCode: 0x0 |
| 142 |
|
| 143 |
debug_str_offsets: |
| 144 |
- Format: DWARF64 |
| 145 |
Version: "0x05" |
| 146 |
Offsets: |
| 147 |
- 0x00000000 |
| 148 |
- 0x00000026 |
| 149 |
- 0x0000002d |
| 150 |
- 0x00000031 |
| 151 |
)"; |
| 152 |
|
| 153 |
YAMLModuleTester t(yamldata); |
| 154 |
auto *symbol_file = |
| 155 |
llvm::cast<SymbolFileDWARF>(t.GetModule()->GetSymbolFile()); |
| 156 |
DWARFUnit *unit = symbol_file->DebugInfo().GetUnitAtIndex(0); |
| 157 |
ASSERT_TRUE(unit); |
| 158 |
ASSERT_EQ(unit->GetFormParams().Format, DwarfFormat::DWARF64); |
| 159 |
ASSERT_EQ(unit->GetVersion(), 5); |
| 160 |
ASSERT_EQ(unit->GetAddressByteSize(), 8); |
| 161 |
|
| 162 |
DWARFFormValue form_value; |
| 163 |
const DWARFDebugInfoEntry *cu_entry = unit->DIE().GetDIE(); |
| 164 |
ASSERT_EQ(cu_entry->Tag(), DW_TAG_compile_unit); |
| 165 |
ASSERT_EQ(unit->GetProducer(), eProducerClang); |
| 166 |
ASSERT_EQ(unit->GetDWARFLanguageType(), DW_LANG_C_plus_plus); |
| 167 |
auto attrs = cu_entry->GetAttributes(unit, DWARFDebugInfoEntry::Recurse::yes); |
| 168 |
attrs.ExtractFormValueAtIndex(3, |
| 169 |
form_value); // Validate DW_AT_str_offsets_bae |
| 170 |
ASSERT_EQ(form_value.Unsigned(), 0x00000010UL); |
| 171 |
DWARFDIE cu_die(unit, cu_entry); |
| 172 |
ASSERT_EQ(ConstString(cu_die.GetName()), "main.c"); |
| 173 |
|
| 174 |
auto func_foo = cu_die.GetFirstChild(); |
| 175 |
ASSERT_TRUE(func_foo.IsValid()); |
| 176 |
ASSERT_EQ(func_foo.Tag(), DW_TAG_subprogram); |
| 177 |
ASSERT_EQ(ConstString(func_foo.GetName()), "foo"); |
| 178 |
|
| 179 |
auto func_main = func_foo.GetSibling(); |
| 180 |
ASSERT_TRUE(func_main.IsValid()); |
| 181 |
ASSERT_EQ(func_main.Tag(), DW_TAG_subprogram); |
| 182 |
ASSERT_EQ(ConstString(func_main.GetName()), "main"); |
| 183 |
} |