我只是花了一些时间来追逐一个归结为以下的错误.代码错误地覆盖了堆栈,我认为它写了函数调用的返回地址.返回后,程序将崩溃并且堆栈将被破坏.在valgrind中运行程序将返回错误,例如:
vex x86->IR: unhandled instruction bytes: 0xEA 0x3 0x0 0x0
==9222== valgrind: Unrecognised instruction at address 0x4e925a8.
Run Code Online (Sandbox Code Playgroud)
我认为这是因为返回跳转到一个随机位置,包含无效的x86操作码.(虽然我有点怀疑这个地址0x4e925a8恰好在一个可执行页面中.我想如果不是这样的话,valgrind会抛出一个不同的错误.)
我确定问题是堆栈覆盖类型,我已经修复了它.现在我正在努力思考如何更有效地捕捉这样的错误.显然,如果我在堆栈上重写数据,valgrind就不能警告我,但是当有人在堆栈上写入返回地址时,它可能会捕获.原则上,它可以检测何时发生'push EIP'(因此它可以标记返回地址在堆栈中的位置).
我想知道是否有人知道Valgrind或其他任何东西能否做到这一点?如果没有,您是否可以有效地评论有关此类调试错误的其他建议.
我有很多可能从valgrind输入.那是什么意思 ?因为我正在使用sqlite并且它经过了很好的测试.我不认为这些是正确的条目.我做错了什么?
16 bytes in 1 blocks are possibly lost in loss record 30 of 844
==23027== at 0x4A05E1C: malloc (vg_replace_malloc.c:195)
==23027== by 0x6525BE: sqlite3MemMalloc (in app_mem.out)
==23027== by 0x63C579: mallocWithAlarm (in app_mem.out)
==23027== by 0x63C904: sqlite3DbMallocRaw (in app_mem.out)
==23027== by 0x6886D6: codeOneLoopStart (in app_mem.out)
==23027== by 0x68A9C8: sqlite3WhereBegin (in app_mem.out)
==23027== by 0x68CC9E: sqlite3Select (in app_mem.out)
==23027== by 0x6A8644: yy_reduce (in app_mem.out)
==23027== by 0x6AAEAC: sqlite3Parser (in app_mem.out)
==23027== by 0x6AB357: sqlite3RunParser (in app_mem.out)
==23027== by 0x6ADF84: sqlite3Prepare (in …
Run Code Online (Sandbox Code Playgroud) 我有以下valgrind输出:
==28099==
==28099== HEAP SUMMARY:
==28099== in use at exit: 0 bytes in 0 blocks
==28099== total heap usage: 131 allocs, 131 frees, 3,472 bytes allocated
==28099==
==28099== All heap blocks were freed -- no leaks are possible
==28099==
==28099== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
--28099--
--28099-- used_suppression: 2 dl-hack3-cond-1
--28099-- used_suppression: 2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a
==28099==
==28099== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
Run Code Online (Sandbox Code Playgroud)
有4个被抑制的错误.虽然这里没有泄漏,但是在移植到另一个系统时创建了问题.
[编辑]
我也重新 valgrind -v
选择了这个 选项.但我没有发现任何错误. …
我编写了一个boost :: thread应用程序,我可能会遇到一些竞争条件.我想调试这个程序.因此我使用了以下valgrind工具:
不幸的是,他们的假阳性率很高.因此,下面真正简单的程序valgrind --tool=drd
抱怨94错误,其中不应该.因此,通过我复杂的程序,我得到大约15000个错误.所以很难找到实际的错误.
我可以使用以下boost库1.46.0和1.47.0重现此行为.并使用valgrind 3.7.0 SVN和valgrind 3.8.0 SVN.操作系统我尝试了Ubuntu 11.10和Mac OS X 10.7.编译器所在的gcc 4.2.1和gcc 4.6.1.
#include <iostream>
#include <boost/thread.hpp>
void run()
{
//do some stuff here
}
int main(int argc, char* argv[])
{
boost::thread thread(run);
thread.join();
std::cerr << "main: done" << std::endl;
return 0;
}
;
Run Code Online (Sandbox Code Playgroud)
你如何调试你的boost程序?还有其他工具可能更适合吗?
解
似乎版本3.6.1之后的valgrind被破坏了.如果我使用valgrind 3.6.1一切正常.
这里的错误报告来自valgrind --tool=drd
:
==60767== Thread 1:
==60767== Conflicting store by thread 1 at 0x100026ec0 size 8
==60767== at 0x2A316E: pthread_mutex_lock (in /usr/lib/system/libsystem_c.dylib)
==60767== by …
Run Code Online (Sandbox Code Playgroud) 我在一个运行无限循环的程序上使用valgrind.
由于memcheck在程序结束后显示内存泄漏,但由于我的程序有无限循环,它将永远不会结束.
那么有什么方法可以强制性地从valgrind转储数据.
谢谢
我有一个C编程(很多数字,很长,不能发布),我编译
gcc -g -O0 program.c -o program
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用gdb和valgrind memcheck进行调试.在对代码进行一些更改后我发现了
valgrind --tool=memcheck --log-file=output.log ./program
Run Code Online (Sandbox Code Playgroud)
给
==15866== Memcheck, a memory error detector
==15866== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==15866== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==15866== Command: ./program
==15866== Parent PID: 3362
==15866==
==15866== Warning: client switching stacks? SP change: 0xbe88bcd8 --> 0xbe4e1f70
==15866== to suppress, use: --max-stackframe=3841384 or greater
==15866== Invalid write of size 4
==15866== at 0x804B7BE: main (program.c:1396)
==15866== …
Run Code Online (Sandbox Code Playgroud) 我已经看过一些关于valgrind的帖子,但没有单一帖子帮助我理解valgrind输出的解释.我用valgrind运行了两个程序(两个都有内存泄漏)
测试1的样本输出
==20422== LEAK SUMMARY:
==20422== definitely lost: 448 bytes in 3 blocks
==20422== indirectly lost: 786,460 bytes in 1 blocks
==20422== possibly lost: 1,576,052 bytes in 46 blocks
==20422== still reachable: 1,077,107 bytes in 2,333 blocks
==20422== suppressed: 0 bytes in 0 blocks
==20422== Rerun with --leak-check=full to see details of leaked memory
==20422==
==20422== For counts of detected and suppressed errors, rerun with: -v
==20422== ERROR SUMMARY: 98307 errors from 5 contexts (suppressed: 2 from 2)
Killed
Run Code Online (Sandbox Code Playgroud)
测试2的输出 …
我工作的一个克隆malloc (3)
功能(malloc
,realloc
和free
现在).
我想添加对Valgrind的支持.我正在使用这些文档.然而,增加呼叫后VALGRIND_MEMPOOL_FREE
,VALGRIND_MEMPOOL_ALLOC
和VALGRIND_CREATE_MEMPOOL
宏,我从Valgrind的以下内容:
==22303== HEAP SUMMARY:
==22303== in use at exit: 0 bytes in 0 blocks
==22303== total heap usage: 7 allocs, 0 frees, 2,039 bytes allocated
==22303==
==22303== All heap blocks were freed -- no leaks are possible
Run Code Online (Sandbox Code Playgroud)
这是我的realloc
呼唤VALGRIND_MEMPOOL_FREE
和我的free
呼唤VALGRIND_MEMPOOL_FREE
.
可能是什么原因造成的?
我正在尝试编写一个嵌入了Lua的C程序..而且,我尝试了一个非常简单的程序来启动,它只是创建了Lua上下文,然后将其销毁:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
int main(int argc, char *argv[]) {
lua_State *L = lua_open();
luaL_openlibs(L);
lua_close(L);
fprintf(stderr, "%s: %d\n", __FILE__, __LINE__);
return(0);
}
Run Code Online (Sandbox Code Playgroud)
我正在编译它:(我实际上使用的是Torch7,所以..)
g++ -c -g3 -O2 -Wall -Werror -I/usr/local/torch/install/include/ -fPIC pure_lua_test.C -o pure_lua_test.o
g++ -g3 -O2 -Wall -Werror -I/usr/local/torch/install/include/ -fPIC -o pure_lua_test pure_lua_test.o -L/usr/local/torch/install/lib/ -lluajit
Run Code Online (Sandbox Code Playgroud)
当我自己运行时,会打印出来
pure_lua_test.C: 16
Run Code Online (Sandbox Code Playgroud)
正如所料,(就在回归之前).
但是,当我用valgrind运行时,(如valgrind ./pure_lua_test)
我明白了
==9165== Memcheck, a memory error detector
==9165== Copyright (C) 2002-2013, and …
Run Code Online (Sandbox Code Playgroud) 我正在运行 MacOS Big Sur 并尝试安装valgrind
以进行作业。
brew install valgrind
当前不起作用,从 tar.bz2 发行版安装也不起作用。
运行./configure
(根据自述文件说明)在最后返回:
checking for a supported OS... ok (darwin20.1.0)
checking for the kernel version... unsupported (20.1.0)
configure: error: Valgrind works on Darwin 10.x, 11.x, 12.x, 13.x, 14.x, 15.x, 16.x and 17.x (Mac OS X 10.6/7/8/9/10/11 and macOS 10.12/13)
Run Code Online (Sandbox Code Playgroud)
从这一点来看,似乎valgrind
在最近的几个 MacOS 版本中不起作用。
是否有当前 MacOS 版本的替代方案,或者这是我在硬盘驱动器上为 Linux 创建分区的好时机?或者我在安装时遗漏了什么?
valgrind ×10
c ×5
memory-leaks ×4
c++ ×2
debugging ×2
memcheck ×2
memory ×2
boost-thread ×1
gcc ×1
gdb ×1
kcachegrind ×1
lua ×1
macos ×1