Skip to content

Commit 095ef91

Browse files
committed
[lldb] Add "address" member to Task formatter
1 parent acc4f5e commit 095ef91

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

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

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
777777
}
778778

779779
constexpr static StringLiteral TaskChildren[] = {
780+
"address",
780781
"id",
781782
"kind",
782783
"enqueuPriority",
@@ -822,29 +823,44 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
822823

823824
switch (idx) {
824825
case 0:
825-
RETURN_CHILD(m_id_sp, id, uint64_type);
826+
if (!m_address_sp) {
827+
// TypeMangling for "Swift.UnsafeRawPointer"
828+
CompilerType raw_pointer_type =
829+
m_ts->GetTypeFromMangledTypename(ConstString("$sSVD"));
830+
831+
addr_t value = m_task_ptr;
832+
DataExtractor data{reinterpret_cast<const void *>(&value),
833+
sizeof(value), endian::InlHostByteOrder(),
834+
sizeof(void *)};
835+
m_address_sp = ValueObject::CreateValueObjectFromData(
836+
"address", data, m_backend.GetExecutionContextRef(),
837+
raw_pointer_type);
838+
}
839+
return m_address_sp;
826840
case 1:
827-
RETURN_CHILD(m_kind_sp, kind, uint32_type);
841+
RETURN_CHILD(m_id_sp, id, uint64_type);
828842
case 2:
829-
RETURN_CHILD(m_enqueue_priority_sp, enqueuePriority, uint32_type);
843+
RETURN_CHILD(m_kind_sp, kind, uint32_type);
830844
case 3:
831-
RETURN_CHILD(m_is_child_task_sp, isChildTask, bool_type);
845+
RETURN_CHILD(m_enqueue_priority_sp, enqueuePriority, uint32_type);
832846
case 4:
833-
RETURN_CHILD(m_is_future_sp, isFuture, bool_type);
847+
RETURN_CHILD(m_is_child_task_sp, isChildTask, bool_type);
834848
case 5:
835-
RETURN_CHILD(m_is_group_child_task_sp, isGroupChildTask, bool_type);
849+
RETURN_CHILD(m_is_future_sp, isFuture, bool_type);
836850
case 6:
837-
RETURN_CHILD(m_is_async_let_task_sp, isAsyncLetTask, bool_type);
851+
RETURN_CHILD(m_is_group_child_task_sp, isGroupChildTask, bool_type);
838852
case 7:
839-
RETURN_CHILD(m_is_cancelled_sp, isCancelled, bool_type);
853+
RETURN_CHILD(m_is_async_let_task_sp, isAsyncLetTask, bool_type);
840854
case 8:
855+
RETURN_CHILD(m_is_cancelled_sp, isCancelled, bool_type);
856+
case 9:
841857
RETURN_CHILD(m_is_status_record_locked_sp, isStatusRecordLocked,
842858
bool_type);
843-
case 9:
844-
RETURN_CHILD(m_is_escalated_sp, isEscalated, bool_type);
845859
case 10:
860+
RETURN_CHILD(m_is_escalated_sp, isEscalated, bool_type);
861+
case 11:
846862
RETURN_CHILD(m_is_enqueued_sp, isEnqueued, bool_type);
847-
case 11: {
863+
case 12: {
848864
if (!m_child_tasks_sp) {
849865
const auto &tasks = m_task_info.childTasks;
850866
std::string mangled_typename =
@@ -859,7 +875,7 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
859875
}
860876
return m_child_tasks_sp;
861877
}
862-
case 12:
878+
case 13:
863879
RETURN_CHILD(m_is_running_sp, isRunning, bool_type);
864880
default:
865881
return {};
@@ -875,19 +891,19 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
875891
ValueObjectSP task_obj_sp = m_backend.GetChildMemberWithName("_task");
876892
if (!task_obj_sp)
877893
return ChildCacheState::eRefetch;
878-
uint64_t task_ptr = task_obj_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
879-
if (task_ptr != LLDB_INVALID_ADDRESS) {
894+
m_task_ptr = task_obj_sp->GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
895+
if (m_task_ptr != LLDB_INVALID_ADDRESS) {
880896
llvm::Expected<ReflectionContextInterface::AsyncTaskInfo> task_info =
881-
reflection_ctx->asyncTaskInfo(task_ptr);
897+
reflection_ctx->asyncTaskInfo(m_task_ptr);
882898
if (auto err = task_info.takeError()) {
883899
LLDB_LOG_ERROR(
884900
GetLog(LLDBLog::DataFormatters | LLDBLog::Types), std::move(err),
885-
"could not get info for async task {0:x}: {1}", task_ptr);
901+
"could not get info for async task {0:x}: {1}", m_task_ptr);
886902
} else {
887903
m_task_info = *task_info;
888904
for (auto child :
889-
{m_id_sp, m_kind_sp, m_enqueue_priority_sp, m_is_child_task_sp,
890-
m_is_future_sp, m_is_group_child_task_sp,
905+
{m_address_sp, m_id_sp, m_kind_sp, m_enqueue_priority_sp,
906+
m_is_child_task_sp, m_is_future_sp, m_is_group_child_task_sp,
891907
m_is_async_let_task_sp, m_is_cancelled_sp,
892908
m_is_status_record_locked_sp, m_is_escalated_sp,
893909
m_is_enqueued_sp, m_child_tasks_sp, m_is_running_sp})
@@ -939,7 +955,9 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
939955

940956
private:
941957
TypeSystemSwiftTypeRef *m_ts = nullptr;
958+
addr_t m_task_ptr = LLDB_INVALID_ADDRESS;
942959
ReflectionContextInterface::AsyncTaskInfo m_task_info;
960+
ValueObjectSP m_address_sp;
943961
ValueObjectSP m_id_sp;
944962
ValueObjectSP m_kind_sp;
945963
ValueObjectSP m_enqueue_priority_sp;

lldb/test/API/lang/swift/async/continuations/TestSwiftContinuationSynthetic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def test_unsafe_continuation_printing(self):
1818
substrs=[
1919
"(UnsafeContinuation<Void, Never>) cont = {",
2020
"task = {",
21+
"address = 0x",
22+
"id = ",
2123
"isFuture = true",
2224
],
2325
)
@@ -34,6 +36,8 @@ def test_checked_continuation_printing(self):
3436
substrs=[
3537
"(CheckedContinuation<Int, Never>) cont = {",
3638
"task = {",
39+
"address = 0x",
40+
"id = ",
3741
"isFuture = true",
3842
],
3943
)

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,7 @@ def test_top_level_task(self):
1919
"frame var task",
2020
substrs=[
2121
"(Task<(), Error>) task = {",
22+
"address = 0x",
2223
"id = 2",
2324
"kind = 0",
2425
"enqueuePriority = 21",
@@ -44,6 +45,8 @@ def test_current_task(self):
4445
"frame var currentTask",
4546
substrs=[
4647
"(UnsafeCurrentTask) currentTask = {",
48+
"address = 0x",
49+
"id = ",
4750
"isChildTask = true",
4851
"isFuture = true",
4952
"isGroupChildTask = false",

lldb/test/API/lang/swift/async/formatters/task/children/TestSwiftSyntheticTaskChildren.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ def test(self):
1818
"language swift task info",
1919
substrs=[
2020
"(UnsafeCurrentTask) current_task = {",
21+
"address = 0x",
2122
"id = 1",
2223
"isChildTask = false",
2324
"isAsyncLetTask = false",
2425
"children = {",
2526
"0 = {",
27+
"address = 0x",
2628
"id = 2",
2729
"isChildTask = true",
2830
"isAsyncLetTask = true",

lldb/test/API/lang/swift/async/taskgroups/TestSwiftTaskGroupSynthetic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ def test_value_printing(self):
1717
"v group",
1818
substrs=[
1919
"[0] = {",
20+
"address = 0x",
21+
"id = ",
2022
"isGroupChildTask = true",
2123
"[1] = {",
24+
"address = 0x",
25+
"id = ",
2226
"isGroupChildTask = true",
2327
"[2] = {",
28+
"address = 0x",
29+
"id = ",
2430
"isGroupChildTask = true",
2531
],
2632
)

0 commit comments

Comments
 (0)