- Address Sanitizer: alternative to valgrind
This document provides guidance and an overview to high level general features and updates for SUSE Linux Enterprise Server 12. Besides architecture or product-specific information, it also describes the capabilities and limitations of SLES 12. Official Home Page for valgrind, a suite of tools for debugging and profiling. Automatically detect memory management and threading bugs, and perform detailed profiling. The current stable version is valgrind-3.17.0. The VALGRINDDISCARDTRANSLATIONS client request is an alternative to −−smc−check=all and −−smc−check=all−non−file that requires more programmer effort but allows Valgrind to run your program faster, by telling it precisely when translations need to be re−made.
Recently, at work, I encountered a strange bug with GCC 7.2 and clang 6 (I didn’t test it with Visual Studio 2017 for different reasons). The bug was not visible on “old” compilers like gcc 4, Visual Studio 2013 or even Intel Compiler 2017. In debug mode, everything was fine, but in release mode, the application crashed. But not always at the same location.
Tools to debug
As we run valgrind all the time, I knew that the error could not be found with valgrind. When debugging the error, there was nothing that was wrong. All the variables were defined properly, were local or passed by value (for shared pointers), so nothing popped up.
But I had a feeling I would be able to find it with Address Sanitizer. So I ran it with the option ASAN_OPTIONS=detect_stack_use_after_return=1. And then I found it. Use after stack, and where ASAN found the error, I could figure out that we kept a reference to a stack variable that was removed.
What Address Sanitizer found and how to understand the reports
The following piece of code is a simplification of what was written. It may well be that the code was correct the first time it was written because Foo was supposed to be used locally. But in this context, it is not correct.
As you can see, Foo keeps a reference to an int, and in this case, that integer was allocated on the stack and was destroyed when we access the reference. In debug mode, you would get 99. In optimized mode, you get anything. Literally.
To compile it, just do
OK, so what does ASAN returns?
The report can be confusing. The trick is to compile with -g to have proper stack information. Here, I get where the bad memory access occurs AND where I stored the wrong reference. Then, the color system allows to check what happens in the memory. Here, it’s only f5, so stack after return information (you could get bound check, deallocated memory…). So we can look for a stack variable that was used, hence the reference that is the culprit.
Conclusion
Address Sanitizer is great. Of course, by default, it checks memory leaks, bound checks… But it can do far more than just these. It is better than valgrind on several aspects, like speed (as it’s not emulation based) but also on what it can check. It saved me lots of time already despite having used it only for a few months, so consider adopting it. It’s a puppy that doesn’t require much time.
The complete source code, including documentation, is available as a tarball for the current release. For downloadable / browseable manual packages, go to the Documentation page. For older releases, see the Release Archive page.
If you would like to be notified when a new valgrind release ismade, you can subscribe to the Valgrind announcementsmailing list.
Valgrind 3.17.0
valgrind 3.17.0 (tar.bz2) [17MB] - 19 March 2021.
For {x86,amd64,arm32,arm64,ppc32,ppc64le,ppc64be,s390x,mips32,mips64}-linux, {arm32,arm64,x86,mips32}-android, {x86,amd64}-solaris and {x86,amd64}-darwin (Mac OS X 10.13).
md5: afe11b5572c3121a781433b7c0ab741b
PGP signature is here.
3.17.0 fixes a number of bugs and adds some functional changes: support for GCC 11, Clang 11, DWARF5 debuginfo, the 'debuginfod' debuginfo server, and some new instructions for Arm64, S390 and POWER. There are also some tool updates. See the release notes for details.
Valkyrie 2.0.0
Alternative To Valgrind Mac
valkyrie 2.0.0 (tar.bz2)[260Kb] - 21 October 2010.
md5: a411dfb803f548dae5f988de0160aeb5
Valkyrie is a Qt4-based GUI for the Valgrind 3.6.x and 3.7.x series, that works for the Memcheck andHelgrind tools. It also has an XML merging tool forMemcheck outputs (vk_logmerge). This tarball is known to build and work withvalgrind-3.6.0 and valgrind-3.7.0.
This version of Valkyrie does not support any version of Valgrindprior to 3.6.0. If you want to use Valkyrie with an older Valgrindversion, we recommend you instead upgrade your Valgrind to 3.6.0and use this version of Valkyrie.
RPMs / Binaries
Alternatives To Valgrind
We do not distribute binaries or RPMs. The releases availableon this website contain the source code and have to be compiledin order to be installed on your system. Many Linuxdistributions come with valgrind these days, so if you do notwant to compile your own, go to your distribution's downloadsite.
System Requirements
Alternatives To Valgrind On Windows
Programs running under Valgrind run significantly more slowly, anduse much more memory -- e.g. more than twice as much as normal underthe Memcheck tool. Therefore, it's best to use Valgrind on the mostcapable machine you can get your hands on.