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 --- /dev/null +++ b/lldb/test/Shell/SymbolFile/DWARF/dump-debug-types.cpp @@ -0,0 +1,9 @@ +// Test dumping types does work even for -fdebug-types-section. + +// 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 diff --git a/lldb/unittests/SymbolFile/CMakeLists.txt b/lldb/unittests/SymbolFile/CMakeLists.txt --- a/lldb/unittests/SymbolFile/CMakeLists.txt +++ b/lldb/unittests/SymbolFile/CMakeLists.txt @@ -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 --- /dev/null +++ b/lldb/unittests/SymbolFile/DWZ/CMakeLists.txt @@ -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 --- /dev/null +++ b/lldb/unittests/SymbolFile/DWZ/Inputs/dwztest.c @@ -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 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ +#endif + +#include + +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(fspec, aspec); + + SymbolFile *symfile = module->GetSymbolFile(); + EXPECT_NE(nullptr, symfile); + EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic()); + SymbolContext sc; + llvm::DenseSet 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())); +}