diff options
| author | Michael Sartain <mikesart@valvesoftware.com> | 2013-07-02 18:13:13 +0000 |
|---|---|---|
| committer | Michael Sartain <mikesart@valvesoftware.com> | 2013-07-02 18:13:13 +0000 |
| commit | 802b055e78eefeb459b26a1d1db89da8d6dbdc55 (patch) | |
| tree | f529ffa73386b07d95778ac0c12cdf67618b8e32 | |
| parent | f0ae35b88c19ddc42673bfe8e74d77069a42c20a (diff) | |
| download | bcm5719-llvm-802b055e78eefeb459b26a1d1db89da8d6dbdc55.tar.gz bcm5719-llvm-802b055e78eefeb459b26a1d1db89da8d6dbdc55.zip | |
Add split symbol support to test makefile & add linux split symbol test case.
llvm-svn: 185455
6 files changed, 165 insertions, 2 deletions
diff --git a/lldb/test/lang/c/shared_lib_stripped_symbols/Makefile b/lldb/test/lang/c/shared_lib_stripped_symbols/Makefile new file mode 100644 index 00000000000..2146ad8d84b --- /dev/null +++ b/lldb/test/lang/c/shared_lib_stripped_symbols/Makefile @@ -0,0 +1,10 @@ +LEVEL = ../../../make + +DYLIB_NAME := libfoo +DYLIB_C_SOURCES := foo.c +C_SOURCES := main.c +CFLAGS_EXTRAS += -fPIC + +SPLIT_DEBUG_SYMBOLS = YES + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py b/lldb/test/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py new file mode 100644 index 00000000000..9cf59da6c9d --- /dev/null +++ b/lldb/test/lang/c/shared_lib_stripped_symbols/TestSharedLibStrippedSymbols.py @@ -0,0 +1,90 @@ +"""Test that types defined in shared libraries with stripped symbols work correctly.""" + +import os, time +import unittest2 +import lldb +from lldbtest import * +import lldbutil + +class SharedLibTestCase(TestBase): + + mydir = os.path.join("lang", "c", "shared_lib") + + @dsym_test + def test_expr_with_dsym(self): + """Test that types work when defined in a shared library and forward-declared in the main executable""" + self.buildDsym() + self.expr() + + @dwarf_test + def test_expr_with_dwarf(self): + """Test that types work when defined in a shared library and forward-declared in the main executable""" + self.buildDwarf() + self.expr() + + @dsym_test + def test_frame_variable_with_dsym(self): + """Test that types work when defined in a shared library and forward-declared in the main executable""" + self.buildDsym() + self.frame_var() + + @dwarf_test + def test_frame_variable_with_dwarf(self): + """Test that types work when defined in a shared library and forward-declared in the main executable""" + self.buildDwarf() + self.frame_var() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line number to break inside main(). + self.line = line_number('main.c', '// Set breakpoint 0 here.') + if sys.platform.startswith("linux"): + self.runCmd("settings set target.env-vars " + self.dylibPath + "=" + os.getcwd()) + self.addTearDownHook(lambda: self.runCmd("settings remove target.env-vars " + self.dylibPath)) + + def common_setup(self): + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + # Break inside the foo function which takes a bar_ptr argument. + lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + + self.runCmd("run", RUN_SUCCEEDED) + + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'stop reason = breakpoint']) + + # The breakpoint should have a hit count of 1. + self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, + substrs = [' resolved, hit count = 1']) + + def expr(self): + """Test that types work when defined in a shared library and forward-declared in the main executable""" + + if "clang" in self.getCompiler() and "3.4" in self.getCompilerVersion(): + self.skipTest("llvm.org/pr16214 -- clang emits partial DWARF for structures referenced via typedef") + + self.common_setup() + + # This should display correctly. + self.expect("expression --show-types -- *my_foo_ptr", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ["(foo)", "(sub_foo)", "other_element = 3"]) + + @unittest2.expectedFailure + # rdar://problem/10381325 + def frame_var(self): + """Test that types work when defined in a shared library and forward-declared in the main executable""" + self.common_setup() + + # This should display correctly. + self.expect("frame variable --show-types -- *my_foo_ptr", VARIABLES_DISPLAYED_CORRECTLY, + substrs = ["(foo)", "(sub_foo)", "other_element = 3"]) + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/lang/c/shared_lib_stripped_symbols/foo.c b/lldb/test/lang/c/shared_lib_stripped_symbols/foo.c new file mode 100644 index 00000000000..6431bc496c3 --- /dev/null +++ b/lldb/test/lang/c/shared_lib_stripped_symbols/foo.c @@ -0,0 +1,22 @@ +#include "foo.h" +#include <stdlib.h> + +struct foo +{ + struct sub_foo sub_element; + int other_element; +}; + +struct foo * +GetMeAFoo() +{ + struct foo *ret_val = (struct foo *) malloc (sizeof (struct foo)); + ret_val->other_element = 3; + return ret_val; +} + +struct sub_foo * +GetMeASubFoo (struct foo *in_foo) +{ + return &(in_foo->sub_element); +} diff --git a/lldb/test/lang/c/shared_lib_stripped_symbols/foo.h b/lldb/test/lang/c/shared_lib_stripped_symbols/foo.h new file mode 100644 index 00000000000..78b3c124538 --- /dev/null +++ b/lldb/test/lang/c/shared_lib_stripped_symbols/foo.h @@ -0,0 +1,12 @@ +struct foo; + +struct sub_foo +{ + int sub_1; + char *sub_2; +}; + +struct foo *GetMeAFoo(); +struct sub_foo *GetMeASubFoo (struct foo *in_foo); + + diff --git a/lldb/test/lang/c/shared_lib_stripped_symbols/main.c b/lldb/test/lang/c/shared_lib_stripped_symbols/main.c new file mode 100644 index 00000000000..b4377de18c1 --- /dev/null +++ b/lldb/test/lang/c/shared_lib_stripped_symbols/main.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include "foo.h" + +int +main () +{ + struct foo *my_foo_ptr; + my_foo_ptr = GetMeAFoo(); + + printf ("My sub foo has: %d.\n", GetMeASubFoo(my_foo_ptr)->sub_1); // Set breakpoint 0 here. + + return 0; +} diff --git a/lldb/test/make/Makefile.rules b/lldb/test/make/Makefile.rules index db7c393887c..7414f04687b 100644 --- a/lldb/test/make/Makefile.rules +++ b/lldb/test/make/Makefile.rules @@ -16,6 +16,7 @@ # FRAMEWORK_INCLUDES (Darwin only) := # CFLAGS_EXTRAS := # LD_EXTRAS := +# SPLIT_DEBUG_SYMBOLS := YES # # And test/functionalities/archives/Makefile: # MAKE_DSYM := NO @@ -79,6 +80,10 @@ else ifeq "$(ARCH)" "i386" override ARCH := $(subst i386,32,$(ARCH)) endif + + ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" + DSYM = $(EXE).debug + endif endif CFLAGS ?= -g -O0 @@ -229,13 +234,20 @@ endif #---------------------------------------------------------------------- # Make the dSYM file from the executable if $(MAKE_DSYM) != "NO" #---------------------------------------------------------------------- +$(DSYM) : $(EXE) ifeq "$(OS)" "Darwin" ifneq "$(MAKE_DSYM)" "NO" ifeq "$(DYLIB_ONLY)" "" -$(DSYM) : $(EXE) $(DS) $(DSFLAGS) -o "$(DSYM)" "$(EXE)" endif endif +else +ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" +ifeq "$(DYLIB_ONLY)" "" + objcopy --only-keep-debug "$(EXE)" "$(DSYM)" + objcopy --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)" +endif +endif endif #---------------------------------------------------------------------- @@ -279,6 +291,10 @@ endif endif else $(LD) $(LDFLAGS) $(DYLIB_OBJECTS) -shared -o "$(DYLIB_FILENAME)" +ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES" + objcopy --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug" + objcopy --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)" +endif endif #---------------------------------------------------------------------- @@ -342,7 +358,7 @@ clean:: ifeq "$(DYLIB_NAME)" "" rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) *.d.[0-9] *.d.[0-9][0-9] *.d.[0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9][0-9] else - rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).dSYM *.d.[0-9] *.d.[0-9][0-9] *.d.[0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9][0-9] + rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).dSYM $(DYLIB_FILENAME).debug *.d.[0-9] *.d.[0-9][0-9] *.d.[0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9] *.d.[0-9][0-9][0-9][0-9][0-9] endif #---------------------------------------------------------------------- |

