valgrind

Does valgrind memcheck support checking mmap

[亡魂溺海] 提交于 2019-12-06 23:57:58
问题 I am trying valgrind for detecting memory leak. It works well on heap leak(i.e. memory allocation from malloc or new). however, does it support check mmap leaking in linux? Thanks Chang 回答1: Not directly, it's very hard to debug, take a look to valgrind.h VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a heap block -- that will be used by the client program -- is allocated. It's best to put it at the outermost level of the allocator if possible; for example, if you

Cross-compiling Valgrind for ARM

▼魔方 西西 提交于 2019-12-06 23:52:16
问题 I need to cross-compile VALGRIND to run on Freescale i.MX278 (ARM 9) running Linux. I have the tool chain provided by Freescale itself. I have already set the PATH variable to tool chain path. I'm using following command further: $ export CROSS_COMPILE=arm-fsl-linux-gnueabi- $ export CC=${CROSS_COMPILE}gcc $ export CPP=${CROSS_COMPILE}cpp $ export CXX=${CROSS_COMPILE}g++ $ export LD=${CROSS_COMPILE}ld $ export AR=${CROSS_COMPILE}ar $ ./configure --target=arm-fsl-linux-gnueabi \ --host=armv7

高并发性能调试经验分享

ε祈祈猫儿з 提交于 2019-12-06 22:06:10
引文 4月份的时候看到一道面试题,据说是腾讯校招面试官提的:在多线程和高并发环境下,如果有一个平均运行一百万次才出现一次的bug,你如何调试这个bug?知乎原贴地址如下: 腾讯实习生面试,这两道题目该怎么回答? - 编程 . 遗憾的是知乎很多答案在抨击这道题本身的正确性,虽然我不是这次的面试官,但我认为这是一道非常好的面试题。当然,只是道加分题,答不上,不扣分。答得不错,说明解决问题的思路和能力要超过应届生平均水平。 之所以写上面这段,是因为我觉得大部分后台服务端开发都有可能遇到这样的BUG,即使没有遇到,这样的题目也能够激发大家不断思考和总结。非常凑巧的是,我在4月份也遇到了一个类似的而且要更加严重的BUG,这是我自己挖的一个很深的坑,不填好,整个项目就无法上线。 现在已经过去了一个多月,趁着有时间,自己好好总结一下,希望里面提到的一些经验和工具能够带给大家一点帮助。 项目背景 我们针对nginx事件框架和openssl协议栈进行了一些深度改造,以提升nginx的HTTPS完全握手计算性能。 由于原生nginx使用本地CPU做RSA计算,ECDHE_RSA算法的单核处理能力只有400 qps左右。前期测试时的并发性能很低,就算开了24核,性能也无法超过1万。 核心功能在去年底就完成了开发,线下测试也没有发现问题。经过优化后的性能提升几倍,为了测试最大性能

new libstdc++ of gcc5.1 may allocate large heap memory

眉间皱痕 提交于 2019-12-06 21:52:26
问题 valgrind detects "still reachable leak" in an empty program compiled with gcc5.1, g++ ./a.cpp , int main () {} valgrind says, valgrind ./a.out , ==32037== HEAP SUMMARY: ==32037== in use at exit: 72,704 bytes in 1 blocks ==32037== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated ==32037== ==32037== LEAK SUMMARY: ==32037== definitely lost: 0 bytes in 0 blocks ==32037== indirectly lost: 0 bytes in 0 blocks ==32037== possibly lost: 0 bytes in 0 blocks ==32037== still reachable: 72,704

linux C/C++内存检测

痴心易碎 提交于 2019-12-06 20:11:39
MTRACE glibc提供了一个检查内存泄漏的方法, 前提是你的程序使用glibc的标准函数 分配内存(如malloc, alloc...): 1. 在需要内存泄漏检查的代码的开始调用void mtrace(void) (在mcheck.h中有声明). mtrace为malloc等函数安装hook, 用于记录内存分配信息. 在需要内存泄漏检查的代码的结束调用void muntrace(void). 注意: 一般情况下不要调用muntrace, 而让程序自然结束. 因为可能有些释放内存代码要到muntrace之后才运行. 2. 用debug模式编译被检查代码(-g或-ggdb) 3. 设置环境变量MALLOC_TRACE为一文件名, 这一文件将存有内存分配信息. 4. 运行被检查程序, 直至结束或muntrace被调用. 5. 用mtrace命令解析内存分配Log文件($MALLOC_TRACE) , (mtrace foo $MALLOC_TRACE, where foo is the executible name) ,如果有内存泄漏, mtrace会输出分配泄漏内存的代码位置,以及分配数量. valgrind 下载完成后执行安装 #sh sutogen.sh #./configure #make #make install 执行 valgrind ls -l 来验证是否成功

