使用STL列表调试问题
gdb and debugging problems with an STL list
我最近在这里问了一个问题,不幸的是没有得到一个我可以使用的答案:
c++ STL列表函数用空列表分段
我一直在尝试使用gdb来调试这个问题,我有一个关于什么意思的问题:
我将list声明为类的成员,如下所示:std::list<Thing*> inventory;
…然后实例化它所在的类(一个名为"pc"的对象)。在gdb中,我假定这表明我为它分配了一些内存。
(gdb) p &pc.inventory
$7 = (std::list<Thing*, std::allocator<Thing*> > *) 0xbffff22c
进一步,在代码的问题行前一行(实际上,调用'inventory.size()'会导致段错误),这仍然成立:
(gdb) p &inventory
$8 = (std::list<Thing*, std::allocator<Thing*> > *) 0xbffff22c
…但是我仍然得到segfault:
(gdb) n
558 if (inventory.size() == 52) {
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0x0804e3fe in std::_List_const_iterator<Thing*>::operator++ (this=0xbfff94e0)
at /usr/include/c++/4.4/bits/stl_list.h:223
223 _M_node = _M_node->_M_next;
我的问题本质上是这样的:当然,如果我有一个成员列表的地址,列表存在,我应该能够在它上面使用size() ?如果不是,为什么不呢?我该如何进一步调试?
谢谢!
要调试内存错误,我建议您在valgrind
中运行程序。valgrind——tool=memcheck program_name
和修复valgrind
相关文章:
- 如何针对特定情况调试和修复此双自由内存损坏问题
- 需要帮助调试"attribute parser"!C++ 来自黑客排名的问题
- 调试模板时出现问题.专门针对 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 错误构建失败:模板参数 1
- 调试C++程序时遇到问题
- 在发布模式下崩溃,但如果可调试为 true - 不是..什么是可能的问题
- C++ CDB 调试器问题
- 如何调试错误代码 77:cudaErrorIllegal地址当 cuda-memcheck 没有发现问题时
- 如何调试我的 OpenGl 问题
- 调试基于 Linux 的 C++ 代码 Visual Studio 代码时出现问题
- Linux Opensuse C 编译器问题.(无法初始化部分调试器的解压缩状态)
- 如何调试这个C++类出了什么问题?
- 每当调试C (Xcode 10.1)时,输入问题
- 调试堆栈损坏问题
- 为什么调试器在排序前显示问题
- C Microsoft Visual Studio 2015调试问题(找不到或打开PDB文件.)
- gdb 7.5.1调试通过g 4.7.2构建的可执行文件的问题
- 在非调试模式下运行代码时出现问题
- 调试Xcode 4.4中的libc++问题
- 在OS X上使用MacPorts GCC调试问题
- 调试问题:(