@@ -2642,30 +2642,32 @@ std::optional<lldb::addr_t> SwiftLanguageRuntime::TrySkipVirtualParentProlog(
26422642 return pc_value + prologue_size;
26432643}
26442644
2645- std::optional<lldb::addr_t > GetTaskAddrFromThreadLocalStorage (Thread &thread) {
2645+ llvm::Expected<lldb::addr_t > GetTaskAddrFromThreadLocalStorage (Thread &thread) {
2646+ #if SWIFT_THREADING_USE_DIRECT_TSD
2647+ return llvm::createStringError (
2648+ " getting the current task from a thread is not supported" );
2649+ #else
26462650 // Compute the thread local storage address for this thread.
2647- StructuredData::ObjectSP info_root_sp = thread.GetExtendedInfo ();
2648- if (!info_root_sp)
2649- return {};
2650- StructuredData::ObjectSP node =
2651- info_root_sp->GetObjectForDotSeparatedPath (" tsd_address" );
2652- if (!node)
2653- return {};
2654- StructuredData::UnsignedInteger *raw_tsd_addr = node->GetAsUnsignedInteger ();
2655- if (!raw_tsd_addr)
2656- return {};
2657- addr_t tsd_addr = raw_tsd_addr->GetUnsignedIntegerValue ();
2651+ addr_t tsd_addr = LLDB_INVALID_ADDRESS;
2652+ if (auto info_sp = thread.GetExtendedInfo ())
2653+ if (auto *info_dict = info_sp->GetAsDictionary ())
2654+ info_dict->GetValueForKeyAsInteger (" tsd_address" , tsd_addr);
2655+
2656+ if (tsd_addr == LLDB_INVALID_ADDRESS)
2657+ return llvm::createStringError (" could not read current task from thread" );
26582658
26592659 // Offset of the Task pointer in a Thread's local storage.
26602660 Process &process = *thread.GetProcess ();
26612661 size_t ptr_size = process.GetAddressByteSize ();
26622662 uint64_t task_ptr_offset_in_tls =
26632663 swift::tls_get_key (swift::tls_key::concurrency_task) * ptr_size;
26642664 addr_t task_addr_location = tsd_addr + task_ptr_offset_in_tls;
2665- Status error;
2666- addr_t task_addr = process.ReadPointerFromMemory (task_addr_location, error);
2667- if (error.Fail ())
2668- return {};
2665+ Status status;
2666+ addr_t task_addr = process.ReadPointerFromMemory (task_addr_location, status);
2667+ if (status.Fail ())
2668+ return llvm::createStringError (" could not get current task from thread: %s" ,
2669+ status.AsCString ());
26692670 return task_addr;
2671+ #endif
26702672}
26712673} // namespace lldb_private
0 commit comments