vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.5k stars 242 forks source link

Support for Rust NDarray #366

Closed selvavm closed 3 years ago

selvavm commented 4 years ago

OS: Windows 8.1 VSCode version: 1.49 Extension version: 0.2.313 Toolchain version: stable-x86_64-pc-windows-msvc Build target: stable-x86_64-pc-windows-msvc Python version:

I am building a rust application and it has lot of 1D and 2D NdArray. I wanted to visualise them in VSCode while debugging but it is showing only pointer. I see that you have a formatter/rust.py and you have defined visualisation for Rust types. I am not an expert in python (and rust as well), so don't know how to define this type. Can you provide some code hints on how to modify?
image

vadimcn commented 3 years ago

Please see lldb formatters docs.

MartinRJDagleish commented 1 year ago

Hey,

I wanted to add my solution to this thread, because it was quite frustrating getting this work with lldb.

For Linux (in my case an Arch WSL2 system) I found that lldb worked very nicely for debugging Rust, so I wanted to stay with lldb.

So with all of that out of the way... my solution was: NOTE: This is a Linux based (Arch WSL2) solution

Solution

  1. Make sure you have the CodeLLDB VSCode extension.
  2. Try running a normal debug session first. (If this works continue, otherwise fix error)
  3. If ndarray Arrays looks like this image then you have the default "representation" using lldb
  4. In your local or global settings.json for VSCode add the lines:
          "lldb.launch.initCommands": [
              "command script import ${workspaceFolder}/.vscode/name_of_ndarray_format.py"
          ],

    with name_of_ndarray_format.py being the file that I will descripe now:

  5. Add a custom file that make the content visualization in VSCode possible. 5.1. SOURCE: https://github.com/hep-rs/boltzmann-solver/blob/master/.vscode/formatter.py - Author: @JP-Ellis 5.2. After creating the file in ${workspaceFolder}/.vscode/, you should be able to start a debug session with lldb and should instead see the ndarray ArrayBase types as: image which is the desired output we want to see in a debugger.

REMARKS

NOTE: I have very limited knowledge about lldb and its innerworkings and I do not provide any warranty for my solution. This was the final solution, which worked for me and wanted to share it, so maybe more people can profit from this.

I also left this answer on: https://github.com/rust-ndarray/ndarray/issues/827