Skip to content

Add disassembly view #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

ColinKennedy
Copy link

Implements a view for nvim-dap's dapui.DAPClient.request.disassemble.

Demo

Scrolling

nvim_dap_ui_disassembly_scroll_example.mp4

"Expand" (<Enter>) Mapping - Returns the user to the current instruction

nvim_dap_ui_disassembly_scroll_example_enter_key_demo.mp4

Summary

The code in this PR works but I've opened it as a draft for several reasons

Reasons for the draft PR

  1. The text highlighting of the buffer is a little weird
Show example

The left of the cursor highlights as expected according to Neovim's colorscheme. The right of the cursor is uncolored

nvim-dap-ui-disassembly_strange_highlighting

  1. I have a script somewhere that highlights the yanked code when you call yy. And doing this in the Disassembly buffer causes the left of the cursor to flash. (This seems to be happening in other canvases too but I wanted to point it out)
Show example

nvim-dap-ui_disassembly_yy_flash_bug_demo

  1. Moving the cursor left and right causes the text to strobe strangely. I was wondering if you've seen that before and can advise
Show example

nvim_dap_ui_strobing_text_disassembly_bug_demo

  1. I couldn't find a great place to store configuration settings to customize the display of the Disassembly canvas. I added it somewhat haphazardly to default_config but if there's a better place, please let me know where it should live

  2. In general, this disassembly view needs a lot of space and most people probably don't need to see it all of the time. How do you pop open a canvas? I couldn't find the API for it but probably I just missed it in the documentation.

  3. In the future I'd like to add a "Disassembly Memory Dump" view which can be popped open by pressing o on an address. To do that, we need the current address / register which requires some parsing. The tree-sitter-disassembly is a step in that direction but it's still PR - Add tree-sitter-disassembly nvim-treesitter/nvim-treesitter#5755

  4. I'm prettty unfamiliar with unittesting in Neovim/lua and was hoping for some advise on what you'd want to see, there

Anyway, the Disassembly view works well from my personal tests. I even could run it while debugging Neovim's source code and on another, multi-million code-base. But I think this work requires some polish.

send_ready()
end

client.listen.scopes(on_reset) -- TODO: Maybe `scopes` should just a more generic event?
Copy link
Author

Choose a reason for hiding this comment

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

Not sure if there's a better way to do this but this is the callback I've been using to get the Disassembly view to update whenever the user steps or does anything in the current debug session

@tenziomek
Copy link

@ColinKennedy
Any updates on this? I tried using the fork but it doesn't work (something about buffer not being valid)

@ColinKennedy
Copy link
Author

@tenziomek I lost the need for this work and the PR didn't get attention so it is left in the current state. It did work at the time when I created it though.

@shmerl
Copy link

shmerl commented Dec 24, 2024

Any plans to complete and merge it? It looks like it's almost there.

@rcarriga
Copy link
Owner

Apologies for not giving this attention. I don't use any debug adapters that provide a disassembly view so it's hard to verify the behaviour and I'm concerned about maintenance as it's a large component with a lot of logic. If someone else is willing to continue the work and verify/maintain this, I could merge

@ColinKennedy
Copy link
Author

ColinKennedy commented Dec 28, 2024

I'm willing to get this PR up to date with the current master branch and verify it but I can't promise I'll be responsive enough to maintain it. If we can find a maintainer that'd be ideal but if not, as a compromise, we could maybe include the view but have it disabled by default so people have to opt-in to it. That way it won't be disruptive for current users. Does that sound good to you?

That said I've learned a lot about Lua / Neovim plugins since writing this PR. I'll probably do better on the second pass. If that sounds good to you then it'd be great to get some answers regarding those questions 1-5, in particular the ones about highlighting.

@rcarriga
Copy link
Owner

Awesome that sounds like a good compromise to me then, I would love to have this as a feature if possible!

The text highlighting of the buffer is a little weird

This is the line hover functionality not working because you're using treesitter highlighting instead of custom extmarks. It looks for extmarks in the dapui namespace

local namespace = api.nvim_create_namespace("dapui")
.

You might be able to get it working by looking through the treesitter highlight namespace instead of dapui 🤔

I have a script somewhere that highlights the yanked code when you call yy. And doing this in the Disassembly buffer causes the left of the cursor to flash. (This seems to be happening in other canvases too but I wanted to point it out)

Same issue, it's actually your yank highlighting the whole line but the right of the cursor is obscured by a different window

Moving the cursor left and right causes the text to strobe strangely. I was wondering if you've seen that before and can advise

And again 😅 Not much to do here, it's just a small visual bug

I couldn't find a great place to store configuration settings to customize the display of the Disassembly canvas. I added it somewhat haphazardly to default_config but if there's a better place, please let me know where it should live

I'm not familiar with other disassembly viewers, would these be commonly adjusted? I'm wondering if it'd be better to just be opinionated and omit them for now by just defining them in the module and potentially exposing later on

In general, this disassembly view needs a lot of space and most people probably don't need to see it all of the time. How do you pop open a canvas? I couldn't find the API for it but probably I just missed it in the documentation.

Users can use dapui.float_element() function or if they want more control over the window, they can use dapui.elements.<name>.buffer() to get an elements buffer and control it manually.

@shmerl
Copy link

shmerl commented Feb 21, 2025

@ColinKennedy: did you have a chance to update it? It would be nice to merge it.

@ColinKennedy
Copy link
Author

ColinKennedy commented Feb 27, 2025

Sorry but some personal things came up and there's little chance I'll look at this. It wasn't that far from done though I'm sure the base branch has shifted since the PR was made. But I have to be realistic, I just don't have the time now and for possibly the foreseeable future. Hopefully someone can take this on. In the meantime if the PR closes I'd understand that

@sleeptightAnsiC
Copy link
Contributor

@ColinKennedy would you be fine with someone taking it and creating standalone sub-plugin in another repository, e.g. nvim-dap-ui-disassembly ?

@rcarriga are you still interested in merging this?

I may take a look at this PR soon.

@ColinKennedy
Copy link
Author

A sub-plugin sounds like a good idea as long as it tracks well with nvim-dap-ui's API.

Some things that I wanted to mention about this PR - I wrote https://github.com/ColinKennedy/tree-sitter-disassembly in order to make parsing in this PR possible. Eventually my plan was to also write an assembly parser and inject it into the (instruction) node. And then if that asm parser could pick out registers and memory addresses accurately, utilize DAP to view the data at that address. It's still a ways away but if this PR's functionality merges it'll probably be fairly easy to make happen.

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.

5 participants