Skip to content

Conversation

@felipepiovezan
Copy link

These are methods that use the MultiMemRead packet to speed up reading unsigned numbers / pointers from memory.
As the comments say, they should go upstream once we find a use for them there (and the timing constraints are a bit more favourable).

continue;
}

DataExtractor data(range.data(), integer_byte_size, GetByteOrder(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You put addr_size in a const int earlier to avoid fetching it for each element, but fetch the byte order for each element. Pls do both the same way.


DataExtractor data(range.data(), integer_byte_size, GetByteOrder(),
addr_size);
lldb::offset_t offset = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super unimportant nit, but you don't need to prefix lldb types with lldb:: in our source files. There were some lldb::addr_t's in the PR as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, that's true. In the headers we do though :(
I'll remove them from the cpp file

llvm::SmallVector<std::optional<addr_t>> read_results =
process->ReadPointersFromMemory(ptr_locs);

for (auto [maybe_ptr, ptr_loc] : llvm::zip(read_results, ptr_locs)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't need this zip

llvm::SmallVector<std::optional<addr_t>> read_results =
process->ReadPointersFromMemory(ptr_locs);

for (auto [maybe_ptr, ptr_loc] : llvm::zip(read_results, ptr_locs)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand these unit tests. Where are the expected_result bytes passed to the DummyProcess, so that the ReadMemory calls work correctly? Is this byte sequence already in DummyProcess so reads from any address will return it? I couldn't find anything like that in the DummyProcess class but maybe I missed it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you looked at the wrong one, there is a "DummyProcess" and there is a "DummyReaderProcess", the tests in this PR are using the latter:

/// A process class that, when asked to read memory from some address X, returns
/// the least significant byte of X.
class DummyReaderProcess : public Process {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which makes me realize: there is a wrong static cast in this test!!

These are methods that use the MultiMemRead packet to speed up reading
unsigned numbers / pointers from memory.
As the comments say, they should go upstream once we find a use for them
there (and the timing constraints are a bit more favourable).
@felipepiovezan
Copy link
Author

Addressed review comments

@felipepiovezan felipepiovezan force-pushed the felipe/proc_read_poiters_from_mem branch from e27c23b to 7ef61a7 Compare October 23, 2025 17:46
@felipepiovezan
Copy link
Author

@swift-ci test

// Read pointers at arbitrary addresses.
llvm::SmallVector<addr_t> ptr_locs = {0x0, 0x100, 0x2000, 0x123400};
// Because of how DummyReaderProcess works, each byte of a memory read result
// is its address modulo 256:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment (and the DummyReaderProcess impl) describe what is done in TestReadUnsignedIntgersFromMemory, but in this test we're reading from a series of addresses that have a low byte of 0, so the returned result will be 64-bits of 0x0 in each case. How does this expected_result get returned?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the returned result will be 64-bits of 0x0 in each case

I don't think that's true. DummyReaderProcess reads byte by byte. So if the pointer's address starts at 0, the pointer will have 8 bytes, the first byte being zero, the last byte being 7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    for (size_t addr = vm_addr; addr < vm_addr + size; addr++)
      buffer[addr - vm_addr] = static_cast<uint8_t>(addr); // LSB of addr.

?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comment above describes exactly this - reading 4 bytes from addr 0x5 will get you a UInt32 of 0x05050505. That's what TestReadUnsignedIntegersFromMemory is doing. But this method is expecting a UInt64 with different values in each byte pos.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading 4 bytes from addr 0x5 will get you a UInt32 of 0x05050505

No, reading 4 bytes from addr 0x5 will get you 0x05060708 (or the other way around, endianness is hard)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah my bad, i see you're incrementing addr in your writer loop. I thought it would not mutate that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw each byte of a memory read result is its address modulo 256 -- I'd probably say "the byte's address" instead of "its address" because it's easy for me to read this as "the address of the byte range % 256"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah my bad, i see you're incrementing addr in your writer loop. I thought it would not mutate that.

addr is the loop variable; the function argument is vm_addr, which is not mutated.
I will try to update that code on a separate PR to change the comment as you described and rename some variables.

@felipepiovezan
Copy link
Author

@swift-ci test macos platform

@felipepiovezan
Copy link
Author

13:00:11 lldb-api :: tools/lldb-dap/attach/TestDAP_attach.py

failed for a second time in a row...

@felipepiovezan
Copy link
Author

@swift-ci test macos platform

@felipepiovezan
Copy link
Author

@swift-ci test windows platform

@felipepiovezan
Copy link
Author

@swift-ci test macOS platform

@jasonmolenda jasonmolenda merged commit 3d23036 into swiftlang:stable/21.x Oct 24, 2025
3 checks passed
@felipepiovezan felipepiovezan deleted the felipe/proc_read_poiters_from_mem branch October 24, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants