valgrind

Magic numbers when debugging with gcc/g++/gdb/valgrind?

我是研究僧i 提交于 2019-12-06 07:29:45
Microsoft's Visual C++ fills memory with 'magic numbers' if it hasn't been initialized by the programmer itself. This helps with debugging of uninitialized memory. ( In Visual Studio C++, what are the memory allocation representations? , 0xDEADBEEF vs. NULL ) Is there a similar function when using linux GNU tools (g++/gdb)? Thanks! John Zwinck You can override the C++ operator new to set allocations to your preferred byte pattern: void* operator new(size_t size) { void* mem = malloc(size); if (!mem) { throw std::bad_alloc(); } memset(mem, 0xEE, size); return mem; } You can see the full GCC

Valgrind memory leak with std::string in std::map

早过忘川 提交于 2019-12-06 03:55:54
问题 Here is the output from Valgrind: ==6519== at 0x4C25885: operator new(unsigned long) (vg_replace_malloc.c:319) ==6519== by 0x4EE65D8: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (new_allocator.h:104) ==6519== by 0x4EE7CE0: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (basic_string.tcc:138) ==6519== by 0x4EE80F7: std::basic_string<char, std::char_traits<char>, std:

valgrind giving error but unable to find location

霸气de小男生 提交于 2019-12-06 03:55:15
I have started using valgrind just one day ago as suggested by someone on SO itself .Its an amazing tool but today i got an issue with it.It gives the following error : definitely lost bytes but unable to tell the location of error. Here is the output of valgrind : udit@udit-Dabba ~ $ valgrind --leak-check=full sendip -v -p ipv6 -f file.txt -6s ::1 -p ah -as 0x20 -aq 0x40 -ak "yugal" -am xorauth.so -p udp -us 21 - ud 21 ::2 ==12885== Memcheck, a memory error detector ==12885== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==12885== Using Valgrind-3.6.1 and LibVEX; rerun with

Segmentation fault- strcat

倖福魔咒の 提交于 2019-12-06 03:48:11
This is my code: #include<stdio.h> #include<stdlib.h> #include<string.h> void main(int arge, char *argv[]) { FILE *f1; char ch,*fn="~/lyrics/"; strcat(fn,argv[1]); strcat(fn,".txt"); if( (f1 = fopen(fn,"r"))==NULL ) { printf("\nWrong filename\n%s not found",argv[1]); return; } while((ch=getw(f1))!=EOF) { printf("%c",ch); } } I compiled it using gcc -g -o file file.c and the compiler gave no error messages. But when I run it I get the error message: Segmentation fault (core dumped) Bad permissions for mapped region at address 0x8048659 at 0x402C36B: strcat (in /usr/lib/valgrind/vgpreload

应用 Valgrind 发现 Linux 程序的内存问题

牧云@^-^@ 提交于 2019-12-06 03:48:04
Valgrind 概述 体系结构 Valgrind是一套Linux下,开放源代码(GPL V2)的仿真调试工具的集合。Valgrind由内核(core)以及基于内核的其他调试工具组成。内核类似于一个框架(framework),它模拟了一个CPU环境,并提供服务给其他工具;而其他工具则类似于插件 (plug-in),利用内核提供的服务完成各种特定的内存调试任务。Valgrind的体系结构如下图所示: 图 1 Valgrind 体系结构 Valgrind包括如下一些工具: Memcheck。 这是valgrind应用最广泛的工具,一个重量级的内存检查器,能够发现开发中绝大多数内存错误使用情况,比如:使用未初始化的内存,使用已经释放了的内存,内存访问越界等。这也是本文将重点介绍的部分。 Callgrind 。它主要用来检查程序中函数调用过程中出现的问题。 Cachegrind 。它主要用来检查程序中缓存使用出现的问题。 Helgrind 。它主要用来检查多线程程序中出现的竞争问题。 Massif 。它主要用来检查程序中堆栈使用中出现的问题。 Extension。 可以利用core提供的功能,自己编写特定的内存调试工具。 Linux 程序内存空间布局 要发现Linux下的内存问题,首先一定要知道在Linux下,内存是如何被分配的?下图展示了一个典型的Linux C程序内存空间布局: 图 2

