Skip to content

Commit ce39e63

Browse files
[lldb] Use MultiMemRead to speed up OperatingSystemSwiftTasks
This concludes the work to remove the extra packets created by OperatingSystemSwiftTasks.
1 parent 483dcf2 commit ce39e63

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
@@ -2964,18 +2964,8 @@ MultiReadPointers(Process &process,
29642964
}
29652965
}
29662966

2967-
/// TODO: convert this loop into a call to the vectorized memory read, once
2968-
/// that is available in Process.
2969-
llvm::SmallVector<std::optional<addr_t>> read_results;
2970-
for (addr_t pointer : to_read) {
2971-
Status status;
2972-
addr_t result = process.ReadPointerFromMemory(pointer, status);
2973-
if (status.Fail())
2974-
read_results.push_back(std::nullopt);
2975-
else
2976-
read_results.push_back(result);
2977-
}
2978-
2967+
llvm::SmallVector<std::optional<addr_t>> read_results =
2968+
process.ReadPointersFromMemory(to_read);
29792969
llvm::MutableArrayRef<std::optional<addr_t>> results_ref = read_results;
29802970

29812971
// 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
@@ -204,19 +204,9 @@ FindTaskIds(llvm::ArrayRef<std::optional<addr_t>> maybe_task_addrs,
204204
}
205205
}
206206

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

221211
// Move the results into the slots not filled by errors from the input.
222212
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)