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,12 @@ +// Test dumping types does work even for -fdebug-types-section. + +// error: unsupported option '-fdebug-types-section' for target 'x86_64-apple-darwin20.1.0' +// UNSUPPORTED: system-darwin + +// 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/test/Shell/SymbolFile/DWARF/dwz-global-variable.c b/lldb/test/Shell/SymbolFile/DWARF/dwz-global-variable.c new file mode 100644 --- /dev/null +++ b/lldb/test/Shell/SymbolFile/DWARF/dwz-global-variable.c @@ -0,0 +1,24 @@ +// Test listing global variables when dwz -m is not in use. + +// REQUIRES: target-x86_64, system-linux, native + +// RUN: %clang_host -Wall -g -O2 -c -o %t-1.o %s -DMAIN +// RUN: %clang_host -Wall -g -O2 -c -o %t-2.o %s +// RUN: %clang_host -Wall -o %t %t-1.o %t-2.o +// RUN: (! which eu-strip dwz) || (! test -x /usr/lib/rpm/sepdebugcrcfix) || \ +// RUN: (eu-strip --remove-comment -f %t.debug %t && dwz %t.debug && \ +// RUN: /usr/lib/rpm/sepdebugcrcfix . "$(realpath --relative-to=$PWD %t)") +// RUN: %lldb %t -o 'b main' -o r -o 'target variable -c' \ +// RUN: -o exit | FileCheck %s + +// CHECK-LABEL: (lldb) target variable -c +// CHECK: `dwz-global-variable.c:{{[0-9]*}}: (const int) file_static_variable = 42 + +static const int file_static_variable = 42; +static const int make_it_dwz_worth = 42; +#ifdef MAIN +int func(void); +int main(void) { return func() + file_static_variable + make_it_dwz_worth; } +#else +int func(void) { return file_static_variable + make_it_dwz_worth; } +#endif 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; +using namespace lldb_private::repro; + +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 + + llvm::cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None)); + 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(); + Reproducer::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())); +}