microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.73k stars 29.09k forks source link

Disassembly View: Milestone 2 #129762

Open yuehuang010 opened 3 years ago

yuehuang010 commented 3 years ago

Use this to keep track of work for the next milestone.

Features:

Bugs from Test Disassembly View #129161

yuehuang010 commented 3 years ago

@isidorn @weinand

isidorn commented 3 years ago

@yuehuang010 Thanks for creating this. We can find all disassembly open issues by looking at what is linked from the test plan item here https://github.com/microsoft/vscode/issues/129161 And looking at open issues assigned to August that have debug label https://github.com/microsoft/vscode/issues?q=is%3Aopen+is%3Aissue+milestone%3A%22August+2021%22+label%3Adebug

xisui-MSFT commented 3 years ago

@isidorn Can you please help me to investigate how to fix an element from horizontally scrolling in a list? Thanks!

isidorn commented 3 years ago

@xisui-MSFT yes, but can you clarify, what is the actual issue? Elements should not automatically horizontally scroll as far as I know and there is no programatic way to control horizontal scrolling.

xisui-MSFT commented 3 years ago

@isidorn Yes. In the original PR we talked about changing the table to a list, to support horizontal scrolling. However, I wasn't able to find a way to fix the breakpoint column (or elements, since we don't have a column concept in list anymore) from scrolling horizontally. Original discussion: https://github.com/microsoft/vscode/pull/125737#discussion_r659882036

Also another question, we would like to implement show/hide source code function, so the source lines (zero or more) can be shown above the corresponding disassembly lines or hidden. I.e., switching between

...
disassembly 1
disassembly 2
disassembly 3
...

and

...
source A
source B
disassembly 1
source C
disassembly 2
disassembly 3
..

I'm not sure we can do this easily using list? Also looked at trees, doesn't seem to be what we want since this is not a one-to-many map but more like a many-to-many one... It would be great if you could provide some suggestions. Thanks!

isidorn commented 3 years ago

1) Aha, so you want to be able to horizontally scroll while still having the breakpoint visible. I suggest to create a new issue and we continue the discussion there. I am not 100% sure how to achieve this but CSS tricks should be possible. 2) For show / hide source function. I would add a context menu action Show Source Function / Hide Source Function. Once that action is triggered you would splice the whole table and your model should be aware that it now needs to feed in the source lines to the tableDataSource. For source lines you would introduce a new renderer and that is it. So should be possible and not hard.

yuehuang010 commented 3 years ago

Hi @isidorn, I am looking to adding Show Source Code. From the disassembly, it provides URI and line number.
I see that ITextModel has getLineContent() but I am not sure how to get TextModel. Maybe use NativeTextFileService to open the stream to new TextModel? Another concern is caching, I want to limit open and closing the same file. Are there existing tool for this? Thanks.

isidorn commented 3 years ago

@yuehuang010 can you clarify? Do you have an URI and a line number and just want to open an editor for those? In that case just use the editorService.openEditor and pass your uri and lineNumber.

yuehuang010 commented 3 years ago

@isidorn, here is the view in VS. The source code of cpp has is intereved between disassembly. MicrosoftTeams-image (1)

The disassemble response contains "Source" information such as filepath, start/end line and column. The viewer needs to render the file content. It is like a simpler "peek" view. Showing "colorization" is an added benefit that is not required. A link to open the file should the user decide to make edits is possible.

isidorn commented 3 years ago

@yuehuang010 ok great, so you would handle the rendering in your table by having special elements that are actually representing the source lines, that way it would be inter-mingled. You will not have colorisation here easily.

Context menu -> "Open Source in Editor" -> use the editor service to open the URI as I suggested in the comment above.

yuehuang010 commented 3 years ago

@isidorn, Is using NativeTextFileService nad TextModel the way to go? Or are there another way to open the file?

isidorn commented 3 years ago

@yuehuang010 you should just use the editorService. Here's an example here https://github.com/microsoft/vscode/blob/main/src/vs/workbench/contrib/debug/common/debugSource.ts#L76

I hope that helps!

Trass3r commented 3 years ago

@isidorn, here is the view in VS. The source code of cpp has is intereved between disassembly.

Could we open the disassembly view in a new tab group to the right until this more involved solution is done? It's annoying having to drag it manually every time just to see both source code and assembly.

Also another thought, when the source code is not available for whatever reason VS automatically shows the disassembly.

isidorn commented 3 years ago

Always opening the disassembly view On the Side might make sense. Let's see what @yuehuang010 and @xisui-MSFT think

As for the second one (when source not available to automatically show), that sounds like a feature request. I suggest you file a new issue and then we can see to potentially add it in the future. I would not do this for starters, but only once we polish the current view much more.

yuehuang010 commented 3 years ago

@Trass3r @isidorn SideBySide source code is ok if the disassembly lines up with one file. But code can jump around between multiple source with inlining, function calls etc.

We might consider it as feature, but won't be on by default.

Trass3r commented 3 years ago

True if you step side-by-side it syncs properly as long as you stay in the same source file but doesn't jump to other files when you reach them. Can totally be a controlled by a setting.

Also btw, I noticed when testing this with the C++ extension that a disassemble request is sent before I even switch to disassembly. Is this a bug on the vscode side?

yuehuang010 commented 3 years ago

"disassemble called made when view is closed", Someone else mentioned it, I will look into it. soon.

