2

I'm using vscode to debug some c++ code, however I cannot inspect any (heap allocated) objects. Like in this example:

float arrayStack[10];  
for (size_t i = 0; i < 10; i++)
{
    arrayStack[i] = -42.3;
}

float *arrayHeap  = new float[10];
for (size_t i = 0; i < 10; i++)
{
    arrayHeap[i] = 84.6;
}

Values of "arrayStack" can be inspected during debugging whereas I can only see the first value of "arrayHeap" but not all elements. Vs-Code allows me to open a "memory.bin" file for "arrayHeap", but it's not really comparable to inspecting "arrayStack". In reality I'm trying to inspect an Eigen::Matrix after initialization and in contrast to my simple example it's really hard to see whats going on there.

  • are all values correctly initialized?
  • is the memory contiguous, i.e. is it save to assume that every 4th "hex-element" corresponds to a float value of my matrix or could the matrix / array be stored accross different patches in the memory?

I've heard about .natvis files for vscode, but I'm not sure if that is helping / best practice for my problem

5
  • You can try to watch arrayHeap + 0,10 (this is the way to inspect an array via a pointer in VisualStudio, perhaps it will work in VS code as well). Commented Jun 14, 2022 at 9:54
  • You can look at the Eigen headers to see what you can expect to find. Note that Eigen::Matrix is a class template so the contents will depend entirely on how it was parameterized. In general, you can inspect memory contents most easily using the Memory tabs in Visual Studio, found under Debugging section. You can choose to group your columns in sizes appropriate to what you're looking for, and even view the contents as a specific primitive datatype. It is a pain when you need to hop through pointers though. Beyond this, .natvis is an option if you want inspectable objects with helpful labels. Commented Jun 14, 2022 at 9:56
  • A note on visualizers... Do some thorough web searching, as someone might have already built one for the object you're trying to visualize. Commented Jun 14, 2022 at 9:57
  • 1
    Relevant: How to expand an array while debugging in visual studio code. Commented Jun 14, 2022 at 10:58
  • 1
    Did you try this: Debugging tips from eigen? Commented Jun 14, 2022 at 13:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.