@@ -91,6 +91,10 @@ const char *SwiftLanguageRuntime::GetStandardLibraryBaseName() {
9191 return " swiftCore" ;
9292}
9393
94+ const char *SwiftLanguageRuntime::GetConcurrencyLibraryBaseName () {
95+ return " swift_Concurrency" ;
96+ }
97+
9498static ConstString GetStandardLibraryName (Process &process) {
9599 // This result needs to be stored in the constructor.
96100 PlatformSP platform_sp (process.GetTarget ().GetPlatform ());
@@ -100,6 +104,14 @@ static ConstString GetStandardLibraryName(Process &process) {
100104 return {};
101105}
102106
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+
103115ConstString SwiftLanguageRuntime::GetStandardLibraryName () {
104116 return ::GetStandardLibraryName (*m_process);
105117}
@@ -109,6 +121,12 @@ static bool IsModuleSwiftRuntime(lldb_private::Process &process,
109121 return module .GetFileSpec ().GetFilename () == GetStandardLibraryName (process);
110122}
111123
124+ static bool IsModuleSwiftConcurrency (lldb_private::Process &process,
125+ lldb_private::Module &module ) {
126+ return module .GetFileSpec ().GetFilename () ==
127+ GetConcurrencyLibraryName (process);
128+ }
129+
112130AppleObjCRuntimeV2 *
113131SwiftLanguageRuntime::GetObjCRuntime (lldb_private::Process &process) {
114132 if (auto objc_runtime = ObjCLanguageRuntime::Get (process)) {
@@ -131,6 +149,11 @@ static bool IsStaticSwiftRuntime(Module &image) {
131149 return image.FindFirstSymbolWithNameAndType (swift_reflection_version_sym);
132150}
133151
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+
134157// / \return the Swift or Objective-C runtime found in the loaded images.
135158static ModuleSP findRuntime (Process &process, RuntimeKind runtime_kind) {
136159 AppleObjCRuntimeV2 *objc_runtime = nullptr ;
@@ -168,6 +191,52 @@ static ModuleSP findRuntime(Process &process, RuntimeKind runtime_kind) {
168191 return runtime_image;
169192}
170193
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+
171240static std::optional<lldb::addr_t >
172241FindSymbolForSwiftObject (Process &process, RuntimeKind runtime_kind,
173242 StringRef object, const SymbolType sym_type) {
0 commit comments