@@ -40,15 +40,24 @@ using namespace swift::remoteAST;
40
40
// / The context for the code we're running. Set by the observer.
41
41
static ASTContext *Context = nullptr ;
42
42
43
+ // / The RemoteAST for the code we're running.
44
+ std::shared_ptr<MemoryReader> reader;
45
+ std::unique_ptr<RemoteASTContext> remoteContext;
46
+
47
+ static RemoteASTContext &getRemoteASTContext () {
48
+ if (remoteContext)
49
+ return *remoteContext;
50
+
51
+ std::shared_ptr<MemoryReader> reader (new InProcessMemoryReader ());
52
+ remoteContext.reset (new RemoteASTContext (*Context, std::move (reader)));
53
+ return *remoteContext;
54
+ }
55
+
43
56
// FIXME: swiftcall
44
57
// / func printType(forMetadata: Any.Type)
45
58
LLVM_ATTRIBUTE_USED extern " C" void SWIFT_REMOTEAST_TEST_ABI
46
59
printMetadataType (const Metadata *typeMetadata) {
47
- assert (Context && " context was not set" );
48
-
49
- std::shared_ptr<MemoryReader> reader (new InProcessMemoryReader ());
50
- RemoteASTContext remoteAST (*Context, std::move (reader));
51
-
60
+ auto &remoteAST = getRemoteASTContext ();
52
61
auto &out = llvm::outs ();
53
62
54
63
auto result =
@@ -66,11 +75,7 @@ printMetadataType(const Metadata *typeMetadata) {
66
75
// / func printDynamicType(_: AnyObject)
67
76
LLVM_ATTRIBUTE_USED extern " C" void SWIFT_REMOTEAST_TEST_ABI
68
77
printHeapMetadataType (void *object) {
69
- assert (Context && " context was not set" );
70
-
71
- std::shared_ptr<MemoryReader> reader (new InProcessMemoryReader ());
72
- RemoteASTContext remoteAST (*Context, std::move (reader));
73
-
78
+ auto &remoteAST = getRemoteASTContext ();
74
79
auto &out = llvm::outs ();
75
80
76
81
auto metadataResult =
@@ -94,11 +99,7 @@ printHeapMetadataType(void *object) {
94
99
95
100
static void printMemberOffset (const Metadata *typeMetadata,
96
101
StringRef memberName, bool passMetadata) {
97
- assert (Context && " context was not set" );
98
-
99
- std::shared_ptr<MemoryReader> reader (new InProcessMemoryReader ());
100
- RemoteASTContext remoteAST (*Context, std::move (reader));
101
-
102
+ auto &remoteAST = getRemoteASTContext ();
102
103
auto &out = llvm::outs ();
103
104
104
105
// The first thing we have to do is get the type.
@@ -147,10 +148,7 @@ printTypeMetadataMemberOffset(const Metadata *typeMetadata,
147
148
LLVM_ATTRIBUTE_USED extern " C" void SWIFT_REMOTEAST_TEST_ABI
148
149
printDynamicTypeAndAddressForExistential (void *object,
149
150
const Metadata *typeMetadata) {
150
- assert (Context && " context was not set" );
151
- std::shared_ptr<MemoryReader> reader (new InProcessMemoryReader ());
152
- RemoteASTContext remoteAST (*Context, std::move (reader));
153
-
151
+ auto &remoteAST = getRemoteASTContext ();
154
152
auto &out = llvm::outs ();
155
153
156
154
// First, retrieve the static type of the existential, so we can understand
0 commit comments