CentOS下安装Valgrind的方法

99封情书 提交于 2019-12-06 20:11:15
一、Valgrind安装 valgrind是一款用于内存调试、内存泄漏检测以及性能分析的软件开发工具。 在安装valgrind之前,要先安装autoconf和automake。您可以使用命令autoconf --version和automake --version检查这两个工具是否有安装。 (1)下载最新的安装包 http://valgrind.org/downloads/current.html 或者是输入命令: wget http://valgrind.org/downloads/valgrind-3.10.1.tar.bz2 (2)解压缩安装包,输入命令: tar -jxvf valgrind-3.10.1.tar.bz2 (3)进入解压缩后生成的目录valgrind-3.10.1,输入命令: cd valgrind-3.10.1 (4)运行./autogen.sh设置环境,输入命令: ./autogen.sh 如果你碰到如下错误:aclocal: command not found 则表示你需要安装autoconf和automake两个工具,请先查看“安装autoconf“和”安装automake“两个步骤。 (5)运行configure文件,生成Makefile。 (6)编译并安装valgrind,输入命令: make;make install (7)检查安装是否成功:

ubuntu 上使用valgrind

懵懂的女人 提交于 2019-12-06 20:10:49
  Valgrind是一个GPL的软件,用于Linux(For x86, amd64 and ppc32)程序的内存调试和代码剖析。你可以在它的环境中运行你的程序来监视内存的使用情况,比如C 语言中的malloc和free或者 C++中的new和 delete。使用Valgrind的工具包,你可以自动的检测许多内存管理和线程的bug,避免花费太多的时间在bug寻找上,使得你的程序更加稳固。   Valgrind的主要功能   Valgrind工具包包含多个工具,如Memcheck,Cachegrind,Helgrind, Callgrind,Massif。下面分别介绍个工具的作用: Memcheck 工具主要检查下面的程序错误:   1.使用未初始化的内存 (Use of uninitialised memory)   2.使用已经释放了的内存 (Reading/writing memory after it has been free’d)   3.使用超过 malloc分配的内存空间(Reading/writing off the end of malloc’d blocks)   4.对堆栈的非法访问 (Reading/writing inappropriate areas on the stack)   5.申请的空间是否有释放 (Memory leaks – where

Memory leak reported by valgrind in dlopen?

爷,独闯天下 提交于 2019-12-06 18:19:57
问题 I've been debugging some app lately with valgrind, and I'm getting very weird reports from dlopen . ==1987== 32 bytes in 1 blocks are still reachable in loss record 1 of 2 ==1987== at 0x4C24477: calloc (vg_replace_malloc.c:418) ==1987== by 0x570F31F: _dlerror_run (dlerror.c:142) ==1987== by 0x570EEE0: dlopen@@GLIBC_2.2.5 (dlopen.c:88) <my call to dlopen> ==1987== ==1987== 264 bytes in 1 blocks are still reachable in loss record 2 of 2 ==1987== at 0x4C25153: malloc (vg_replace_malloc.c:195) =

Why valgrind report my memory as “definitely lost”?

旧城冷巷雨未停 提交于 2019-12-06 09:42:46
Consider this code: #include <stdlib.h> int* alloc() { return malloc(250 * sizeof(int)); } int main() { int i; int *vars[3]; for(i = 0; i < 3; ++i) { vars[i] = alloc(); } } Valgrind output: $ valgrind --leak-check=full ./lala ==16775== Memcheck, a memory error detector ==16775== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==16775== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==16775== Command: ./lala ==16775== ==16775== ==16775== HEAP SUMMARY: ==16775== in use at exit: 3,000 bytes in 3 blocks ==16775== total heap usage: 3 allocs, 0 frees, 3,000 bytes

Problems with memory dynamic allocation: main: malloc.c:3096: sYSMALLOc

大城市里の小女人 提交于 2019-12-06 07:55:36
I'm writing a simple function to create a list which represents a deck of cards. Here's the definition of the structs typedef struct { float valoreEff; char *seme; char *valore; } carta; struct Mazzo { carta info; struct Mazzo *nextPtr; }; typedef struct Mazzo mazzo; typedef mazzo *mazzoPtr; Here's the function which returns a pointer to the first element of the list mazzoPtr caricaMazzo(void){ mazzoPtr sMazzoPtr=NULL; int val,seme; carta buffer; mazzoPtr newPtr; char *tabValori[10]={"Asso","Due","Tre","Quattro","Cinque","Sei","Sette","Donna","Cavallo","Re"}; char *tabSeme[4]={"Denari","Spade"