Skip to content

Commit 808bd19

Browse files
committed
[lldb] Add missing int fields to Task synthetic
(cherry-picked from commit 7ef499e)
1 parent 37775d5 commit 808bd19

File tree

4 files changed

+76
-20
lines changed

4 files changed

+76
-20
lines changed

lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
1818
#include "lldb/DataFormatters/FormattersHelpers.h"
1919
#include "lldb/DataFormatters/StringPrinter.h"
20+
#include "lldb/Symbol/CompilerType.h"
2021
#include "lldb/Target/Process.h"
2122
#include "lldb/Utility/ConstString.h"
2223
#include "lldb/Utility/DataBufferHeap.h"
@@ -755,12 +756,33 @@ class EnumSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
755756
class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
756757
public:
757758
TaskSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
758-
: SyntheticChildrenFrontEnd(*valobj_sp.get()) {}
759+
: SyntheticChildrenFrontEnd(*valobj_sp.get()) {
760+
auto target_sp = m_backend.GetTargetSP();
761+
auto ts_or_err =
762+
target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeSwift);
763+
if (auto err = ts_or_err.takeError()) {
764+
LLDB_LOG(
765+
GetLog(LLDBLog::DataFormatters | LLDBLog::Types),
766+
"could not get Swift type system for Task synthetic provider: {0}",
767+
fmt_consume(std::move(err)));
768+
return;
769+
}
770+
m_ts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(ts_or_err->get());
771+
}
759772

760773
constexpr static StringLiteral TaskChildren[] = {
761-
"isChildTask", "isFuture", "isGroupChildTask",
762-
"isAsyncLetTask", "isCancelled", "isStatusRecordLocked",
763-
"isEscalated", "isEnqueued", "isRunning",
774+
"id",
775+
"kind",
776+
"enqueuPriority",
777+
"isChildTask",
778+
"isFuture",
779+
"isGroupChildTask",
780+
"isAsyncLetTask",
781+
"isCancelled",
782+
"isStatusRecordLocked",
783+
"isEscalated",
784+
"isEnqueued",
785+
"isRunning",
764786
};
765787

