diff options
| -rw-r--r-- | lldb/test/functionalities/archives/Makefile | 9 | ||||
| -rw-r--r-- | lldb/test/functionalities/archives/TestBSDArchives.py | 65 | ||||
| -rw-r--r-- | lldb/test/functionalities/archives/a.c | 19 | ||||
| -rw-r--r-- | lldb/test/functionalities/archives/b.c | 19 | ||||
| -rw-r--r-- | lldb/test/functionalities/archives/main.c | 17 | ||||
| -rw-r--r-- | lldb/test/make/Makefile.rules | 63 | 
6 files changed, 186 insertions, 6 deletions
diff --git a/lldb/test/functionalities/archives/Makefile b/lldb/test/functionalities/archives/Makefile new file mode 100644 index 00000000000..64da83becbd --- /dev/null +++ b/lldb/test/functionalities/archives/Makefile @@ -0,0 +1,9 @@ +LEVEL = ../../make + +C_SOURCES := main.c + +MAKE_DSYM := NO +ARCHIVE_NAME := libfoo.a +ARCHIVE_C_SOURCES := a.c b.c + +include $(LEVEL)/Makefile.rules diff --git a/lldb/test/functionalities/archives/TestBSDArchives.py b/lldb/test/functionalities/archives/TestBSDArchives.py new file mode 100644 index 00000000000..1a7499e7213 --- /dev/null +++ b/lldb/test/functionalities/archives/TestBSDArchives.py @@ -0,0 +1,65 @@ +"""Test breaking inside functions defined within a BSD archive file libfoo.a.""" + +import os, time +import unittest2 +import lldb +from lldbtest import * + +class BSDArchivesTestCase(TestBase): + +    mydir = os.path.join("functionalities", "archives") + +    def test_with_dwarf(self): +        """Break inside a() and b() defined within libfoo.a.""" +        self.buildDwarf() +        self.break_inside_bsd_archives() + +    def setUp(self): +        # Call super's setUp(). +        TestBase.setUp(self) +        # Find the line number in a(int) to break at. +        self.line = line_number('a.c', '// Set file and line breakpoint inside a().') + +    def break_inside_bsd_archives(self): +        """Break inside a() and b() defined within libfoo.a.""" +        exe = os.path.join(os.getcwd(), "a.out") +        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) + +        # Break inside a() by file and line first. +        self.expect("breakpoint set -f a.c -l %d" % self.line, BREAKPOINT_CREATED, +            startstr = "Breakpoint created: 1: file ='a.c', line = %d" % +                        self.line) +        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']) + +        # Break at a(int) first. +        self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY, +            substrs = ['(int) arg = 1']) +        self.expect("frame variable __a_global", VARIABLES_DISPLAYED_CORRECTLY, +            substrs = ['(int) __a_global = 1']) + +        # Set breakpoint for b() next. +        self.expect("breakpoint set -n b", BREAKPOINT_CREATED, +            startstr = "Breakpoint created: 2: name = 'b'", +            substrs = ['resolved = 1']) + +        # Continue the program, we should break at b(int) next. +        self.runCmd("continue") +        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, +            substrs = ['stopped', +                       'stop reason = breakpoint']) +        self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY, +            substrs = ['(int) arg = 2']) +        self.expect("frame variable __b_global", VARIABLES_DISPLAYED_CORRECTLY, +            substrs = ['(int) __b_global = 2']) + + +if __name__ == '__main__': +    import atexit +    lldb.SBDebugger.Initialize() +    atexit.register(lambda: lldb.SBDebugger.Terminate()) +    unittest2.main() diff --git a/lldb/test/functionalities/archives/a.c b/lldb/test/functionalities/archives/a.c new file mode 100644 index 00000000000..2b6ebbe47a7 --- /dev/null +++ b/lldb/test/functionalities/archives/a.c @@ -0,0 +1,19 @@ +//===-- a.c -----------------------------------------------------*- C++ -*-===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +int __a_global = 1; + +int a(int arg) { +    int result = arg + __a_global; +    return result; // Set file and line breakpoint inside a(). +} + +int aa(int arg1) { +    int result1 = arg1 - __a_global; +    return result1; +} diff --git a/lldb/test/functionalities/archives/b.c b/lldb/test/functionalities/archives/b.c new file mode 100644 index 00000000000..51d77dd4bcd --- /dev/null +++ b/lldb/test/functionalities/archives/b.c @@ -0,0 +1,19 @@ +//===-- b.c -----------------------------------------------------*- C++ -*-===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +static int __b_global = 2; + +int b(int arg) { +    int result = arg + __b_global; +    return result; +} + +int bb(int arg1) { +    int result2 = arg1 - __b_global; +    return result2; +} diff --git a/lldb/test/functionalities/archives/main.c b/lldb/test/functionalities/archives/main.c new file mode 100644 index 00000000000..c5b1cc2f0d1 --- /dev/null +++ b/lldb/test/functionalities/archives/main.c @@ -0,0 +1,17 @@ +//===-- main.c --------------------------------------------------*- C++ -*-===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#include <stdio.h> + +extern int a(int); +extern int b(int); +int main (int argc, char const *argv[]) +{ +    printf ("a(1) returns %d\n", a(1)); +    printf ("b(2) returns %d\n", b(2)); +} diff --git a/lldb/test/make/Makefile.rules b/lldb/test/make/Makefile.rules index 8963ae6ff4b..50efad349d2 100644 --- a/lldb/test/make/Makefile.rules +++ b/lldb/test/make/Makefile.rules @@ -58,6 +58,8 @@ ifeq "$(OS)" "Darwin"  	DS := dsymutil  	DSFLAGS =  	DSYM = $(EXE).dSYM +	AR := libtool +	ARFLAGS := -static -o  endif  CXXFLAGS +=$(CFLAGS) @@ -130,6 +132,42 @@ ifneq "$(strip $(OBJCXX_SOURCES))" ""  	endif  endif +#---------------------------------------------------------------------- +# Check if we have any C source files for archive +#---------------------------------------------------------------------- +ifneq "$(strip $(ARCHIVE_C_SOURCES))" "" +	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_C_SOURCES:.c=.o)) +endif + +#---------------------------------------------------------------------- +# Check if we have any C++ source files for archive +#---------------------------------------------------------------------- +ifneq "$(strip $(ARCHIVE_CXX_SOURCES))" "" +	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_CXX_SOURCES:.cpp=.o)) +	CXX = $(call cxx_compiler,$(CC)) +	LD = $(call cxx_linker,$(CC)) +endif + +#---------------------------------------------------------------------- +# Check if we have any ObjC source files for archive +#---------------------------------------------------------------------- +ifneq "$(strip $(ARCHIVE_OBJC_SOURCES))" "" +	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJC_SOURCES:.m=.o)) +	LDFLAGS +=-lobjc +endif + +#---------------------------------------------------------------------- +# Check if we have any ObjC++ source files for archive +#---------------------------------------------------------------------- +ifneq "$(strip $(ARCHIVE_OBJCXX_SOURCES))" "" +	ARCHIVE_OBJECTS +=$(strip $(ARCHIVE_OBJCXX_SOURCES:.mm=.o)) +	CXX = $(call cxx_compiler,$(CC)) +	LD = $(call cxx_linker,$(CC)) +	ifeq $(findstring lobjc,$(LDFLAGS)) "" +		LDFLAGS +=-lobjc +	endif +endif +  #----------------------------------------------------------------------  # DYLIB_ONLY variable can be used to skip the building of a.out. @@ -154,14 +192,27 @@ endif  #----------------------------------------------------------------------  ifneq "$(DYLIB_NAME)" ""  ifeq "$(DYLIB_ONLY)" "" -$(EXE) : $(OBJECTS) $(DYLIB_FILENAME) -	$(LD) $(LDFLAGS) $(OBJECTS) -L. -l$(DYLIB_NAME) -o "$(EXE)" +$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) $(DYLIB_FILENAME) +	$(LD) $(LDFLAGS) $(OBJECTS) $(ARCHIVE_NAME) -L. -l$(DYLIB_NAME) -o "$(EXE)"  else  EXE = $(DYLIB_FILENAME)  endif  else -$(EXE) : $(OBJECTS) -	$(LD) $(LDFLAGS) $(OBJECTS) -o "$(EXE)" +$(EXE) : $(OBJECTS) $(ARCHIVE_NAME) +	$(LD) $(LDFLAGS) $(OBJECTS) $(ARCHIVE_NAME) -o "$(EXE)" +endif + +#---------------------------------------------------------------------- +# Make the archive +#---------------------------------------------------------------------- +ifneq "$(ARCHIVE_NAME)" "" +ifeq "$(OS)" "Darwin" +$(ARCHIVE_NAME) : $(ARCHIVE_OBJECTS) +	$(AR) $(ARFLAGS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) +	$(RM) $(ARCHIVE_OBJECTS) +else +$(ARCHIVE_NAME) : $(foreach ar_obj,$(ARCHIVE_OBJECTS),$(ARCHIVE_NAME)($(ar_obj))) +endif  endif  #---------------------------------------------------------------------- @@ -228,9 +279,9 @@ dsym:	$(DSYM)  all:	$(EXE) $(DSYM)  clean::  ifeq "$(DYLIB_NAME)" "" -	rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) +	rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS)  else -	rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).dSYM +	rm -rf "$(EXE)" "$(DSYM)" $(OBJECTS) $(PREREQS) $(ARCHIVE_NAME) $(ARCHIVE_OBJECTS) $(DYLIB_OBJECTS) $(DYLIB_PREREQS) $(DYLIB_FILENAME) $(DYLIB_FILENAME).dSYM  endif  #----------------------------------------------------------------------  | 

