vscode-debug-visualizer icon indicating copy to clipboard operation
vscode-debug-visualizer copied to clipboard

C/C++ visualization

Open khamyl opened this issue 3 years ago • 10 comments

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

khamyl avatar Jul 09 '21 10:07 khamyl

Interesting, that should work.

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

hediet avatar Jul 09 '21 10:07 hediet

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

image

khamyl avatar Jul 09 '21 12:07 khamyl

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

khamyl avatar Jul 22 '21 11:07 khamyl

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.

hediet avatar Jul 22 '21 11:07 hediet

May I help somehow?

khamyl avatar Aug 05 '21 08:08 khamyl

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

hediet avatar Aug 05 '21 09:08 hediet

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

thijssteel avatar Apr 29 '22 16:04 thijssteel

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.

hediet avatar May 02 '22 07:05 hediet

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.

thijssteel avatar May 02 '22 12:05 thijssteel