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

llvm-svn: 148066
This commit is contained in:
Johnny Chen 2012-01-12 23:09:42 +00:00
parent 49c4dfb534
commit fe14162e71
6 changed files with 186 additions and 6 deletions

View File

@ -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

View File

@ -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()

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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
#----------------------------------------------------------------------