September 19, 2008

[C/C++] - Watching all values of arrays (of free pointers) in Visual Studio C++ debugger

“How do I get Visual Studio debugger to show me the data in the arrays? I don’t want to see just one value at a time; I want to see the values contained in array indices [50] to [100] for example”.

Using for Visual Studio 2005:

If yours were fixed length arrays, getting the value of a range would not be difficult. The debugger would then provide a small + sign beside your array object in the quick watch, and you could expand it to see all the elements.

With free pointers, the debugger cannot do that. Becasue it does not know the length of the array. So you must use some little tricks:

  • Use the managed framework and declare an arraylist object, load it using your native array specifying the length. Your debugger will instantly show all the elements of the array list object expandable/ collapsible with a + sign
  • Write them down to a file on the hard disk ([index]:[value] format), open and inspect the file while debugging.
  • Declare a test only fixed length array (that you can comment later on), copy the contents of the native pointer array to it, and let the debugger do the rest.

No comments: