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
;
18 TEST(DWARFDIETest
, ChildIteration
) {
19 // Tests DWARFDIE::child_iterator.
21 const char *yamldata
= R
"(
32 Tag: DW_TAG_compile_unit
33 Children: DW_CHILDREN_yes
35 - Attribute: DW_AT_language
39 Children: DW_CHILDREN_no
41 - Attribute: DW_AT_encoding
43 - Attribute: DW_AT_byte_size
49 - AbbrCode: 0x00000001
51 - Value: 0x000000000000000C
52 - AbbrCode: 0x00000002
54 - Value: 0x0000000000000007 # DW_ATE_unsigned
55 - Value: 0x0000000000000004
56 - AbbrCode: 0x00000002
58 - Value: 0x0000000000000007 # DW_ATE_unsigned
59 - Value: 0x0000000000000008
60 - AbbrCode: 0x00000002
62 - Value: 0x0000000000000005 # DW_ATE_signed
63 - Value: 0x0000000000000008
64 - AbbrCode: 0x00000000
67 YAMLModuleTester
t(yamldata
);
68 ASSERT_TRUE((bool)t
.GetDwarfUnit());
70 DWARFUnit
*unit
= t
.GetDwarfUnit();
71 const DWARFDebugInfoEntry
*die_first
= unit
->DIE().GetDIE();
73 // Create a DWARFDIE that has three DW_TAG_base_type children.
74 DWARFDIE
top_die(unit
, die_first
);
76 // Create the iterator range that has the three tags as elements.
77 llvm::iterator_range
<DWARFDIE::child_iterator
> children
= top_die
.children();
79 // Compare begin() to the first child DIE.
80 DWARFDIE::child_iterator child_iter
= children
.begin();
81 ASSERT_NE(child_iter
, children
.end());
82 const DWARFDebugInfoEntry
*die_child0
= die_first
->GetFirstChild();
83 EXPECT_EQ((*child_iter
).GetDIE(), die_child0
);
85 // Step to the second child DIE.
87 ASSERT_NE(child_iter
, children
.end());
88 const DWARFDebugInfoEntry
*die_child1
= die_child0
->GetSibling();
89 EXPECT_EQ((*child_iter
).GetDIE(), die_child1
);
91 // Step to the third child DIE.
93 ASSERT_NE(child_iter
, children
.end());
94 const DWARFDebugInfoEntry
*die_child2
= die_child1
->GetSibling();
95 EXPECT_EQ((*child_iter
).GetDIE(), die_child2
);
97 // Step to the end of the range.
99 EXPECT_EQ(child_iter
, children
.end());
101 // Take one of the DW_TAG_base_type DIEs (which has no children) and make
102 // sure the children range is now empty.
103 DWARFDIE
no_children_die(unit
, die_child0
);
104 EXPECT_TRUE(no_children_die
.children().empty());