@@ -91,6 +91,10 @@ const char *SwiftLanguageRuntime::GetStandardLibraryBaseName() {
91
91
return " swiftCore" ;
92
92
}
93
93
94
+ const char *SwiftLanguageRuntime::GetConcurrencyLibraryBaseName () {
95
+ return " swift_Concurrency" ;
96
+ }
97
+
94
98
static ConstString GetStandardLibraryName (Process &process) {
95
99
// This result needs to be stored in the constructor.
96
100
PlatformSP platform_sp (process.GetTarget ().GetPlatform ());
@@ -100,6 +104,14 @@ static ConstString GetStandardLibraryName(Process &process) {
100
104
return {};
101
105
}
102
106
107
+ static ConstString GetConcurrencyLibraryName (Process &process) {
108
+ PlatformSP platform_sp = process.GetTarget ().GetPlatform ();
109
+ if (platform_sp)
110
+ return platform_sp->GetFullNameForDylib (
111
+ ConstString (SwiftLanguageRuntime::GetConcurrencyLibraryBaseName ()));
112
+ return {};
113
+ }
114
+
103
115
ConstString SwiftLanguageRuntime::GetStandardLibraryName () {
104
116
return ::GetStandardLibraryName (*m_process);
105
117
}
@@ -109,6 +121,12 @@ static bool IsModuleSwiftRuntime(lldb_private::Process &process,
109
121
return module .GetFileSpec ().GetFilename () == GetStandardLibraryName (process);
110
122
}
111
123
124
+ static bool IsModuleSwiftConcurrency (lldb_private::Process &process,
125
+ lldb_private::Module &module ) {
126
+ return module .GetFileSpec ().GetFilename () ==
127
+ GetConcurrencyLibraryName (process);
128
+ }
129
+
112
130
AppleObjCRuntimeV2 *
113
131
SwiftLanguageRuntime::GetObjCRuntime (lldb_private::Process &process) {
114
132
if (auto objc_runtime = ObjCLanguageRuntime::Get (process)) {
@@ -131,6 +149,11 @@ static bool IsStaticSwiftRuntime(Module &image) {
131
149
return image.FindFirstSymbolWithNameAndType (swift_reflection_version_sym);
132
150
}
133
151
152
+ static bool IsStaticSwiftConcurrency (Module &image) {
153
+ static const ConstString task_switch_symbol (" _swift_task_switch" );
154
+ return image.FindFirstSymbolWithNameAndType (task_switch_symbol);
155
+ }
156
+
134
157
// / \return the Swift or Objective-C runtime found in the loaded images.
135
158
static ModuleSP findRuntime (Process &process, RuntimeKind runtime_kind) {
136
159
AppleObjCRuntimeV2 *objc_runtime = nullptr ;
@@ -168,6 +191,52 @@ static ModuleSP findRuntime(Process &process, RuntimeKind runtime_kind) {
168
191
return runtime_image;
169
192
}
170
193
194
+ ModuleSP SwiftLanguageRuntime::FindConcurrencyModule (Process &process) {
195
+ ModuleSP concurrency_module;
196
+ process.GetTarget ().GetImages ().ForEach ([&](const ModuleSP &candidate) {
197
+ if (candidate && IsModuleSwiftConcurrency (process, *candidate)) {
198
+ concurrency_module = candidate;
199
+ return false ;
200
+ }
201
+ return true ;
202
+ });
203
+ if (concurrency_module)
204
+ return concurrency_module;
205
+
206
+ // Do a more expensive search for a statically linked Swift runtime.
207
+ process.GetTarget ().GetImages ().ForEach ([&](const ModuleSP &candidate) {
208
+ if (candidate && IsStaticSwiftConcurrency (*candidate)) {
209
+ concurrency_module = candidate;
210
+ return false ;
211
+ }
212
+ return true ;
213
+ });
214
+ return concurrency_module;
215
+ }
216
+
217
+ std::optional<uint32_t >
218
+ SwiftLanguageRuntime::FindConcurrencyDebugVersion (Process &process) {
219
+ ModuleSP concurrency_module = FindConcurrencyModule (process);
220
+ if (!concurrency_module)
221
+ return {};
222
+
223
+ const Symbol *version_symbol =
224
+ concurrency_module->FindFirstSymbolWithNameAndType (
225
+ ConstString (" _swift_concurrency_debug_internal_layout_version" ));
226
+ if (!version_symbol)
227
+ return 0 ;
228
+
229
+ addr_t symbol_addr = version_symbol->GetLoadAddress (&process.GetTarget ());
230
+ if (symbol_addr == LLDB_INVALID_ADDRESS)
231
+ return {};
232
+ Status error;
233
+ uint64_t version = process.ReadUnsignedIntegerFromMemory (
234
+ symbol_addr, /* width*/ 4 , /* fail_value=*/ 0 , error);
235
+ if (error.Fail ())
236
+ return {};
237
+ return version;
238
+ }
239
+
171
240
static std::optional<lldb::addr_t >
172
241
FindSymbolForSwiftObject (Process &process, RuntimeKind runtime_kind,
173
242
StringRef object, const SymbolType sym_type) {
0 commit comments