36
36
#include " swift/Demangling/ManglingMacros.h"
37
37
#include " llvm/ADT/STLExtras.h"
38
38
#include " llvm/ADT/StringRef.h"
39
+ #include " llvm/ADT/iterator_range.h"
39
40
#include " llvm/Support/Error.h"
40
41
#include " llvm/Support/FormatAdapters.h"
41
42
#include " llvm/Support/raw_ostream.h"
@@ -778,10 +779,13 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
778
779
}
779
780
780
781
constexpr static StringLiteral TaskChildren[] = {
782
+ // clang-format off
781
783
" address" ,
782
784
" id" ,
783
- " kind" ,
784
- " enqueuPriority" ,
785
+ " enqueuePriority" ,
786
+ " children" ,
787
+
788
+ // Children below this point are hidden.
785
789
" isChildTask" ,
786
790
" isFuture" ,
787
791
" isGroupChildTask" ,
@@ -790,13 +794,13 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
790
794
" isStatusRecordLocked" ,
791
795
" isEscalated" ,
792
796
" isEnqueued" ,
793
- " children" ,
794
797
" isRunning" ,
798
+ // clang-format on
795
799
};
796
800
797
801
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 ;
800
804
}
801
805
802
806
lldb::ValueObjectSP GetChildAtIndex (uint32_t idx) override {
@@ -805,15 +809,6 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
805
809
// TypeMangling for "Swift.Bool"
806
810
CompilerType bool_type =
807
811
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" ));
817
812
818
813
#define RETURN_CHILD (FIELD, NAME, TYPE ) \
819
814
if (!FIELD) { \
@@ -841,12 +836,34 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
841
836
raw_pointer_type);
842
837
}
843
838
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" ));
845
843
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" ));
849
849
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
+ }
850
867
case 4 :
851
868
RETURN_CHILD (m_is_child_task_sp, isChildTask, bool_type);
852
869
case 5 :
@@ -865,22 +882,10 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
865
882
case 11 :
866
883
RETURN_CHILD (m_is_enqueued_sp, isEnqueued, bool_type);
867
884
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 {};
881
888
}
882
- case 13 :
883
- RETURN_CHILD (m_is_running_sp, isRunning, bool_type);
884
889
default :
885
890
return {};
886
891
}
@@ -1641,6 +1646,42 @@ bool lldb_private::formatters::swift::TaskPriority_SummaryProvider(
1641
1646
return true ;
1642
1647
}
1643
1648
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
+
1644
1685
namespace {
1645
1686
1646
1687
// / Enumerate the kinds of SIMD elements.
0 commit comments