3636#include " swift/Demangling/ManglingMacros.h"
3737#include " llvm/ADT/STLExtras.h"
3838#include " llvm/ADT/StringRef.h"
39+ #include " llvm/ADT/iterator_range.h"
3940#include " llvm/Support/Error.h"
4041#include " llvm/Support/FormatAdapters.h"
4142#include " llvm/Support/raw_ostream.h"
@@ -778,10 +779,13 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
778779 }
779780
780781 constexpr static StringLiteral TaskChildren[] = {
782+ // clang-format off
781783 " address" ,
782784 " id" ,
783- " kind" ,
784- " enqueuPriority" ,
785+ " enqueuePriority" ,
786+ " children" ,
787+
788+ // Children below this point are hidden.
785789 " isChildTask" ,
786790 " isFuture" ,
787791 " isGroupChildTask" ,
@@ -790,13 +794,13 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
790794 " isStatusRecordLocked" ,
791795 " isEscalated" ,
792796 " isEnqueued" ,
793- " children" ,
794797 " isRunning" ,
798+ // clang-format on
795799 };
796800
797801 llvm::Expected<uint32_t > CalculateNumChildren () override {
798- auto count = ArrayRef (TaskChildren). size ();
799- return m_task_info. hasIsRunning ? count : count - 1 ;
802+ // Show only the first four children address/id/enqueuePriority/children.
803+ return 4 ;
800804 }
801805
802806 lldb::ValueObjectSP GetChildAtIndex (uint32_t idx) override {
@@ -805,15 +809,6 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
805809 // TypeMangling for "Swift.Bool"
806810 CompilerType bool_type =
807811 m_ts->GetTypeFromMangledTypename (ConstString (" $sSbD" ));
808- // TypeMangling for "Swift.UInt32"
809- CompilerType uint32_type =
810- m_ts->GetTypeFromMangledTypename (ConstString (" $ss6UInt32VD" ));
811- // TypeMangling for "Swift.UInt64"
812- CompilerType uint64_type =
813- m_ts->GetTypeFromMangledTypename (ConstString (" $ss6UInt64VD" ));
814- // TypeMangling for "Swift.TaskPriority"
815- CompilerType priority_type =
816- m_ts->GetTypeFromMangledTypename (ConstString (" $sScPD" ));
817812
818813#define RETURN_CHILD (FIELD, NAME, TYPE ) \
819814 if (!FIELD) { \
@@ -841,12 +836,34 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
841836 raw_pointer_type);
842837 }
843838 return m_address_sp;
844- case 1 :
839+ case 1 : {
840+ // TypeMangling for "Swift.UInt64"
841+ CompilerType uint64_type =
842+ m_ts->GetTypeFromMangledTypename (ConstString (" $ss6UInt64VD" ));
845843 RETURN_CHILD (m_id_sp, id, uint64_type);
846- case 2 :
847- RETURN_CHILD (m_kind_sp, kind, uint32_type);
848- case 3 :
844+ }
845+ case 2 : {
846+ // TypeMangling for "Swift.TaskPriority"
847+ CompilerType priority_type =
848+ m_ts->GetTypeFromMangledTypename (ConstString (" $sScPD" ));
849849 RETURN_CHILD (m_enqueue_priority_sp, enqueuePriority, priority_type);
850+ }
851+ case 3 : {
852+ if (!m_child_tasks_sp) {
853+ using task_type = decltype (m_task_info.childTasks )::value_type;
854+ const std::vector<task_type> &tasks = m_task_info.childTasks ;
855+ std::string mangled_typename =
856+ mangledTypenameForTasksTuple (tasks.size ());
857+ CompilerType tasks_tuple_type =
858+ m_ts->GetTypeFromMangledTypename (ConstString (mangled_typename));
859+ DataExtractor data{tasks.data (), tasks.size () * sizeof (task_type),
860+ endian::InlHostByteOrder (), sizeof (void *)};
861+ m_child_tasks_sp = ValueObject::CreateValueObjectFromData (
862+ " children" , data, m_backend.GetExecutionContextRef (),
863+ tasks_tuple_type);
864+ }
865+ return m_child_tasks_sp;
866+ }
850867 case 4 :
851868 RETURN_CHILD (m_is_child_task_sp, isChildTask, bool_type);
852869 case 5 :
@@ -865,22 +882,10 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
865882 case 11 :
866883 RETURN_CHILD (m_is_enqueued_sp, isEnqueued, bool_type);
867884 case 12 : {
868- if (!m_child_tasks_sp) {
869- const auto &tasks = m_task_info.childTasks ;
870- std::string mangled_typename =
871- mangledTypenameForTasksTuple (tasks.size ());
872- CompilerType tasks_tuple_type =
873- m_ts->GetTypeFromMangledTypename (ConstString (mangled_typename));
874- DataExtractor data{tasks.data (), tasks.size () * sizeof (tasks[0 ]),
875- endian::InlHostByteOrder (), sizeof (void *)};
876- m_child_tasks_sp = ValueObject::CreateValueObjectFromData (
877- " children" , data, m_backend.GetExecutionContextRef (),
878- tasks_tuple_type);
879- }
880- return m_child_tasks_sp;
885+ if (m_task_info.hasIsRunning )
886+ RETURN_CHILD (m_is_running_sp, isRunning, bool_type);
887+ return {};
881888 }
882- case 13 :
883- RETURN_CHILD (m_is_running_sp, isRunning, bool_type);
884889 default :
885890 return {};
886891 }
@@ -1641,6 +1646,42 @@ bool lldb_private::formatters::swift::TaskPriority_SummaryProvider(
16411646 return true ;
16421647}
16431648
1649+ static const std::pair<StringRef, StringRef> TASK_FLAGS[] = {
1650+ {" isRunning" , " running" },
1651+ {" isCancelled" , " cancelled" },
1652+ {" isEscalated" , " escalated" },
1653+ {" isEnqueued" , " enqueued" },
1654+ {" isGroupChildTask" , " groupChildTask" },
1655+ {" isAsyncLetTask" , " asyncLetTask" },
1656+ {" isChildTask" , " childTask" },
1657+ {" isFuture" , " future" },
1658+ {" isStatusRecordLocked" , " statusRecordLocked" },
1659+ };
1660+
1661+ bool lldb_private::formatters::swift::Task_SummaryProvider (
1662+ ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
1663+ auto get_member = [&valobj](StringRef name) -> uint64_t {
1664+ if (auto member_sp = valobj.GetChildMemberWithName (name))
1665+ if (auto synthetic_sp = member_sp->GetSyntheticValue ())
1666+ return synthetic_sp->GetValueAsUnsigned (0 );
1667+ return 0 ;
1668+ };
1669+
1670+ stream.Format (" id:{0}" , get_member (" id" ));
1671+
1672+ std::vector<StringRef> flags;
1673+ for (auto [member, flag] : TASK_FLAGS)
1674+ if (get_member (member))
1675+ flags.push_back (flag);
1676+
1677+ if (!flags.empty ())
1678+ // Append the flags in an `|` separated list. This matches the format used
1679+ // by swift-inspect dump-concurrency.
1680+ stream.Format (" flags:{0:$[|]}" , iterator_range (flags));
1681+
1682+ return true ;
1683+ }
1684+
16441685namespace {
16451686
16461687// / Enumerate the kinds of SIMD elements.
0 commit comments