开发者

Watch content of stl vector via gdb

I've got a stl 开发者_运维知识库vector of custom class objects defined in a global namespace (yeah, evil, I know). Now I would like to set a watchpoint in gdb to monitor possible changes in a (public) member variable for a certain element of this vector. Something like:

watch custom_namespace::vec[123].aVariable

If I do this, then gdb (Version 7.1 on Ubuntu Lucid) segfaults. Are there alternative ways. Is this possible at all?


See if this applies to your case (from gdb manual):

Sometimes, gdb cannot set a hardware watchpoint because the data type of the watched expression is wider than what a hardware watchpoint on the target machine can handle. For example, some systems can only watch regions that are up to 4 bytes wide; on such systems you cannot set hardware watchpoints for an expression that yields a double-precision floating-point number (which is typically 8 bytes wide). As a work-around, it might be possible to break the large region into a series of smaller ones and watch them with separate watchpoints.


Try casting the address to (int*). Does it still segfault?

Also STL vector will move its content if it needs to extend the internal buffer, so your object might just be "stolen" from under the watchpoint.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