[Lldb-commits] [lldb] r148066 - in /lldb/trunk/test: functionalities/archives/ functionalities/archives/Makefile functionalities/archives/TestBSDArchives.py functionalities/archives/a.c functionalities/archives/b.c functionalities/archives/main.c make/Makefile.rules
Johnny Chen
johnny.chen at apple.com
Thu Jan 12 15:09:42 PST 2012
Author: johnny
Date: Thu Jan 12 17:09:42 2012
New Revision: 148066
URL: http://llvm.org/viewvc/llvm-project?rev=148066&view=rev
Log:
rdar://problem/10680957
Need a test case that tests DWARF with .o in .a files
test/functionalities/archives:
Produces libfoo.a from a.o and b.o. Test breaking inside functions defined
inside the libfoo.a BSD Archive.
test/make/makefile.rules:
Some additional rules to sepcify archive building. For example:
ARCHIVE_NAME := libfoo.a
ARCHIVE_C_SOURCES := a.c b.c
Added:
lldb/trunk/test/functionalities/archives/
lldb/trunk/test/functionalities/archives/Makefile
lldb/trunk/test/functionalities/archives/TestBSDArchives.py
lldb/trunk/test/functionalities/archives/a.c
lldb/trunk/test/functionalities/archives/b.c
lldb/trunk/test/functionalities/archives/main.c
Modified:
lldb/trunk/test/make/Makefile.rules
Added: lldb/trunk/test/functionalities/archives/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/archives/Makefile?rev=148066&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/archives/Makefile (added)
+++ lldb/trunk/test/functionalities/archives/Makefile Thu Jan 12 17:09:42 2012
@@ -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
Added: lldb/trunk/test/functionalities/archives/TestBSDArchives.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/archives/TestBSDArchives.py?rev=148066&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/archives/TestBSDArchives.py (added)
+++ lldb/trunk/test/functionalities/archives/TestBSDArchives.py Thu Jan 12 17:09:42 2012
@@ -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()
Added: lldb/trunk/test/functionalities/archives/a.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/archives/a.c?rev=148066&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/archives/a.c (added)
+++ lldb/trunk/test/functionalities/archives/a.c Thu Jan 12 17:09:42 2012
@@ -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;
+}
Added: lldb/trunk/test/functionalities/archives/b.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/archives/b.c?rev=148066&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/archives/b.c (added)
+++ lldb/trunk/test/functionalities/archives/b.c Thu Jan 12 17:09:42 2012
@@ -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;
+}
Added: lldb/trunk/test/functionalities/archives/main.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/archives/main.c?rev=148066&view=auto
==============================================================================
--- lldb/trunk/test/functionalities/archives/main.c (added)
+++ lldb/trunk/test/functionalities/archives/main.c Thu Jan 12 17:09:42 2012
@@ -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));
+}
Modified: lldb/trunk/test/make/Makefile.rules
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/make/Makefile.rules?rev=148066&r1=148065&r2=148066&view=diff
==============================================================================
--- lldb/trunk/test/make/Makefile.rules (original)
+++ lldb/trunk/test/make/Makefile.rules Thu Jan 12 17:09:42 2012
@@ -58,6 +58,8 @@
DS := dsymutil
DSFLAGS =
DSYM = $(EXE).dSYM
+ AR := libtool
+ ARFLAGS := -static -o
endif
CXXFLAGS +=$(CFLAGS)
@@ -130,6 +132,42 @@
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 @@
#----------------------------------------------------------------------
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 @@
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
#----------------------------------------------------------------------
More information about the lldb-commits
mailing list