Skip to content

Commit 5b5fd2c

Browse files
committed
Use UnsafeRawPointer?; Fix num children
1 parent d9d6986 commit 5b5fd2c

File tree

4 files changed

+63
-14
lines changed

4 files changed

+63
-14
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -734,12 +734,10 @@ namespace lldb_private {
734734
namespace formatters {
735735
namespace swift {
736736

737-
namespace {
738737
/// The size of Swift Tasks. Fragments are tail allocated.
739738
static constexpr size_t AsyncTaskSize = sizeof(::swift::AsyncTask);
740739
/// The offset of ChildFragment, which is the first fragment of an AsyncTask.
741740
static constexpr offset_t ChildFragmentOffset = AsyncTaskSize;
742-
} // namespace
743741

744742
class EnumSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
745743
public:
@@ -831,8 +829,9 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
831829
};
832830

833831
llvm::Expected<uint32_t> CalculateNumChildren() override {
834-
// Show only the first four children address/id/enqueuePriority/children.
835-
return 4;
832+
// Show only the first five children
833+
// address/id/enqueuePriority/parent/children.
834+
return 5;
836835
}
837836

838837
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
@@ -882,21 +881,24 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
882881
}
883882
case 3: {
884883
if (!m_parent_task_sp) {
885-
// TypeMangling for "Swift.UnsafeRawPointer"
884+
auto process_sp = m_backend.GetProcessSP();
885+
if (!process_sp)
886+
return {};
887+
888+
// TypeMangling for "Swift.Optional<Swift.UnsafeRawPointer>"
886889
CompilerType raw_pointer_type =
887-
m_ts->GetTypeFromMangledTypename(ConstString("$sSVD"));
890+
m_ts->GetTypeFromMangledTypename(ConstString("$sSVSgD"));
888891

889892
addr_t parent_addr = 0;
890893
if (m_task_info.isChildTask) {
891-
if (auto process_sp = m_backend.GetProcessSP()) {
892-
Status status;
893-
// Read ChildFragment::Parent, the first field of the ChildFragment.
894-
parent_addr = process_sp->ReadPointerFromMemory(
895-
m_task_ptr + ChildFragmentOffset, status);
896-
if (status.Fail() || parent_addr == LLDB_INVALID_ADDRESS)
897-
parent_addr = 0;
898-
}
894+
// Read ChildFragment::Parent, the first field of the ChildFragment.
895+
Status status;
896+
parent_addr = process_sp->ReadPointerFromMemory(
897+
m_task_ptr + ChildFragmentOffset, status);
898+
if (status.Fail() || parent_addr == LLDB_INVALID_ADDRESS)
899+
parent_addr = 0;
899900
}
901+
900902
addr_t value = parent_addr;
901903
DataExtractor data{reinterpret_cast<const void *>(&value),
902904
sizeof(value), endian::InlHostByteOrder(),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SWIFT_SOURCES := main.swift
2+
SWIFTFLAGS_EXTRAS := -parse-as-library
3+
include Makefile.rules
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import re
2+
import lldb
3+
from lldbsuite.test.decorators import *
4+
from lldbsuite.test.lldbtest import *
5+
from lldbsuite.test import lldbutil
6+
7+
8+
ADDR_PATTERN = "(0x[0-9a-f]{6,})"
9+
10+
class TestCase(TestBase):
11+
12+
@skipUnlessDarwin
13+
@swiftTest
14+
def test(self):
15+
self.build()
16+
_, process, _, _ = lldbutil.run_to_name_breakpoint(self, "breakHere")
17+
18+
# First breakpoint hit occurrs in a root task, with no parent.
19+
self.expect("task info", substrs=["parent = nil"])
20+
root_task = self._extract("task info", f"address = {ADDR_PATTERN}")
21+
22+
# Continue to the next hit of the same breakpoint, which is called from
23+
# an async let child task.
24+
process.Continue()
25+
parent_of_child_task = self._extract("task info", f"parent = {ADDR_PATTERN}")
26+
27+
# Ensure the parent of the child is the same as the root task.
28+
self.assertEqual(root_task, parent_of_child_task)
29+
30+
def _extract(self, command: str, pattern: str) -> str:
31+
ret = lldb.SBCommandReturnObject()
32+
self.ci.HandleCommand(command, ret)
33+
match = re.search(pattern, ret.GetOutput(), flags=re.I)
34+
self.assertTrue(match)
35+
return match.group(1) if match else ""
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
func breakHere() {}
2+
3+
@main struct Main {
4+
static func main() async {
5+
await breakHere()
6+
async let x = breakHere()
7+
await x
8+
}
9+
}

0 commit comments

Comments
 (0)