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
;
17 TEST(DWARFUnitTest
, NullUnitDie
) {
18 // Make sure we don't crash parsing a null unit DIE.
19 const char *yamldata
= R
"(
30 Tag: DW_TAG_compile_unit
31 Children: DW_CHILDREN_yes
33 - Attribute: DW_AT_language
39 - AbbrCode: 0x00000000
42 YAMLModuleTester
t(yamldata
);
43 ASSERT_TRUE((bool)t
.GetDwarfUnit());
45 DWARFUnit
*unit
= t
.GetDwarfUnit();
46 const DWARFDebugInfoEntry
*die_first
= unit
->DIE().GetDIE();
47 ASSERT_NE(die_first
, nullptr);
48 EXPECT_TRUE(die_first
->IsNULL());
51 TEST(DWARFUnitTest
, MissingSentinel
) {
52 // Make sure we don't crash if the debug info is missing a null DIE sentinel.
53 const char *yamldata
= R
"(
64 Tag: DW_TAG_compile_unit
65 Children: DW_CHILDREN_yes
67 - Attribute: DW_AT_language
73 - AbbrCode: 0x00000001
75 - Value: 0x000000000000000C
78 YAMLModuleTester
t(yamldata
);
79 ASSERT_TRUE((bool)t
.GetDwarfUnit());
81 DWARFUnit
*unit
= t
.GetDwarfUnit();
82 const DWARFDebugInfoEntry
*die_first
= unit
->DIE().GetDIE();
83 ASSERT_NE(die_first
, nullptr);
84 EXPECT_EQ(die_first
->GetFirstChild(), nullptr);
85 EXPECT_EQ(die_first
->GetSibling(), nullptr);
88 TEST(DWARFUnitTest
, ClangProducer
) {
89 const char *yamldata
= R
"(
98 - 'Apple clang version 13.0.0 (clang-1300.0.29.3)'
102 Tag: DW_TAG_compile_unit
103 Children: DW_CHILDREN_yes
105 - Attribute: DW_AT_producer
117 YAMLModuleTester
t(yamldata
);
118 DWARFUnit
*unit
= t
.GetDwarfUnit();
119 ASSERT_TRUE((bool)unit
);
120 EXPECT_EQ(unit
->GetProducer(), eProducerClang
);
121 EXPECT_EQ(unit
->GetProducerVersion(), llvm::VersionTuple(1300, 0, 29, 3));
124 TEST(DWARFUnitTest
, LLVMGCCProducer
) {
125 const char *yamldata
= R
"(
134 - 'i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)'
138 Tag: DW_TAG_compile_unit
139 Children: DW_CHILDREN_yes
141 - Attribute: DW_AT_producer
153 YAMLModuleTester
t(yamldata
);
154 DWARFUnit
*unit
= t
.GetDwarfUnit();
155 ASSERT_TRUE((bool)unit
);
156 EXPECT_EQ(unit
->GetProducer(), eProducerLLVMGCC
);
159 TEST(DWARFUnitTest
, SwiftProducer
) {
160 const char *yamldata
= R
"(
169 - 'Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)'
173 Tag: DW_TAG_compile_unit
174 Children: DW_CHILDREN_yes
176 - Attribute: DW_AT_producer
188 YAMLModuleTester
t(yamldata
);
189 DWARFUnit
*unit
= t
.GetDwarfUnit();
190 ASSERT_TRUE((bool)unit
);
191 EXPECT_EQ(unit
->GetProducer(), eProducerSwift
);
192 EXPECT_EQ(unit
->GetProducerVersion(), llvm::VersionTuple(1300, 0, 31, 1));