48
48
#include " lldb/ValueObject/ValueObjectCast.h"
49
49
#include " lldb/ValueObject/ValueObjectConstResult.h"
50
50
#include " lldb/ValueObject/ValueObjectVariable.h"
51
- #include " llvm/Support/FormatAdapters.h"
52
51
53
52
#include " lldb/lldb-enumerations.h"
54
53
#include " swift/AST/ASTMangler.h"
@@ -2103,7 +2102,7 @@ class CommandObjectLanguageSwiftTaskBacktrace final
2103
2102
return ;
2104
2103
}
2105
2104
2106
- if (command[0 ].ref ().empty ()) {
2105
+ if (command. empty () || command [0 ].ref ().empty ()) {
2107
2106
result.AppendError (" no task variable" );
2108
2107
return ;
2109
2108
}
@@ -2116,26 +2115,29 @@ class CommandObjectLanguageSwiftTaskBacktrace final
2116
2115
ValueObjectSP valobj_sp = frame.GetValueForVariableExpressionPath (
2117
2116
command[0 ].c_str (), eDynamicDontRunTarget, path_options, var_sp,
2118
2117
status);
2119
- if (!valobj_sp)
2118
+ if (!valobj_sp) {
2119
+ result.AppendError (status.AsCString ());
2120
2120
return ;
2121
+ }
2121
2122
2122
- ValueObjectSP task_obj_sp = valobj_sp->GetChildMemberWithName (" _task" );
2123
- if (!task_obj_sp)
2124
- return ;
2125
- uint64_t task_ptr = task_obj_sp->GetValueAsUnsigned (LLDB_INVALID_ADDRESS);
2126
- if (task_ptr == LLDB_INVALID_ADDRESS)
2127
- return ;
2128
- auto *runtime = SwiftLanguageRuntime::Get (m_exe_ctx.GetProcessSP ());
2129
- if (!runtime)
2123
+ addr_t task_ptr = LLDB_INVALID_ADDRESS;
2124
+ ThreadSafeReflectionContext reflection_ctx;
2125
+ if (ValueObjectSP task_obj_sp =
2126
+ valobj_sp->GetChildMemberWithName (" _task" )) {
2127
+ task_ptr = task_obj_sp->GetValueAsUnsigned (LLDB_INVALID_ADDRESS);
2128
+ if (task_ptr != LLDB_INVALID_ADDRESS)
2129
+ if (auto *runtime = SwiftLanguageRuntime::Get (m_exe_ctx.GetProcessSP ()))
2130
+ reflection_ctx = runtime->GetReflectionContext ();
2131
+ }
2132
+ if (task_ptr == LLDB_INVALID_ADDRESS || !reflection_ctx) {
2133
+ result.AppendError (" failed to access Task data from runtime" );
2130
2134
return ;
2131
- ThreadSafeReflectionContext reflection_ctx =
2132
- runtime-> GetReflectionContext ();
2135
+ }
2136
+
2133
2137
llvm::Expected<ReflectionContextInterface::AsyncTaskInfo> task_info =
2134
2138
reflection_ctx->asyncTaskInfo (task_ptr);
2135
- if (auto err = task_info.takeError ()) {
2136
- LLDB_LOG (GetLog (LLDBLog::DataFormatters | LLDBLog::Types),
2137
- " could not get info for async task {0:x}: {1}" , task_ptr,
2138
- fmt_consume (std::move (err)));
2139
+ if (auto error = task_info.takeError ()) {
2140
+ result.AppendError (toString (std::move (error)));
2139
2141
return ;
2140
2142
}
2141
2143
@@ -2145,8 +2147,10 @@ class CommandObjectLanguageSwiftTaskBacktrace final
2145
2147
result.AppendError (toString (std::move (error)));
2146
2148
return ;
2147
2149
}
2150
+
2151
+ // GetStatus prints the backtrace.
2148
2152
thread_task.get ()->GetStatus (result.GetOutputStream (), 0 , UINT32_MAX, 0 ,
2149
- false , false );
2153
+ false , true );
2150
2154
result.SetStatus (lldb::eReturnStatusSuccessFinishResult);
2151
2155
}
2152
2156
};
0 commit comments