1 //===-- DWARFUnitTest.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 //===----------------------------------------------------------------------===//
8 
9 #include "Plugins/SymbolFile/DWARF/DWARFUnit.h"
10 #include "TestingSupport/Symbol/YAMLModuleTester.h"
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
13 
14 using namespace lldb;
15 using namespace lldb_private;
16 
17 TEST(DWARFUnitTest, NullUnitDie) {
18   // Make sure we don't crash parsing a null unit DIE.
19   const char *yamldata = R"(
20 --- !ELF
21 FileHeader:
22   Class:   ELFCLASS64
23   Data:    ELFDATA2LSB
24   Type:    ET_EXEC
25   Machine: EM_386
26 DWARF:
27   debug_abbrev:
28     - Table:
29         - Code:            0x00000001
30           Tag:             DW_TAG_compile_unit
31           Children:        DW_CHILDREN_yes
32           Attributes:
33             - Attribute:       DW_AT_language
34               Form:            DW_FORM_data2
35   debug_info:
36     - Version:         4
37       AddrSize:        8
38       Entries:
39         - AbbrCode:        0x00000000
40 )";
41 
42   YAMLModuleTester t(yamldata);
43   ASSERT_TRUE((bool)t.GetDwarfUnit());
44 
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());
49 }
50