如何使用 icc 编译器检查 gdb 中 std::vector 的内容? [英] How do I examine the contents of an std::vector in gdb, using the icc compiler?

查看:48
本文介绍了如何使用 icc 编译器检查 gdb 中 std::vector 的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查 gdb 中 std::vector 的内容,但我无权访问 _M_impl,因为我使用的是 icc,而不是 gcc,我该怎么做?为了简单起见,我们假设它是一个 std::vector.

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.

有一个非常好的答案 here 但是如果我使用 icc 这不起作用,错误消息是没有名为 _M_impl 的成员或方法".此处 似乎有一个不错的调试工具集,但它也依赖于 _M_impl.

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.

推荐答案

不确定这是否适用于您的载体,但对我有用.

Not sure this will work with your vector, but it worked for me.

#include <string>
#include <vector>

int main() {
    std::vector<std::string> vec;
    vec.push_back("Hello");
    vec.push_back("world");
    vec.push_back("!");
    return 0;
}

gdb:

(gdb) break source.cpp:8
(gdb) run
(gdb) p vec.begin()
$1 = {
   _M_current = 0x300340
}
(gdb) p $1._M_current->c_str()
$2 = 0x3002fc "Hello"
(gdb) p $1._M_current +1
$3 = (string *) 0x300344
(gdb) p $3->c_str()
$4 = 0x30032c "world"

这篇关于如何使用 icc 编译器检查 gdb 中 std::vector 的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