microsoft/vscode-cpptools

[Feature Request] Implement Assembly View/Disassembly View for Debugger

Opened this issue ยท 54 comments

Being able to view assembly and step through assembly instructions would be useful. Especially when debug information isn't available for a certain library. Right now it just displays a message saying unknown source, when it goes into one of these functions. Being able to view values of registers in the GUI some way. Not entirely sure how that would work with VSCode, but being able to the registers all the time and able to modify them such other assembly debuggers.

@marktrz if you're on Linux, nemiver does it all and is quite a performer. I'm using it as an alternative to vs debugger on linux and so far it performs well. Now only if vscode could implement its features ๐ŸŽ

Thanks for the feedback. You can view disassembly in vscode using the -exec disassembly command in the debug console. Registers can be viewed the same way (-exec info registers).

I have code in C which calls code in ASM and it would be very useful to debug the ASM code within vs code without calling specific gdb commands which only show part of the source.

A register display would be very useful in situations like this, having it update as you step around.

If I'm not mistaken, since it's been a couple of years since I used it, the sublime gdb plugin for sublime text 2 supported asm debugging, showing registers and everything (https://github.com/quarnster/SublimeGDB). Probably there is a way for it to be done on vs code

So, could you please add a disassembler viewer in dubug view. It will be so helpful for C/C++ developers.
It should not take long time to implement this.

Below placed examples how this view looks like:

disassembler_1

disassembler_2

kgfly commented

Please add

ASM window
Memory window
Register window

I have just spent days looking for alternatives to VSCode because I would like to have assembler, memory and register windows. Reworking a large open source project based on VSCode/CMmake to a new tool is considerable effort. There are many people asking for a memory view for a long time. Please do consider adding such a window. Memory view can execute the GDB x command after each step / trace as it is so last decade to enter that command repeatedly (or up arrow enter). Ideally the window would also highlight values that have changed.

@doingnz You could try using Visual Studio 2017 -- they have some remote to Linux ability: https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/ .

ci70 commented

Please add

ASM window
Memory window
Register window

This is probably related to #941

ci70 commented

Has this been implemented yet???

No, but I think that they would happily accept a PR.

ci70 commented

Oh I am sure they would. PlatformIO has implemented this a long time ago.
What's the hold up?

ci70 commented

What's the hold up? Nothing about it in new insider build. @sean-mcmanus

@optomux

Not that I think that this feature is not needed, but I guess that's not top priority here. Just wait patiently or do it yourself. You can always copy appropriate code from PlatformIO to this extension and submit a pull request.

ci70 commented

I wish someone made an extension for it. Would PlatformIO work with this?

@optomux I don't work on the debugger stuff at all. The other debugger people spend most of their time working on the Visual Studio debugger (a paid product, although there are some free versions with restricted licenses). Implementing an assembler view or other advanced debugging features isn't a priority for the debugger team and not on their schedule to implement.

@sean-mcmanus Hi!
If you could give a few pointers of example code to have an idea of how vs code interacts with gdb, sends commands, and sets the UI, I would be willing to try to implement this.

@Izikiel Ask @WardenGnaw (or @pieandcakes when he gets back from vacation in January). I don't know much about how the debugger works since I just work on the language service stuff. I think most of it is open source. Another repo that may be relevant is https://github.com/Microsoft/MIEngine .

mirao commented

I tried debugging in VSCode extension PlatformIO on my embedded device. Nice, it's possible to switch fluently between debugging of C source and disassembly view.
It would be great to have such possibility with desktop apps as well.

Please add

ASM window
Memory window
Register window

pkeir commented

@jacdavis How does "-exec disassembly" work? While debugging, I type "-exec disassembly" + RETURN in the DEBUG CONSOLE window, but receive only "identifier "exec" is undefined".

@pkeir which debug "type" are you using? that command works for gdb.

Thanks for the feedback. You can view disassembly in vscode using the -exec disassembly command in the debug console. Registers can be viewed the same way (-exec info registers).

-exec disassembly
Undefined command: "disassembly".  Try "help".
help
-var-create: unable to create variable object
mirao commented

@liar666 -exec disassemble or -exec disas works for me.
I'm running VSCode 1.44.2, ms-vscode.cpptools 0.27.0, gdb 9.1

-exec disassemble or -exec disas works for me.

At least with set disassembly-flavor intel ๐Ÿ˜‰

For the record the feature is in the DAP by now microsoft/debug-adapter-protocol#50, microsoft/debug-adapter-protocol#49
More information is in microsoft/MIEngine#816 (comment).
It is implemented for embedded use-cases in PlatformIO and https://github.com/Marus/cortex-debug.
For desktop applications it would be also useful whenever you don't have source code, see #811.
Edit: It is also implemented in https://github.com/vadimcn/vscode-lldb/blob/master/MANUAL.md#disassembly-view

+1 for this
I would like to know, in order to do it properly, VS Code needs to provide an UI for Assembly, same as Source View, to provide at the same time SteppingGranularity for the "Next Request", and supports for instructionBreakpoints.
Or is it a work to provide in DebugAdapter side, like CppTools.

For general purpose use (arbitrary address ranges) DisassembleRequest would need to be implemented in the adapter similar to https://github.com/microsoft/MIEngine/compare/dev/waan/readMemory.
This isn't implemented in vscode though and seems quite useless.

The important use-case is covered by https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Source (vscode implementation.
If there is no source code available you simply send an assembly document like this. They defined a custom language but I'd rather reuse something like https://marketplace.visualstudio.com/items?itemName=maziac.asm-code-lens.

Then you need to handle stepping, goto, breakpoints and stacktraces.
See disassembly references in https://github.com/vadimcn/vscode-lldb/blob/master/adapter/src/debug_session.rs.

All of this probably goes into MIEngine.

+1 for this

xhliu commented

+1 for this

sshsu commented

4 years have passed, when does these features will be added ? it is really usefully for c/c++, please pay more attention to ASM window, Memory window, Register window, thanks~

Well the DAP disassemble request has been implemented but I think VSCode doesn't use it:
microsoft/vscode#105406

Registers are done, read-only at least.

We are starting the planning for adding this feature to one of our releases this year. The specific release is not set yet as there is a significant amount of work that needs to go into this. As we get more clarity on the schedule, we will assign this to the appropriate milestone.

I have a disassembly viewer using DAP in my local environment.
Is there anyone interested in this?

1

I have a disassembly viewer using DAP in my local environment.
Is there anyone interested in this?

A disassembler view in a debugger is expected to follow the current instruction pointer, not just a listing of disassembled bytes at some address.

That's correct.
I have an experimental function that displays the current instruction pointer value. However, it has not been tested because I have not yet implemented the instruction level steps.

2

While you're there, it would help a lot if the disassembly view can also show the source text in the same view. This usually helps identify which instructions were generated for which source lines.

There are still some limitations, but it is published.

https://github.com/nextarg/disassembly-view/releases

The workaround is written in the README, but I'm not good at English, so there may be mistakes.

it will be cool

I am trying to execute the instruction steps using vscode-cpptools + cppvsdbg, however, I have a wonder about it.
If the address has no source information, are there any limitations?

For example, when I do a stepinto an address with no source information, it seems that a temporary step is being executed.
(ex: call @ILT+X when using incremental link).

Does anyone know anything about this behavior?

Below is a comparison with VS.

VS

vs

RIP : 00000001400BDF3D
=>  00000001400BDF3D E8 E1 75 FE FF       call        func (01400A5523h) 
    00000001400BDF42 33 C0                xor         eax,eax 
RIP : 00000001400A5523
=>  00000001400A5523 E9 38 76 01 00       jmp         func (01400BCB60h)
RIP : 00000001400BCB60
=>  00000001400BCB60 40 55                push        rbp 

VS Code

vscode

RIP : 00000001400BDF3D
=> 0x00000001400BDF3D	E8 E1 75 FE FF	call func (01400A5523h)
   0x00000001400BDF42	33 C0		xor eax,eax
RIP : 00000001400BDF42
   0x00000001400BDF3D	E8 E1 75 FE FF	call func (01400A5523h)
=> 0x00000001400BDF42	33 C0		xor eax,eax
RIP : 00000001400BCB60
=> 0x00000001400BCB60	40 55		push rbp
mirao commented

I'm playing with Rust and CodeLLDB in VSCode. Just FYI a screenshot from dissasembly view where you can "end up" during debugging of Rust code. Hope it's not so off-topic
image

Official support is on the roadmap:
https://github.com/microsoft/vscode/wiki/Roadmap#debug

For those following along, we are now tracking implementing this support directly in VS Code. You can subscribe to this issue for updates: microsoft/vscode#124163

The first iteration of this feature is now available in VS Code Insiders. Give it a try and let us know what you think.
microsoft/vscode#124163 (comment)

๐Ÿ‘๐Ÿฝ

Note that you'll need the step granularity feature from MIEngine main which has not been released yet.
The stepping performance will need some improvement, esp. when registers are expanded.
As will the link between original source and disassembly. I usually pull the disassembly view to the right manually to see both and they both update but when you step into another source file you won't see the code anymore.
Eventually a mixed view like in VS and objdump is desirable.

This should be addressed in 1.6.0-insiders.

Yeah indeed it works with the insider version. Even the performance is a bit better.
Oddly though vscode sends a disassemble request even before you open the disassembly view, quite wasteful.

One missing feature is syntax highlighting. There are wonderful extensions for this like ASM Code Lens but since this view is not a normal editor there's no chance of them ever working. (It's also a bit weird in general that you can't select the code.)

Btw Intel syntax can be set via ~/.gdbinit with set disassembly-flavor intel.

This should be addressed in 1.6.0-insiders.

Hi, I downloaded insiders 1.6.0 , I'm on mac.
How can I enable or use this feature?
I really like the memory view in Visual Studio Community 2019.
I hoope this feature can reach VS code.

It's in the editor context menu during debugging.

One missing feature is syntax highlighting. There are wonderful extensions for this like ASM Code Lens but since this view is not a normal editor there's no chance of them ever working. (It's also a bit weird in general that you can't select the code.)

microsoft/vscode#131210
microsoft/vscode#129762

it seems that disassembly doesn't work on the gdb which is customized like for mips. .

Also no disassembly on esp32-C3 under esf-idf. Memory, code and registers are all visible within gdbgui. I'm running insiders 1.6.4.

Is there something I need to enable or select to see these viewers (no context menu item, unless I'm being really dumb)