Valgrind On Windows

Using Valgrind Code Analysis Tools. Valgrind tools are supported locally only on Linux and macOS. However, according to Valgrind.org, support on macOS 10.8 and 10.9 is experimental and mostly broken. You can run the tools on a remote Linux machine or device from any development host. Valgrind is an instrumentation framework for building dynamic analysis tools that can be used to profile applications in detail. Valgrind tools are generally used to automatically detect many memory management and threading problems. The Valgrind suite also includes tools that allow you to build new profiling tools to suit your needs. Valgrind is installed on the department machines. To invoke it on an executable called a.out, you simply run the command valgrind./a.out (with any arguments your program might need). As when using gdb, you will want to make sure to compile your program with the flag -g, so that you can see line numbers in the output. How to build and run Valgrind for Windows from a command prompt Check out the source code. Open a Windows command prompt (cmd.exe). Cd to the source code directory. Run: sh./autogen.sh. Configure either for the 32 bit or 64 bit version. Build the source by running: make.

  1. Valgrind Equivalent On Windows
  2. Valgrind Windows Download
  3. Install Valgrind On Windows 10
Active6 years, 8 months ago
votes

I was looking into Valgrind to help improve my C coding/debugging when I discovered it is only for Linux - I have no other need or interest in moving my OS to Linux so I was wondering if there is a equally good program for Windows.

KindDragon
4,6832 gold badges34 silver badges67 bronze badges
DrakeDrake
7663 gold badges12 silver badges24 bronze badges

locked by WillJan 24 '13 at 14:41

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. See the help center for guidance on writing a good question.

Read more about locked posts here.

38 Answers

12 next
votes
oriporip
48.8k20 gold badges102 silver badges143 bronze badges
votes

As jakobengblom2 pointed out, valgrind has a suit of tools. Depending which one you are talking about there are different windows counter parts. I will only mention OSS or free tools here.

1. MemCheck:

Dr. Memory. It is a relatively new tool, works very well on Windows 7. My favorite feature is that it groups the same leaks' allocation stacks in the report.

