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

Matt
  • 2,554
  • 2
  • 24
  • 45
mcExchange
  • 6,154
  • 12
  • 57
  • 103
  • 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). – wohlstad Jun 14 '22 at 09: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. – paddy Jun 14 '22 at 09: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. – paddy Jun 14 '22 at 09:57
  • 1
    Relevant: [How to expand an array while debugging in visual studio code](https://stackoverflow.com/q/52721440/580083). – Daniel Langr Jun 14 '22 at 10:58
  • 1
    Did you try this: [Debugging tips](http://www.eigen.tuxfamily.org/index.php?title=Developer%27s_Corner#Debugging_tips) from eigen? – Matt Jun 14 '22 at 13:06

0 Answers0