From 4887626344a50be3bc2ba7d2b99b4a3f136e8516 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Mon, 30 Jun 2025 10:09:14 -0700 Subject: [PATCH] [lldb] Include "suspended" flag for Tasks --- .../Plugins/Language/Swift/SwiftFormatters.cpp | 11 ++++++++--- .../LanguageRuntime/Swift/ReflectionContext.cpp | 1 + .../Swift/ReflectionContextInterface.h | 1 + .../async/formatters/task/suspended/Makefile | 3 +++ .../task/suspended/TestSwiftTaskSuspended.py | 16 ++++++++++++++++ .../async/formatters/task/suspended/main.swift | 9 +++++++++ 6 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 lldb/test/API/lang/swift/async/formatters/task/suspended/Makefile create mode 100644 lldb/test/API/lang/swift/async/formatters/task/suspended/TestSwiftTaskSuspended.py create mode 100644 lldb/test/API/lang/swift/async/formatters/task/suspended/main.swift diff --git a/lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp b/lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp index 2eaf88d0c7738..9097c673fd072 100644 --- a/lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp +++ b/lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp @@ -824,6 +824,7 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd { "isEscalated", "isEnqueued", "isComplete", + "isSuspended", "isRunning", // clang-format on }; @@ -957,7 +958,9 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd { RETURN_CHILD(m_is_enqueued_sp, isEnqueued, bool_type); case 13: RETURN_CHILD(m_is_complete_sp, isComplete, bool_type); - case 14: { + case 14: + RETURN_CHILD(m_is_suspended_sp, isSuspended, bool_type); + case 15: { if (m_task_info.hasIsRunning) RETURN_CHILD(m_is_running_sp, isRunning, bool_type); return {}; @@ -990,8 +993,8 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd { m_is_child_task_sp, m_is_future_sp, m_is_group_child_task_sp, m_is_async_let_task_sp, m_is_cancelled_sp, m_is_status_record_locked_sp, m_is_escalated_sp, - m_is_enqueued_sp, m_is_complete_sp, m_parent_task_sp, - m_child_tasks_sp, m_is_running_sp}) + m_is_enqueued_sp, m_is_complete_sp, m_is_suspended_sp, + m_parent_task_sp, m_child_tasks_sp, m_is_running_sp}) child.reset(); } } @@ -1027,6 +1030,7 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd { ValueObjectSP m_is_escalated_sp; ValueObjectSP m_is_enqueued_sp; ValueObjectSP m_is_complete_sp; + ValueObjectSP m_is_suspended_sp; ValueObjectSP m_parent_task_sp; ValueObjectSP m_child_tasks_sp; ValueObjectSP m_is_running_sp; @@ -1917,6 +1921,7 @@ bool lldb_private::formatters::swift::TaskPriority_SummaryProvider( static const std::pair TASK_FLAGS[] = { {"isComplete", "complete"}, + {"isSuspended", "suspended"}, {"isRunning", "running"}, {"isCancelled", "cancelled"}, {"isEscalated", "escalated"}, diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp b/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp index ee0e5505c6d7d..4f4e8d03d2f26 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp +++ b/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContext.cpp @@ -415,6 +415,7 @@ class TargetReflectionContext : public ReflectionContextInterface { result.isRunning = task_info.IsRunning; result.isEnqueued = task_info.IsEnqueued; result.isComplete = task_info.IsComplete; + result.isSuspended = task_info.IsSuspended; result.id = task_info.Id; result.kind = task_info.Kind; result.enqueuePriority = task_info.EnqueuePriority; diff --git a/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContextInterface.h b/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContextInterface.h index 94de3e8c66a6f..4779b622ab72e 100644 --- a/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContextInterface.h +++ b/lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContextInterface.h @@ -169,6 +169,7 @@ class ReflectionContextInterface { bool isRunning = false; bool isEnqueued = false; bool isComplete = false; + bool isSuspended = false; uint64_t id = 0; uint32_t kind = 0; uint32_t enqueuePriority = 0; diff --git a/lldb/test/API/lang/swift/async/formatters/task/suspended/Makefile b/lldb/test/API/lang/swift/async/formatters/task/suspended/Makefile new file mode 100644 index 0000000000000..cca30b939e652 --- /dev/null +++ b/lldb/test/API/lang/swift/async/formatters/task/suspended/Makefile @@ -0,0 +1,3 @@ +SWIFT_SOURCES := main.swift +SWIFTFLAGS_EXTRAS := -parse-as-library +include Makefile.rules diff --git a/lldb/test/API/lang/swift/async/formatters/task/suspended/TestSwiftTaskSuspended.py b/lldb/test/API/lang/swift/async/formatters/task/suspended/TestSwiftTaskSuspended.py new file mode 100644 index 0000000000000..c2a4cde98634e --- /dev/null +++ b/lldb/test/API/lang/swift/async/formatters/task/suspended/TestSwiftTaskSuspended.py @@ -0,0 +1,16 @@ +import textwrap +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class TestCase(TestBase): + + @swiftTest + def test(self): + self.build() + lldbutil.run_to_source_breakpoint( + self, "break here", lldb.SBFileSpec("main.swift") + ) + self.expect("v task", substrs=["flags:suspended"]) diff --git a/lldb/test/API/lang/swift/async/formatters/task/suspended/main.swift b/lldb/test/API/lang/swift/async/formatters/task/suspended/main.swift new file mode 100644 index 0000000000000..5566d540ad3e9 --- /dev/null +++ b/lldb/test/API/lang/swift/async/formatters/task/suspended/main.swift @@ -0,0 +1,9 @@ +@main struct Main { + static func main() async { + let task = Task { + try? await Task.sleep(for: .seconds(100)) + } + try? await Task.sleep(for: .seconds(0.5)) + print("break here") + } +}