Tuesday, July 28, 2009

Examining arrays in Visual Studio C++ debugger?

OK. I'm at a breakpoint in the debugger and now I want to examine the values stored in my arrays. 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 [100] to [199] for example.





Surely there has to be an easy way to do this. I've been doing it since the 90's in the Borland IDE and since the 80's on VAXs.





And while I'm at it, is there any way that I can plot data from arrays while in the debugger like you can in Matlab?

Examining arrays in Visual Studio C++ debugger?
I don't know about other versions, but right now I'm using VS2005, and I can see the values in an array while stopped in debug mode by right clicking on the variable and selecting "Quick Watch..."





That will produce a nice little window listing all the values in the array. I'm not sure if that's exactly what you want, but that's the closest thing that I'm aware of.





Personally, I have to use VS everyday, and I'm convinced it's the biggest piece of trash IDE that I've ever used.
Reply:int* p = new int[100]; // Assume a Pointer created like this.


In the watch window type: p,100


(The comma is your friend here!)


To view values with indices 50-60 type: (p+50),10


For plotting see: http://arraydebugview.sourcefo... Report It

Reply:One way is to specify the index in your debugger. Like arrayname[105] - that should give you the exact value at that index.





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.





But with free pointers, the debugger cannot do that. Becasue it does not know the length of the array. And Microsoft has taken a very tight fisted approach towards accessing out of bounds values, even in read only mode by the debugger - so it does not take any risk.





If you are so hell bent on seeing the values of a range, you have to do some little extra work dude:





Option A: 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





Option B: Write them down to a file on the hard disk ([index]:[value] format), open and inspect the file while debugging.





Option C: 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.





Option D, E, F, ...: Give it up. There are better things to do in life.

bridal flowers

No comments:

Post a Comment