@@ -2164,58 +2164,72 @@ class CommandObjectSwift_RefCount : public CommandObjectRaw {
21642164// / Construct a `ThreadTask` instance for a Task variable contained in the first
21652165// / argument.
21662166static llvm::Expected<ThreadSP>
2167- ThreadForTaskVariable (Args &command, ExecutionContext &exe_ctx) {
2167+ ThreadForTaskArgument (Args &command, ExecutionContext &exe_ctx) {
21682168 if (!exe_ctx.GetFramePtr ())
21692169 return llvm::createStringError (" no active frame selected" );
21702170
21712171 if (command.empty () || command[0 ].ref ().empty ())
21722172 return llvm::createStringError (" missing task variable argument" );
21732173
2174+ StringRef arg = command[0 ].ref ();
2175+
21742176 StackFrame &frame = exe_ctx.GetFrameRef ();
21752177 uint32_t path_options =
21762178 StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
21772179 VariableSP var_sp;
21782180 Status status;
21792181 ValueObjectSP valobj_sp = frame.GetValueForVariableExpressionPath (
2180- command[0 ].c_str (), eDynamicDontRunTarget, path_options, var_sp, status);
2181- if (!valobj_sp)
2182- return status.takeError ();
2182+ arg, eDynamicDontRunTarget, path_options, var_sp, status);
21832183
21842184 addr_t task_ptr = LLDB_INVALID_ADDRESS;
2185- ThreadSafeReflectionContext reflection_ctx;
2186- if (ValueObjectSP task_obj_sp = valobj_sp->GetChildMemberWithName (" _task" )) {
2187- task_ptr = task_obj_sp->GetValueAsUnsigned (LLDB_INVALID_ADDRESS);
2188- if (task_ptr != LLDB_INVALID_ADDRESS)
2189- if (auto *runtime = SwiftLanguageRuntime::Get (exe_ctx.GetProcessSP ()))
2190- reflection_ctx = runtime->GetReflectionContext ();
2185+ if (status.Success () && valobj_sp) {
2186+ if (auto task_obj_sp = valobj_sp->GetChildMemberWithName (" _task" ))
2187+ task_ptr = task_obj_sp->GetValueAsUnsigned (LLDB_INVALID_ADDRESS);
2188+ if (task_ptr == LLDB_INVALID_ADDRESS)
2189+ return llvm::createStringError (" failed to access Task pointer" );
2190+ } else {
2191+ // The argument is not a valid variable expression, try parsing it as a
2192+ // (task) address.
2193+ if (arg.getAsInteger (0 , task_ptr))
2194+ return status.takeError ();
21912195 }
2192- if (task_ptr == LLDB_INVALID_ADDRESS || !reflection_ctx)
2193- return llvm::createStringError (" failed to access Task data from runtime" );
21942196
2195- llvm::Expected<ReflectionContextInterface::AsyncTaskInfo> task_info =
2196- reflection_ctx->asyncTaskInfo (task_ptr);
2197- if (auto error = task_info.takeError ())
2198- return error;
2197+ if (auto *runtime = SwiftLanguageRuntime::Get (exe_ctx.GetProcessSP ()))
2198+ if (auto reflection_ctx = runtime->GetReflectionContext ()) {
2199+ if (auto task_info = reflection_ctx->asyncTaskInfo (task_ptr))
2200+ return ThreadTask::Create (task_info->id , task_info->resumeAsyncContext ,
2201+ exe_ctx);
2202+ else
2203+ return task_info.takeError ();
2204+ }
21992205
2200- return ThreadTask::Create (task_info->id , task_info->resumeAsyncContext ,
2201- exe_ctx);
2206+ return llvm::createStringError (" failed to access Task data from runtime" );
22022207}
22032208
22042209class CommandObjectLanguageSwiftTaskBacktrace final
22052210 : public CommandObjectParsed {
22062211public:
22072212 CommandObjectLanguageSwiftTaskBacktrace (CommandInterpreter &interpreter)
2208- : CommandObjectParsed(interpreter, " backtrace" ,
2209- " Show the backtrace of Swift tasks. See `thread "
2210- " backtrace` for customizing backtrace output." ,
2211- " language swift task backtrace <variable-name>" ) {
2212- AddSimpleArgumentList (eArgTypeVarName);
2213+ : CommandObjectParsed(
2214+ interpreter, " backtrace" ,
2215+ " Show the backtrace of Swift tasks. See `thread "
2216+ " backtrace` for customizing backtrace output." ,
2217+ " language swift task backtrace <variable-name | address>" ) {
2218+ CommandArgumentEntry arg_entry;
2219+ arg_entry.emplace_back (eArgTypeVarName, eArgRepeatPlain, LLDB_OPT_SET_1);
2220+ arg_entry.emplace_back (eArgTypeAddress, eArgRepeatPlain, LLDB_OPT_SET_2);
2221+ m_arguments.push_back (arg_entry);
22132222 }
22142223
22152224private:
22162225 void DoExecute (Args &command, CommandReturnObject &result) override {
2226+ if (command.GetArgumentCount () != 1 ) {
2227+ result.AppendError (" missing <variable-name> or <address> argument" );
2228+ return ;
2229+ }
2230+
22172231 llvm::Expected<ThreadSP> thread_task =
2218- ThreadForTaskVariable (command, m_exe_ctx);
2232+ ThreadForTaskArgument (command, m_exe_ctx);
22192233 if (auto error = thread_task.takeError ()) {
22202234 result.AppendError (toString (std::move (error)));
22212235 return ;
@@ -2235,14 +2249,22 @@ class CommandObjectLanguageSwiftTaskSelect final : public CommandObjectParsed {
22352249 interpreter, " select" ,
22362250 " Change the currently selected thread to thread representation of "
22372251 " the given Swift Task. See `thread select`." ,
2238- " language swift task select <variable-name>" ) {
2239- AddSimpleArgumentList (eArgTypeVarName);
2252+ " language swift task select <variable-name | address>" ) {
2253+ CommandArgumentEntry arg_entry;
2254+ arg_entry.emplace_back (eArgTypeVarName, eArgRepeatPlain, LLDB_OPT_SET_1);
2255+ arg_entry.emplace_back (eArgTypeAddress, eArgRepeatPlain, LLDB_OPT_SET_2);
2256+ m_arguments.push_back (arg_entry);
22402257 }
22412258
22422259private:
22432260 void DoExecute (Args &command, CommandReturnObject &result) override {
2261+ if (command.GetArgumentCount () != 1 ) {
2262+ result.AppendError (" missing <variable-name> or <address> argument" );
2263+ return ;
2264+ }
2265+
22442266 llvm::Expected<ThreadSP> thread_task =
2245- ThreadForTaskVariable (command, m_exe_ctx);
2267+ ThreadForTaskArgument (command, m_exe_ctx);
22462268 if (auto error = thread_task.takeError ()) {
22472269 result.AppendError (toString (std::move (error)));
22482270 return ;
0 commit comments