This repository has been archived by the owner on Apr 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from tfiala/SR-2637-v2
support debugging statically-linked Swift binaries on macOS
- Loading branch information
Showing
14 changed files
with
340 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/Python/lldbsuite/test/lang/swift/static_linking/macOS/A.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Foundation | ||
|
||
@objc public class A: NSObject { | ||
public func foo() -> Int { | ||
return 4 // Set breakpoint here | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/Python/lldbsuite/test/lang/swift/static_linking/macOS/B.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Foundation | ||
|
||
@objc public class B: NSObject { | ||
public func bar() -> Int { | ||
return 8 // Set breakpoint here | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/Python/lldbsuite/test/lang/swift/static_linking/macOS/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Build swift modules with debug info | ||
|
||
LEVEL=../../../../make | ||
|
||
# Don't use 'all' target. There is a default build rule that will kick in that | ||
# will be wrong. WE use 'first' so that the normal 'make' command (without | ||
# a target) selects the first (but not 'all') target so we avoid the undesired | ||
# default behavior. | ||
first: main | ||
|
||
include $(LEVEL)/Makefile.rules | ||
|
||
# To use the path commented out below, which is what we'd really want to do, | ||
# we'd also need to require that the Swift standard library be built along | ||
# with the compiler. I'd like to avoid that requirement. | ||
# SWIFT_LIB_DIR=$(dir $(SWIFTCC))../lib | ||
SWIFT_LIB_DIR="$(shell xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx" | ||
|
||
main: A.o B.o objc_main.m | ||
$(CC) objc_main.m -fobjc-arc -o main A.o B.o -L$(SWIFT_LIB_DIR) -Xlinker -add_ast_path -Xlinker A.swiftmodule -Xlinker -add_ast_path -Xlinker B.swiftmodule -Xlinker -rpath -Xlinker $(SWIFT_LIB_DIR) | ||
|
||
A.o: A.swift | ||
$(SWIFTCC) -c -g -Onone -sdk "$(SWIFTSDKROOT)" -parse-as-library -module-name A -emit-module-path A.swiftmodule -emit-objc-header-path A-Swift.h -output-file-map output_map A.swift | ||
|
||
B.o: B.swift | ||
$(SWIFTCC) -c -g -Onone -sdk "$(SWIFTSDKROOT)" -parse-as-library -module-name B -emit-module-path B.swiftmodule -emit-objc-header-path B-Swift.h -output-file-map output_map B.swift -o B.o | ||
|
||
clean:: | ||
rm -f *.o main *-Swift.h *.swiftmodule *.swiftdoc |
114 changes: 114 additions & 0 deletions
114
...ages/Python/lldbsuite/test/lang/swift/static_linking/macOS/TestSwiftStaticLinkingMacOS.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# TestSwiftStaticLinkingMacOS.py | ||
# | ||
# This source file is part of the Swift.org open source project | ||
# | ||
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors | ||
# Licensed under Apache License v2.0 with Runtime Library Exception | ||
# | ||
# See http://swift.org/LICENSE.txt for license information | ||
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
# | ||
# ------------------------------------------------------------------------------ | ||
""" | ||
Test that macOS can statically link two separately-compiled Swift modules | ||
with one Objective-C module, link them through the clang driver, and still | ||
access debug info for each of the Swift modules. | ||
""" | ||
from __future__ import print_function | ||
|
||
|
||
# System imports | ||
import os | ||
import commands | ||
|
||
# Third-party imports | ||
|
||
# LLDB imports | ||
import lldb | ||
from lldbsuite.test.lldbtest import TestBase | ||
from lldbsuite.test import decorators, lldbtest, lldbutil | ||
|
||
|
||
class SwiftStaticLinkingMacOSTestCase(TestBase): | ||
|
||
mydir = TestBase.compute_mydir(__file__) | ||
|
||
NO_DEBUG_INFO_TESTCASE = True | ||
|
||
def expect_self_var_available_at_breakpoint( | ||
self, process, breakpoint, module_name): | ||
# Frame #0 should be at the given breakpoint | ||
threads = lldbutil.get_threads_stopped_at_breakpoint( | ||
process, breakpoint) | ||
|
||
self.assertEquals(1, len(threads)) | ||
self.thread = threads[0] | ||
self.frame = self.thread.frames[0] | ||
self.assertTrue(self.frame, "Frame 0 is valid.") | ||
|
||
patterns = [ | ||
# Ensure we report a self with an address. | ||
r"self\s*=\s*0x[0-9a-fA-F]+", | ||
# Ensure we think it is an NSObject. | ||
r"ObjectiveC.NSObject"] | ||
substrs = [ | ||
"(%s.%s)" % (module_name, module_name) | ||
] | ||
self.expect("frame variable self", patterns=patterns, | ||
substrs=substrs) | ||
|
||
@decorators.skipUnlessDarwin | ||
def test_variables_print_from_both_swift_modules(self): | ||
"""Test that variables from two modules can be accessed.""" | ||
self.build() | ||
|
||
# I could not find a reasonable way to say "skipUnless(archs=[])". | ||
# That would probably be worth adding. | ||
if self.getArchitecture() != 'x86_64': | ||
self.skipTest("This test requires x86_64 as the architecture " | ||
"for the inferior") | ||
|
||
exe_name = "main" | ||
src_a = lldb.SBFileSpec("A.swift") | ||
line_a = 5 | ||
src_b = lldb.SBFileSpec("B.swift") | ||
line_b = 5 | ||
exe = os.path.join(os.getcwd(), exe_name) | ||
|
||
# Create the target | ||
target = self.dbg.CreateTarget(exe) | ||
self.assertTrue(target, lldbtest.VALID_TARGET) | ||
|
||
# Set the breakpoints | ||
# breakpoint_a = target.BreakpointCreateBySourceRegex( | ||
# 'Set breakpoint here', src_a) | ||
breakpoint_a = target.BreakpointCreateByLocation( | ||
src_a, line_a) | ||
self.assertTrue(breakpoint_a.GetNumLocations() > 0, | ||
lldbtest.VALID_BREAKPOINT) | ||
|
||
# breakpoint_b = target.BreakpointCreateBySourceRegex( | ||
# 'Set breakpoint here', src_b) | ||
breakpoint_b = target.BreakpointCreateByLocation( | ||
src_b, line_b) | ||
self.assertTrue(breakpoint_b.GetNumLocations() > 0, | ||
lldbtest.VALID_BREAKPOINT) | ||
|
||
# Launch the process, and do not stop at the entry point. | ||
envp = ['DYLD_FRAMEWORK_PATH=.'] | ||
process = target.LaunchSimple(None, envp, os.getcwd()) | ||
|
||
self.assertTrue(process, lldbtest.PROCESS_IS_VALID) | ||
|
||
# We should be at breakpoint in module A. | ||
self.expect_self_var_available_at_breakpoint( | ||
process, breakpoint_a, "A") | ||
|
||
# Jump to the next breakpoint | ||
process.Continue() | ||
|
||
# We should be at breakpoint in module B. | ||
self.expect_self_var_available_at_breakpoint( | ||
process, breakpoint_b, "B") | ||
|
||
return |
13 changes: 13 additions & 0 deletions
13
packages/Python/lldbsuite/test/lang/swift/static_linking/macOS/objc_main.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
#import "A-Swift.h" | ||
#import "B-Swift.h" | ||
|
||
int main(int argc, const char * argv[]) { | ||
@autoreleasepool { | ||
NSLog(@"Hello, World!"); | ||
NSLog(@"A = %ld", [[[A alloc] init] foo]); | ||
NSLog(@"B = %ld", [[[B alloc] init] bar]); | ||
} | ||
return 0; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/Python/lldbsuite/test/lang/swift/static_linking/macOS/output_map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{'A.swift': {'object': 'A.o'}, | ||
'B.swift': {'object': 'B.o'}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.