From 8410ddd8b6738dbd4d983c6d634660e2943f7e48 Mon Sep 17 00:00:00 2001 From: Kate Stone Date: Tue, 19 Apr 2016 18:20:11 +0000 Subject: [PATCH] Adds a test to detect when clang omits specialized generic types from debug information when using precompiled headers and -gmodules. llvm-svn: 266791 --- lldb/packages/Python/lldbsuite/test/decorators.py | 14 ++++++ .../lldbsuite/test/lang/cpp/gmodules/Makefile | 7 +++ .../lang/cpp/gmodules/TestWithModuleDebugging.py | 56 ++++++++++++++++++++++ .../lldbsuite/test/lang/cpp/gmodules/main.cpp | 5 ++ .../Python/lldbsuite/test/lang/cpp/gmodules/pch.h | 12 +++++ .../Python/lldbsuite/test/make/Makefile.rules | 24 ++++++++++ 6 files changed, 118 insertions(+) create mode 100644 lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/Makefile create mode 100644 lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py create mode 100644 lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp create mode 100644 lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index 79dfaf6..a6143cd 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -15,6 +15,7 @@ import unittest2 # LLDB modules import use_lldb_suite +import lldbtest import lldb from . import configuration @@ -507,3 +508,16 @@ def skipUnlessCompilerRt(func): compilerRtPath = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "llvm","projects","compiler-rt") return "compiler-rt not found" if not os.path.exists(compilerRtPath) else None return skipTestIfFn(is_compiler_rt_missing)(func) + +def skipUnlessClangModules(): + """Decorate the item to skip test unless Clang -gmodules flag is supported.""" + def is_compiler_clang_with_gmodules(self): + builder = lldbtest.builder_module() + compiler_path = builder.getCompiler() + compiler = os.path.basename(compiler_path) + if compiler != "clang": + return "Test requires clang as compiler" + clang_help = os.popen("%s --help" % (compiler_path)).read() + match = re.match(".* -gmodules ", clang_help, re.DOTALL) + return "Clang version doesn't support -gmodules flag" if not match else None + return skipTestIfFn(is_compiler_clang_with_gmodules) diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/Makefile b/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/Makefile new file mode 100644 index 0000000..da6f39a --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/Makefile @@ -0,0 +1,7 @@ +LEVEL = ../../../make + +PCH_CXX_SOURCE = pch.h +CXX_SOURCES = main.cpp +CFLAGS_EXTRAS += $(MODULE_DEBUG_INFO_FLAGS) + +include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py new file mode 100644 index 0000000..bbb3305 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/TestWithModuleDebugging.py @@ -0,0 +1,56 @@ +import lldb, os +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + +class TestWithGmodulesDebugInfo(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll(bugnumber="llvm.org/pr27412") + @skipUnlessClangModules() + def test_specialized_typedef_from_pch(self): + clang_help = os.popen("clang --help").read() + match = re.match(".* -gmodules ", clang_help, re.DOTALL) + if not match: + self.skipTest("Clang version doesn't support -gmodules flag") + return + + self.build() + cwd = os.getcwd() + + src_file = os.path.join(cwd, "main.cpp") + src_file_spec = lldb.SBFileSpec(src_file) + self.assertTrue(src_file_spec.IsValid(), "breakpoint file") + + # Get the path of the executable + exe_path = os.path.join(cwd, 'a.out') + + # Load the executable + target = self.dbg.CreateTarget(exe_path) + self.assertTrue(target.IsValid(), VALID_TARGET) + + # Break on interesting line + breakpoint = target.BreakpointCreateBySourceRegex("break here", src_file_spec) + self.assertTrue(breakpoint.IsValid() and breakpoint.GetNumLocations() >= 1, VALID_BREAKPOINT) + + # Launch the process + process = target.LaunchSimple(None, None, self.get_process_working_directory()) + self.assertTrue(process.IsValid(), PROCESS_IS_VALID) + + # Get the thread of the process + self.assertTrue(process.GetState() == lldb.eStateStopped) + thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint) + self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition") + + # Get frame for current thread + frame = thread.frames[0] + + testValue = frame.EvaluateExpression("test") + self.assertTrue(testValue.GetError().Success(), "Test expression value invalid: %s" % (testValue.GetError().GetCString())) + self.assertTrue(testValue.GetTypeName() == "IntContainer", "Test expression type incorrect") + + memberValue = testValue.GetChildMemberWithName("storage") + self.assertTrue(memberValue.GetError().Success(), "Member value missing or invalid: %s" % (testValue.GetError().GetCString())) + self.assertTrue(memberValue.GetTypeName() == "int", "Member type incorrect") + self.assertEqual(42, memberValue.GetValueAsSigned(), "Member value incorrect") diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp new file mode 100644 index 0000000..aa40136 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/main.cpp @@ -0,0 +1,5 @@ +int main(int argc, const char * argv[]) +{ + IntContainer test(42); + return 0; // break here +} diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h b/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h new file mode 100644 index 0000000..a6c59b9 --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/gmodules/pch.h @@ -0,0 +1,12 @@ +template +class GenericContainer { + private: + T storage; + + public: + GenericContainer(T value) { + storage = value; + }; +}; + +typedef GenericContainer IntContainer; diff --git a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules index 762726d..f39ab9a 100644 --- a/lldb/packages/Python/lldbsuite/test/make/Makefile.rules +++ b/lldb/packages/Python/lldbsuite/test/make/Makefile.rules @@ -183,9 +183,11 @@ endif LIMIT_DEBUG_INFO_FLAGS = NO_LIMIT_DEBUG_INFO_FLAGS = +MODULE_DEBUG_INFO_FLAGS = ifneq (,$(findstring clang,$(CC))) LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info NO_LIMIT_DEBUG_INFO_FLAGS += -fno-limit-debug-info + MODULE_DEBUG_INFO_FLAGS += -gmodules endif DEBUG_INFO_FLAG ?= -g @@ -344,6 +346,14 @@ ifneq "$(strip $(DYLIB_CXX_SOURCES))" "" endif #---------------------------------------------------------------------- +# Check if we have a precompiled header +#---------------------------------------------------------------------- +ifneq "$(strip $(PCH_CXX_SOURCE))" "" + PCH_OUTPUT = $(PCH_CXX_SOURCE:.h=.h.pch) + PCHFLAGS = -include $(PCH_CXX_SOURCE) +endif + +#---------------------------------------------------------------------- # Check if we have any C source files #---------------------------------------------------------------------- ifneq "$(strip $(C_SOURCES))" "" @@ -502,6 +512,17 @@ endif endif #---------------------------------------------------------------------- +# Make the precompiled header and compile C++ sources against it +#---------------------------------------------------------------------- + +#ifneq "$(PCH_OUTPUT)" "" +$(PCH_OUTPUT) : $(PCH_CXX_SOURCE) + $(CXX) $(CXXFLAGS) -x c++-header -o $(PCH_OUTPUT) $(PCH_CXX_SOURCE) +%.o : %.cpp $(PCH_OUTPUT) + $(CXX) $(PCHFLAGS) $(CXXFLAGS) $(CFLAGS) -c -o $@ $< +#endif + +#---------------------------------------------------------------------- # Automatic variables based on items already entered. Below we create # an object's lists from the list of sources by replacing all entries # that end with .c with .o, and we also create a list of prerequisite @@ -574,6 +595,9 @@ 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 endif +ifneq "$(PCH_OUTPUT)" "" + $(RM) $(PCH_OUTPUT) +endif ifneq "$(DSYM)" "" $(RM) -r "$(DSYM)" endif -- 2.7.4