hediet / vscode-debug-visualizer

An extension for VS Code that visualizes data during debugging.
https://marketplace.visualstudio.com/items?itemName=hediet.debug-visualizer
GNU General Public License v3.0
7.93k stars 413 forks source link

C/C++ visualization #119

Open khamyl opened 3 years ago

khamyl commented 3 years ago

Hello,

I am so happy that something like this exists! Unfortunately, I cannot make it work for C++ (cppvsdbg). I took the example form demo code and implemented it like this:

std::string visualize = "{\
        \"kind\":{ \"plotly\": true },\
        \"data\":[\
            { \"y\": [1, 2, 4, 8, 16] },\
            { \"y\": [14, 3, 0, 15, 10] }\
        ]\
    }";

The result is as following: image

How to create a JSON string in C++ that would be parsed as expected?

Related to #108

hediet commented 3 years ago

Interesting, that should work.

What does the debug console say when evaluating this expression there?

khamyl commented 3 years ago
"{        \"kind\":{ \"plotly\": true },        \"data\":[            { \"y\": [1, 2, 4, 8, 16] },            { \"y\": [14, 3, 0, 15, 10] }        ]    }"

image

khamyl commented 3 years ago

Is that a bug, or am I doing something incorrectly?

hediet commented 3 years ago

I'm sorry, I did not find time to look into it... But I really want to.

I think this might be a bug. If it is not a bug, the extension is not doing a great job at showing what is wrong, so in both cases, I need to look into it.

khamyl commented 3 years ago

May I help somehow?

hediet commented 3 years ago

Yeah sure, you should be able to debug the extension (see contributing).

I think this is a good code pointer: https://github.com/hediet/vscode-debug-visualizer/blob/master/extension/src/VisualizationBackend/GenericVisualizationSupport.ts#L60

thijssteel commented 2 years ago

I ran into the same issue and I think I found the problem and a solution.

The problem seems to be that evaluating 'visualise', just outputs the STL container and not the actual string. Enabling pretty printing solves that issue. ( -exec -enable-pretty-printing )

A second issue in the example above is that there are a lot of spaces in the string. GDB will shorten this to say <repeated 12 times> which the JSON parser cannot read. The easiest solution is to remove the spaces, although a different printing method may be necessary for things like "aaaaa".

This is related to https://github.com/microsoft/vscode-cpptools/issues/201

hediet commented 2 years ago

Do you have ideas how to improve this generally?

I noticed that debug adapters change their output from time to time. I think it should be easier to debug that.

thijssteel commented 2 years ago

I don't really know.

Getting the full string is easier if you additionally use the commands: -exec set print elements 0 -exec set print repeats 0

But that's not a true solution either. I think the best you can do in this library is add a warning in the cpp example about gdb's behaviour and these three commands that hopefully make it better.

arjunarjun07 commented 3 months ago

I am facing the same with MSVC compiler in vscode. The debug visualizer displays the same output as the above. Any help would be appreciated.

image