Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ debugging by Visual Studio - Watchpoint on vector size change

I want to explore the changes with my vector. Thus I want to set a whatchpoint on the vector size. Thereby, Visual Studio will let me to see what is in my vector after each size change. How I can do this?

Here in this link you can find how to set a conditional breakpoint. And I tried to set a condition like this: my_vect.size() variable on Has changed event (according to 8. Conditional breakpoints), but it sucks.

like image 913
Narek Avatar asked Sep 18 '25 22:09

Narek


1 Answers

my_vect.size() is not a variable, but a function. It looks like this:

size_type size() const _NOEXCEPT
    {   // return length of sequence
    return (this->_Mylast - this->_Myfirst);
    }

So here is the solution: start your program with the debugger. Break before the vector size changes. Add a New Data Breakpoint. Suppose your vector is called myvec. Then in the address field type &myvec._Myfirst and add another breakpoint with &myvec._Mylast. Now, the debugger will stop whenever the pointers to the first or last elements in the vector change.

like image 64
Marius Bancila Avatar answered Sep 21 '25 15:09

Marius Bancila