|
43 | 43 | #include "lldb/Utility/LLDBLog.h"
|
44 | 44 | #include "lldb/Utility/Log.h"
|
45 | 45 | #include "lldb/Utility/OptionParsing.h"
|
| 46 | +#include "lldb/Utility/StructuredData.h" |
46 | 47 | #include "lldb/Utility/Timer.h"
|
47 | 48 | #include "lldb/ValueObject/ValueObject.h"
|
48 | 49 | #include "lldb/ValueObject/ValueObjectCast.h"
|
|
52 | 53 | #include "lldb/lldb-enumerations.h"
|
53 | 54 | #include "swift/AST/ASTMangler.h"
|
54 | 55 | #include "swift/Demangling/Demangle.h"
|
55 |
| -#include "swift/RemoteInspection/ReflectionContext.h" |
56 | 56 | #include "swift/RemoteAST/RemoteAST.h"
|
| 57 | +#include "swift/RemoteInspection/ReflectionContext.h" |
| 58 | +#include "swift/Threading/ThreadLocalStorage.h" |
57 | 59 |
|
58 | 60 | #include "clang/AST/ASTContext.h"
|
59 | 61 | #include "clang/AST/DeclCXX.h"
|
@@ -2639,4 +2641,31 @@ std::optional<lldb::addr_t> SwiftLanguageRuntime::TrySkipVirtualParentProlog(
|
2639 | 2641 | : sc.function->GetPrologueByteSize();
|
2640 | 2642 | return pc_value + prologue_size;
|
2641 | 2643 | }
|
| 2644 | + |
| 2645 | +std::optional<lldb::addr_t> GetTaskAddrFromThreadLocalStorage(Thread &thread) { |
| 2646 | + // 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(); |
| 2658 | + |
| 2659 | + // Offset of the Task pointer in a Thread's local storage. |
| 2660 | + Process &process = *thread.GetProcess(); |
| 2661 | + size_t ptr_size = process.GetAddressByteSize(); |
| 2662 | + uint64_t task_ptr_offset_in_tls = |
| 2663 | + swift::tls_get_key(swift::tls_key::concurrency_task) * ptr_size; |
| 2664 | + 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 {}; |
| 2669 | + return task_addr; |
| 2670 | +} |
2642 | 2671 | } // namespace lldb_private
|
0 commit comments