Centos下Valgrind使用与安装

好久不见. 提交于 2019-12-06 03:47:51
第一步: 获取Valgrind 包 可以先使用浏览器访问http://valgrind.org/downloads/查看当前版本 wget http://valgrind.org/downloads/valgrind-3.10.1.tar.bz2 第二步: 将下载的文件解压 tar -jxvf valgrind-3.10.1.tar.bz2 第三步: 安装和配置 ./autogen.sh ./configure make; make install Linux下利用Valgrind工具进行内存泄露检测和性能分析 Valgrind通常用来成分析程序性能及程序中的内存泄露错误 一 Valgrind工具集简绍 Valgrind包含下列工具: 1、memcheck:检查程序中的内存问题,如泄漏、越界、非法指针等。 2、callgrind:检测程序代码的运行时间和调用过程,以及分析程序性能。 3、cachegrind:分析CPU的cache命中率、丢失率,用于进行代码优化。 4、helgrind:用于检查多线程程序的竞态条件。 5、massif:堆栈分析器,指示程序中使用了多少堆内存等信息。 6、lackey: 7、nulgrind: 这几个工具的使用是通过命令:valgrand --tool=name 程序名来分别调用的,当不指定tool参数时默认是 --tool=memcheck 二

How to get complete stack dump from profiler in every sample for use in flame graph?

走远了吗. 提交于 2019-12-06 03:18:58
I really like the idea of the Flame Graph for profiling since it will help in eliminating unneeded function calls. There is a catch however in that it requires the profiler to do a complete stack dump each time it collects a sample. This can be accomplished with DTrace or SystemTap quite easily, but I need to be able to do this on an ARM device running ubuntu (which eliminates DTrace). I would also like to do this without recompiling the kernel (which eliminates SystemTap). Is it possible to get Valgrind/Callgrind or OProfile (or some other profiling tool that can run on an ARM device in

Valgrind shows memory leak on empty program on Mac OSX 10.8

夙愿已清 提交于 2019-12-05 23:55:35
问题 Valgrind installed using brew. #include <stdio.h> #include <stdlib.h> int main() { return 0; } gcc -g -o hello hello.c valgrind --tool=memcheck --leak-check=yes ./hello 回答1: This is not a memory leak you need to worry about. ImageLoader is part of the OS X runtime and is responsible for loading binaries and dynamic libraries. It allocates some memory once, during initialization and forgets about it, but it's harmless because it's a small block of memory allocated only once. And it does a

Getting a valgrind for android. Problems with `valgrind`'s looking for `memcheck-arm-linux`

牧云@^-^@ 提交于 2019-12-05 22:23:24
Context is developing an android app that uses several static executable binaries through sh syscall. One of the binaries eventually segfaults when using a samsung galaxy s4 cellphone (but not when using emulator or a Sony Xperia tipo cellphone), so following http://embetek.blogspot.com.es/2011/10/valgrind-for-arm.html with several custom modifications (CFLAGS='-static -march=armv7-a') end up getting a $ ldd valgrind not a dynamic executable $ file valgrind valgrind: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, not stripped. Loaded on the target

fork with invalid command cause a memory leak in valgrind

旧街凉风 提交于 2019-12-05 19:14:28
I have the following code which execute a non valid command within a fork. The following code return a memory leak in valgrind. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdarg.h> #include <errno.h> #include <unistd.h> int external_cmd(char **argv) { int pid; if ((pid = fork()) == -1) return -1; if (pid == 0) { /* child */ execvp(argv[0], argv); exit(0); } else if (pid < 0) return -1; int status; while (wait(&status) != pid); return 0; } int main () { char *argv[8] = {0}; argv[0] = "tawtaw"; //<--------- invalid command argv[1] = "-a"; char *mem = strdup("anychar");