xisui-MSFT commented 3 years ago

"disassemble called made when view is closed", Someone else mentioned it, I will look into it. soon.

Currently it loads disassembly on pause debugging. We should probably add a focus check.

jureid commented 2 years ago

A customer at CppCon has a few feature requests for Disassembly View:

xisui-MSFT commented 2 years ago

More information in the tab title about what is being disassembled. For example "my_bin (Disassembly)" or "my_func (Disassembly)" would be helpful, depending on whether you're showing disassembly for a single function or a whole binary.

@jureid We always show disassembly of the whole binary (load on scroll), and never a single function/file.

Trass3r commented 2 years ago
* Support for intel syntax in the disassembly (preferred to AT&T syntax).

+1 att is horrible. Workaround is adding set disassembly-flavor intel to .gdbinit.

yuehuang010 commented 2 years ago
* Support for intel syntax in the disassembly (preferred to AT&T syntax).

+1 att is horrible. Workaround is adding set disassembly-flavor intel to .gdbinit.

Is this something the C++ extension should handle?

WardenGnaw commented 2 years ago
* Support for intel syntax in the disassembly (preferred to AT&T syntax).

+1 att is horrible. Workaround is adding set disassembly-flavor intel to .gdbinit.

Is this something the C++ extension should handle?

Yes. Disassembly flavor should be set by the debug adapter.

AnthonyLeonardoGracio commented 1 year ago

Hello!

I was wondering how hard it would be to get a working Disassembly view for other languages that can be debugged through GDB or LLDB? Basically we would like to get the Disassembly view working for the Ada language, but since the view is only available for C/C++ files, I can't get it work.

Does someone have ideas on how could this work? Also, let me know if this discussion should occur on a separate issue, I can open one if needed!

haneefdm commented 1 year ago

The disassembly support is not dependent on the language or even the debugger like gdb/lldb. Your debug adapters (interface between gdb/lldb and VSCode) have to support it and even they do not much care (in many instances) what language is being used.

Not clear what debug adapter (or extension) you are using to debug your ADA program today...and this request would belong to that extension to support the protocols required by the VSCode disassembler (documented in the Debug Adapter Protocol).

If you can debug via gdb/lldb however, then you can even use existing debuggers (cppdbg from cpptools) to debug your executable. For instance, you can debug a program written in Rust because the compiler produces and ELF file that can be debugged via GDB/LLDB

When you setup your launch.json for cppdbg just make sure you are using your elf file if you have one and then you should be able to use it just like C/C++/Rust programmers do.

I can say this because I author a debug adapter extension that supports disassembly and any language is fine with us so long as we can debug with GDB.

AnthonyLeonardoGracio commented 1 year ago

Thanks for this very detailed answer @haneefdm!

Currently we are using the Native Debug extension to debug Ada code, which launches GDB basically. But when using it I don't get the 'Open disassembly view' contextual menu when debugging.

I tried to usecppdbg do debug my Ada code, but the menu was not available too, while it was the case when debugging C/C++. It may be a setup issue, I will try again. I just wanted to make sure that there is nothing that prevents me to get this feature when using GDB but for other languages such as Ada, and apparently it's the case from what you say ;)

I will try again and keep you posted then!

haneefdm commented 1 year ago

Yes, Native Debug will have to support disassembly. We originally forked from that several years ago,

Note that the launch.json contents will be very different for cppdbg. Just follow instructions/examples for cppdbg as if you have a C++ program. cppdbg will not know the difference.

AnthonyLeonardoGracio commented 1 year ago

@haneefdm

So I have tried to use cppdg by using a simple launch.json configuration found on the web, and I am able to debug my Ada code properly on simple projects. The Open Disassembly View contextual menu is available, I can see the disassembly in the Debug Console, but I get a new view with Disassembly not available at the end, without knowing exactly why.

Any ideas of what could be wrong? I have attached my launch.json contents and a simple screenshot, if that helps.

launch.txt

Capture d’écran 2022-12-16 à 12 31 39
haneefdm commented 1 year ago

Can you get disassembly from gdb command line? If not neither can cpptools. It has to do with how you compiled (did you compile for debug and saving saving/debug info).

You should file an issue with cpptools if gdb works but cpptools isn't giving you disassembly. Just for fun, try a larger program with at least a few thousand instructions.

haneefdm commented 1 year ago

You can enable logging to see what commands are being sent to gdb, etc. But first, make sure your gdb is working.

AnthonyLeonardoGracio commented 1 year ago

Yes, I can get disassembly from GDB's command line. Note that I am also able to get the Assembly view working in GNAT Studio (an IDE dedicated to Ada), with the same compiled executable (compiled with -g -O0)

Attaching the whole GDB output: as you can see, the -data-disassemble seems to work fine.

gdb_output.txt

AnthonyLeonardoGracio commented 1 year ago

Any idea @haneefdm ? ;)

haneefdm commented 1 year ago

You should approach the cpptools team for help. It appears they are doing the right thing but why you are seeing an empty Disassembly window, I cannot explain.

https://github.com/microsoft/vscode-cpptools

They may direct you to VSCode main repo

AnthonyLeonardoGracio commented 1 year ago

Ok I will do that, thanks for your help ;)

thegecko commented 11 months ago

Can this scope also include a context menu which can be a contribution point for other extensions?

ref: https://github.com/microsoft/vscode/issues/171548