Skip to content

Commit 47e8dc8

Browse files
committed
[lldb] Support direct ivar access in Swift
1 parent 1338be5 commit 47e8dc8

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

lldb/source/Plugins/Language/Swift/SwiftLanguage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// Other libraries and framework includes
1919
// Project includes
2020
#include "lldb/Target/Language.h"
21+
#include "lldb/Utility/ConstString.h"
2122
#include "lldb/lldb-private.h"
2223

2324
namespace lldb_private {
@@ -88,6 +89,8 @@ class SwiftLanguage : public Language {
8889

8990
bool SymbolNameFitsToLanguage(Mangled mangled) const override;
9091

92+
ConstString GetInstanceVariableName() override { return ConstString("self"); }
93+
9194
//------------------------------------------------------------------
9295
// PluginInterface protocol
9396
//------------------------------------------------------------------

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwift.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "lldb/Symbol/TypeSystem.h"
2020
#include "lldb/Utility/ConstString.h"
2121
#include "lldb/Utility/Flags.h"
22+
#include "lldb/lldb-enumerations.h"
2223
#include "lldb/lldb-private.h"
2324

2425
namespace clang {
@@ -198,13 +199,12 @@ class TypeSystemSwift : public TypeSystem {
198199
ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override {
199200
return {};
200201
}
201-
bool
202-
DeclContextIsClassMethod(void *opaque_decl_ctx,
203-
lldb::LanguageType *language_ptr,
204-
bool *is_instance_method_ptr,
205-
ConstString *language_object_name_ptr) override {
202+
bool DeclContextIsClassMethod(void *opaque_decl_ctx) override {
206203
return false;
207204
}
205+
lldb::LanguageType DeclContextGetLanguage(void *) override {
206+
return lldb::eLanguageTypeSwift;
207+
}
208208
bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override {
209209
return false;
210210
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SWIFT_SOURCES := main.swift
2+
include Makefile.rules
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import lldb
2+
from lldbsuite.test.lldbtest import *
3+
from lldbsuite.test.decorators import *
4+
from lldbsuite.test import lldbutil
5+
6+
7+
class TestCase(TestBase):
8+
@skipUnlessDarwin
9+
def test_objc_self(self):
10+
self.build()
11+
lldbutil.run_to_source_breakpoint(self, "check self", lldb.SBFileSpec("main.swift"))
12+
self.expect("frame variable _prop", startstr="(Int) _prop = 30")
13+
14+
@skipUnlessDarwin
15+
def test_objc_self_capture_idiom(self):
16+
self.build()
17+
lldbutil.run_to_source_breakpoint(self, "check idiomatic self", lldb.SBFileSpec("main.swift"))
18+
self.expect("frame variable self", startstr="(a.Classic) self = 0x")
19+
self.expect("frame variable _prop", startstr="(Int) _prop = 30")
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Classic {
2+
var _prop = 30
3+
4+
func fun() {
5+
print("check self")
6+
}
7+
8+
func run() {
9+
{ [weak self] in
10+
guard let self else { fatalError("cannot happen") }
11+
print("check idiomatic self")
12+
self.fun()
13+
}()
14+
}
15+
}
16+
17+
func main() {
18+
var c = Classic()
19+
c.run()
20+
}
21+
22+
main()

lldb/test/API/lang/swift/archetype_in_expression/TestArchetypeInExpression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ def test(self):
2222
self.expect("e U.self", substrs=["[Int].Type"])
2323
# Assert that frame variable doesn't work
2424
self.expect("v First.self",
25-
substrs=["no variable named 'First' found in this frame"],
25+
substrs=["no variable or instance variable named 'First' found in this frame"],
2626
error=True)
2727
self.expect("v T.self",
28-
substrs=["no variable named 'T' found in this frame"],
28+
substrs=["no variable or instance variable named 'T' found in this frame"],
2929
error=True)
3030

3131
# Check that referring to a shadowed archetype works correctly.
3232
lldbutil.continue_to_breakpoint(process, breakpoint)
3333
self.expect("e T.self", substrs=["String.Type"])
3434
# Assert that frame variable doesn't work
3535
self.expect("v T.self",
36-
substrs=["no variable named 'T' found in this frame"],
36+
substrs=["no variable or instance variable named 'T' found in this frame"],
3737
error=True)
3838

3939
# Check that you refer to archetypes in nested generic functions.

0 commit comments

Comments
 (0)