Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lldb/test/API/lang/swift/unmanaged_clang_bridged/Foo/Foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
typedef struct __attribute__((objc_bridge(id))) {
} *MyBridgedRef;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Foo {
header "Foo.h"
}
4 changes: 4 additions & 0 deletions lldb/test/API/lang/swift/unmanaged_clang_bridged/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SWIFT_OBJC_INTEROP := 1
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS = -Xcc -I$(SRCDIR)/Foo
include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftUnmanagedClangBridged(TestBase):
@swiftTest
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this need to be Darwin only?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could still be some clang type outside of darwin, it's not necessarily an objc type either.

def test(self):
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)
self.runCmd("settings set symbols.swift-enable-ast-context false")

frame = thread.frames[0]

someU = frame.FindVariable("someU")
lldbutil.check_variable(
self, someU, typename="Swift.Unmanaged<Foo.MyBridgedRef>"
)
self.assertEqual(
someU.GetChildMemberWithName("_value").GetValueAsUnsigned(), 0xdeadbeef
Comment thread
augusto2112 marked this conversation as resolved.
)

optU = frame.FindVariable("optU")
lldbutil.check_variable(
self,
optU,
typename="Swift.Optional<Swift.Unmanaged<Foo.MyBridgedRef>>",
value="some",
)
self.assertEqual(
optU.GetChildMemberWithName("_value").GetValueAsUnsigned(), 0xdeadbeef
)

nilU = frame.FindVariable("nilU")
lldbutil.check_variable(
self,
nilU,
typename="Swift.Optional<Swift.Unmanaged<Foo.MyBridgedRef>>",
summary="nil",
)
14 changes: 14 additions & 0 deletions lldb/test/API/lang/swift/unmanaged_clang_bridged/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foo

@inline(never)
func makeNil() -> Unmanaged<MyBridged>? { return nil }

func f() {
let nilU: Unmanaged<MyBridged>? = makeNil()
let p = UnsafeMutableRawPointer(bitPattern: 0xdeadbeef)!
let someU: Unmanaged<MyBridged> = Unmanaged.fromOpaque(p)
let optU: Unmanaged<MyBridged>? = Unmanaged.fromOpaque(p)
print("break here", nilU as Any)
}

f()
3 changes: 3 additions & 0 deletions lldb/test/API/lang/swift/unmanaged_foundationtype/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SWIFT_SOURCES := main.swift

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil


class TestSwiftUnmanagedFoundationType(TestBase):
@swiftTest
@skipUnlessFoundation
def test(self):
"""Inspect Unmanaged of a Clang-imported reference type without the AST context."""
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, "break here", lldb.SBFileSpec("main.swift")
)
self.runCmd("settings set symbols.swift-enable-ast-context false")

frame = thread.frames[0]

unmanaged = frame.FindVariable("unmanaged")
lldbutil.check_variable(
self, unmanaged, typename="Swift.Unmanaged<CoreFoundation.CFErrorRef>"
)
self.assertNotEqual(
unmanaged.GetChildMemberWithName("_value").GetValueAsUnsigned(), 0
)

optUnmanaged = frame.FindVariable("optUnmanaged")
lldbutil.check_variable(
self,
optUnmanaged,
typename="Swift.Optional<Swift.Unmanaged<CoreFoundation.CFErrorRef>>",
value="some",
)
self.assertNotEqual(
optUnmanaged.GetChildMemberWithName("_value").GetValueAsUnsigned(), 0
)

nilUnmanaged = frame.FindVariable("nilUnmanaged")
lldbutil.check_variable(
self,
nilUnmanaged,
typename="Swift.Optional<Swift.Unmanaged<CoreFoundation.CFErrorRef>>",
summary="nil",
)
15 changes: 15 additions & 0 deletions lldb/test/API/lang/swift/unmanaged_foundationtype/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

@inline(never)
func makeNil() -> Unmanaged<CFError>? { return nil }

func f() {
let unmanaged: Unmanaged<CFError> = Unmanaged.passUnretained(
CFErrorCreate(nil, kCFErrorDomainPOSIX, 0, nil))
let optUnmanaged: Unmanaged<CFError>? = Unmanaged.passUnretained(
CFErrorCreate(nil, kCFErrorDomainPOSIX, 0, nil))
let nilUnmanaged: Unmanaged<CFError>? = makeNil()
print("break here \(unmanaged)")
}

f()