Debugging gdb中向量的访问向量

Debugging gdb中向量的访问向量,debugging,vector,gdb,Debugging,Vector,Gdb,我有一些不知道编译的可执行文件 用于构建它的标志(优化、调试信息等) 在它里面,我有一个带有一个名为values的输入变量的函数 (参考通过): 我明白了: $15 = std::vector of length 1, capacity 1 = {std::vector of length 4, capacity 4 = {0 '\000', 0 '\000', 50 '2', 0 '\000'}} Could not find operator[]. $2 = std::vector of

我有一些不知道编译的可执行文件 用于构建它的标志(优化、调试信息等)

在它里面,我有一个带有一个名为values的输入变量的函数 (参考通过):

我明白了:

$15 = std::vector of length 1, capacity 1 = {std::vector of length 4, capacity 4 = {0 '\000', 0 '\000', 50 '2', 0 '\000'}}
Could not find operator[].
$2 = std::vector of length 1, capacity 1 = {std::vector of length 3, capacity 3 = {48 '0', 49 '1', 50 '2'}}
也就是说,大小为1的向量包含大小为4的向量

当我尝试使用gdb访问内部大小为4的向量时:

(gdb) print values[0]
我明白了:

$15 = std::vector of length 1, capacity 1 = {std::vector of length 4, capacity 4 = {0 '\000', 0 '\000', 50 '2', 0 '\000'}}
Could not find operator[].
$2 = std::vector of length 1, capacity 1 = {std::vector of length 3, capacity 3 = {48 '0', 49 '1', 50 '2'}}
但是,当我编译和调试一个简单的“向量世界的hello vector”时,没有优化,并且-ggdb标志

(gdb) print values
我明白了:

$15 = std::vector of length 1, capacity 1 = {std::vector of length 4, capacity 4 = {0 '\000', 0 '\000', 50 '2', 0 '\000'}}
Could not find operator[].
$2 = std::vector of length 1, capacity 1 = {std::vector of length 3, capacity 3 = {48 '0', 49 '1', 50 '2'}}
当我尝试访问内部向量时:

(gdb) print values[0]
一切正常:

$3 = std::vector of length 3, capacity 3 = {48 '0', 49 '1', 50 '2'}
这可能是优化的问题吗??调试信息

非常感谢您的帮助。。。谢谢

这可能是优化的问题吗

当您
打印值[0]
时,GDB尝试查找要调用的函数,这里
std::vector::operator[](size\u t)
。在非优化的情况下,GDB会找到它,调用它,并打印结果。在优化的情况下,函数已经内联,因此GDB可以使用的可执行文件中没有外部调用的函数;因此,
无法找到运算符[]
错误