如何为向量设置断点长度增加?
我有一个空向量,有东西在某处填充,但我找不到它。我想设置一个内存断点,这样当push_back发生时程序就会中断。
我使用的是 Visual Studio 2008,问题是向量不会在监视窗口中显示其内部成员(它似乎具有自定义格式)。它看起来像这样:
myVector[0]() std::vector< int,std::分配器<整数> >
指示尺寸 0。有什么提示吗?
I have a vector that is empty, something is filling it somewhere and I cant find it. I want to set a memory breakpoint so that when the push_back occurs the program will break.
I'm using Visual Studio 2008, and the problem is that the vector doesnt display its internal members in the watch window (it seems to have a custom formatting). It just looks like this:
myVector[0]() std::vector< int,std::allocator< int > >
Indicating size 0. Any tips?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此答案适用于 VS 2010 - 其他版本中的详细信息可能有所不同。
由于调试器使用数据可视化工具(或任何名称)来显示
std::vector
的状态,因此您必须查看
标头以了解确定类的实际成员的名称以及哪些成员可能负责跟踪元素的数量。执行此操作的一个简单方法是逐步调用vector::push_back()
。在 VC++ 2010 中,这是一个名为
_Mylast
的成员指针。因此,您所要做的就是在写入
&v._Mylast
时设置数据断点(其中v
是您有兴趣调试的向量)。下次添加元素时,调试器将中断并显示确切位置的调用堆栈。
This answer is for VS 2010 - details might differ in other versions.
Since the debugger uses a data visualizer (or whatever it's called) to display the state of a
std::vector
, you have to look in the<vector>
header to determine the names of the actual members of the class and which one(s) might be responsible for tracking the number of elements. An easy way to do this is to step through a call tovector::push_back()
.In VC++ 2010 this is a member pointer named
_Mylast
.So all you have to do is set a data breakpoint on writes to
&v._Mylast
(wherev
is the vector you are interested in debugging).The next time an element is added, the debugger will break with a call stack showing exactly where.
在VC2010中显示为0,[0]表示向量的大小,项目将显示在()中。
您可以使用内存输出窗口来找出内存地址。
It shows 0 in VC2010, [0] indicates the size of the vector and the items will be displayed in ().
and you can use memory output windows to find out the memory address.