1 //===-- DWARFUnitTest.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/DWARFUnit.h"
10 #include "TestingSupport/Symbol/YAMLModuleTester.h"
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
15 using namespace lldb_private
;
16 using namespace lldb_private::plugin::dwarf
;
18 TEST(DWARFUnitTest
, NullUnitDie
) {
19 // Make sure we don't crash parsing a null unit DIE.
20 const char *yamldata
= R
"(
31 Tag: DW_TAG_compile_unit
32 Children: DW_CHILDREN_yes
34 - Attribute: DW_AT_language
40 - AbbrCode: 0x00000000
43 YAMLModuleTester
t(yamldata
);
44 ASSERT_TRUE((bool)t
.GetDwarfUnit());
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());
52 TEST(DWARFUnitTest
, MissingSentinel
) {
53 // Make sure we don't crash if the debug info is missing a null DIE sentinel.
54 const char *yamldata
= R
"(
65 Tag: DW_TAG_compile_unit
66 Children: DW_CHILDREN_yes
68 - Attribute: DW_AT_language
74 - AbbrCode: 0x00000001
76 - Value: 0x000000000000000C
79 YAMLModuleTester
t(yamldata
);
80 ASSERT_TRUE((bool)t
.GetDwarfUnit());
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);
89 TEST(DWARFUnitTest
, ClangProducer
) {
90 const char *yamldata
= R
"(
99 - 'Apple clang version 13.0.0 (clang-1300.0.29.3)'
103 Tag: DW_TAG_compile_unit
104 Children: DW_CHILDREN_yes
106 - Attribute: DW_AT_producer
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));
125 TEST(DWARFUnitTest
, LLVMGCCProducer
) {
126 const char *yamldata
= R
"(
135 - 'i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)'
139 Tag: DW_TAG_compile_unit
140 Children: DW_CHILDREN_yes
142 - Attribute: DW_AT_producer
154 YAMLModuleTester
t(yamldata
);
155 DWARFUnit
*unit
= t
.GetDwarfUnit();
156 ASSERT_TRUE((bool)unit
);
157 EXPECT_EQ(unit
->GetProducer(), eProducerLLVMGCC
);
160 TEST(DWARFUnitTest
, SwiftProducer
) {
161 const char *yamldata
= R
"(
170 - 'Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)'
174 Tag: DW_TAG_compile_unit
175 Children: DW_CHILDREN_yes
177 - Attribute: DW_AT_producer
189 YAMLModuleTester
t(yamldata
);
190 DWARFUnit
*unit
= t
.GetDwarfUnit();
191 ASSERT_TRUE((bool)unit
);
192 EXPECT_EQ(unit
->GetProducer(), eProducerSwift
);
193 EXPECT_EQ(unit
->GetProducerVersion(), llvm::VersionTuple(1300, 0, 31, 1));