如何使用 icc 编译器检查 gdb 中 std::vector 的内容?
我想检查 gdb 中 std::vector 的内容,但我无法访问 _M_impl 因为我使用的是 icc,而不是 gcc,我该怎么做? 为了简单起见,我们假设它是一个 std::vector 。
这里有一个非常好的答案 但如果我使用 icc,这不起作用,错误消息是“没有名为 _M_impl 的成员或方法”。 这里似乎有一个不错的调试工具集,但它也依赖于 _M_impl 。
I want to examine the contents of a std::vector in gdb but I don't have access to _M_impl because I'm using icc, not gcc, how do I do it? Let's say it's a std::vector for the sake of simplicity.
There is a very nice answer here but this doesn't work if I use icc, the error message is "There is no member or method named _M_impl". There appears to be a nice debug toolset here but it also relies on _M_impl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定这是否适用于你的向量,但它对我有用。
数据库:
Not sure this will work with your vector, but it worked for me.
gdb:
通常,当我在调试器中处理容器类时,我会构建对元素的引用作为局部变量,因此很容易在调试器中看到,而无需在容器实现中进行修改。
这是一个人为的例子。
这是我使用的习语。
Generally when I deal with the container classes in a debugger, I build a reference to the element, as a local variable, so it is easy to see in the debugger, without mucking about in the container implementation.
Here is a contrived example.
That is the idiom I use.
std::vector
模板保证数据连续存储。 如果获取前面元素的地址(例如,&v[0]
),则可以通过 C 样式数组访问向量中的任何其他元素。 这并不要求您的调试器可以使用 STL 的源代码。在搞乱了一些之后,看起来
v.front()
和v.begin()
很可能是内联的,而 GDB 没有找到它们。 我会继续寻找,但就我个人而言,我会简单地将行int* i = &v[0]
添加到源文件中,然后在i
上使用 GDB 命令调试时。 请注意,编译器可以自由删除死代码。 您可能需要输出i
的值来避免这种情况,或者干脆不启动优化。The
std::vector
template guarantees the data is stored contiguously. If you take the address of the front element (say,&v[0]
, for instance), you can access any other element in the vector through a C-style array. That doesn't require you to have the source code of the STL available to your debugger.After messing with this some, it appears that
v.front()
andv.begin()
are likely inlined and GDB isn't finding them. I'll keep looking, but personally I would simply add the lineint* i = &v[0]
to the source file, and then use GDB commands oni
while debugging. Note that the compiler is free to remove that dead code. You may need to output the value ofi
to avoid that, or simply not crank up optimizations.