[Lldb-commits] [lldb] 06e4f69 - Add a getter to retrieve the XcodeSDK from Module and unit-test it. (NFC)

Adrian Prantl via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 24 17:00:56 PDT 2020


Author: Adrian Prantl
Date: 2020-04-24T17:00:34-07:00
New Revision: 06e4f69b225753af396a28be69637f4fc2d8839d

URL: https://github.com/llvm/llvm-project/commit/06e4f69b225753af396a28be69637f4fc2d8839d
DIFF: https://github.com/llvm/llvm-project/commit/06e4f69b225753af396a28be69637f4fc2d8839d.diff

LOG: Add a getter to retrieve the XcodeSDK from Module and unit-test it. (NFC)

This API is used by swift-lldb.

(Recommit with missing file git-added)

Added: 
    lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp

Modified: 
    lldb/include/lldb/Core/Module.h
    lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
    lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
    lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp
    lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/Module.h b/lldb/include/lldb/Core/Module.h
index 35d00d295fa8..c8cb03e2dee8 100644
--- a/lldb/include/lldb/Core/Module.h
+++ b/lldb/include/lldb/Core/Module.h
@@ -864,6 +864,11 @@ class Module : public std::enable_shared_from_this<Module>,
   bool RemapSourceFile(llvm::StringRef path, std::string &new_path) const;
   bool RemapSourceFile(const char *, std::string &) const = delete;
 
+  /// Return the Xcode SDK this module was compiled against.  This
+  /// is computed by merging the SDKs from each compilation unit in
+  /// the module.
+  XcodeSDK GetXcodeSDK() const { return m_xcode_sdk; }
+
   /// Update the ArchSpec to a more specific variant.
   bool MergeArchitecture(const ArchSpec &arch_spec);
 

diff  --git a/lldb/unittests/SymbolFile/DWARF/CMakeLists.txt b/lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
index 0a4d3cc2938d..ece8266d7ffd 100644
--- a/lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
+++ b/lldb/unittests/SymbolFile/DWARF/CMakeLists.txt
@@ -1,6 +1,7 @@
 add_lldb_unittest(SymbolFileDWARFTests
   DWARFASTParserClangTests.cpp
   SymbolFileDWARFTests.cpp
+  XcodeSDKModuleTests.cpp
 
   LINK_LIBS
     lldbCore

diff  --git a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
index 4ec76bda8646..21c2d165c37b 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
+#include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "gmock/gmock.h"
@@ -114,3 +115,47 @@ TEST_F(DWARFASTParserClangTests,
   EXPECT_THAT(ast_parser.GetDeclContextToDIEMapKeys(),
               testing::UnorderedElementsAre(decl_ctxs[0], decl_ctxs[3]));
 }
+
+
+#ifndef __APPLE__
+TEST_F(DWARFASTParserClangTests, TestXcodeSDK) {
+  PlatformDarwin::Initialize();
+  const char *yamldata = R"(
+debug_str:
+  - MacOSX10.9.sdk
+debug_abbrev:
+  - Code:            0x00000001
+    Tag:             DW_TAG_compile_unit
+    Children:        DW_CHILDREN_no
+    Attributes:
+      - Attribute:       DW_AT_language
+        Form:            DW_FORM_data2
+      - Attribute:       DW_AT_APPLE_sdk
+        Form:            DW_FORM_strp
+debug_info:
+  - Length:
+      TotalLength:     8
+    Version:         2
+    AbbrOffset:      0
+    AddrSize:        8
+    Entries:
+      - AbbrCode:        0x00000001
+        Values:
+          - Value:           0x000000000000000C
+          - Value:           0x0000000000000000
+      - AbbrCode:        0x00000000
+        Values:          []
+...
+)";
+
+  YAMLModuleTester t(yamldata, "x86_64-apple-macosx");
+  auto dwarf_unit_sp = t.GetDwarfUnit();
+  auto *dwarf_cu = llvm::cast<DWARFCompileUnit>(dwarf_unit_sp.get());
+  ASSERT_TRUE((bool)dwarf_cu);
+  ASSERT_TRUE((bool)dwarf_cu->GetSymbolFileDWARF().GetCompUnitForDWARFCompUnit(
+      *dwarf_cu));
+  auto module = t.GetModule();
+  XcodeSDK sdk = module->GetXcodeSDK();
+  ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
+}
+#endif