766788
llvm::Expected<uint32_t> CalculateNumChildren() override {
@@ -770,31 +792,53 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
770792

771793
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
772794
auto target_sp = m_backend.GetTargetSP();
773-
#define RETURN_CHILD(FIELD, NAME) \
774-
if (!FIELD) \
775-
FIELD = ValueObject::CreateValueObjectFromBool(target_sp, \
776-
m_task_info.NAME, #NAME); \
777-
return FIELD
795+
796+
// TypeMangling for "Swift.Bool"
797+
CompilerType bool_type =
798+
m_ts->GetTypeFromMangledTypename(ConstString("$sSbD"));
799+
// TypeMangling for "Swift.UInt32"
800+
CompilerType uint32_type =
801+
m_ts->GetTypeFromMangledTypename(ConstString("$ss6UInt32VD"));
802+
// TypeMangling for "Swift.UInt64"
803+
CompilerType uint64_type =
804+
m_ts->GetTypeFromMangledTypename(ConstString("$ss6UInt64VD"));
805+
806+
#define RETURN_CHILD(FIELD, NAME, TYPE) \
807+
if (!FIELD) { \
808+
auto value = m_task_info.NAME; \
809+
DataExtractor data{reinterpret_cast<const void *>(&value), sizeof(value), \
810+
endian::InlHostByteOrder(), sizeof(void *)}; \
811+
FIELD = ValueObject::CreateValueObjectFromData( \
812+
#NAME, data, m_backend.GetExecutionContextRef(), TYPE); \
813+
} \
814+
return FIELD;
778815

779816
switch (idx) {
780817
case 0:
781-
RETURN_CHILD(m_is_child_task_sp, isChildTask);
818+
RETURN_CHILD(m_id_sp, id, uint64_type);
782819
case 1:
783-
RETURN_CHILD(m_is_future_sp, isFuture);
820+
RETURN_CHILD(m_kind_sp, kind, uint32_type);
784821
case 2:
785-
RETURN_CHILD(m_is_group_child_task_sp, isGroupChildTask);
822+
RETURN_CHILD(m_enqueue_priority_sp, enqueuePriority, uint32_type);
786823
case 3:
787-
RETURN_CHILD(m_is_async_let_task_sp, isAsyncLetTask);
824+
RETURN_CHILD(m_is_child_task_sp, isChildTask, bool_type);
788825
case 4:
789-
RETURN_CHILD(m_is_cancelled_sp, isCancelled);
826+
RETURN_CHILD(m_is_future_sp, isFuture, bool_type);
790827
case 5:
791-
RETURN_CHILD(m_is_status_record_locked_sp, isStatusRecordLocked);
828+
RETURN_CHILD(m_is_group_child_task_sp, isGroupChildTask, bool_type);
792829
case 6:
793-
RETURN_CHILD(m_is_escalated_sp, isEscalated);
830+
RETURN_CHILD(m_is_async_let_task_sp, isAsyncLetTask, bool_type);
794831
case 7:
795-
RETURN_CHILD(m_is_enqueued_sp, isEnqueued);
832+
RETURN_CHILD(m_is_cancelled_sp, isCancelled, bool_type);
796833
case 8:
797-
RETURN_CHILD(m_is_running_sp, isRunning);
834+
RETURN_CHILD(m_is_status_record_locked_sp, isStatusRecordLocked,
835+
bool_type);
836+
case 9:
837+
RETURN_CHILD(m_is_escalated_sp, isEscalated, bool_type);
838+
case 10:
839+
RETURN_CHILD(m_is_enqueued_sp, isEnqueued, bool_type);
840+
case 11:
841+
RETURN_CHILD(m_is_running_sp, isRunning, bool_type);
798842
default:
799843
return {};
800844
}
@@ -820,7 +864,8 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
820864
} else {
821865
m_task_info = *task_info;
822866
for (auto child :
823-
{m_is_child_task_sp, m_is_future_sp, m_is_group_child_task_sp,
867+
{m_id_sp, m_kind_sp, m_enqueue_priority_sp, m_is_child_task_sp,
868+
m_is_future_sp, m_is_group_child_task_sp,
824869
m_is_async_let_task_sp, m_is_cancelled_sp,
825870
m_is_status_record_locked_sp, m_is_escalated_sp,
826871
m_is_enqueued_sp, m_is_running_sp})
@@ -835,14 +880,18 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
835880

836881
size_t GetIndexOfChildWithName(ConstString name) override {
837882
ArrayRef children = TaskChildren;
838-
auto it = llvm::find(children, name);
883+
const auto *it = llvm::find(children, name);
839884
if (it == children.end())
840885
return UINT32_MAX;
841886
return std::distance(children.begin(), it);
842887
}
843888

844889
private:
890+
TypeSystemSwiftTypeRef *m_ts = nullptr;
845891
ReflectionContextInterface::AsyncTaskInfo m_task_info;
892+
ValueObjectSP m_id_sp;
893+
ValueObjectSP m_kind_sp;
894+
ValueObjectSP m_enqueue_priority_sp;
846895
ValueObjectSP m_is_child_task_sp;
847896
ValueObjectSP m_is_future_sp;
848897
ValueObjectSP m_is_group_child_task_sp;

lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ class TargetReflectionContext : public ReflectionContextInterface {
404404
result.isRunning = task_info.IsRunning;
405405
result.isEnqueued = task_info.IsEnqueued;
406406
result.id = task_info.Id;
407+
result.kind = task_info.Kind;
408+
result.enqueuePriority = task_info.EnqueuePriority;
407409
result.resumeAsyncContext = task_info.ResumeAsyncContext;
408410
return result;
409411
}

lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContextInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ class ReflectionContextInterface {
167167
bool isRunning = false;
168168
bool isEnqueued = false;
169169
uint64_t id = 0;
170+
uint32_t kind = 0;
171+
uint32_t enqueuePriority = 0;
170172
lldb::addr_t resumeAsyncContext = LLDB_INVALID_ADDRESS;
171173
};
172174
// The default limits are copied from swift-inspect.

lldb/test/API/lang/swift/async/formatters/task/TestSwiftTaskSyntheticProvider.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def test_top_level_task(self):
1919
"frame var task",
2020
substrs=[
2121
"(Task<(), Error>) task = {",
22+
"id = 2",
23+
"kind = 0",
24+
"enqueuePriority = 21",
2225
"isChildTask = false",
2326
"isFuture = true",
2427
"isGroupChildTask = false",

0 commit comments

Comments
 (0)