Eclipse-C++-Debugging: see content of an Array
If you want to avoid having to repeatedly do "Display As Array", open the "Expressions" tab and add the expression (*array@dimension)
. Not sure why the parentheses are necessary. Without them you'd get an error.
In the "Expressions" tab, if you do what cleong noted and type (*array@dimension)
then you can dynamically set the size of the array to display as well. This even works when you need another expression to get it.
So say you have a variable x
that contains your array size, you type (*array@x)
and it'll use the content of x as a dimension.
"x" can also be things like struct contents or pointer dereferences and the like - i.e.
(*array@SomePtrToStruct->x)
works just fine.
In Eclipse, in order to see the content of a dynamically allocated array (for anyone else who stumbles over this question),
- Make sure you are in the debugging perspective;
- Look for the "Variables" window. if you don't see it, click "Window" > "Show view" > "Variables";
- Right-click on the array variable;
- Click "display as array...";
- 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.
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).