Skip to content

Commit acc5765

Browse files
[lldb] Use MultiMemRead to speed up OperatingSystemSwiftTasks
This concludes the work to remove the extra packets created by OperatingSystemSwiftTasks. (cherry picked from commit ce39e63)
1 parent fe78930 commit acc5765

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,18 +2984,8 @@ MultiReadPointers(Process &process,
29842984
}
29852985
}
29862986

2987-
/// TODO: convert this loop into a call to the vectorized memory read, once
2988-
/// that is available in Process.
2989-
llvm::SmallVector<std::optional<addr_t>> read_results;
2990-
for (addr_t pointer : to_read) {
2991-
Status status;
2992-
addr_t result = process.ReadPointerFromMemory(pointer, status);
2993-
if (status.Fail())
2994-
read_results.push_back(std::nullopt);
2995-
else
2996-
read_results.push_back(result);
2997-
}
2998-
2987+
llvm::SmallVector<std::optional<addr_t>> read_results =
2988+
process.ReadPointersFromMemory(to_read);
29992989
llvm::MutableArrayRef<std::optional<addr_t>> results_ref = read_results;
30002990

30012991
// Move the results in the slots not filled by errors from the input.

lldb/source/Plugins/OperatingSystem/SwiftTasks/OperatingSystemSwiftTasks.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,9 @@ FindTaskIds(llvm::ArrayRef<std::optional<addr_t>> maybe_task_addrs,
203203
}
204204
}
205205

206-
/// TODO: replace this loop with a vectorized memory read.
207-
llvm::SmallVector<std::optional<addr_t>> read_results;
208-
for (addr_t task_id_addr : to_read) {
209-
Status error;
210-
// The Task ID is at offset job_id_offset from the Task pointer.
211-
constexpr uint32_t num_bytes_task_id = 4;
212-
auto task_id = process.ReadUnsignedIntegerFromMemory(
213-
task_id_addr, num_bytes_task_id, LLDB_INVALID_ADDRESS, error);
214-
if (error.Fail())
215-
read_results.push_back(std::nullopt);
216-
else
217-
read_results.push_back(task_id);
218-
}
206+
constexpr uint32_t num_bytes_task_id = 4;
207+
llvm::SmallVector<std::optional<addr_t>> read_results =
208+
process.ReadUnsignedIntegersFromMemory(to_read, num_bytes_task_id);
219209

220210
// Move the results into the slots not filled by errors from the input.
221211
llvm::ArrayRef<std::optional<addr_t>> results_ref = read_results;

lldb/test/API/lang/swift/async/stepping/step_over/TestSwiftAsyncStepOver.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,32 @@ def test(self):
3838
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
3939
self.check_is_in_line(thread, expected_line_num)
4040
self.check_x_is_available(thread.frames[0])
41+
42+
@skipIfOutOfTreeDebugserver
43+
@swiftTest
44+
@skipIf(oslist=["windows", "linux"])
45+
def test_efficient_step_over_packets(self):
46+
"""Test that MultiMemRead is used while stepping"""
47+
logfile = os.path.join(self.getBuildDir(), "log.txt")
48+
self.runCmd(f"log enable -f {logfile} gdb-remote packets process")
49+
self.addTearDownHook(lambda: self.runCmd("log disable gdb-remote packets"))
50+
51+
self.build()
52+
53+
source_file = lldb.SBFileSpec("main.swift")
54+
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
55+
self, "BREAK HERE", source_file
56+
)
57+
bkpt.SetEnabled(False) # avoid hitting multiple locations in async breakpoints
58+
59+
self.runCmd(f"proc plugin packet send StartTesting", check=False)
60+
thread.StepOver()
61+
self.runCmd(f"proc plugin packet send EndTesting", check=False)
62+
stop_reason = thread.GetStopReason()
63+
self.assertStopReason(stop_reason, lldb.eStopReasonPlanComplete)
64+
65+
self.assertTrue(os.path.exists(logfile))
66+
log_text = open(logfile).read()
67+
log_text = log_text.split("StartTesting", 1)[-1].split("EndTesting", 1)[0]
68+
self.assertIn("MultiMemRead:", log_text)
69+
self.assertNotIn("MultiMemRead error", log_text)

0 commit comments

Comments
 (0)