Skip to content

Print a hint about using frame variable when self cannot be reconstru… #4157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,10 @@ static llvm::Optional<llvm::Error> AddVariableInfo(
// Not realizing self is a fatal error for an expression and the
// Swift compiler error alone is not particularly useful.
if (is_self)
return make_error<StringError>(inconvertibleErrorCode(),
"Couldn't realize type of self.");
return make_error<StringError>(
inconvertibleErrorCode(),
"Couldn't realize Swift AST type of self. Hint: using `v` to "
"directly inspect variables and fields may still work.");
return {};
}

Expand Down
11 changes: 11 additions & 0 deletions lldb/test/API/lang/swift/private_discriminator/Builder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Generic

private class Private{
fileprivate typealias MyNumber = Int
fileprivate init() { n = MyNumber(23) }
let n : MyNumber
}

public func getObj() -> some P {
return S(Private())
}
25 changes: 25 additions & 0 deletions lldb/test/API/lang/swift/private_discriminator/Generic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public protocol P {
func action()
}

public struct S<T> : P, CustomDebugStringConvertible {
let m_t : T
public var debugDescription: String { return "S { m_t = \(m_t) }" }
public init(_ t : T) { m_t = t }
public func action() {
// self cannot be resolved in the expression evaluator,
// because there is no AST type for it.
let visible = Visible()
print("break here")
}
}

private struct Visible {
let n = 42
public init() {}
}

public func sanity_check() {
let visible = Visible()
print("break here")
}
27 changes: 27 additions & 0 deletions lldb/test/API/lang/swift/private_discriminator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
SWIFT_SOURCES := main.swift
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
LD_EXTRAS = -L$(BUILDDIR) -lGeneric -lBuilder

all: libBuilder.dylib $(EXE)

include Makefile.rules

libGeneric.dylib: $(SRCDIR)/Generic.swift
$(MAKE) -f $(MAKEFILE_RULES) \
DYLIB_ONLY=YES \
DYLIB_NAME=Generic \
DYLIB_SWIFT_SOURCES=Generic.swift \
DYLIB_MODULENAME=Generic \
SWIFTFLAGS_EXTRAS=-enable-library-evolution

libBuilder.dylib: $(SRCDIR)/Builder.swift libGeneric.dylib
$(MAKE) -f $(MAKEFILE_RULES) \
DYLIB_ONLY=YES \
DYLIB_NAME=Builder \
DYLIB_SWIFT_SOURCES=Builder.swift \
DYLIB_MODULENAME=Builder \
DYLIB_HIDE_SWIFTMODULE=YES \
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR)" \
LD_EXTRAS="-L$(BUILDDIR) -lGeneric" \
MAKE_DSYM=NO
rm -f $(BUILDDIR)/Builder.swiftmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import lldb
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbtest as lldbtest
import lldbsuite.test.lldbutil as lldbutil
import unittest2


class TestSwiftPrivateDiscriminator(lldbtest.TestBase):

NO_DEBUG_INFO_TESTCASE = True
mydir = lldbtest.TestBase.compute_mydir(__file__)

@swiftTest
# FIXME: The only reason this doesn't work on Linux is because the
# dylib hasn't been loaded when run_to_source_breakpoint wants to
# set the breakpoints.
@skipUnlessDarwin
def test(self):
"""Test what happens when a private type cannot be reconstructed in the AST."""
self.build()
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('Generic.swift'),
extra_images=['Generic', 'Builder'])

self.expect("frame var -d run -- self",
substrs=['Builder.Private', 'n', '23'])
self.expect("p self", error=True, substrs=["Hint"])
process.Continue()
# This should work.
self.expect("frame var -d run -- visible",
substrs=['Generic.Visible', 'n', '42'])
self.expect("p visible", substrs=['Generic.Visible', 'n', '42'])
5 changes: 5 additions & 0 deletions lldb/test/API/lang/swift/private_discriminator/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Builder
import Generic

Builder.getObj().action()
sanity_check()