I have also used UMDH( http://support.microsoft.com/kb/268343 ) and found it quiet useful and easy to setup. It works from Win2000 to Win7.

AppVerifier is a must have swissknife for windows native code developers, its 'memory' checker does similar job http://msdn.microsoft.com/en-us/library/dd371695%28v=vs.85%29.aspx

2. Callgrind:

My favorite is verysleepy ( http://www.codersnotes.com/sleepy ) It is tiny but very useful and easy to use.

If you need more features, AMD CodeAnalyst™ Performance Analyzer is free:http://developer.amd.com/documentation/videos/pages/introductiontoamdcodeanalystperformanceanalyzer.aspx

Windows Performance Analysis tools is free from Microsoft, not very easy to use but can get the job done if you are willing to spend the time. http://blogs.microsoft.co.il/blogs/sasha/archive/2008/03/15/xperf-windows-performance-toolkit.aspxDownload:http://msdn.microsoft.com/en-us/performance/cc752957

3. Massif:

Similar(not quite exact match) free tools on windows are:

VMMap from sysinternals : http://technet.microsoft.com/en-us/sysinternals/dd535533

!heap command in windbg : http://hacksoflife.blogspot.com/2009/06/heap-debugging-memoryresource-leak-with.html

4. Cachegrind:

Above mentioned Windows Performance Tools has certain level of L2 cache miss profiling capability but not quite as good and easy to use as Cachegrind.

5. DRD:

Haven't found anything free and as powerful on Windows yet, the only free tool for windows I can find that is slightly close is the 'lock' checker in AppVerifier:http://msdn.microsoft.com/en-us/library/dd371695%28v=vs.85%29.aspx

Lailin ChenLailin Chen
2,2212 gold badges13 silver badges10 bronze badges
votes

Why not use Valgrind + Wine to debug your Windows app? See http://wiki.winehq.org/Wine_and_Valgrind

(Chromium uses this to check the Windows version for memory errors; see build.chromium.organd look at the experimental or memory waterfalls, and search for wine.)

There's also Dr. Memory, see dynamorio.org/drmemory.html

Dan KegelDan Kegel
votes

For Visual C++, try Visual Leak Detector. When I used it, it detected a memory leak from a new call and returned the actual line in source code of the leak. The latest release can be found at http://vld.codeplex.com/.

Andreas Haferburg
3,5291 gold badge21 silver badges48 bronze badges
tgs_stdiotgs_stdio
votes

Development environment for Windows you are using may contain its own tools. Visual Studio, for example, lets you detect and isolate memory leaks in your programs

dmityugovdmityugov
votes

i would like to list some tool , hope will be useful

read this article for more detail

  1. Purify
  2. Bounds Checker
  3. Coverity (basically its a code analyzer but, it will catch memory leak in static )
  4. Glow Code
  5. dmalloc
  6. ccmalloc
  7. NJAMD
  8. YAMD
  9. Valgrind
  10. mpatrol
  11. Insure++
SatbirSatbir
4,3546 gold badges32 silver badges51 bronze badges
votes
Diaa SamiDiaa Sami
votes

There is Pageheap.exe part of the debugging tools for Windows. It's free and is basically a custom memory allocator/deallocator.

See http://support.microsoft.com/kb/286470

user88930
votes

In combination with Visual Studio I generally use Visual Leak Detector or simply _CrtDumpMemoryLeaks() which is a win32 api call. Both are nothing fancy but they get the job done.

Jasper BekkersJasper Bekkers
votes

Amd 7750 driver windows 10 hp. I had the chance to use Compuware DevPartner Studio in the past and that was really good, but it's quite expensive.A cheaper solution could be GlowCode, i just worked with a 5.x version and, despite some problems in attaching to a process i needed to debug, it worked quite well.

ManuelManuel
3,1691 gold badge20 silver badges22 bronze badges
votes

I've been loving Memory Validator, from a company called Software Verification.

stevexstevex
votes

Viusual Studio can help detecting memory leaks itself. See Microsoft Visual C++ Tips and Tricks -> 'Memory Leaks' section.See also this post in SO

Valgrind Equivalent On Windows

Although real tracing is only possible with the Team Edtion of Visual Studio.

Community
fmueckefmuecke
8,3801 gold badge16 silver badges24 bronze badges
votes

See the 'Source Test Tools' link on the Software QA Testing and Test Tool Resources page for a list of similar tools.

I've used BoundsChecker,DevPartner Studio and Intel V-Tune in the past for profiling. I liked V-Tune the best; you could emulate various Intel chipsets and it would give you hints on how to optimize for that platform.

Patrick CuffPatrick Cuff
24.2k9 gold badges59 silver badges92 bronze badges
votes

Does Jochen Kalmbach's Memory Leak Detector qualify?

PS: The URL to the latest version is buried somewhere in the article's comment thread.

Agnel KurianAgnel Kurian
29k35 gold badges128 silver badges200 bronze badges
votes

LeakDiag, UMDH, App Verifier, DebugDiag, are all useful tools to improve robustness of code and find memory leaks.

Alex BudovskiAlex Budovski
14.2k6 gold badges45 silver badges55 bronze badges
votes
zr.zr.
3,7407 gold badges41 silver badges75 bronze badges
votes
grigygrigy
3,84610 gold badges41 silver badges70 bronze badges
votes

Try Intel's Inspector XE product which can help you detect both memory and threading issues: http://software.intel.com/en-us/articles/intel-inspector-xe/

Alexey AlexandrovAlexey Alexandrov
1,7561 gold badge13 silver badges21 bronze badges
votes

Perhaps CodeSnitch would be something you're after? http://www.entrek.com/codesnitch.html

GEOCHET
19k15 gold badges68 silver badges94 bronze badges
Alex FortAlex Fort
15.5k5 gold badges38 silver badges51 bronze badges
votes

If you are developing with Borland/CodeGear/Embarcadero C++ Builder, you could use CodeGuard.

VinceVince
9961 gold badge11 silver badges19 bronze badges
votes

More or less all Profilers include checking for memory leaks and show you the stack when the memory was allocated.

I can recommend Intels Parallel Inspector. Simple to use and no recompilation needed. The trial version runs for 30 days.

GlowCode and AtromatedQA also include such capabilites. They all offer free trials.

Compuware DevPartner (aka BoundsChecker) in Contrast needs a slowed down 'instrumentation' recompile and the application also runs slower when checking for errors. And BoundsChecker can not work with 64 Bit evsrions at all. We gave up on that tool.

RED SOFT ADAIRRED SOFT ADAIR
8,1708 gold badges43 silver badges80 bronze badges
votes

The best tool I ever used is DevPartner BoundsChecker - it's not free but it has an evaluation period.

Dror HelperDror Helper
24.5k13 gold badges72 silver badges123 bronze badges
votes

Another memory tool for your list: Memory Validator.

Not free, but nowhere near as expensive as Purify or Boundschecker.

Stephen KellettStephen Kellett
2,2851 gold badge15 silver badges23 bronze badges
votes

If you're not afraid of mingw, here are some links (some might work with MSVC)..http://betterlogic.com/roger/?p=1140

Valgrind Windows Download

rogerdpackrogerdpack
38.3k21 gold badges148 silver badges272 bronze badges

Install Valgrind On Windows 10

votes

We are just completing a Memory Safety checking tool for Windows, that handles GCC and Micrsoft Visual C (not C++ yet), and are looking for Beta testers.

EDIT June 12, 2011: Not Beta anymore, now production for GCC and Microsoft Visual Studio C.

Ira BaxterIra Baxter
82.7k11 gold badges137 silver badges281 bronze badges
votes

I found this SF project today:

They are porting valgrind to Windows. Probably in several years we will have a reliable valgrind on windows.

CalmariusCalmarius
9,24713 gold badges84 silver badges124 bronze badges
vote

Check out this question: Is there a good Valgrind substitute for Windows? . Though general substitute for valgrind is asked, it mainly discusses memory leak detectors and not race conditions detections.

Community
maykeyemaykeye
1,0101 gold badge11 silver badges16 bronze badges
vote

I used Insure++ which does excellent job in finding c++ memory leaks/corruptions and many other bugs like uninitialized variables, pointer errors, strings etc., It also does visual 'Code coverage' and run time memory usage etc. which give more confident on your code. You can try it for trail version.

RedRed
vote

You might want to read what Mozilla is doing regarding memory leaks. One tool in their toolbox is the Hans Boehm garbage collector used as memory leak detector.

Cristian AdamCristian Adam
vote

You can give a try to RuntimeChecker trial ot to IBM Purify trial.

A free solution would be to use the following code in Visual Studio:

Just write this in the top of all your cpp files.This will detect memory leaks of your application whenc stopping debug run and list them in the output window. Double clicking on a memory leaks line will higlight you the line where memory is allocated and never released. This may help you : http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml

Patrice BernassolaPatrice Bernassola
11.2k3 gold badges38 silver badges52 bronze badges

Not the answer you're looking for? Browse other questions tagged cwindowsdebuggingmemory-leaksvalgrind or ask your own question.

Valgrind
Original author(s)Julian Seward
Developer(s)Valgrind Development Team[1]
Stable release3.15.0 (April 12, 2019; 5 months ago)[±][2]
Repository
Operating systemLinux
macOS
Solaris
Android[3]
TypeProfiler, Memory debugger
LicenseGNU General Public License
Websitewww.valgrind.org

Valgrind/ˈvælɡrɪnd/ is a programming tool for memory debugging, memory leak detection, and profiling.

Valgrind was originally designed to be a freememory debugging tool for Linux on x86, but has since evolved to become a generic framework for creating dynamic analysis tools such as checkers and profilers.

The name Valgrind is a reference to the main entrance of Valhalla from Norse Mythology. During development (before release) the project was named Heimdall; however, the name would have conflicted with a security package.

  • 2Tools

Overview[edit]

Valgrind is in essence a virtual machine using just-in-time (JIT) compilation techniques, including dynamic recompilation. Nothing from the original program ever gets run directly on the host processor. Instead, Valgrind first translates the program into a temporary, simpler form called Intermediate Representation (IR), which is a processor-neutral, SSA-based form. After the conversion, a tool (see below) is free to do whatever transformations it would like on the IR, before Valgrind translates the IR back into machine code and lets the host processor run it. Valgrind recompiles binary code to run on host and target (or simulated) CPUs of the same architecture. It also includes a GDB stub to allow debugging of the target program as it runs in Valgrind, with 'monitor commands' that allow you to query the Valgrind tool for various sorts of information.

A considerable amount of performance is lost in these transformations (and usually, the code the tool inserts); usually, code run with Valgrind and the 'none' tool (which does nothing to the IR) runs at 1/4 to 1/5 of the speed of the normal program.[4][5]

Tools[edit]

Memcheck[edit]

There are multiple tools included with Valgrind (and several external ones). The default (and most used) tool is Memcheck. Memcheck inserts extra instrumentation code around almost all instructions, which keeps track of the validity (all unallocated memory starts as invalid or 'undefined', until it is initialized into a deterministic state, possibly from other memory) and addressability (whether the memory address in question points to an allocated, non-freed memory block), stored in the so-called V bits and A bits respectively. As data is moved around or manipulated, the instrumentation code keeps track of the A and V bits, so they are always correct on a single-bit level.

In addition, Memcheck replaces the standard C memory allocator with its own implementation, which also includes memory guards around all allocated blocks (with the A bits set to 'invalid'). This feature enables Memcheck to detect off-by-one errors where a program reads or writes outside an allocated block by a small amount. The problems Memcheck can detect and warn about include the following:

  • Use of uninitialized memory
  • Reading/writing memory after it has been free'd
  • Reading/writing off the end of malloc'd blocks

The price of this is lost performance. Programs running under Memcheck usually run 20–30 times slower[6] than running outside Valgrind and use more memory (there is a memory penalty per allocation). Thus, few developers run their code under Memcheck (or any other Valgrind tool) all the time. They most commonly use such tools either to trace down some specific bug, or to verify that there are no latent bugs (of the kind Memcheck can detect) in the code.

Other tools[edit]

In addition to Memcheck, Valgrind has several other tools:[7]

  • None, runs the code in the virtual machine without performing any analysis and thus has the smallest possible CPU and memory overhead of all tools. Since valgrind itself provides a trace back from a segmentation fault, the none tool provides this traceback at minimal overhead.
  • Addrcheck, similar to Memcheck but with much smaller CPU and memory overhead, thus catching fewer types of bugs. Addrcheck has been removed as of version 3.2.0.[8]
  • Massif, a heapprofiler. The separate GUI massif-visualizer visualizes output from Massif.
  • Helgrind and DRD, detect race conditions in multithreaded code
  • Cachegrind, a cache profiler. The separate GUI KCacheGrind visualizes output from Cachegrind.
  • Callgrind, a callgraph analyzer created by Josef Weidendorfer was added to Valgrind as of version 3.2.0. KCacheGrind can visualize output from Callgrind.
  • exp-sgcheck (named exp-ptrcheck prior to version 3.7), an experimental tool to find stack and global array overrun errors which Memcheck cannot find.[9] Some code results in false positives from this tool.[10]
  • exp-dhat, dynamic heap analysis tool which analyzes how much memory is allocated and for how long as well as patterns of memory usage.
  • exp-bbv, a performance simulator that extrapolates performance from a small sample set.

There are also several externally developed tools available. One such tool is ThreadSanitizer, another detector of race conditions.[11][12]

Platforms supported[edit]

As of version 3.4.0, Valgrind supports Linux on x86, x86-64 and PowerPC. Support for OS X was added in version 3.5.0.[13] Support for Linux on ARMv7 (used for example in certain smartphones) was added in version 3.6.0.[14] Support for Solaris was added in version 3.11.0.[3] There are unofficial ports to other UNIX-like platforms (like FreeBSD,[15]OpenBSD,[16] and NetBSD[17]). From version 3.7.0 the ARM/Android platform support was added.[3]

Since version 3.9.0 there is support for Linux on MIPS64 little and big endian, for MIPS DSP ASE on MIPS32, for s390x Decimal Floating Point instructions, for POWER8 (Power ISA 2.07) instructions, for Intel AVX2 instructions, for Intel Transactional Synchronization Extensions, both RTM and HLE and initial support for Hardware Transactional Memory on POWER.[2]

History and development[edit]

It is named after the main entrance to Valhalla in Norse mythology.[18]

The original author of Valgrind is Julian Seward, who in 2006 won a Google-O'Reilly Open Source Award for his work on Valgrind.[19][20]

Several others have also made significant contributions, including Cerion Armour-Brown, Jeremy Fitzhardinge, Tom Hughes, Nicholas Nethercote, Paul Mackerras, Dirk Mueller, Bart Van Assche, Josef Weidendorfer, and Robert Walsh.[21]

It is used by a number of Linux-based projects.[22]

Limitations of Memcheck[edit]

In addition to the performance penalty, an important limitation of Memcheck is its inability to detect all cases of bounds errors in the use of static or stack-allocated data.[23] The following code will pass the Memcheck tool in Valgrind without incident, despite containing the errors described in the comments:

The experimental valgrind tool exp-sgcheck has been written to address this limitation in Memcheck. It will detect array overrun errors, provided the first access to an array is within the array bounds. Note that exp-sgcheck will not detect the array overrun in the code above, since the first access to an array is out of bounds, but it will detect the array overrun error in the following code.

The inability to detect all errors involving the access of stack allocated data is especially noteworthy sincecertain types of stack errors make software vulnerable to the classicstack smashing exploit.

See also[edit]

  • AddressSanitizer et al.

Notes[edit]

  1. ^http://valgrind.org/info/developers.html
  2. ^ abValgrind News
  3. ^ abcValgrind release notes
  4. ^Valgrind homepage
  5. ^Valgrind Manual
  6. ^http://valgrind.org/docs/manual/quick-start.html#quick-start.mcrun
  7. ^Valgrind main tool list
  8. ^[1]
  9. ^section on exp-sgcheck in the Valgrind user manual
  10. ^[2]
  11. ^http://valgrind.org/downloads/variants.html
  12. ^K Serebryany, T Iskhodzhanov, ThreadSanitizer–data race detection in practice, Proceedings of the Workshop on Binary Instrumentation and Applications WBIA'09
  13. ^OS X port
  14. ^ARM/Linux port
  15. ^Valgrind FreeBSD port
  16. ^Valgrind OpenBSD port
  17. ^'Valgrind NetBSD port'. Archived from the original on 2006-02-09. Retrieved 2006-01-28.
  18. ^Valgrind FAQ
  19. ^valgrind.org's list of awards
  20. ^Google-O'Reilly Open Source Awards – Hall of Fame
  21. ^The Valgrind Developers
  22. ^valgrind.org's list of users
  23. ^Valgrind FAQ

References[edit]

  • Nethercote, Nicholas; Seward, Julian. 'Valgrind: A Framework for Heavyweight Dynamic Binary Instrumentation'. Proceedings of ACM SIGPLAN 2007 Conference on Programming Language Design and Implementation (PLDI 2007). ACM.
  • Seward, Julian; Nethercote, Nicholas. 'Using Valgrind to detect undefined value errors with bit-precision'. Proceedings of the USENIX Annual Technical Conference 2005. USENIX Association.
  • Seward, J.; Nethercote, N.; Weidendorfer, J.; Valgrind Development Team (March 2008). Valgrind 3.3 – Advanced Debugging and Profiling for GNU/Linux applications. Network Theory Ltd. pp. 164 pages. ISBN0-9546120-5-1.

External links[edit]

Wikibooks has a book on the topic of: Valgrind
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Valgrind&oldid=916612014'