简体   繁体   English

在没有valgrind的情况下(或使用最少的valgrind类应用程序)在嵌入式系统上寻找内存泄漏

[英]Hunting for memory leaks on embedded system without valgrind (or using minimal valgrind-like application)

I'm working with embedded linux development, and we're currently having some trouble with some memory page allocation faults, which led me to believe we have a leak somewhere. 我正在从事嵌入式Linux开发,并且当前在一些内存页面分配错误方面遇到了一些麻烦,这使我相信我们在某处存在泄漏。

Currently, I am trying to cross compile valgrind to use on our system, but I'm losing my faith on this solution because of the sheer amount of memory valgrind will use up (we have serious memory restrictions). 当前,我正在尝试交叉编译valgrind以在我们的系统上使用,但是由于valgrind会耗尽大量内存(我们有严格的内存限制),因此我对这种解决方案失去了信心。

This has made me wonder: is there any way of hunting for a memory leak without valgrind or with a valgrind-like application with minimal memory usage? 这让我感到奇怪:如果没有valgrind或使用类似valgrind的应用程序且内存使用量最少,有没有办法寻找内存泄漏? Creating wrappers for malloc() and free() is out of question. 为malloc()和free()创建包装器是毫无疑问的。

Also, the test that caused the allocation failures was a simple stress test of copying a file n times and checking its md5sum, in case anyone is curious. 同样,导致分配失败的测试是一个简单的压力测试,即在有人好奇的情况下,将文件复制n次并检查其md5sum。

I'm using the Linaro toolchain for cross compiling, glibc 2.15, and the system is set up without a swap partition. 我正在使用Linaro工具链进行交叉编译,glibc 2.15,并且系统的设置没有交换分区。 The system has around 64MB of RAM, making valgrind, or any other memory intensive application a tad difficult to use. 该系统具有大约64MB的RAM,这使得valgrind或任何其他内存密集型应用程序很难使用。

Regards, Guilherme 问候,Guilherme

Since you are using glibc, you should have its built-in memory-tracing support available to you. 由于您正在使用glibc,因此您应该可以使用其内置的内存跟踪支持。 Your program would enable this by calling mtrace(3) at or near startup. 您的程序可以通过在启动时或启动时调用mtrace(3)来启用此功能。 mtrace() installs hook functions into the memory allocator to log allocations and deallocations, under runtime control via environment variable MALLOC_TRACE . mtrace()将挂钩函数安装到内存分配器中,以在运行时通过环境变量MALLOC_TRACE控制下记录分配和释放。

You probably also want to be aware of mtrace(1) , a Perl script for interpreting log files produced by the mtrace facility. 您可能还想知道mtrace(1) ,这是一个Perl脚本,用于解释由mtrace工具生成的日志文件。

This facility traces only allocations and deallocations, which is much less than Valgrind does. 此功能仅跟踪分配和释放,这比Valgrind少得多。 Nevertheless, those are the main items of interest when you are looking for a memory leak. 但是,当您正在寻找内存泄漏时,这些是您感兴趣的主要项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM