Author: jingham Date: Mon Jan 13 14:44:26 2014 New Revision: 199134 URL: http://llvm.org/viewvc/llvm-project?rev=199134&view=rev Log: This is a macosx specific test case for stepping & setting breakpoints on indirect and re-exported symbols. I don't know if Linux has the latter, if it does, we could probably make this a generic test. Somebody who knows how to make these gadgets on Linux can maybe take a look...
Added: lldb/trunk/test/macosx/indirect_symbol/ lldb/trunk/test/macosx/indirect_symbol/Makefile lldb/trunk/test/macosx/indirect_symbol/TestIndirectSymbols.py lldb/trunk/test/macosx/indirect_symbol/alias.list lldb/trunk/test/macosx/indirect_symbol/indirect.c lldb/trunk/test/macosx/indirect_symbol/main.c lldb/trunk/test/macosx/indirect_symbol/reexport.c Added: lldb/trunk/test/macosx/indirect_symbol/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/macosx/indirect_symbol/Makefile?rev=199134&view=auto ============================================================================== --- lldb/trunk/test/macosx/indirect_symbol/Makefile (added) +++ lldb/trunk/test/macosx/indirect_symbol/Makefile Mon Jan 13 14:44:26 2014 @@ -0,0 +1,48 @@ +CC ?= clang +ifeq "$(ARCH)" "" + ARCH = x86_64 +endif + +ifeq "$(OS)" "" + OS = $(shell uname -s) +endif + +CFLAGS ?= -g -O0 +CWD := $(shell pwd) + +LIB_PREFIX := lib + +ifeq "$(OS)" "Darwin" + CFLAGS += -arch $(ARCH) + DS := dsymutil + LD_FLAGS := -dynamiclib + LIB_INDIRECT := $(LIB_PREFIX)indirect.dylib + LIB_REEXPORT := $(LIB_PREFIX)reexport.dylib + EXEC_PATH := "@executable_path" + EXEC_PATH_INDIRECT := -install_name $(EXEC_PATH)/$(LIB_INDIRECT) + EXEC_PATH_REEXPORT := -install_name $(EXEC_PATH)/$(LIB_REEXPORT) +endif + +all: a.out $(LIB_INDIRECT) $(LIB_REEXPORT) + +a.out: main.o $(LIB_INDIRECT) $(LIB_REEXPORT) + $(CC) $(CFLAGS) -o a.out main.o -L. $(LIB_INDIRECT) $(LIB_REEXPORT) + +main.o: main.c + $(CC) $(CFLAGS) -c main.c + +$(LIB_INDIRECT): indirect.o + $(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_INDIRECT) -o $(LIB_INDIRECT) indirect.o + if [ "$(OS)" = "Darwin" ]; then dsymutil $(LIB_INDIRECT); fi + +indirect.o: indirect.c + $(CC) $(CFLAGS) -c indirect.c + +$(LIB_REEXPORT): reexport.o $(LIB_INDIRECT) + $(CC) $(CFLAGS) $(LD_FLAGS) $(EXEC_PATH_REEXPORT) -o $(LIB_REEXPORT) reexport.o -L. -lindirect -Wl,-alias_list,$(CWD)/alias.list + if [ "$(OS)" = "Darwin" ]; then dsymutil $(LIB_REEXPORT); fi + +reexport.o: reexport.c + $(CC) $(CFLAGS) -c reexport.c +clean: + rm -rf *.o *~ *.dylib *.so a.out *.dSYM Added: lldb/trunk/test/macosx/indirect_symbol/TestIndirectSymbols.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/macosx/indirect_symbol/TestIndirectSymbols.py?rev=199134&view=auto ============================================================================== --- lldb/trunk/test/macosx/indirect_symbol/TestIndirectSymbols.py (added) +++ lldb/trunk/test/macosx/indirect_symbol/TestIndirectSymbols.py Mon Jan 13 14:44:26 2014 @@ -0,0 +1,106 @@ +"""Test stepping and setting breakpoints in indirect and re-exported symbols.""" + +import os, time +import unittest2 +import lldb +import lldbutil +from lldbtest import * + +class TestObjCStepping(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @python_api_test + @dsym_test + def test_with_dsym_and_python_api(self): + """Test stepping and setting breakpoints in indirect and re-exported symbols.""" + self.buildDsym() + self.indirect_stepping() + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + @python_api_test + @dwarf_test + def test_with_dwarf_and_python_api(self): + """Test stepping and setting breakpoints in indirect and re-exported symbols.""" + self.buildDwarf() + self.indirect_stepping() + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line numbers that we will step to in main: + self.main_source = "main.c" + + def indirect_stepping(self): + """Test stepping and setting breakpoints in indirect and re-exported symbols.""" + exe = os.path.join(os.getcwd(), "a.out") + + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + + self.main_source_spec = lldb.SBFileSpec (self.main_source) + + break1 = target.BreakpointCreateBySourceRegex ("Set breakpoint here to step in indirect.", self.main_source_spec) + self.assertTrue(break1, VALID_BREAKPOINT) + + break2 = target.BreakpointCreateBySourceRegex ("Set breakpoint here to step in reexported.", self.main_source_spec) + self.assertTrue(break2, VALID_BREAKPOINT) + + # Now launch the process, and do not stop at entry point. + process = target.LaunchSimple (None, None, self.get_process_working_directory()) + + self.assertTrue(process, PROCESS_IS_VALID) + + # The stop reason of the thread should be breakpoint. + threads = lldbutil.get_threads_stopped_at_breakpoint (process, break1) + if len(threads) != 1: + self.fail ("Failed to stop at breakpoint 1.") + + thread = threads[0] + + # Now do a step-into, and we should end up in the hidden target of this indirect function. + thread.StepInto() + curr_function = thread.GetFrameAtIndex(0).GetFunctionName() + self.assertTrue (curr_function == "call_through_indirect_hidden", "Stepped into indirect symbols.") + + # Now set a breakpoint using the indirect symbol name, and make sure we get to that: + break_indirect = target.BreakpointCreateByName ("call_through_indirect"); + self.assertTrue (break_indirect, VALID_BREAKPOINT) + + # Now continue should take us to the second call through the indirect symbol: + + threads = lldbutil.continue_to_breakpoint (process, break_indirect) + self.assertTrue (len(threads) == 1, "Stopped at breakpoint in indirect function.") + curr_function = thread.GetFrameAtIndex(0).GetFunctionName() + self.assertTrue (curr_function == "call_through_indirect_hidden", "Stepped into indirect symbols.") + + # Delete this breakpoint so it won't get in the way: + target.BreakpointDelete (break_indirect.GetID()) + + # Now continue to the site of the first re-exported function call in main: + threads = lldbutil.continue_to_breakpoint (process, break2) + + # This is stepping Into through a re-exported symbol to an indirect symbol: + thread.StepInto() + curr_function = thread.GetFrameAtIndex(0).GetFunctionName() + self.assertTrue (curr_function == "call_through_indirect_hidden", "Stepped into indirect symbols.") + + # And the last bit is to set a breakpoint on the re-exported symbol and make sure we are again in out target function. + break_reexported = target.BreakpointCreateByName ("reexport_to_indirect"); + self.assertTrue (break_reexported, VALID_BREAKPOINT) + + # Now continue should take us to the second call through the indirect symbol: + + threads = lldbutil.continue_to_breakpoint (process, break_reexported) + self.assertTrue (len(threads) == 1, "Stopped at breakpoint in reexported function target.") + curr_function = thread.GetFrameAtIndex(0).GetFunctionName() + self.assertTrue (curr_function == "call_through_indirect_hidden", "Stepped into indirect symbols.") + + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() Added: lldb/trunk/test/macosx/indirect_symbol/alias.list URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/macosx/indirect_symbol/alias.list?rev=199134&view=auto ============================================================================== --- lldb/trunk/test/macosx/indirect_symbol/alias.list (added) +++ lldb/trunk/test/macosx/indirect_symbol/alias.list Mon Jan 13 14:44:26 2014 @@ -0,0 +1 @@ +_call_through_indirect _reexport_to_indirect \ No newline at end of file Added: lldb/trunk/test/macosx/indirect_symbol/indirect.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/macosx/indirect_symbol/indirect.c?rev=199134&view=auto ============================================================================== --- lldb/trunk/test/macosx/indirect_symbol/indirect.c (added) +++ lldb/trunk/test/macosx/indirect_symbol/indirect.c Mon Jan 13 14:44:26 2014 @@ -0,0 +1,14 @@ +#define MakeResolver(name) \ + void * name ## Resolver(void) __asm__("_" #name); \ + void * name ## Resolver(void) { \ + __asm__(".symbol_resolver _" #name); \ + return name ## _hidden; \ + } + +int +call_through_indirect_hidden(int arg) +{ + return arg + 5; +} + +MakeResolver(call_through_indirect) Added: lldb/trunk/test/macosx/indirect_symbol/main.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/macosx/indirect_symbol/main.c?rev=199134&view=auto ============================================================================== --- lldb/trunk/test/macosx/indirect_symbol/main.c (added) +++ lldb/trunk/test/macosx/indirect_symbol/main.c Mon Jan 13 14:44:26 2014 @@ -0,0 +1,14 @@ +extern int call_through_indirect(int); +extern int call_through_reexport(int); + +int +main () +{ + int indirect_result = call_through_indirect(20); // Set breakpoint here to step in indirect. + indirect_result = call_through_indirect(30); + + int reexport_result = reexport_to_indirect (20); // Set breakpoint here to step in reexported. + reexport_result = reexport_to_indirect (30); + + return 0; +} Added: lldb/trunk/test/macosx/indirect_symbol/reexport.c URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/macosx/indirect_symbol/reexport.c?rev=199134&view=auto ============================================================================== --- lldb/trunk/test/macosx/indirect_symbol/reexport.c (added) +++ lldb/trunk/test/macosx/indirect_symbol/reexport.c Mon Jan 13 14:44:26 2014 @@ -0,0 +1,7 @@ +extern int call_through_indirect(int); + +int +fake_call_through_reexport(int value) +{ + return value + 10; +} _______________________________________________ lldb-commits mailing list lldb-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits