jankratochvil updated this revision to Diff 135063.
jankratochvil retitled this revision from "DWZ 12/12: DWZ test mode" to "DWZ
10/11: DWZ test mode".
jankratochvil added a comment.
Herald added subscribers: JDevlieghere, mgorny.
It now includes also unittests/SymbolFile/DWZ/ which should PASS even on
systems without DWZ tool(s).
https://reviews.llvm.org/D40475
Files:
packages/Python/lldbsuite/test/lldbinline.py
packages/Python/lldbsuite/test/lldbtest.py
packages/Python/lldbsuite/test/make/Makefile.rules
packages/Python/lldbsuite/test/plugins/builder_base.py
packages/Python/lldbsuite/test/test_categories.py
unittests/SymbolFile/CMakeLists.txt
unittests/SymbolFile/DWZ/CMakeLists.txt
unittests/SymbolFile/DWZ/Inputs/dwztest.c
unittests/SymbolFile/DWZ/Inputs/dwztest.debug
unittests/SymbolFile/DWZ/Inputs/dwztest.debug.dwz
unittests/SymbolFile/DWZ/Inputs/dwztest.out
unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp
Index: unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp
===================================================================
--- /dev/null
+++ unittests/SymbolFile/DWZ/SymbolFileDWZTests.cpp
@@ -0,0 +1,89 @@
+//===-- 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/SymbolFile/DWARF/SymbolFileDWARF.h"
+#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
+#include "lldb/Core/Module.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/ClangASTContext.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
+
+ HostInfo::Initialize();
+ SymbolFileDWARF::Initialize();
+ ClangASTContext::Initialize();
+ ObjectFileELF::Initialize();
+ SymbolVendorELF::Initialize();
+
+ m_dwztest_out = GetInputFilePath("dwztest.out");
+ }
+
+ void TearDown() override {
+ SymbolVendorELF::Terminate();
+ ObjectFileELF::Terminate();
+ ClangASTContext::Terminate();
+ SymbolFileDWARF::Terminate();
+ HostInfo::Terminate();
+
+#if defined(_MSC_VER)
+ ::CoUninitialize();
+#endif
+ }
+
+protected:
+ std::string m_dwztest_out;
+};
+
+TEST_F(SymbolFileDWZTests, TestSimpleClassTypes) {
+ FileSpec fspec(m_dwztest_out.c_str(), false);
+ ArchSpec aspec("x86_64-pc-linux");
+ lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
+
+ SymbolVendor *plugin = module->GetSymbolVendor();
+ EXPECT_NE(nullptr, plugin);
+ SymbolFile *symfile = plugin->GetSymbolFile();
+ EXPECT_NE(nullptr, symfile);
+ EXPECT_EQ(symfile->GetPluginName(), SymbolFileDWARF::GetPluginNameStatic());
+ SymbolContext sc;
+ llvm::DenseSet<SymbolFile *> searched_files;
+ TypeMap results;
+ EXPECT_EQ(1u,
+ symfile->FindTypes(sc, ConstString("StructMovedToDWZCommonFile"), nullptr,
+ false, 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(ClangASTContext::IsClassType(compiler_type.GetOpaqueQualType()));
+}
Index: unittests/SymbolFile/DWZ/Inputs/dwztest.c
===================================================================
--- /dev/null
+++ unittests/SymbolFile/DWZ/Inputs/dwztest.c
@@ -0,0 +1,9 @@
+// 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;
+}
Index: unittests/SymbolFile/DWZ/CMakeLists.txt
===================================================================
--- /dev/null
+++ 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}")
Index: unittests/SymbolFile/CMakeLists.txt
===================================================================
--- unittests/SymbolFile/CMakeLists.txt
+++ unittests/SymbolFile/CMakeLists.txt
@@ -1,4 +1,5 @@
add_subdirectory(DWARF)
+add_subdirectory(DWZ)
if (LLVM_ENABLE_DIA_SDK)
add_subdirectory(PDB)
endif()
Index: packages/Python/lldbsuite/test/test_categories.py
===================================================================
--- packages/Python/lldbsuite/test/test_categories.py
+++ packages/Python/lldbsuite/test/test_categories.py
@@ -7,6 +7,8 @@
# System modules
import sys
+import os
+import distutils.spawn
# Third-party modules
@@ -38,6 +40,12 @@
'watchpoint': 'Watchpoint-related tests',
}
+if (os.access("/usr/lib/rpm/sepdebugcrcfix", os.X_OK)
+ and distutils.spawn.find_executable("eu-strip") is not None
+ and distutils.spawn.find_executable("dwz") is not None):
+ debug_info_categories.append('dwz')
+ all_categories['dwz'] = 'Tests using DWZ and its DWARF partial units';
+
def unique_string_match(yourentry, list):
candidate = None
@@ -61,6 +69,8 @@
if platform not in ["linux", "freebsd", "darwin", "macosx", "ios", "watchos", "tvos", "bridgeos"]:
return False
return gmodules.is_compiler_clang_with_gmodules(compiler_path)
+ elif category == "dwz":
+ return platform in ["linux"]
return True
Index: packages/Python/lldbsuite/test/plugins/builder_base.py
===================================================================
--- packages/Python/lldbsuite/test/plugins/builder_base.py
+++ packages/Python/lldbsuite/test/plugins/builder_base.py
@@ -226,6 +226,24 @@
# True signifies that we can handle building with gmodules.
return True
+def buildDwz(
+ sender=None,
+ architecture=None,
+ compiler=None,
+ dictionary=None,
+ clean=True):
+ """Build the binaries with type units (type in a .debug_types section)."""
+ commands = []
+ if clean:
+ commands.append([getMake(), "clean", getCmdLine(dictionary)])
+ # dwz has a bug being unable to process non-separated debug info.
+ commands.append([getMake(), "MAKE_DSYM=NO", "DWZ=YES",
+ getArchSpec(architecture), getCCSpec(compiler),
+ getCmdLine(dictionary)])
+
+ runBuildCommands(commands, sender=sender)
+ # True signifies that we can handle building dwo.
+ return True
def cleanup(sender=None, dictionary=None):
"""Perform a platform-specific cleanup after the test."""
Index: packages/Python/lldbsuite/test/make/Makefile.rules
===================================================================
--- packages/Python/lldbsuite/test/make/Makefile.rules
+++ packages/Python/lldbsuite/test/make/Makefile.rules
@@ -19,6 +19,7 @@
# LD_EXTRAS :=
# SPLIT_DEBUG_SYMBOLS := YES
# CROSS_COMPILE :=
+# DWZ := YES
#
# And test/functionalities/archives/Makefile:
# MAKE_DSYM := NO
@@ -318,6 +319,19 @@
LDFLAGS += -pie
endif
+#----------------------------------------------------------------------
+# Make the dSYM file from the executable if $(DWZ) = "YES"
+#----------------------------------------------------------------------
+ifeq "$(DWZ)" "YES"
+ dwz_strip = \
+ eu-strip --remove-comment -f "$(1).debug" "$(1)" \
+ && cp "$(1).debug" "$(1).debug.dup" \
+ && dwz -m "$(1).debug.dwz" "$(1).debug" "$(1).debug.dup" \
+ && /usr/lib/rpm/sepdebugcrcfix . "$(1)"
+else
+ dwz_strip =
+endif
+
#----------------------------------------------------------------------
# Windows specific options
#----------------------------------------------------------------------
@@ -502,12 +516,14 @@
ifeq "$(DYLIB_ONLY)" ""
$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME)
$(LD) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) $(LDFLAGS) -o "$(EXE)"
+ $(call dwz_strip,$(EXE))
else
EXE = $(DYLIB_FILENAME)
endif
else
$(EXE) : $(OBJECTS) $(ARCHIVE_NAME)
$(LD) $(OBJECTS) $(LDFLAGS) $(ARCHIVE_NAME) -o "$(EXE)"
+ $(call dwz_strip,$(EXE))
endif
#----------------------------------------------------------------------
@@ -563,6 +579,7 @@
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
endif
+ $(call dwz_strip,$(DYLIB_FILENAME))
endif
#----------------------------------------------------------------------
@@ -648,6 +665,7 @@
ifneq "$(DYLIB_NAME)" ""
$(RM) -r $(DYLIB_FILENAME).dSYM
$(RM) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_PREREQS:.d=.d.tmp) $(DYLIB_DWOS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).debug
+ $(RM) $(DYLIB_FILENAME).debug.dup $(DYLIB_FILENAME).debug.dwz
endif
ifneq "$(PCH_OUTPUT)" ""
$(RM) $(PCH_OUTPUT)
@@ -663,7 +681,7 @@
$(RM) $(DYLIB_NAME).lib $(DYLIB_NAME).exp
endif
else
- $(RM) "$(EXE)"
+ $(RM) "$(EXE)" "$(EXE).debug" "$(EXE).debug.dup" "$(EXE).debug.dwz"
endif
#----------------------------------------------------------------------
Index: packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- packages/Python/lldbsuite/test/lldbtest.py
+++ packages/Python/lldbsuite/test/lldbtest.py
@@ -1589,6 +1589,22 @@
dictionary, clean, testdir, testname):
raise Exception("Don't know how to build binary with gmodules")
+ def buildDwz(
+ self,
+ architecture=None,
+ compiler=None,
+ dictionary=None,
+ clean=True):
+ """Platform specific way to build binaries with dwz optimizer."""
+ module = builder_module()
+ if not module.buildDwz(
+ self,
+ architecture,
+ compiler,
+ dictionary,
+ clean):
+ raise Exception("Don't know how to build binary with DWZ")
+
def buildGo(self):
"""Build the default go binary.
"""
@@ -1802,6 +1818,16 @@
gmodules_test_method.debug_info = "gmodules"
newattrs[gmodules_method_name] = gmodules_test_method
+ if "dwz" in supported_categories:
+ @decorators.add_test_categories(["dwz"])
+ @wraps(attrvalue)
+ def dwz_test_method(self, attrvalue=attrvalue):
+ self.debug_info = "dwz"
+ return attrvalue(self)
+ dwz_method_name = attrname + "_dwz"
+ dwz_test_method.__name__ = dwz_method_name
+ newattrs[dwz_method_name] = dwz_test_method
+
else:
newattrs[attrname] = attrvalue
return super(
@@ -2325,6 +2351,8 @@
elif self.getDebugInfo() == "gmodules":
return self.buildGModules(architecture, compiler, dictionary,
clean)
+ elif self.debug_info == "dwz":
+ return self.buildDwz(architecture, compiler, dictionary, clean)
else:
self.fail("Can't build for debug info: %s" % self.getDebugInfo())
Index: packages/Python/lldbsuite/test/lldbinline.py
===================================================================
--- packages/Python/lldbsuite/test/lldbinline.py
+++ packages/Python/lldbsuite/test/lldbinline.py
@@ -168,6 +168,12 @@
self.do_test()
__test_with_gmodules.debug_info = "gmodules"
+ def __test_with_dwz(self):
+ self.using_dsym = False
+ self.BuildMakefile()
+ self.buildDwz()
+ self.do_test()
+
def execute_user_command(self, __command):
exec(__command, globals(), locals())
@@ -250,6 +256,10 @@
"gmodules", target_platform, configuration.compiler):
test.test_with_gmodules = ApplyDecoratorsToFunction(
test._InlineTest__test_with_gmodules, decorators)
+ if test_categories.is_supported_on_platform(
+ "dwz", target_platform, configuration.compiler):
+ test.test_with_dwz = ApplyDecoratorsToFunction(
+ test._InlineTest__test_with_dwz, decorators)
# Add the test case to the globals, and hide InlineTest
__globals.update({test_name: test})
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits