Hi Nourhan, Gurleen, Ben, and Daco,
This is a great discussion.I have also been doing some research and taking a deep dive into the architecture for this project, specifically looking at how we can achieve LLDB-style safety without breaking remote Flutter debugging.
Nourhan, your point about reading memory from the outside to prevent a SIGSEGV crashing the VM is exactly the right safety model. However, as Ben pointed out, relying on DDS to do the reading introduces a major topological issue: in remote Flutter debugging (e.g., debugging an Android device from a Mac), DDS runs on the host machine, while the target memory lives on the mobile device. DDS physically cannot execute OS-level memory reads across a network boundary. Furthermore, an external DDS process reading the VM's memory on macOS would likely be blocked by System Integrity Protection (SIP) without elevated privileges.
However, I think we can get the exact
out-of-process safety you described while staying entirely
in-process inside the VM Service.
A process is allowed to use OS-level safe-read APIs to read its own memory. If the VM Service routes all DAP ReadMemory requests through these APIs—targeting its own PID—the OS kernel will validate the page tables. If the pointer is dangling or unmapped, the kernel simply aborts the copy and returns an error (like EFAULT), and no hardware MMU trap or SIGSEGV is ever generated. The VM doesn't crash.
The cross-platform implementations for the VM Service would look like this:
- Linux/Android: process_vm_readv (targeting its own PID) or reading from /proc/self/mem.
- Windows: ReadProcessMemory(GetCurrentProcess(),...)
- macOS/iOS: mach_vm_read_overwrite(mach_task_self(),...) (This completely bypasses SIP issues).
If we implement this safe-read wrapper inside the VM Service, we solve the remote debugging topology problem, bypass all cross-process security permissions, and completely protect the Dart VM from segmentation faults when a developer inspects a bad Pointer.
I am currently looking into how we can pair this safe-read mechanism with the layout metadata to serve standard DAP ReadMemoryRequest payloads.
Would love to hear your thoughts on this approach!