我在调试代码时遇到问题,并且对gdb输出感到有点困惑.我已经在下面附加了gdb输出.最后两行,第13行和第14行是我的代码,但其他所有内容都来自C++库.令我感到困惑的是,从第7行向上,似乎是在调用delete.这是初始化代码,在代码流中没有删除或释放.但有些事情导致在C++库中的某处调用delete.
这是一个带有g ++ 4.7.2的debian盒子
任何人都有一个可以帮助我的线索吗?
编辑:谢谢你们的帮助.我确实认为这里还有其他事情发生.由于我的代码的意图是使用几个append()调用来构造一个字符串,我在ctor中为该字符串添加了对reserve()的调用,因此它足够大以处理一些append()调用而不必获取更多的空间.这显然有所帮助,因为我现在更难以强制崩溃.但我确实同意原因可能在我的代码中的其他地方.再次感谢您的帮助.
Program received signal SIGABRT, Aborted.
0xb7fe1424 in __kernel_vsyscall ()
(gdb) bt
#0 0xb7fe1424 in __kernel_vsyscall ()
#1 0xb7a9a941 in *__GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2 0xb7a9dd72 in *__GI_abort () at abort.c:92
#3 0xb7ad6e15 in __libc_message (do_abort=2, fmt=0xb7baee70 "*** glibc detected *** %s: %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:189
#4 0xb7ae0f01 in malloc_printerr (action=<optimized out>, str=0x6 <Address 0x6 out of bounds>, ptr=0xb71117f0) at malloc.c:6283
#5 0xb7ae2768 in _int_free (av=<optimized out>, p=<optimized out>) at malloc.c:4795
#6 0xb7ae581d in *__GI___libc_free (mem=0xb71117f0) at malloc.c:3738
#7 0xb7f244bf in operator delete(void*) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#8 0xb7f8b48b in std::string::_Rep::_M_destroy(std::allocator<char> const&) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#9 0xb7f8b4d0 in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#10 0xb7f8c7a0 in std::string::reserve(unsigned int) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#11 0xb7f8caaa in std::string::append(char const*, unsigned int) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#12 0xb7f8cb76 in std::string::append(char const*) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#13 0x0804fa38 in MethodRequest::MethodRequest (this=0x80977a0) at cLogProxy.cpp:26
#14 0x0804fac0 in DebugMethodRequest::DebugMethodRequest (this=0x80977a0,
Run Code Online (Sandbox Code Playgroud)
谢谢,
-Andres
你在呼唤std::string::append,最终导致delete被召唤.如果我们完成所涉及的步骤std::string::append,那么为什么delete被调用可能更有意义.
说你有:
std::string s("abc");
s.append("def");
Run Code Online (Sandbox Code Playgroud)
创建时s,必须分配内存以保存"abc".最后s.append("def");,必须有足够的内存s来保持"abcdef".到达那里的步骤:
s=> 的长度3."def"=> 3.6."abc"到新分配的内存."def"到新分配的内存.s.s.(这是delete进入图片的地方).