@@ -2161,10 +2161,10 @@ class CommandObjectSwift_RefCount : public CommandObjectRaw {
21612161 }
21622162};
21632163
2164- // / Construct a `ThreadTask` instance for a Task variable contained in the first
2165- // / argument.
2164+ // / Construct a `ThreadTask` instance for a live (yet to be completed) Task
2165+ // / variable contained in the first argument.
21662166static llvm::Expected<ThreadSP>
2167- ThreadForTaskArgument (Args &command, ExecutionContext &exe_ctx) {
2167+ ThreadForLiveTaskArgument (Args &command, ExecutionContext &exe_ctx) {
21682168 if (!exe_ctx.GetFramePtr ())
21692169 return llvm::createStringError (" no active frame selected" );
21702170
@@ -2196,12 +2196,15 @@ ThreadForTaskArgument(Args &command, ExecutionContext &exe_ctx) {
21962196
21972197 if (auto *runtime = SwiftLanguageRuntime::Get (exe_ctx.GetProcessSP ()))
21982198 if (auto reflection_ctx = runtime->GetReflectionContext ()) {
2199- if (auto task_info = reflection_ctx->asyncTaskInfo (task_ptr))
2200- return std::make_shared<ThreadTask>(task_info->id ,
2201- task_info->resumeAsyncContext ,
2202- task_info->runJob , exe_ctx);
2203- else
2199+ auto task_info = reflection_ctx->asyncTaskInfo (task_ptr);
2200+ if (!task_info)
22042201 return task_info.takeError ();
2202+ if (task_info->isComplete )
2203+ return llvm::createStringError (" task has completed" );
2204+
2205+ return std::make_shared<ThreadTask>(task_info->id ,
2206+ task_info->resumeAsyncContext ,
2207+ task_info->runJob , exe_ctx);
22052208 }
22062209
22072210 return llvm::createStringError (" failed to access Task data from runtime" );
@@ -2230,7 +2233,7 @@ class CommandObjectLanguageSwiftTaskBacktrace final
22302233 }
22312234
22322235 llvm::Expected<ThreadSP> thread_task =
2233- ThreadForTaskArgument (command, m_exe_ctx);
2236+ ThreadForLiveTaskArgument (command, m_exe_ctx);
22342237 if (auto error = thread_task.takeError ()) {
22352238 result.AppendError (toString (std::move (error)));
22362239 return ;
@@ -2265,7 +2268,7 @@ class CommandObjectLanguageSwiftTaskSelect final : public CommandObjectParsed {
22652268 }
22662269
22672270 llvm::Expected<ThreadSP> thread_task =
2268- ThreadForTaskArgument (command, m_exe_ctx);
2271+ ThreadForLiveTaskArgument (command, m_exe_ctx);
22692272 if (auto error = thread_task.takeError ()) {
22702273 result.AppendError (toString (std::move (error)));
22712274 return ;
0 commit comments