160 lines · cpp
1//===-- DWARFUnitTest.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-exception6//7//===----------------------------------------------------------------------===//8 9#include "Plugins/SymbolFile/DWARF/DWARFUnit.h"10#include "TestingSupport/Symbol/YAMLModuleTester.h"11#include "gmock/gmock.h"12#include "gtest/gtest.h"13 14using namespace lldb;15using namespace lldb_private;16using namespace lldb_private::plugin::dwarf;17 18TEST(DWARFUnitTest, NullUnitDie) {19 // Make sure we don't crash parsing a null unit DIE.20 const char *yamldata = R"(21--- !ELF22FileHeader:23 Class: ELFCLASS6424 Data: ELFDATA2LSB25 Type: ET_EXEC26 Machine: EM_38627DWARF:28 debug_abbrev:29 - Table:30 - Code: 0x0000000131 Tag: DW_TAG_compile_unit32 Children: DW_CHILDREN_yes33 Attributes:34 - Attribute: DW_AT_language35 Form: DW_FORM_data236 debug_info:37 - Version: 438 AddrSize: 839 Entries:40 - AbbrCode: 0x0000000041)";42 43 YAMLModuleTester t(yamldata);44 ASSERT_TRUE((bool)t.GetDwarfUnit());45 46 DWARFUnit *unit = t.GetDwarfUnit();47 const DWARFDebugInfoEntry *die_first = unit->DIE().GetDIE();48 ASSERT_NE(die_first, nullptr);49 EXPECT_TRUE(die_first->IsNULL());50}51 52TEST(DWARFUnitTest, MissingSentinel) {53 // Make sure we don't crash if the debug info is missing a null DIE sentinel.54 const char *yamldata = R"(55--- !ELF56FileHeader:57 Class: ELFCLASS6458 Data: ELFDATA2LSB59 Type: ET_EXEC60 Machine: EM_38661DWARF:62 debug_abbrev:63 - Table:64 - Code: 0x0000000165 Tag: DW_TAG_compile_unit66 Children: DW_CHILDREN_yes67 Attributes:68 - Attribute: DW_AT_language69 Form: DW_FORM_data270 debug_info:71 - Version: 472 AddrSize: 873 Entries:74 - AbbrCode: 0x0000000175 Values:76 - Value: 0x000000000000000C77)";78 79 YAMLModuleTester t(yamldata);80 ASSERT_TRUE((bool)t.GetDwarfUnit());81 82 DWARFUnit *unit = t.GetDwarfUnit();83 const DWARFDebugInfoEntry *die_first = unit->DIE().GetDIE();84 ASSERT_NE(die_first, nullptr);85 EXPECT_EQ(die_first->GetFirstChild(), nullptr);86 EXPECT_EQ(die_first->GetSibling(), nullptr);87}88 89TEST(DWARFUnitTest, ClangProducer) {90 const char *yamldata = R"(91--- !ELF92FileHeader:93 Class: ELFCLASS6494 Data: ELFDATA2LSB95 Type: ET_EXEC96 Machine: EM_38697DWARF:98 debug_str:99 - 'Apple clang version 13.0.0 (clang-1300.0.29.3)'100 debug_abbrev:101 - Table:102 - Code: 0x00000001103 Tag: DW_TAG_compile_unit104 Children: DW_CHILDREN_yes105 Attributes:106 - Attribute: DW_AT_producer107 Form: DW_FORM_strp108 debug_info:109 - Version: 4110 AddrSize: 8111 Entries:112 - AbbrCode: 0x1113 Values:114 - Value: 0x0115 - AbbrCode: 0x0116)";117 118 YAMLModuleTester t(yamldata);119 DWARFUnit *unit = t.GetDwarfUnit();120 ASSERT_TRUE((bool)unit);121 EXPECT_EQ(unit->GetProducer(), eProducerClang);122 EXPECT_EQ(unit->GetProducerVersion(), llvm::VersionTuple(1300, 0, 29, 3));123}124 125TEST(DWARFUnitTest, SwiftProducer) {126 const char *yamldata = R"(127--- !ELF128FileHeader:129 Class: ELFCLASS64130 Data: ELFDATA2LSB131 Type: ET_EXEC132 Machine: EM_386133DWARF:134 debug_str:135 - 'Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)'136 debug_abbrev:137 - Table:138 - Code: 0x00000001139 Tag: DW_TAG_compile_unit140 Children: DW_CHILDREN_yes141 Attributes:142 - Attribute: DW_AT_producer143 Form: DW_FORM_strp144 debug_info:145 - Version: 4146 AddrSize: 8147 Entries:148 - AbbrCode: 0x1149 Values:150 - Value: 0x0151 - AbbrCode: 0x0152)";153 154 YAMLModuleTester t(yamldata);155 DWARFUnit *unit = t.GetDwarfUnit();156 ASSERT_TRUE((bool)unit);157 EXPECT_EQ(unit->GetProducer(), eProducerSwift);158 EXPECT_EQ(unit->GetProducerVersion(), llvm::VersionTuple(1300, 0, 31, 1));159}160