Skip to content

[lldb] Fail when running task select or backtrace with a completed task #10325

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 @@ -2161,10 +2161,10 @@ class CommandObjectSwift_RefCount : public CommandObjectRaw {
}
};

/// Construct a `ThreadTask` instance for a Task variable contained in the first
/// argument.
/// Construct a `ThreadTask` instance for a live (yet to be completed) Task
/// variable contained in the first argument.
static llvm::Expected<ThreadSP>
ThreadForTaskArgument(Args &command, ExecutionContext &exe_ctx) {
ThreadForLiveTaskArgument(Args &command, ExecutionContext &exe_ctx) {
if (!exe_ctx.GetFramePtr())
return llvm::createStringError("no active frame selected");

Expand Down Expand Up @@ -2196,12 +2196,15 @@ 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 std::make_shared<ThreadTask>(task_info->id,
task_info->resumeAsyncContext,
task_info->runJob, exe_ctx);
else
auto task_info = reflection_ctx->asyncTaskInfo(task_ptr);
if (!task_info)
return task_info.takeError();
if (task_info->isComplete)
return llvm::createStringError("task has completed");

return std::make_shared<ThreadTask>(task_info->id,
task_info->resumeAsyncContext,
task_info->runJob, exe_ctx);
}

return llvm::createStringError("failed to access Task data from runtime");
Expand Down Expand Up @@ -2230,7 +2233,7 @@ class CommandObjectLanguageSwiftTaskBacktrace final
}

llvm::Expected<ThreadSP> thread_task =
ThreadForTaskArgument(command, m_exe_ctx);
ThreadForLiveTaskArgument(command, m_exe_ctx);
if (auto error = thread_task.takeError()) {
result.AppendError(toString(std::move(error)));
return;
Expand Down Expand Up @@ -2265,7 +2268,7 @@ class CommandObjectLanguageSwiftTaskSelect final : public CommandObjectParsed {
}

llvm::Expected<ThreadSP> thread_task =
ThreadForTaskArgument(command, m_exe_ctx);
ThreadForLiveTaskArgument(command, m_exe_ctx);
if (auto error = thread_task.takeError()) {
result.AppendError(toString(std::move(error)));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ def test(self):
self, "break here", lldb.SBFileSpec("main.swift")
)
self.expect("v task", substrs=["flags:complete"])
self.expect(
"language swift task backtrace task",
error=True,
substrs=["task has completed"],
)
self.expect(
"language swift task select task",
error=True,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated: I wondered if task select should print something when successful?

substrs=["task has completed"],
)