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

夙愿已清 提交于 2019-12-06 07:45:07

问题


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.


回答1:


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 put &myvec._Mylast and respectively &myvec._Mylast. Now, the debugger will stop whenever the pointers to the first or last elements in the vector change.




回答2:


You can open the <vector> header and set a breakpoint at the start (or at the end) of each method of std::vector that changes the size of the vector (like push_back, erase, etc).



来源:https://stackoverflow.com/questions/14620614/c-debugging-by-visual-studio-watchpoint-on-vector-size-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!