How to see all elements of array created using pointer during debug time

Oct 31, 2016 at 9:28pm
When debugging a program it is possible to see the values of everything in the program, especially the local variables of the function where we have entered break mode.

With pointers we only see the first element that we would get if the pointer itself was dereferenced. In my program I am using dynamic memory allocation to create variable length char arrays. In function call a pointer to this array and length of array is sent. But during the debug mode I cannot see the values of the whole array in the "locals" window, only first element. What is the work around for this?
Oct 31, 2016 at 10:43pm
in gdb
> print *name_of_pointer@length
Nov 3, 2016 at 8:56am
eerrrrrr, what is gdb?

Can't the debug and immediate windows be used for this purpose at all?
Nov 3, 2016 at 10:45am
> what is gdb?

The GNU debugger. As far as C++ is concerned, the poor cousin of the Visual Studio debugger.


> Can't the debug and immediate windows be used for this purpose at all?

Say we have:
1
2
int* pa = new int[100] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;
std::iota( pa, pa+100, 100 ) ; // fill with values 100, 101, 102, ... 199  

In the immediate window:
To show all 100 values, enter: ? pa, 100
To show 10 values starting at pa[50], enter: ? pa+50, 10

In a Watch or the QuickWatch window, enter the expression to watch as: pa, 100 or pa+50, 10

If the number of elements in the dynamically allocated array is not known, in most cases we can use the hv specifier (ask the debugger to try to determine the length of the array). For instance, in the immediate window: ? pa, hv

If type information has been lost (say, because of an implicit conversion to pointer to void), use a cast;
for instance ? static_cast<const int*>(pvoid), 7
Topic archived. No new replies allowed.