4848#include " lldb/ValueObject/ValueObjectCast.h"
4949#include " lldb/ValueObject/ValueObjectConstResult.h"
5050#include " lldb/ValueObject/ValueObjectVariable.h"
51- #include " llvm/Support/FormatAdapters.h"
5251
5352#include " lldb/lldb-enumerations.h"
5453#include " swift/AST/ASTMangler.h"
@@ -2103,7 +2102,7 @@ class CommandObjectLanguageSwiftTaskBacktrace final
21032102 return ;
21042103 }
21052104
2106- if (command[0 ].ref ().empty ()) {
2105+ if (command. empty () || command [0 ].ref ().empty ()) {
21072106 result.AppendError (" no task variable" );
21082107 return ;
21092108 }
@@ -2116,26 +2115,29 @@ class CommandObjectLanguageSwiftTaskBacktrace final
21162115 ValueObjectSP valobj_sp = frame.GetValueForVariableExpressionPath (
21172116 command[0 ].c_str (), eDynamicDontRunTarget, path_options, var_sp,
21182117 status);
2119- if (!valobj_sp)
2118+ if (!valobj_sp) {
2119+ result.AppendError (status.AsCString ());
21202120 return ;
2121+ }
21212122
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" );
21302134 return ;
2131- ThreadSafeReflectionContext reflection_ctx =
2132- runtime-> GetReflectionContext ();
2135+ }
2136+
21332137 llvm::Expected<ReflectionContextInterface::AsyncTaskInfo> task_info =
21342138 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)));
21392141 return ;
21402142 }
21412143
@@ -2145,8 +2147,10 @@ class CommandObjectLanguageSwiftTaskBacktrace final
21452147 result.AppendError (toString (std::move (error)));
21462148 return ;
21472149 }
2150+
2151+ // GetStatus prints the backtrace.
21482152 thread_task.get ()->GetStatus (result.GetOutputStream (), 0 , UINT32_MAX, 0 ,
2149- false , false );
2153+ false , true );
21502154 result.SetStatus (lldb::eReturnStatusSuccessFinishResult);
21512155 }
21522156};
0 commit comments