Skip to content

Commit 0ab2ffb

Browse files
committed
Refactor GetTaskAddrFromThreadLocalStorage to return Expected
1 parent 56e929b commit 0ab2ffb

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ GetAsyncUnwindRegisterNumbers(llvm::Triple::ArchType triple);
852852

853853
/// Inspects thread local storage to find the address of the currently executing
854854
/// task.
855-
std::optional<lldb::addr_t> GetTaskAddrFromThreadLocalStorage(Thread &thread);
855+
llvm::Expected<lldb::addr_t> GetTaskAddrFromThreadLocalStorage(Thread &thread);
856856
} // namespace lldb_private
857857

858858
#endif // liblldb_SwiftLanguageRuntime_h_

0 commit comments

Comments
 (0)