@@ -2164,58 +2164,72 @@ class CommandObjectSwift_RefCount : public CommandObjectRaw {
2164
2164
// / Construct a `ThreadTask` instance for a Task variable contained in the first
2165
2165
// / argument.
2166
2166
static llvm::Expected<ThreadSP>
2167
- ThreadForTaskVariable (Args &command, ExecutionContext &exe_ctx) {
2167
+ ThreadForTaskArgument (Args &command, ExecutionContext &exe_ctx) {
2168
2168
if (!exe_ctx.GetFramePtr ())
2169
2169
return llvm::createStringError (" no active frame selected" );
2170
2170
2171
2171
if (command.empty () || command[0 ].ref ().empty ())
2172
2172
return llvm::createStringError (" missing task variable argument" );
2173
2173
2174
+ StringRef arg = command[0 ].ref ();
2175
+
2174
2176
StackFrame &frame = exe_ctx.GetFrameRef ();
2175
2177
uint32_t path_options =
2176
2178
StackFrame::eExpressionPathOptionsAllowDirectIVarAccess;
2177
2179
VariableSP var_sp;
2178
2180
Status status;
2179
2181
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);
2183
2183
2184
2184
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 ();
2191
2195
}
2192
- if (task_ptr == LLDB_INVALID_ADDRESS || !reflection_ctx)
2193
- return llvm::createStringError (" failed to access Task data from runtime" );
2194
2196
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
+ }
2199
2205
2200
- return ThreadTask::Create (task_info->id , task_info->resumeAsyncContext ,
2201
- exe_ctx);
2206
+ return llvm::createStringError (" failed to access Task data from runtime" );
2202
2207
}
2203
2208
2204
2209
class CommandObjectLanguageSwiftTaskBacktrace final
2205
2210
: public CommandObjectParsed {
2206
2211
public:
2207
2212
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);
2213
2222
}
2214
2223
2215
2224
private:
2216
2225
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
+
2217
2231
llvm::Expected<ThreadSP> thread_task =
2218
- ThreadForTaskVariable (command, m_exe_ctx);
2232
+ ThreadForTaskArgument (command, m_exe_ctx);
2219
2233
if (auto error = thread_task.takeError ()) {
2220
2234
result.AppendError (toString (std::move (error)));
2221
2235
return ;
@@ -2235,14 +2249,22 @@ class CommandObjectLanguageSwiftTaskSelect final : public CommandObjectParsed {
2235
2249
interpreter, " select" ,
2236
2250
" Change the currently selected thread to thread representation of "
2237
2251
" 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);
2240
2257
}
2241
2258
2242
2259
private:
2243
2260
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
+
2244
2266
llvm::Expected<ThreadSP> thread_task =
2245
- ThreadForTaskVariable (command, m_exe_ctx);
2267
+ ThreadForTaskArgument (command, m_exe_ctx);
2246
2268
if (auto error = thread_task.takeError ()) {
2247
2269
result.AppendError (toString (std::move (error)));
2248
2270
return ;
0 commit comments