Skip to content

Add memoryReference field for variables in dap protocol#218

Draft
thekatze wants to merge 1 commit into
Samsung:masterfrom
FHS-Creative-Technologies:feat/memory-address
Draft

Add memoryReference field for variables in dap protocol#218
thekatze wants to merge 1 commit into
Samsung:masterfrom
FHS-Creative-Technologies:feat/memory-address

Conversation

@thekatze
Copy link
Copy Markdown

@thekatze thekatze commented Mar 10, 2026

This adds the memoryReference field for the DAP variables request.
Other requests returning the memoryReference field have not been implemented yet.

Use Case

I am programming a visualization tool that recursively traverses variables. The memoryReference field is used to detect if a variable has already been queried and must not be queried again.

TODO

  • Only send memoryReference field if client announces supportsMemoryReferences
  • Add/Update Tests
  • Determine if this PR should also implement the memoryReference field for
    • setVariable request
    • evaluate request
    • setExpression request

These TODOs are currently not implemented because they are not required for my use case.

Please let me know whether the project is interested in adding this functionality, and if so, to what extent it should be implemented so it can be upstreamed.

@viewizard
Copy link
Copy Markdown
Member

I am worry about memoryReference usage itself. The point is - now debugger could guaranty that memoryReference in your changes is valid only before any managed code execution, since managed code execution could trigger GC that could move not pinned objects to another memory location. This mean, that during break (before continue or step) runtime also may invalidate memoryReference by any code execution (for example, during another expression evaluation, property's getter execution or even just object fields analyze that force debugger to execute static constructor).

Note, by default all ICorDebugValue created with strong handle, not pinned:
http://github.com/dotnet/diagnostics/blob/18cf9d154ed98f467ad9811e3786a53417debd3b/src/shared/inc/cordebug.idl#L1609-L1619

Pinned handle should be created manually, see:
https://learn.microsoft.com/en-us/dotnet/core/unmanaged-api/debugging/icordebug/icordebugheapvalue2-createhandle-method

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