Questions tagged [valgrind]

Valgrind is a dynamic analysis tool for Linux, FreeBSD, macOS, Android, and Solaris systems. It can be used for execution and data profiling as well as for finding memory leaks, race conditions, and threading errors.

Valgrind is an open source instrumentation framework for building dynamic analysis tools. It was originally developed on Linux and has since been ported to other UNIX-like systems. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.

Valgrind works by effectively running your code in a virtual machine where extra instrumentation is available to monitor the behavior of your code in detail.

When instrumenting your code you should compile with debug symbols, like -g2 or -g3; and you should lower optimizations, like -O0 or -O1. Higher optimizations sometimes produce false positives. Also see The Valgrind Quick Start Guide.

Available GUIs frontends:

  • valkyrie
  • KDevelop lets you use Valgrind as a plugin
  • Eclipse has a GUI plugin to integrate Valgrind into its C++ Development Tools
  • Qt Creator can use memcheck and callgrind.

There are several tools for visualizing the Valgrind output

4117 questions
19
votes
2 answers

Callgrind: Profile a specific part of my code

I'm trying to profile (with Callgrind) a specific part of my code by removing noise and computation that I don't care about. Here is an example of what I want to do: for (int i=0; i
joetde
  • 1,556
  • 1
  • 16
  • 26
19
votes
1 answer

Valgrind's massif tool will not profile my application

I am developing a statically-linked 64-bit C++ application on 64-bit CentOS 5.8 using the standard gcc 4.4 packages from the CentOS repositories. It appears to be using more memory than I expected, so I tried using massif to profile the memory…
Tyson
  • 193
  • 1
  • 5
18
votes
1 answer

Are valgrind "uninitialized value" warnings false positives in ATLAS multithreaded BLAS routines?

I am using ATLAS for LAPACK and multithreaded BLAS routines, and have noticed that when my matrices get large enough for ATLAS to use the multithreaded versions of BLAS, I get initialization errors from Valgrind. Here is a minimal example from my…
Emilie
  • 237
  • 1
  • 10
18
votes
3 answers

valgrind mac os sierra 10.12.1

Is there any possible ways to install valgrind on new Mac OS? brew tell brew install -HEAD valgrind valgrind: This formula either does not compile or function as expected on macOS versions newer than El Capitan due to an upstream…
Glement
  • 413
  • 1
  • 5
  • 18
18
votes
1 answer

Possible Memory Leak Valgrind in OSX El Capitan

I'm getting a warning for possibly lost: 2,064 bytes in 1 blocks when using Valgrind on OSX Yosemite. Is there a fix to this? I installed valgrind using brew. Below is an example of how to reproduce ~/cat hello.c int main() { return…
Idr
  • 6,000
  • 6
  • 34
  • 49
18
votes
3 answers

How to detect segmentation fault details using Valgrind?

I have a std::map< std::string, std::string> which initialized with some API call. When I'm trying to use this map I'm getting segmentation fault. How can I detect invalid code or what is invalid or any detail which can help me to fix problem? Code…
Davit Siradeghyan
  • 6,053
  • 6
  • 24
  • 29
18
votes
3 answers

Valgrind stack misses a function completely

i have two c files: a.c void main(){ ... getvtable()->function(); } the vtable is pointing to a function that is located in b.c: void function(){ malloc(42); } now if i trace the program in valgrind I get the following: ==29994== 4,155…
Stasik
  • 2,568
  • 1
  • 25
  • 44
18
votes
3 answers

Is anyone using valgrind and Qt?

I am trying to debug a large application build using Qt/C++ and valgrind is reporting a lot of memory leak from internal Qt stuff. Could anyone share a proper valgrind suppression file for Qt apps ? Thanks ! Eg. #include int main() { …
malat
  • 12,152
  • 13
  • 89
  • 158
17
votes
1 answer

Boost thread Leakage C++

Could someone let me know whether boost thread library leaks. It seems to me that it does: Google says that I should compile with both boost thread and pthread which I am doing and that in version 1.40 this problem has been fixed but I still get…
Testboo Boos
  • 173
  • 5
17
votes
4 answers

strdup(): Confused about warnings ('implicit declaration', 'makes pointer...without a cast', memory leak)

When I compile the short piece of code below (in which we define a string and then use strdup to make a copy), I get 3 warnings: 2 compiler warnings from GCC and 1 run-time warning/error from valgrind. I suspect the memory leak error (reported by…
iceman
  • 2,020
  • 2
  • 17
  • 24
17
votes
5 answers

Valgrind and CUDA: Are reported leaks real?

I have a very simple CUDA component in my application. Valgrind reports a lot of leaks and still-reachables, all related to the cudaMalloc calls. Are these leaks real? I call cudaFree for every cudaMalloc. Is this valgrind's inability to interpret…
jsj
  • 9,019
  • 17
  • 58
  • 103
17
votes
1 answer

How do you interpret cachegrind output for caching misses?

Out of curiosity I ran coded up several different versions of matrix Multiplication and ran cachegrind against it. In my results below, I was wondering which parts were L1,L2,L3 misses and references and what it all really means? Below is my code…
Kevin Melkowski
  • 463
  • 1
  • 5
  • 17
17
votes
3 answers

How would you generically detect cache line associativity from user mode code?

I'm putting together a small patch for the cachegrind/callgrind tool in valgrind which will auto-detect, using completely generic code, CPU instruction and cache configuration (right now only x86/x64 auto-configures, and other architectures don't…
Niall Douglas
  • 9,212
  • 2
  • 44
  • 54
17
votes
3 answers

getaddrinfo memory leak

I have this code for getting information about IPv4 address: struct addrinfo hints, *info = NULL; char addr4[INET_ADDRSTRLEN]; memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_INET; if…
Petr Přikryl
  • 1,641
  • 4
  • 22
  • 34
16
votes
2 answers

Debugging Symbols Lost When Linking?

I'm trying to compile a program with debugging symbols so that valgrind will give me line numbers. I have found that if I compile a simple test program in one go (with -g) then it contains the symbols. However, if I compile in two passes (i.e.…
Peter Cogan
  • 865
  • 1
  • 11
  • 19