C++ 带地址和问号的Valgrind输出?
我刚刚收到valgrind的输出,我不太明白:C++ 带地址和问号的Valgrind输出?,c++,memory-management,memory-leaks,valgrind,ode,C++,Memory Management,Memory Leaks,Valgrind,Ode,我刚刚收到valgrind的输出,我不太明白: ==20290== Invalid read of size 1 ==20290== at 0x8C1D678: ??? ==20290== by 0x5D74C47: ??? ==20290== Address 0xee818c7d is not stack'd, malloc'd or (recently) free'd ==20290== ==20290== ==20290== Process terminating wit
==20290== Invalid read of size 1
==20290== at 0x8C1D678: ???
==20290== by 0x5D74C47: ???
==20290== Address 0xee818c7d is not stack'd, malloc'd or (recently) free'd
==20290==
==20290==
==20290== Process terminating with default action of signal 11 (SIGSEGV)
==20290== Access not within mapped region at address 0xEE818C7D
==20290== at 0x8C1D678: ???
==20290== by 0x5D74C47: ???
==20290== If you believe this happened as a result of a stack
==20290== overflow in your program's main thread (unlikely but
==20290== possible), you can try to increase the size of the
==20290== main thread stack using the --main-stacksize= flag.
==20290== The main thread stack size used in this run was 8388608.
==20290==
特别是,我对这些问号感到困惑。通常情况下,您在此处看到的是valgrind检测到的错误的位置。我以前使用过valgrind,所有的输出都如中所述。我使用了这个valgrind命令:
valgrind --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=20 --track-origins=yes
程序本身会喊出一个分段错误。虽然valgrind这次没有告诉我内存泄漏的任何位置,但通过调试,我已经确定了分段故障发生的位置。不幸的是,它位于英特尔ODE解算器库(dodesol)的ODE解算器函数中,我无法访问它。我已经仔细检查了多次传递给该函数的所有参数,这些参数似乎都正常(至少与手册中的参数和我之前的示例一致)。几乎可以肯定的是,
?
意味着Valgrind无法在相关地址附近找到符号。我怀疑您在没有代码的地方执行代码。这可能是覆盖堆栈上的返回地址的结果,例如,可能是由于缓冲区溢出(但其他指针错误可能会触发它)的结果Valgrind非常擅长处理动态分配内存的问题,但它在处理局部变量时难度更大,因为它并不总是能够确定堆栈上数组的结束位置。获得此结果的一种情况是,如果在剥离的二进制文件/库上运行Valgrind,它在本地符号(例如静态函数)中发现错误
使用仍然包含所有本地符号信息的二进制/库的非压缩版本,将在Valgrind输出中给出源文件和行号。不幸的是,情况并非如此,我的程序是自一致的,尽管使用了一些外部库(gsl和intel ode解算器,问题似乎出在这些库中)。在我将intel ode解算器连接到它之前,它工作得很好。无论如何,谢谢你的回答!使用
-g3
或-g2
编译以确保符号存在。使用-O1
或-O0
编译以确保符号准确。另请参见《Valgrind快速入门指南》中的。