Skip to content

Commit 522a7a6

Browse files
Merge pull request #4157 from adrian-prantl/self-hint
Print a hint about using frame variable when self cannot be reconstru…
2 parents 0c27db5 + 18a60ba commit 522a7a6

File tree

6 files changed

+104
-2
lines changed

6 files changed

+104
-2
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,10 @@ static llvm::Optional<llvm::Error> AddVariableInfo(
693693
// Not realizing self is a fatal error for an expression and the
694694
// Swift compiler error alone is not particularly useful.
695695
if (is_self)
696-
return make_error<StringError>(inconvertibleErrorCode(),
697-
"Couldn't realize type of self.");
696+
return make_error<StringError>(
697+
inconvertibleErrorCode(),
698+
"Couldn't realize Swift AST type of self. Hint: using `v` to "
699+
"directly inspect variables and fields may still work.");
698700
return {};
699701
}
700702

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Generic
2+
3+
private class Private{
4+
fileprivate typealias MyNumber = Int
5+
fileprivate init() { n = MyNumber(23) }
6+
let n : MyNumber
7+
}
8+
9+
public func getObj() -> some P {
10+
return S(Private())
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public protocol P {
2+
func action()
3+
}
4+
5+
public struct S<T> : P, CustomDebugStringConvertible {
6+
let m_t : T
7+
public var debugDescription: String { return "S { m_t = \(m_t) }" }
8+
public init(_ t : T) { m_t = t }
9+
public func action() {
10+
// self cannot be resolved in the expression evaluator,
11+
// because there is no AST type for it.
12+
let visible = Visible()
13+
print("break here")
14+
}
15+
}
16+
17+
private struct Visible {
18+
let n = 42
19+
public init() {}
20+
}
21+
22+
public func sanity_check() {
23+
let visible = Visible()
24+
print("break here")
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS = -I$(BUILDDIR)
3+
LD_EXTRAS = -L$(BUILDDIR) -lGeneric -lBuilder
4+
5+
all: libBuilder.dylib $(EXE)
6+
7+
include Makefile.rules
8+
9+
libGeneric.dylib: $(SRCDIR)/Generic.swift
10+
$(MAKE) -f $(MAKEFILE_RULES) \
11+
DYLIB_ONLY=YES \
12+
DYLIB_NAME=Generic \
13+
DYLIB_SWIFT_SOURCES=Generic.swift \
14+
DYLIB_MODULENAME=Generic \
15+
SWIFTFLAGS_EXTRAS=-enable-library-evolution
16+
17+
libBuilder.dylib: $(SRCDIR)/Builder.swift libGeneric.dylib
18+
$(MAKE) -f $(MAKEFILE_RULES) \
19+
DYLIB_ONLY=YES \
20+
DYLIB_NAME=Builder \
21+
DYLIB_SWIFT_SOURCES=Builder.swift \
22+
DYLIB_MODULENAME=Builder \
23+
DYLIB_HIDE_SWIFTMODULE=YES \
24+
SWIFTFLAGS_EXTRAS="-I$(BUILDDIR)" \
25+
LD_EXTRAS="-L$(BUILDDIR) -lGeneric" \
26+
MAKE_DSYM=NO
27+
rm -f $(BUILDDIR)/Builder.swiftmodule
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
import lldbsuite.test.lldbtest as lldbtest
4+
import lldbsuite.test.lldbutil as lldbutil
5+
import unittest2
6+
7+
8+
class TestSwiftPrivateDiscriminator(lldbtest.TestBase):
9+
10+
NO_DEBUG_INFO_TESTCASE = True
11+
mydir = lldbtest.TestBase.compute_mydir(__file__)
12+
13+
@swiftTest
14+
# FIXME: The only reason this doesn't work on Linux is because the
15+
# dylib hasn't been loaded when run_to_source_breakpoint wants to
16+
# set the breakpoints.
17+
@skipUnlessDarwin
18+
def test(self):
19+
"""Test what happens when a private type cannot be reconstructed in the AST."""
20+
self.build()
21+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
22+
self, 'break here', lldb.SBFileSpec('Generic.swift'),
23+
extra_images=['Generic', 'Builder'])
24+
25+
self.expect("frame var -d run -- self",
26+
substrs=['Builder.Private', 'n', '23'])
27+
self.expect("p self", error=True, substrs=["Hint"])
28+
process.Continue()
29+
# This should work.
30+
self.expect("frame var -d run -- visible",
31+
substrs=['Generic.Visible', 'n', '42'])
32+
self.expect("p visible", substrs=['Generic.Visible', 'n', '42'])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Builder
2+
import Generic
3+
4+
Builder.getObj().action()
5+
sanity_check()

0 commit comments

Comments
 (0)