Skip to content

DAP: view and edit memory (readMemory, writeMemory and the memory event) #2112

Open

Description

@lagergren

What

  • readMemory, gated by supportsReadMemoryRequest.
  • writeMemory, gated by supportsWriteMemoryRequest.
  • The memory event, which needs the client capability supportsMemoryEvent.
  • memoryReference on Variable, EvaluateResponse, SetVariableResponse and SetExpressionResponse. Per the spec it "may be returned by a debug adapter if corresponding capability supportsMemoryReferences is true", a client capability.
  • Details: data is base64, offsets can be negative, unreadableBytes, allowPartial.

Why

Read and write:

  • Both: vscode-js-debug (debugAdapter.ts:308-309), CodeLLDB (debug_session.rs:617, :622), lldb-dap (RequestHandler.h:622, :673), Delve (server.go:1034-1035), GDB (dap/memory.py).
  • Read only: MIEngine (AD7DebugSession.cs:1091, :3156).

memoryReference:

  • js-debug: on typed arrays, DataView, ArrayBuffer and WebAssembly memory (variableStore.ts:64-69, :906).
  • CodeLLDB: on variables and evaluate, only when the client sends supportsMemoryReferences (debug_session/variables.rs:397).
  • lldb-dap: on variables, evaluate and setVariable.
  • Delve: on child variables (server.go:3023).
  • GDB: on pointers, only with supportsMemoryReferences (dap/varref.py:254-264).
  • MIEngine: on pointers and arrays.

memory event: lldb-dap only, after setVariable, and only with supportsMemoryEvent (EventHelper.cpp:404-412).

None of this: debugpy, netcoredbg, rdbg, java-debug.

What users miss: seeing and changing the bytes behind a pointer, buffer or array, in C, C++, Rust, Go, WebAssembly or JavaScript typed arrays. In VS Code, "View Memory" on a variable with memoryReference opens the Hex Editor extension (variablesView.ts:734-783).

Today

  • LSP4IJ sends neither supportsMemoryReferences nor supportsMemoryEvent (DebugAdapterDescriptor.java:232-251). So CodeLLDB and GDB send no memoryReference.
  • The others send it, but LSP4IJ uses memory references only for disassembly, from the frame's instructionPointerReference (DisassemblyFile.java:105). memory() is not overridden.
  • IntelliJ IDEA has no hex memory view:
    • com.intellij.xdebugger.memory.* in both versions is the Java "Memory" view of instance counts (MemoryViewManager, InstancesTracker);
    • no hex or memory viewer class is in 2026.3's lib/ jars.
  • CLion and RustRover have a Memory View of their own; Address editor in RustRover's Memory View tab triggers LSP requests #560 is about its address field in RustRover. Whether a debug process that isn't CIDR's can use it was not checked: no CLion or RustRover distribution was available.

How it could be done

Capabilities and data:

  • Set supportsMemoryReferences = true. Set supportsMemoryEvent = true once the event is handled.
  • Keep memoryReference: DAPDebuggerEvaluator drops it today (DAPDebuggerEvaluator.java:124). DAPValueModifier should copy it from the setVariable answer.

The action:

  • Add an action DAP.ViewMemory, "View Memory", in XDebugger.ValueGroup. That group exists in both versions, and LSP4IJ already adds DAP.HexadecimalValues and DAP.BreakOnValueChange to it.
  • It is enabled when the selected value has a memoryReference and its client supports readMemory. Find the value with DAPBreakOnValueChangeAction.getValue(DataContext), which already handles the 2025.3+ split UI through reflection.

The memory editor, built like the disassembly view (DisassemblyFile and DisassemblyFileEditorProvider):

  • a LightVirtualFile per client and memoryReference, opened with FileEditorManager.openFile(VirtualFile, boolean) (both versions);
  • a read-only document with lines of address, 16 hex bytes and ASCII; unreadable bytes show as ??;
  • pages of 1 to 4 KiB read with readMemory(memoryReference, offset, count), and more when scrolling. Offsets can be negative.
  • The address column comes from ReadMemoryResponse.address. Its width could come from the pointerSize of the Process event (DAP: handle the process event #2114).

Refresh:

  • at each stop of that client (XDebugSessionListener.sessionPaused, both versions);
  • on a memory event whose range overlaps what is shown;
  • shown as out of date while the program runs;
  • closed or disabled when the client ends.

Write, with supportsWriteMemoryRequest:

  • "Write Bytes…" on a selection, typed in hex, calls writeMemory(memoryReference, offset, base64, allowPartial = false).
  • On a partial write, show bytesWritten.
  • Then call session.rebuildViews(), or rely on the adapter's invalidated.

Threading: requests run off the EDT; document changes happen in a write action on the EDT.

Multi-session: a memoryReference belongs to the client, possibly a child session, that returned it.

Later step: disassemble from a function pointer's memoryReference. The spec says "For executable data, this reference may later be used in a disassemble request".

Compatibility: the action is hidden without a reference or the capability. Behaviour change: CodeLLDB and GDB add memoryReference fields once the flag is set.

Test

  • Unit tests: the hex dump layout, base64, unreadableBytes, page offsets, and the overlap check for the event.
  • Session test: an in-process server backed by a byte array.
    • A variable with memoryReference enables the action.
    • Check the readMemory requests and the document text, and the writeMemory arguments.
    • A memory event reloads the view.
  • Initialize arguments: both new flags are set, in the style of DebugAdapterDescriptorTest.

Effort and risk

Large: a new editor, paging and editing. Medium UI risk. Open questions:

  • Ship read-only first?
  • How should editing work?
  • Can this plug into CLion's and RustRover's Memory View?
  • Size limits?

Related: #560 and #601 (an LSP-side fix for RustRover's Memory View address field).

Activity

  1. added
    enhancement
    dap
    on Nov 22, 2026
  2. added this to the Backlog milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    UIdapenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions