Skip to content

[lldb] Factor out iteration over runtime types from GetChildCompilerT… #10607

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
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 @@ -67,6 +67,8 @@ struct SuperClassType;
using ThreadSafeReflectionContext = LockGuarded<ReflectionContextInterface>;

class SwiftLanguageRuntime : public LanguageRuntime {
friend class SwiftRuntimeTypeVisitor;

protected:
SwiftLanguageRuntime(Process &process);

Expand Down

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8623,10 +8623,6 @@ std::string SwiftASTContext::GetSwiftName(const clang::Decl *clang_decl,
return {};
}

CompilerType SwiftASTContext::GetBuiltinRawPointerType() {
return GetTypeFromMangledTypename(ConstString("$sBpD"));
}

CompilerType
SwiftASTContext::ConvertClangTypeToSwiftType(CompilerType clang_type) {
auto ts = GetTypeSystemSwiftTypeRef();
Expand Down
1 change: 0 additions & 1 deletion lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ class SwiftASTContext : public TypeSystemSwift {
std::string GetSwiftName(const clang::Decl *clang_decl,
TypeSystemClang &clang_typesystem) override;

CompilerType GetBuiltinRawPointerType() override;
CompilerType GetBuiltinIntType();

/// Attempts to convert a Clang type into a Swift type.
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ bool TypeSystemSwift::IsScalarType(opaque_compiler_type_t type) {
return (GetTypeInfo(type, nullptr) & eTypeIsScalar) != 0;
}

CompilerType TypeSystemSwift::GetBuiltinRawPointerType() {
return GetTypeFromMangledTypename(ConstString("$sBpD"));
}

CompilerType TypeSystemSwift::GetBuiltinUnknownObjectType() {
return GetTypeFromMangledTypename(ConstString("$sBOD"));
}

bool TypeSystemSwift::ShouldTreatScalarValueAsAddress(
opaque_compiler_type_t type) {
return Flags(GetTypeInfo(type, nullptr))
Expand Down
3 changes: 2 additions & 1 deletion lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ class TypeSystemSwift : public TypeSystem {
virtual std::string GetSwiftName(const clang::Decl *clang_decl,
TypeSystemClang &clang_typesystem) = 0;

virtual CompilerType GetBuiltinRawPointerType() = 0;
CompilerType GetBuiltinRawPointerType();
CompilerType GetBuiltinUnknownObjectType();

/// Attempts to convert a Clang type into a Swift type.
/// For example, int is converted to Int32.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1445,11 +1445,6 @@ TypeSystemSwiftTypeRef::GetSwiftName(const clang::Decl *clang_decl,
return {};
}

CompilerType TypeSystemSwiftTypeRef::GetBuiltinRawPointerType() {
return GetTypeFromMangledTypename(ConstString("$sBpD"));
}


static bool IsImportedType(swift::Demangle::NodePointer node) {
if (!node)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
std::string GetSwiftName(const clang::Decl *clang_decl,
TypeSystemClang &clang_typesystem) override;

CompilerType GetBuiltinRawPointerType() override;

/// Wrap \p node as \p Global(TypeMangling(node)), remangle the type
/// and create a CompilerType from it.
CompilerType RemangleAsType(swift::Demangle::Demangler &dem,
Expand Down
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,19 @@
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil

class TestSwiftObjCBaseClassMemberLookup(TestBase):
NO_DEBUG_INFO_TESTCASE = True
@skipUnlessDarwin
@swiftTest
def test(self):
"""Test accessing a static member from a member function"""
self.build()
lldbutil.run_to_source_breakpoint(
self, 'break here', lldb.SBFileSpec('main.swift')
)

p = self.frame().FindVariable("p").GetStaticValue()
self.assertEqual(p.GetNumChildren(), 1)
self.assertEqual(p.GetChildAtIndex(0).GetSummary(), '"hello"')
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

func foo(p: NSCopying) {
print("break here")
}

let s : NSString = "hello"
foo(p: s)

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestSwiftUnknownReference(lldbtest.TestBase):
mydir = lldbtest.TestBase.compute_mydir(__file__)

def check_class(self, var_self):
lldbutil.check_variable(self, var_self, num_children=2)
lldbutil.check_variable(self, var_self, use_dynamic=True, num_children=2)
m_base_string = var_self.GetChildMemberWithName("base_string")
m_string = var_self.GetChildMemberWithName("string")
lldbutil.check_variable(self, m_base_string, summary='"hello"')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class TestSwiftUnknownSelf(lldbtest.TestBase):

def check_class(self, var_self, weak):
self.expect("v self", substrs=["hello", "world"])
lldbutil.check_variable(self, var_self, num_children=2)
# FIXME: This is inconsistent. If self is Optional, an extra
# indirection is needed.
lldbutil.check_variable(self, var_self, num_children=2 if weak else 1)
m_base_string = var_self.GetChildMemberWithName("base_string")
m_string = var_self.GetChildMemberWithName("string")
# FIXME: This is inconsistent. If self is Optional, an extra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_swift_protocol_types(self):
self.expect("expression --dynamic-type no-dynamic-values"
" --raw-output --show-types -- loc3dCB",
substrs=['PointUtils & Swift.AnyObject) $R',
'(Builtin.RawPointer) object = 0x',
'(Builtin.UnknownObject) object = 0x',
'(Builtin.RawPointer) wtable = 0x'])

self.expect("expression -- loc3dCB",
Expand Down