1 //===-- XcodeSDKModuleTests.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/Platform/MacOSX/PlatformMacOSX.h"
10 #include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h"
11 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
12 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
13 #include "TestingSupport/Symbol/YAMLModuleTester.h"
14 #include "lldb/Core/PluginManager.h"
15 #include "gmock/gmock.h"
16 #include "gtest/gtest.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 #ifdef __APPLE__
22 namespace {
23 class XcodeSDKModuleTests : public testing::Test {
24   SubsystemRAII<HostInfoBase, PlatformMacOSX> subsystems;
25 };
26 } // namespace
27 
28 
TEST_F(XcodeSDKModuleTests,TestModuleGetXcodeSDK)29 TEST_F(XcodeSDKModuleTests, TestModuleGetXcodeSDK) {
30   const char *yamldata = R"(
31 --- !ELF
32 FileHeader:
33   Class:   ELFCLASS64
34   Data:    ELFDATA2LSB
35   Type:    ET_EXEC
36   Machine: EM_386
37 DWARF:
38   debug_str:
39     - MacOSX10.9.sdk
40   debug_abbrev:
41     - Table:
42         - Code:            0x00000001
43           Tag:             DW_TAG_compile_unit
44           Children:        DW_CHILDREN_no
45           Attributes:
46             - Attribute:       DW_AT_language
47               Form:            DW_FORM_data2
48             - Attribute:       DW_AT_APPLE_sdk
49               Form:            DW_FORM_strp
50   debug_info:
51     - Version:         2
52       AddrSize:        8
53       Entries:
54         - AbbrCode:        0x00000001
55           Values:
56             - Value:           0x000000000000000C
57             - Value:           0x0000000000000000
58         - AbbrCode:        0x00000000
59 ...
60 )";
61 
62   YAMLModuleTester t(yamldata);
63   DWARFUnit *dwarf_unit = t.GetDwarfUnit();
64   auto *dwarf_cu = llvm::cast<DWARFCompileUnit>(dwarf_unit);
65   ASSERT_TRUE(static_cast<bool>(dwarf_cu));
66   SymbolFileDWARF &sym_file = dwarf_cu->GetSymbolFileDWARF();
67   CompUnitSP comp_unit = sym_file.GetCompileUnitAtIndex(0);
68   ASSERT_TRUE(static_cast<bool>(comp_unit.get()));
69   ModuleSP module = t.GetModule();
70   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 0u);
71   XcodeSDK sdk = sym_file.ParseXcodeSDK(*comp_unit);
72   ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
73   ASSERT_EQ(module->GetSourceMappingList().GetSize(), 1u);
74 }
75 #endif
76