Skip to content

Conversation

@MistaTwista
Copy link
Contributor

@MistaTwista MistaTwista commented Aug 8, 2025

Motivation

Large Go strings are still truncated in common debugging workflows (variables view uses ~512 chars; hover / “Copy Value” use ~4096 chars). That’s often not enough for JSON payloads, logs, etc., and users rely on awkward workarounds (manual slicing, multiple reads).

Adding DAP readMemory enables clients to page the underlying bytes on demand and render full values.
Aug-09-2025 00-51-53

Fixes: #4084

Vscode-go feature: golang/vscode-go#3817

SupportsVariablePaging bool `json:"supportsVariablePaging,omitempty"`
SupportsRunInTerminalRequest bool `json:"supportsRunInTerminalRequest,omitempty"`
SupportsMemoryReferences bool `json:"supportsMemoryReferences,omitempty"`
SupportsReadMemoryRequest bool `json:"supportsReadMemoryRequest,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

You can't change vendored packages like this, you need to make a PR to google/go-dap first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeap, i know, i did google/go-dap#94

Copy link
Member

Choose a reason for hiding this comment

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

Great!

@MistaTwista MistaTwista marked this pull request as ready for review August 12, 2025 23:13
@aarzilli
Copy link
Member

LGTM but held because we need the go-dap change.
@h9jiang do you know who's maintaining google/go-dap now?

@h9jiang
Copy link

h9jiang commented Aug 14, 2025

Hi @aarzilli

I think the go tools team is the maintainer of google/go-dap, I will discuss this within the team and review the PR and CL that @MistaTwista drafted.

@MistaTwista
Copy link
Contributor Author

MistaTwista commented Sep 7, 2025

sorry for inconvenience with go-dap PR. I closed it because it looks like we don't need those changes here 😐

@aarzilli
Copy link
Member

aarzilli commented Sep 7, 2025

Many tests fail.

@aarzilli
Copy link
Member

aarzilli commented Sep 8, 2025

PS. the TODO on line service/dap/server.go:841 needs to be removed.

@MistaTwista
Copy link
Contributor Author

Hey @aarzilli, I’ve fixed the previously failing tests and also added a new one for my changes to be sure everything works.

The main idea of this new test is to generate a large JSON payload, retrieve it from the Delve server via the read-memory request page-by-page, compute a hash, and compare it with the original hash to ensure there are no duplicates or missing data.

All tests pass locally, but the CI still fails for my test with:

=== RUN   TestReadMemory_StringPagination
Error compiling ../../_fixtures/readmem_json.go: wait6: no child processes

FAIL	github.com/go-delve/delve/service/dap	50.196s
?   	github.com/go-delve/delve/service/dap/daptest	[no test files]
?   	github.com/go-delve/delve/service/dap/daptest/gen	[no test files]

It seems like an environment difference between my setup and the CI runner, and I can’t reproduce it locally. Do you have any idea what might be wrong?

@aarzilli
Copy link
Member

I think the reason the tests do not pass is just because your branch is fairly old and needs to be rebased.
However, I also tested this with vscode and I don't get the "open in new document" option that you have.

@MistaTwista
Copy link
Contributor Author

MistaTwista commented Sep 13, 2025

I think the reason the tests do not pass is just because your branch is fairly old and needs to be rebased.

Ok, I'll rebase it and try again, thanks

However, I also tested this with vscode and I don't get the "open in new document" option that you have.

I'm not sure I understand you correctly. In the description of the original issue I showed what functionality I'm trying to archive in vscode and why.

And this comment is about why I’m proposing delve changes.

@aarzilli
Copy link
Member

So, this would also require a change to vscode?

@MistaTwista
Copy link
Contributor Author

not vscode itself, but vscode-go plugin for vscode golang/vscode-go#3818

Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

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

I was looking over the DAP specification again and it occurs to me that memory references are used in one other place in the spec: for disassembly.

I think it would be prudent to put memory references for disassembly and the ones for the memory of variables in the same address space, in case clients expects them to be. That would mean that instead of using a sequential number to number memory references you just send the address of the variable formatted into a string.

@MistaTwista
Copy link
Contributor Author

I think it would be prudent to put memory references for disassembly and the ones for the memory of variables in the same address space, in case clients expects them to be

done 👌 test is also updated for the new format, but still there are some issues

@aarzilli
Copy link
Member

aarzilli commented Oct 1, 2025

I don't know why your test is failing like that on freebsd, there is no obvious problem that would lead to that. I think it's fine to just add a skip for freebsd (if runtime.GOOS == "freebsd" { t.Skip(...) })

Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

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

LGTM

@MistaTwista
Copy link
Contributor Author

Screenshot 2025-10-02 at 3 32 59 PM Screenshot 2025-10-02 at 3 32 51 PM

I'm thinking about support that kind of strings representation too. Make it possible in this PR or make the new one? Current version gives me error for them like

Screenshot 2025-10-02 at 3 36 08 PM

But it looks obvious for me that this is a good case to support. What do you think?

@aarzilli
Copy link
Member

aarzilli commented Oct 2, 2025

The []byte variable, sure, not the string() thing we return.

@MistaTwista
Copy link
Contributor Author

Oct-04-2025 22-09-41
I've added slices

Oct-04-2025 22-12-52
and removed max limit to get memory address, because it can be useful to check even small variables in a hex editor

Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

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

LGTM

@MistaTwista
Copy link
Contributor Author

LGTM

Do I need to do something (like rebase to current master) or just wait until merge?

@aarzilli
Copy link
Member

aarzilli commented Oct 7, 2025

Just wait.

@derekparker
Copy link
Member

@MistaTwista this patch does need a rebase now. After the rebase I will merge.

@MistaTwista
Copy link
Contributor Author

Done, would you like me to squash the commits, or should I improve the commit messages for better documentation?

- enable setting SupportsReadMemoryRequest in Initialize response
- variable listings now include MemoryReference for strings and slices
- implement Session.onReadMemoryRequest handling for readMemory requests
@MistaTwista
Copy link
Contributor Author

MistaTwista commented Oct 15, 2025

fixed conflict with master, squashed commits, made better description of a commit

@derekparker derekparker merged commit 9103a45 into go-delve:master Oct 15, 2025
7 of 8 checks passed
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.

dap: Support readMemory for strings to enable full-length string viewing in clients and expose memoryReference

4 participants