Merge branch 'addmainunit3-altlink-sharedstmt-dieref-dwz3-testcategory' into addmainu...
authorJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 20 Jan 2021 23:46:16 +0000 (00:46 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Wed, 20 Jan 2021 23:46:16 +0000 (00:46 +0100)
lldb/test/Shell/SymbolFile/DWARF/dump-debug-types.cpp [new file with mode: 0644]
lldb/unittests/SymbolFile/CMakeLists.txt
lldb/unittests/SymbolFile/DWZ/CMakeLists.txt [new file with mode: 0644]
lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.c [new file with mode: 0644]
lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.debug [new file with mode: 0755]
lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.debug.dwz [new file with mode: 0644]
lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.out [new file with mode: 0755]
lldb/unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp [new file with mode: 0644]

diff --git a/lldb/test/Shell/SymbolFile/DWARF/dump-debug-types.cpp b/lldb/test/Shell/SymbolFile/DWARF/dump-debug-types.cpp
new file mode 100644 (file)
index 0000000..51f2334
--- /dev/null
@@ -0,0 +1,12 @@
+// XFAIL: target-arm && linux-gnu
+// UNSUPPORTED: system-windows
+//
+// Test to verify we are correctly generating anonymous flags when parsing
+// anonymous class and unnamed structs from DWARF to the a clang AST node.
+
+// RUN: %clangxx_host -g -fdebug-types-section -c -o %t.o %s
+// RUN: lldb-test symbols -dump-clang-ast %t.o | FileCheck %s
+
+struct StructName {} a;
+
+// CHECK: StructName
index 804555f..8c114b6 100644 (file)
@@ -1,5 +1,6 @@
 add_subdirectory(DWARF)
 add_subdirectory(NativePDB)
+add_subdirectory(DWZ)
 if (LLVM_ENABLE_DIA_SDK)
   add_subdirectory(PDB)
 endif()
diff --git a/lldb/unittests/SymbolFile/DWZ/CMakeLists.txt b/lldb/unittests/SymbolFile/DWZ/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3626c21
--- /dev/null
@@ -0,0 +1,21 @@
+add_lldb_unittest(SymbolFileDWZTests
+  SymbolFileDWZTests.cpp
+
+  LINK_LIBS
+    lldbCore
+    lldbHost
+    lldbSymbol
+    lldbPluginSymbolFileDWARF
+    lldbUtilityHelpers
+    lldbPluginObjectFileELF
+    lldbPluginSymbolVendorELF
+  LINK_COMPONENTS
+    Support
+  )
+
+set(test_inputs
+   dwztest.out
+   dwztest.debug
+   dwztest.debug.dwz)
+
+add_unittest_inputs(SymbolFileDWZTests "${test_inputs}")
diff --git a/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.c b/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.c
new file mode 100644 (file)
index 0000000..a57e070
--- /dev/null
@@ -0,0 +1,11 @@
+// gcc -Wall -g -o dwztest.out dwztest.c; eu-strip --remove-comment -f
+// dwztest.debug dwztest.out; cp -p dwztest.debug dwztest.debug.dup; dwz -m
+// dwztest.debug.dwz dwztest.debug dwztest.debug.dup;rm dwztest.debug.dup;
+// /usr/lib/rpm/sepdebugcrcfix . dwztest.out
+
+struct StructMovedToDWZCommonFile {
+  int i1, i2, i3, i4, i5, i6, i7, i8, i9;
+} VarWithStructMovedToDWZCommonFile;
+static const int sizeof_StructMovedToDWZCommonFile =
+    sizeof(struct StructMovedToDWZCommonFile);
+int main() { return sizeof_StructMovedToDWZCommonFile; }
diff --git a/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.debug b/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.debug
new file mode 100755 (executable)
index 0000000..c18e7f2
Binary files /dev/null and b/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.debug differ
diff --git a/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.debug.dwz b/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.debug.dwz
new file mode 100644 (file)
index 0000000..44be34f
Binary files /dev/null and b/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.debug.dwz differ
diff --git a/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.out b/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.out
new file mode 100755 (executable)
index 0000000..c96d464
Binary files /dev/null and b/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.out differ
diff --git a/lldb/unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp b/lldb/unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp
new file mode 100644 (file)
index 0000000..56ba878
--- /dev/null
@@ -0,0 +1,88 @@
+//===-- SymbolFileDWZTests.cpp ----------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "TestingSupport/TestUtilities.h"
+
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
+#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Host/HostInfo.h"
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/FileSpec.h"
+
+#if defined(_MSC_VER)
+#include "lldb/Host/windows/windows.h"
+#include <objbase.h>
+#endif
+
+#include <algorithm>
+
+using namespace lldb_private;
+
+class SymbolFileDWZTests : public testing::Test {
+public:
+  void SetUp() override {
+// Initialize and TearDown the plugin every time, so we get a brand new
+// AST every time so that modifications to the AST from each test don't
+// leak into the next test.
+#if defined(_MSC_VER)
+    ::CoInitializeEx(nullptr, COINIT_MULTITHREADED);
+#endif
+
+    FileSystem::Initialize();
+    HostInfo::Initialize();
+    SymbolFileDWARF::Initialize();
+    TypeSystemClang::Initialize();
+    ObjectFileELF::Initialize();
+    SymbolVendorELF::Initialize();
+
+    m_dwztest_out = GetInputFilePath("dwztest.out");
+  }
+
+  void TearDown() override {
+    SymbolVendorELF::Terminate();
+    ObjectFileELF::Terminate();
+    TypeSystemClang::Terminate();
+    SymbolFileDWARF::Terminate();
+    HostInfo::Terminate();
+    FileSystem::Terminate();
+
+#if defined(_MSC_VER)
+    ::CoUninitialize();
+#endif
+  }
+
+protected:
+  std::string m_dwztest_out;
+};
+
+TEST_F(SymbolFileDWZTests, TestSimpleClassTypes) {
+  FileSpec fspec(m_dwztest_out);
+  ArchSpec aspec("x86_64-pc-linux");
+  lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
+
+  SymbolFile *symfile = module->GetSymbolFile();
+  EXPECT_NE(nullptr, symfile);
+  EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic());
+  SymbolContext sc;
+  llvm::DenseSet<SymbolFile *> searched_files;
+  TypeMap results;
+  symfile->FindTypes(ConstString("StructMovedToDWZCommonFile"), CompilerDeclContext(), 0,
+                     searched_files, results);
+  EXPECT_EQ(1u, results.GetSize());
+  lldb::TypeSP udt_type = results.GetTypeAtIndex(0);
+  EXPECT_EQ(ConstString("StructMovedToDWZCommonFile"), udt_type->GetName());
+  CompilerType compiler_type = udt_type->GetForwardCompilerType();
+  EXPECT_TRUE(TypeSystemClang::IsClassType(compiler_type.GetOpaqueQualType()));
+}