diff  --git a/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp b/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
new file mode 100644
index 000000000000..43c67c65bfe7
--- /dev/null
+++ b/lldb/unittests/SymbolFile/DWARF/XcodeSDKModuleTests.cpp
@@ -0,0 +1,67 @@
+//===-- XcodeSDKModuleTests.cpp -------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h"
+#include "Plugins/SymbolFile/DWARF/DWARFCompileUnit.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
+#include "TestingSupport/Symbol/YAMLModuleTester.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+#ifndef __APPLE__
+namespace {
+class XcodeSDKModuleTests : public testing::Test {
+  void SetUp() override { PlatformDarwin::Initialize(); }
+  void TearDown() override { PlatformDarwin::Terminate(); }
+};
+} // namespace
+
+
+TEST_F(XcodeSDKModuleTests, TestModuleGetXcodeSDK) {
+  const char *yamldata = R"(
+debug_str:
+  - MacOSX10.9.sdk
+debug_abbrev:
+  - Code:            0x00000001
+    Tag:             DW_TAG_compile_unit
+    Children:        DW_CHILDREN_no
+    Attributes:
+      - Attribute:       DW_AT_language
+        Form:            DW_FORM_data2
+      - Attribute:       DW_AT_APPLE_sdk
+        Form:            DW_FORM_strp
+debug_info:
+  - Length:
+      TotalLength:     8
+    Version:         2
+    AbbrOffset:      0
+    AddrSize:        8
+    Entries:
+      - AbbrCode:        0x00000001
+        Values:
+          - Value:           0x000000000000000C
+          - Value:           0x0000000000000000
+      - AbbrCode:        0x00000000
+        Values:          []
+...
+)";
+
+  YAMLModuleTester t(yamldata, "x86_64-apple-macosx");
+  auto dwarf_unit_sp = t.GetDwarfUnit();
+  auto *dwarf_cu = llvm::cast<DWARFCompileUnit>(dwarf_unit_sp.get());
+  ASSERT_TRUE((bool)dwarf_cu);
+  ASSERT_TRUE((bool)dwarf_cu->GetSymbolFileDWARF().GetCompUnitForDWARFCompUnit(
+      *dwarf_cu));
+  auto module = t.GetModule();
+  XcodeSDK sdk = module->GetXcodeSDK();
+  ASSERT_EQ(sdk.GetType(), XcodeSDK::Type::MacOSX);
+}
+#endif

diff  --git a/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp b/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp
index 59b6bcc123ea..f40ff1db8232 100644
--- a/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp
+++ b/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.cpp
@@ -51,7 +51,8 @@ class YAMLObjectFile : public lldb_private::ObjectFile {
       lldb::SectionType sect_type =
           llvm::StringSwitch<lldb::SectionType>(name)
               .Case("debug_info", lldb::eSectionTypeDWARFDebugInfo)
-              .Case("debug_abbrev", lldb::eSectionTypeDWARFDebugAbbrev);
+              .Case("debug_abbrev", lldb::eSectionTypeDWARFDebugAbbrev)
+              .Case("debug_str", lldb::eSectionTypeDWARFDebugStr);
       auto &membuf = entry.getValue();
       lldb::addr_t file_vm_addr = 0;
       lldb::addr_t vm_size = 0;

diff  --git a/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h b/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h
index c8ce1310f629..7a638b56e872 100644
--- a/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h
+++ b/lldb/unittests/TestingSupport/Symbol/YAMLModuleTester.h
@@ -32,7 +32,8 @@ class YAMLModuleTester {
 public:
   /// Parse the debug info sections from the YAML description.
   YAMLModuleTester(llvm::StringRef yaml_data, llvm::StringRef triple);
-  DWARFUnitSP GetDwarfUnit() { return m_dwarf_unit; }
+  DWARFUnitSP GetDwarfUnit() const { return m_dwarf_unit; }
+  lldb::ModuleSP GetModule() const { return m_module_sp; }
 };
 
 } // namespace lldb_private


        


More information about the lldb-commits mailing list