Eclipse-C++-Debugging: see content of an Array

brandstaetter picture brandstaetter · Dec 1, 2009 · Viewed 21.7k times · Source

Is it possible to see the content of a dynamically allocated array, as in:

int *array = new int[dimension];

I only see the value of the pointer.

edit: just found the option "display as an array", but I always have to manually enter the size of the array. Is it possible to get that automagically?

Answer

Alexander Taylor picture Alexander Taylor · Jan 22, 2012

In Eclipse, in order to see the content of a dynamically allocated array (for anyone else who stumbles over this question),

  1. Make sure you are in the debugging perspective;
  2. Look for the "Variables" window. if you don't see it, click "Window" > "Show view" > "Variables";
  3. Right-click on the array variable;
  4. Click "display as array...";
  5. Eclipse does not know how big your array is. So type 0 for the start index and choose the number of elements dynamically allocated for the length. Of course, you can use these values to display any part of the array of your liking.

choose display as array in eclipse

And, dealing with a pointer, take note of clicking 'Display as Array' when hovering on the pointer itself (arrow icon), and not on the value it is referenced at first (say in the position of (x)= counts in the picture). Otherwise you get an error of the type

Failed to execute MI command:
-data-evaluate-expression [specifics]
Error message from debugger back end:
Cannot access memory at address 0x[address of older *counts]

showing up in the dialogue window just below the list (starting with "Name:" in the screenshot above).