[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / SymbolFile / DWARF / DWARFDIETest.cpp
blob8497855b2f3db596397a0c587631eef8cc61d9be
1 //===-- DWARFDIETest.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-exception
6 //
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"
15 using namespace lldb;
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"(
23 --- !ELF
24 FileHeader:
25 Class: ELFCLASS64
26 Data: ELFDATA2LSB
27 Type: ET_EXEC
28 Machine: EM_386
29 DWARF:
30 debug_abbrev:
31 - Table:
32 - Code: 0x00000001
33 Tag: DW_TAG_compile_unit
34 Children: DW_CHILDREN_yes
35 Attributes:
36 - Attribute: DW_AT_language
37 Form: DW_FORM_data2
38 - Code: 0x00000002
39 Tag: DW_TAG_base_type
40 Children: DW_CHILDREN_no
41 Attributes:
42 - Attribute: DW_AT_encoding
43 Form: DW_FORM_data1
44 - Attribute: DW_AT_byte_size
45 Form: DW_FORM_data1
46 debug_info:
47 - Version: 4
48 AddrSize: 8
49 Entries:
50 - AbbrCode: 0x00000001
51 Values:
52 - Value: 0x000000000000000C
53 - AbbrCode: 0x00000002
54 Values:
55 - Value: 0x0000000000000007 # DW_ATE_unsigned
56 - Value: 0x0000000000000004
57 - AbbrCode: 0x00000002
58 Values:
59 - Value: 0x0000000000000007 # DW_ATE_unsigned
60 - Value: 0x0000000000000008
61 - AbbrCode: 0x00000002
62 Values:
63 - Value: 0x0000000000000005 # DW_ATE_signed
64 - Value: 0x0000000000000008
65 - AbbrCode: 0x00000000
66 )";
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.
87 ++child_iter;
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.
93 ++child_iter;
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.
99 ++child_iter;
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());