Skip to content

[lldb] Construct ThreadTask fully from AsyncTaskInfo fields (NFC) #10321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class TargetReflectionContext : public ReflectionContextInterface {
result.kind = task_info.Kind;
result.enqueuePriority = task_info.EnqueuePriority;
result.resumeAsyncContext = task_info.ResumeAsyncContext;
result.runJob = task_info.RunJob;
for (auto child : task_info.ChildTasks)
result.childTasks.push_back(child);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class ReflectionContextInterface {
uint32_t kind = 0;
uint32_t enqueuePriority = 0;
lldb::addr_t resumeAsyncContext = LLDB_INVALID_ADDRESS;
lldb::addr_t runJob = LLDB_INVALID_ADDRESS;
std::vector<lldb::addr_t> childTasks;
};
// The default limits are copied from swift-inspect.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2197,8 +2197,9 @@ ThreadForTaskArgument(Args &command, ExecutionContext &exe_ctx) {
if (auto *runtime = SwiftLanguageRuntime::Get(exe_ctx.GetProcessSP()))
if (auto reflection_ctx = runtime->GetReflectionContext()) {
if (auto task_info = reflection_ctx->asyncTaskInfo(task_ptr))
return ThreadTask::Create(task_info->id, task_info->resumeAsyncContext,
exe_ctx);
return std::make_shared<ThreadTask>(task_info->id,
task_info->resumeAsyncContext,
task_info->runJob, exe_ctx);
else
return task_info.takeError();
}
Expand Down
22 changes: 0 additions & 22 deletions lldb/source/Plugins/LanguageRuntime/Swift/SwiftTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@ RegisterContextSP lldb_private::ThreadTask::GetRegisterContext() {
return m_async_reg_ctx_sp;
}

llvm::Expected<std::shared_ptr<ThreadTask>>
ThreadTask::Create(tid_t tid, addr_t async_ctx, ExecutionContext &exe_ctx) {
auto &process = exe_ctx.GetProcessRef();
auto &target = exe_ctx.GetTargetRef();

// A simplified description of AsyncContext. See swift/Task/ABI.h
// struct AsyncContext {
// AsyncContext *Parent; // offset 0
// TaskContinuationFunction *ResumeParent; // offset 8
// };
// The resume function is stored at `offsetof(AsyncContext, ResumeParent)`,
// which is the async context's base address plus the size of a pointer.
uint32_t ptr_size = target.GetArchitecture().GetAddressByteSize();
addr_t resume_ptr = async_ctx + ptr_size;
Status status;
addr_t resume_fn = process.ReadPointerFromMemory(resume_ptr, status);
if (status.Fail() || resume_fn == LLDB_INVALID_ADDRESS)
return createStringError("failed to read task's resume function");

return std::make_shared<ThreadTask>(tid, async_ctx, resume_fn, exe_ctx);
}

RegisterContextTask::RegisterContextTask(Thread &thread,
RegisterContextSP reg_info_sp,
addr_t resume_fn, addr_t async_ctx)
Expand Down
3 changes: 0 additions & 3 deletions lldb/source/Plugins/LanguageRuntime/Swift/SwiftTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class ThreadTask final : public Thread {
ThreadTask(tid_t tid, addr_t async_ctx, addr_t resume_fn,
ExecutionContext &exe_ctx);

static llvm::Expected<std::shared_ptr<ThreadTask>>
Create(tid_t tid, addr_t async_ctx, ExecutionContext &exe_ctx);

/// Returns a Task specific register context (RegisterContextTask).
RegisterContextSP GetRegisterContext() override;

Expand Down