diff options
author | Tamas Berghammer <tberghammer@google.com> | 2015-12-11 16:24:14 +0000 |
---|---|---|
committer | Tamas Berghammer <tberghammer@google.com> | 2015-12-11 16:24:14 +0000 |
commit | e43482b626b5f8e8fe85aad0c91fd8e637f67cd4 (patch) | |
tree | 45a6102b113f507e6ffea6d03932b7ed30d46054 /lldb/packages/Python/lldbsuite | |
parent | 734a0b3f81e24d106e1e4b46d000a11f865a42e6 (diff) | |
download | llvm-e43482b626b5f8e8fe85aad0c91fd8e637f67cd4.zip llvm-e43482b626b5f8e8fe85aad0c91fd8e637f67cd4.tar.gz llvm-e43482b626b5f8e8fe85aad0c91fd8e637f67cd4.tar.bz2 |
Create test for llvm.org/pr25806
LLDB don't detect the loading of a shared object file linked against the
main executable before the static initializers are executed for the
given module. Because of this it is not possible to get breakpoint hits
in these static initializers and to display proper debug info in case of
a crash in these codes.
llvm-svn: 255342
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
13 files changed, 100 insertions, 15 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/Makefile index cbac629..779745c 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/Makefile +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/Makefile @@ -3,7 +3,7 @@ LEVEL := ../../make LIB_PREFIX := loadunload_ LD_EXTRAS := -L. -l$(LIB_PREFIX)d -ldl -C_SOURCES := main.c +CXX_SOURCES := main.cpp include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py index b42bc45..481e7c8 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/TestLoadUnload.py @@ -24,9 +24,9 @@ class LoadUnloadTestCase(TestBase): # Call super's setUp(). TestBase.setUp(self) # Find the line number to break for main.cpp. - self.line = line_number('main.c', + self.line = line_number('main.cpp', '// Set break point at this line for test_lldb_process_load_and_unload_commands().') - self.line_d_function = line_number('d.c', + self.line_d_function = line_number('d.cpp', '// Find this line number within d_dunction().') if not self.platformIsDarwin(): if not lldb.remote_platform and "LD_LIBRARY_PATH" in os.environ: @@ -164,7 +164,7 @@ class LoadUnloadTestCase(TestBase): substrs = [os.path.basename(old_dylib)], matching=True) - lldbutil.run_break_set_by_file_and_line (self, "d.c", self.line_d_function, num_expected_locations=1) + lldbutil.run_break_set_by_file_and_line (self, "d.cpp", self.line_d_function, num_expected_locations=1) # After run, make sure the non-hidden library is picked up. self.expect("run", substrs=["return", "700"]) @@ -194,10 +194,10 @@ class LoadUnloadTestCase(TestBase): exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) - # Break at main.c before the call to dlopen(). + # Break at main.cpp before the call to dlopen(). # Use lldb's process load command to load the dylib, instead. - lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) @@ -296,7 +296,7 @@ class LoadUnloadTestCase(TestBase): self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break by function name a_function (not yet loaded). - lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) + lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) @@ -311,3 +311,47 @@ class LoadUnloadTestCase(TestBase): self.expect("thread list", "step over succeeded.", substrs = ['stopped', 'stop reason = step over']) + + @skipIfFreeBSD # llvm.org/pr14424 - missing FreeBSD Makefiles/testcase support + @skipUnlessListedRemote(['android']) + @skipIfWindows # Windows doesn't have dlopen and friends, dynamic libraries work differently + @unittest2.expectedFailure("llvm.org/pr25806") + def test_static_init_during_load (self): + """Test that we can set breakpoints correctly in static initializers""" + + self.build() + self.copy_shlibs_to_remote() + + exe = os.path.join(os.getcwd(), "a.out") + self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + + a_init_bp_num = lldbutil.run_break_set_by_symbol(self, "a_init", num_expected_locations=0) + b_init_bp_num = lldbutil.run_break_set_by_symbol(self, "b_init", num_expected_locations=0) + d_init_bp_num = lldbutil.run_break_set_by_symbol(self, "d_init", num_expected_locations=1) + + self.runCmd("run", RUN_SUCCEEDED) + + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'd_init', + 'stop reason = breakpoint %d' % d_init_bp_num]) + + self.runCmd("continue") + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'a_init', + 'stop reason = breakpoint %d' % a_init_bp_num]) + self.expect("thread backtrace", + substrs = ['a_init', + 'dlopen', + 'main']) + + self.runCmd("continue") + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs = ['stopped', + 'b_init', + 'stop reason = breakpoint %d' % b_init_bp_num]) + self.expect("thread backtrace", + substrs = ['b_init', + 'dlopen', + 'main']) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/a.c b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/a.cpp index 9d471177..235749a 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/a.c +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/a.cpp @@ -8,7 +8,14 @@ //===----------------------------------------------------------------------===// extern int b_function (); -int +int a_init() +{ + return 234; +} + +int a_global = a_init(); + +extern "C" int a_function () { return b_function (); diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/a.mk b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/a.mk index a5c37561..e8ca3d5 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/a.mk +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/a.mk @@ -6,9 +6,11 @@ CFLAGS_EXTRAS := -fPIC LD_EXTRAS := -L. -l$(LIB_PREFIX)b DYLIB_NAME := $(LIB_PREFIX)a -DYLIB_C_SOURCES := a.c +DYLIB_CXX_SOURCES := a.cpp DYLIB_ONLY := YES +CXXFLAGS += -fPIC + include $(LEVEL)/Makefile.rules .PHONY: diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/b.c b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/b.cpp index 6c62932..4d38316 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/b.c +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/b.cpp @@ -6,8 +6,16 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// + +int b_init() +{ + return 345; +} + +int b_global = b_init(); + int b_function () { - return 500; + return 500; } diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/b.mk b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/b.mk index 956dc37..c1b0877 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/b.mk +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/b.mk @@ -3,7 +3,9 @@ LEVEL := ../../make LIB_PREFIX := loadunload_ DYLIB_NAME := $(LIB_PREFIX)b -DYLIB_C_SOURCES := b.c +DYLIB_CXX_SOURCES := b.cpp DYLIB_ONLY := YES +CXXFLAGS += -fPIC + include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/c.c b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/c.cpp index b1778b4..f0dfb4e 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/c.c +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/c.cpp @@ -6,7 +6,7 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -int +extern "C" int c_function () { return 600; diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/c.mk b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/c.mk index ebb5ce1..5b5691e 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/c.mk +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/c.mk @@ -3,7 +3,9 @@ LEVEL := ../../make LIB_PREFIX := loadunload_ DYLIB_NAME := $(LIB_PREFIX)c -DYLIB_C_SOURCES := c.c +DYLIB_CXX_SOURCES := c.cpp DYLIB_ONLY := YES +CXXFLAGS += -fPIC + include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/d.c b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/d.cpp index 6e5f062..55f2a6b 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/d.c +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/d.cpp @@ -6,6 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// + +int d_init() +{ + return 123; +} + +int d_global = d_init(); + int d_function () { // Find this line number within d_dunction(). diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/d.mk b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/d.mk index 437c150..b6b6eea 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/d.mk +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/d.mk @@ -5,7 +5,9 @@ LIB_PREFIX := loadunload_ DYLIB_EXECUTABLE_PATH := $(CURDIR) DYLIB_NAME := $(LIB_PREFIX)d -DYLIB_C_SOURCES := d.c +DYLIB_CXX_SOURCES := d.cpp DYLIB_ONLY := YES +CXXFLAGS += -fPIC + include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/hidden/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/hidden/Makefile index 09aa39b..f84d830 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/hidden/Makefile +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/hidden/Makefile @@ -3,7 +3,9 @@ LEVEL := ../../../make LIB_PREFIX := loadunload_ DYLIB_NAME := $(LIB_PREFIX)d -DYLIB_C_SOURCES := d.c +DYLIB_CXX_SOURCES := d.cpp DYLIB_ONLY := YES +CXXFLAGS += -fPIC + include $(LEVEL)/Makefile.rules diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/hidden/d.c b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/hidden/d.cpp index f20aa09..6a7642c 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/hidden/d.c +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/hidden/d.cpp @@ -6,6 +6,14 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// + +int d_init() +{ + return 456; +} + +int d_global = d_init(); + int d_function () { // Find this line number within d_dunction(). diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/main.c b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/main.cpp index bff9a31..bff9a31 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/main.c +++ b/lldb/packages/Python/lldbsuite/test/functionalities/load_unload/main.cpp |