我正在gdb调试器中调试一个gdb程序,并试图访问vector的第5个元素,该元素仅包含4个元素。尝试此错误后,屏幕上出现了以下错误:
(gdb) list main
1 #include <memory>
2 #include <vector>
3
4 int main(int argc, char *argv[]){
5
6
7 std::vector<int> v_num = {1, 3, 5, 67};
8 std::unique_ptr<std::vector<int>> p(&v_num);
9
10
(gdb) p v_num.at (5)
Python Exception <class 'IndexError'> Vector index "5" should not be >= 4.:
Error while executing Python code.
(gdb) 除了在gdb中看到Python之外,我没有看到。有人能解释我为什么会遇到这样的错误吗?gdb在内部使用python吗?
发布于 2022-07-19 21:11:14
在内部使用python吗?
是的,它在很多方面都使用Python来扩展自己,参见https://sourceware.org/gdb/onlinedocs/gdb/Python.html#Python。
您所发现的称为Python,请参阅https://sourceware.org/gdb/onlinedocs/gdb/Xmethods-In-Python.html。Xmethods用于替换C++源代码中定义的内联或优化的out方法。libstdc++对于标准容器有许多xmethods。您可以使用info xmethod命令看到它们。对于std::vector,在我的框中定义了6个x方法:
libstdc++::vector
size
empty
front
back
at
operator[]可以使用disable xmethod命令禁用所有xmethods。如果这样做,GDB将无法调用at方法:
(gdb) p v_num.at (5)
Cannot evaluate function -- may be inlinedhttps://stackoverflow.com/questions/73025746
复制相似问题