Skip to content

Commit e5e1999

Browse files
authored
[lldb] Construct ThreadTask fully from AsyncTaskInfo fields (NFC) (#10321)
Instead of determining the resume function by reading memory out of the `AsyncContext` pointer, use the already available `RunJob` field of `AsyncTaskInfo`.
1 parent 8c09a32 commit e5e1999

File tree

5 files changed

+5
-27
lines changed

5 files changed

+5
-27
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
414414
result.kind = task_info.Kind;
415415
result.enqueuePriority = task_info.EnqueuePriority;
416416
result.resumeAsyncContext = task_info.ResumeAsyncContext;
417+
result.runJob = task_info.RunJob;
417418
for (auto child : task_info.ChildTasks)
418419
result.childTasks.push_back(child);
419420
return result;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class ReflectionContextInterface {
173173
uint32_t kind = 0;
174174
uint32_t enqueuePriority = 0;
175175
lldb::addr_t resumeAsyncContext = LLDB_INVALID_ADDRESS;
176+
lldb::addr_t runJob = LLDB_INVALID_ADDRESS;
176177
std::vector<lldb::addr_t> childTasks;
177178
};
178179
// The default limits are copied from swift-inspect.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,8 +2197,9 @@ ThreadForTaskArgument(Args &command, ExecutionContext &exe_ctx) {
21972197
if (auto *runtime = SwiftLanguageRuntime::Get(exe_ctx.GetProcessSP()))
21982198
if (auto reflection_ctx = runtime->GetReflectionContext()) {
21992199
if (auto task_info = reflection_ctx->asyncTaskInfo(task_ptr))
2200-
return ThreadTask::Create(task_info->id, task_info->resumeAsyncContext,
2201-
exe_ctx);
2200+
return std::make_shared<ThreadTask>(task_info->id,
2201+
task_info->resumeAsyncContext,
2202+
task_info->runJob, exe_ctx);
22022203
else
22032204
return task_info.takeError();
22042205
}

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,6 @@ RegisterContextSP lldb_private::ThreadTask::GetRegisterContext() {
2222
return m_async_reg_ctx_sp;
2323
}
2424

25-
llvm::Expected<std::shared_ptr<ThreadTask>>
26-
ThreadTask::Create(tid_t tid, addr_t async_ctx, ExecutionContext &exe_ctx) {
27-
auto &process = exe_ctx.GetProcessRef();
28-
auto &target = exe_ctx.GetTargetRef();
29-
30-
// A simplified description of AsyncContext. See swift/Task/ABI.h
31-
// struct AsyncContext {
32-
// AsyncContext *Parent; // offset 0
33-
// TaskContinuationFunction *ResumeParent; // offset 8
34-
// };
35-
// The resume function is stored at `offsetof(AsyncContext, ResumeParent)`,
36-
// which is the async context's base address plus the size of a pointer.
37-
uint32_t ptr_size = target.GetArchitecture().GetAddressByteSize();
38-
addr_t resume_ptr = async_ctx + ptr_size;
39-
Status status;
40-
addr_t resume_fn = process.ReadPointerFromMemory(resume_ptr, status);
41-
if (status.Fail() || resume_fn == LLDB_INVALID_ADDRESS)
42-
return createStringError("failed to read task's resume function");
43-
44-
return std::make_shared<ThreadTask>(tid, async_ctx, resume_fn, exe_ctx);
45-
}
46-
4725
RegisterContextTask::RegisterContextTask(Thread &thread,
4826
RegisterContextSP reg_info_sp,
4927
addr_t resume_fn, addr_t async_ctx)

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ class ThreadTask final : public Thread {
2020
ThreadTask(tid_t tid, addr_t async_ctx, addr_t resume_fn,
2121
ExecutionContext &exe_ctx);
2222

23-
static llvm::Expected<std::shared_ptr<ThreadTask>>
24-
Create(tid_t tid, addr_t async_ctx, ExecutionContext &exe_ctx);
25-
2623
/// Returns a Task specific register context (RegisterContextTask).
2724
RegisterContextSP GetRegisterContext() override;
2825

0 commit comments

Comments
 (0)