1 //===-- DWARFDIETest.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/DWARFDIE.h"
10 #include "TestingSupport/Symbol/YAMLModuleTester.h"
11 #include "llvm/ADT/STLExtras.h"
12 #include "gmock/gmock.h"
13 #include "gtest/gtest.h"
16 using namespace lldb_private
;
17 using namespace lldb_private::plugin::dwarf
;
19 TEST(DWARFDIETest
, ChildIteration
) {
20 // Tests DWARFDIE::child_iterator.
22 const char *yamldata
= R
"(
33 Tag: DW_TAG_compile_unit
34 Children: DW_CHILDREN_yes
36 - Attribute: DW_AT_language
40 Children: DW_CHILDREN_no
42 - Attribute: DW_AT_encoding
44 - Attribute: DW_AT_byte_size
50 - AbbrCode: 0x00000001
52 - Value: 0x000000000000000C
53 - AbbrCode: 0x00000002
55 - Value: 0x0000000000000007 # DW_ATE_unsigned
56 - Value: 0x0000000000000004
57 - AbbrCode: 0x00000002
59 - Value: 0x0000000000000007 # DW_ATE_unsigned
60 - Value: 0x0000000000000008
61 - AbbrCode: 0x00000002
63 - Value: 0x0000000000000005 # DW_ATE_signed
64 - Value: 0x0000000000000008
65 - AbbrCode: 0x00000000
68 YAMLModuleTester
t(yamldata
);
69 ASSERT_TRUE((bool)t
.GetDwarfUnit());
71 DWARFUnit
*unit
= t
.GetDwarfUnit();
72 const DWARFDebugInfoEntry
*die_first
= unit
->DIE().GetDIE();
74 // Create a DWARFDIE that has three DW_TAG_base_type children.
75 DWARFDIE
top_die(unit
, die_first
);
77 // Create the iterator range that has the three tags as elements.
78 llvm::iterator_range
<DWARFDIE::child_iterator
> children
= top_die
.children();
80 // Compare begin() to the first child DIE.
81 DWARFDIE::child_iterator child_iter
= children
.begin();
82 ASSERT_NE(child_iter
, children
.end());
83 const DWARFDebugInfoEntry
*die_child0
= die_first
->GetFirstChild();
84 EXPECT_EQ((*child_iter
).GetDIE(), die_child0
);
86 // Step to the second child DIE.
88 ASSERT_NE(child_iter
, children
.end());
89 const DWARFDebugInfoEntry
*die_child1
= die_child0
->GetSibling();
90 EXPECT_EQ((*child_iter
).GetDIE(), die_child1
);
92 // Step to the third child DIE.
94 ASSERT_NE(child_iter
, children
.end());
95 const DWARFDebugInfoEntry
*die_child2
= die_child1
->GetSibling();
96 EXPECT_EQ((*child_iter
).GetDIE(), die_child2
);
98 // Step to the end of the range.
100 EXPECT_EQ(child_iter
, children
.end());
102 // Take one of the DW_TAG_base_type DIEs (which has no children) and make
103 // sure the children range is now empty.
104 DWARFDIE
no_children_die(unit
, die_child0
);
105 EXPECT_TRUE(no_children_die
.children().empty());