Menu
Where to get Valgrind¶. Linux: Download Valgrind directly, or use your distribution’s package manager. MacOSX: Get Valgrind trunk from SVN and build it. Don’t use 3.10.x or any other tarball. Make sure you have version 3.10.1 or later of Valgrind. Newer versions tend to have better compatibility with both Firefox’s JITs and newer toolchain components (compiler, libc and linker versions). Valgrind is only compatible with x86 binaries on Mac OS, so if you have x8664 you'll need to ensure that x86 binaries are being built. To do this, right click on the project and select Properties. Within the Properties window, select C/C Build then add '-m32' to the Command field for the MacOS X C Linker, GCC C Compiler and GCC C Compiler. With the June 15, 2017 release of valgrind 3.13.0, I am able to install and make use of valgrind on macOS Sierra (10.12.5). As a base case, I can successfully evaluate a very basic valgrind ls -l.I will be continuing to evaluate this build of valgrind as I complete the exercises in ZS's LCTHW.
This page describes how to use Valgrind (specifically, its Memchecktool) to find memory errors.
Supported platforms¶
Valgrind runs desktop Firefox fine on Linux, especially on x86 andx86-64. Firefox for Android and Firefox OS on ARMv7 should also run,though perhaps not as smoothly. The other architectures supported byValgrind on Linux (AARCH64, PPC{32,64}, MIPS{32,64}, S390X) should alsowork, in theory.
MacOS X 10.10 (Yosemite), 64-bit only, works, although it can be a bitof a rough ride.
Where to get Valgrind¶
Linux: Download Valgrind directly, or useyour distribution’s package manager.
MacOSX: Get Valgrind trunk fromSVN and build it.Don’t use 3.10.x or any other tarball.
Make sure you have version 3.10.1 or later of Valgrind. Newer versionstend to have better compatibility with both Firefox’s JITs and newertoolchain components (compiler, libc and linker versions).
Basics¶Build¶
Build Firefox with the following options, which maximize speed andaccuracy.
Run¶
Note that programs run much more slowly under Valgrind than they donatively. Slow-downs of 20x or 30x aren’t unexpected, and it’s slower onMac than on Linux. Don’t try this on an underpowered machine.
Linux¶
On Linux, run Valgrind with the following options.
The
--smc-check and --vex-iropt-register-updates options arenecessary to avoid crashes in JIT-generated code.
The
--show-mismatched-frees option is necessary due to inconsistentinlining of new and delete – i.e. one gets inlined but theother doesn’t – which lead to false-positive mismatched-free errors.
The
--read-inline-info option improves stack trace readability inthe presence of inlining.
Also, run with the following environment variable set.
This is necessary to get the Gnome system libraries to use plain
malloc instead of pool allocators.
Mac¶
On Mac, run Valgrind with the following options.
The
--dsymutil option ensures line number information is present instack traces.
Advanced usage¶Shared suppression files¶
/build/valgrind/contains the suppression files used by the periodic Valgrind jobs onTinderbox. Some of these files are platform-specific.
Running mochitests under Valgrind?¶
To run a mochitest under Valgrind, use the following command.
Where
$VALGRIND_OPTIONS are the options describedabove. You might alsoneed --trace-children=yes to trace into child processes.
As of December 2014 it is possible to do a complete run ofmochitests-plain on Valgrind in about 8 CPU hours on a Core i4910(Haswell) machine. Maximum process size is 5.4G, of which about 80% isin memory. Runs of small subsets of mochitests take far less memory.
Bits and pieces¶
For un-released Linux distros (Fedora Rawhide, etc.) you’ll need to usea version of Valgrind trunk build, because fixes for the latest gcc andglibc versions appear there first. Without them you’ll be flooded withfalse errors from Memcheck, and have debuginfo reading problems.
On Linux, code compiled by LLVM at high optimisation levels can causeMemcheck to report false uninitialised value errors. Seehere for an easyworkaround. On Mac, Valgrind has this workaround built in.
You can make stack traces easier to read by asking for source file namesto be given relative to the root of your source tree. Do this by using
--fullpath-after= to specify the rightmost part of the absolute paththat you don’t want to see. For example, if your source tree is rootedat /home/sewardj/MC-20-12-2014 , use --fullpath-after=2014/ toget path names relative to the source directory.
The
--track-origins=yes slows down Valgrind greatly, so don’t use itunless you are hunting down a specific uninitialised value error. But ifyou are hunting down such an error, it’s extremely helpful and worthwaiting for.
Additional help¶
The Valgrind Quick StartGuide is shortand worth reading. The UserManual is also useful.
If Valgrind asserts, crashes, doesn’t do what you expect, or otherwiseacts up, first of all read this page and make sure you have both Firefoxand Valgrind correctly configured. If that’s all OK, try using theValgrind trunk fromSVN. Oftentimesbugs are fixed in the trunk before most users fall across them. If thatdoesn’t help, consider filing a bugreport, and/ormailing Julian Seward or Nick Nethercote.
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.
![]()
The Valgrind plug-in for Eclipse (documented herein) integrates several Valgrind tools into Eclipse. This allows Eclipse users to seamlessly include profiling capabilities into their workflow. At present, the Valgrind plug-in for Eclipse supports four Valgrind tools: Memcheck, Massif, Cachegrind and Helgrind.
For more information about Valgrind, refer to http://www.valgrind.org/.
In order for the Valgrind plug-in for Eclipse to work properly, you should have the valgrind-3.3.0 (or later) package installed on your system first.
Once the valgrind package is installed, the easiest way to install the Valgrind plug-in for Eclipse is through the Software Updates and Add-ons menu. For information on how to use this menu, refer to this link.
You can use the Valgrind plug-in's 'one-click launch' shortcut to run a default profile. Doing so is similar to running
valgrind ./program_name from the command line. To use the one-click launch shortcut, right-click on the project or binary name in the Project Explorer window and navigate to Profiling Tools > Profile With Valgrind. If a source file belonging to that program is available on any open editor, you can also right-click inside the editor to navigate to the one-click launch.Configuring a Profile Run
To configure a Valgrind profile run, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu.
The Profile Configurations menu allows you to configure a profile run with some basic Valgrind profiling options, along with the most useful options for each Valgrind tool. These settings can be configured in the Valgrind Options tab of a specific profile run.
General Options
The General Options tab allows you to configure the following options:
For more information about these options, refer to
man valgrind .
Suppressions
You can also configure your profile run to use a suppressions file (similar to the
--suppressions= option. To do this, click the Suppressions tab.
The Workspace button allows you to select a resource from the workspace as your suppressions file. To use a suppressions file outisde of the workspace, use the File System button.
Exporting Valgrind Data
To export the raw data collected during a Valgrind profile run, use the Export wizard menu. To access the Export wizard menu, navigate to File > Export and select Valgrind Log Files under the category Other.
Alternatively, you can also use the Export Valgrind Log Files icon ( ) on the Valgrind view toolbar to access the Export wizard menu.
Error Markers
The Valgrind Eclipse plug-in uses error markers to identify specific errors, found by the underlying Valgrind tool, to the user. The sub-tools that make use of these markers are Memcheck and Helgrind; each emitting specific memory or concurrency error.
In post 2.1 releases of Linux Tools, it is possible to clear these error markers by simply re-building or cleaning the respective project. For the older versions the Remove Markers toolbar action is available to manually clear the markers.
Other Operating Systems
The Valgrind Eclipse plugins were designed and tested on Linux systems only. However, the Valgrind tools are also available on Mac OS X and so too are the Linux Tools Eclipse Valgrind plugins. The plugins are not officially supported on Mac OS X, but here are instructions to get it working.
Mac OS X 10.6Valgrind Mac Os 10.15
As of Apr 19, 2010 the official release of the Valgrind tool does not work on 10.6. However, there are patches available to make it work.
Brief instructions to compile the Valgrind tool is here: http://code.google.com/p/data-race-test/wiki/ValgrindOnSnowLeopard
Essentially, you need to run the following script. (Ensure you have wget installed)
Once this is done, see instructions below for other Mac OS's
x86_64 Mac OS
Valgrind is only compatible with x86 binaries on Mac OS, so if you have x86_64 you'll need to ensure that x86 binaries are being built. To do this, right click on the project and select Properties.
Within the Properties window, select C/C++ Build then add '-m32' to the Command field for the MacOS X C++ Linker, GCC C++ Compiler and GCC C Compiler. This will cause x86 binaries to be created.
All Mac OS
First ensure you have a release of the Valgrind command-line tool installed. See http://valgrind.org/ and see above for special Valgrind instructions. After installing, you will need to create a symlink to /usr/bin/valgrind so the Valgrind plugin can find it.
Use
which valgrind to find the install location of the Valgrind binary.
ln -s /usr/bin/valgrind /location/of/valgrind will create the symlink.
After that, the Eclipse Valgrind plugin should work as specified in other parts of this wiki page.
Memcheck is the default tool used by Valgrind and the Valgrind plug-in for Eclipse. It allows you to detect memory-related problems such as memory leaks, use of uninitialized memory, and reads from/writes to inappropriate stack areas. For more information about Memcheck, refer to http://www.valgrind.org/docs/manual/mc-manual.html.
Analyzing Memcheck Profile Results
Any memory management errors detected by Memcheck are displayed in the Valgrind view, which appears automatically after a profile run. Each displayed error can be expanded in the Valgrind view to display its stack trace.
In some cases, Memcheck can determine which section of the source code causes a reported error. Whenever this is the case, double-clicking on the stack trace of the reported error will open the related source file and place the insertion point on the line responsible for the error.
Configuring a Memcheck Profile Run
To configure a Memcheck profile run, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu. In the Valgrind Options tab, navigate further to Memcheck Options.
Mac Install Valgrind
The Memcheck Options tab allows you to configure the following Memcheck options:
Refer to http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.suppfiles for information about Memcheck suppression files. For more information about each Memcheck option in the Valgrind plug-in for Eclipse, refer to
man valgrind .
Massif is a Valgrind tool that measures how much heap memory an application uses. Heap memory profiling is useful in determining how to reduce the memory usage of an application. For more information about Massif, refer to http://www.valgrind.org/docs/manual/ms-manual.html.
To use Massif, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu. Open the Valgrind Options tab and choose Massif from the Tool to run: drop-down list.
Analyzing Massif Profile Results
Massif distills a large volume of data. The Valgrind plug-in for Eclipse presents three ways to view this data:
Configuring a Massif Profile Run
To configure a Massif profile run, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu. In the Valgrind Options tab, navigate further to Massif Options.
The Massif Options tab allows you to configure the following Massif options:
For more information about each Massif option in the Valgrind plug-in for Eclipse, refer to
man valgrind .
Cachegrind performs cache and branching profiling. A Cachegrind profile run measures the number of cache misses and branch mispredictions performed by an application. Cachegrind collects the following statistics:
To use Cachegrind, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu. Open the Valgrind Options tab and choose Cachegrind from the Tool to run: drop-down list.
Analyzing Cachegrind Profile Results
The results of a Cachegrind profile run are displayed in the Valgrind view. These results show Cachegrind's cache/branch data in different levels of granularity. Double-clicking on any file, function, or line will open the corresponding source file and place the cursor on the appropriate location (if the source can be resolved).
Configuring a Cachegrind Profile Run
To configure a Massif profile run, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu. In the Valgrind Options tab, navigate further to Cachegrind Options.
The Cachegrind Options tab allows you to configure the following Cachegrind options:
For more information about each Cachegrind option in the Valgrind plug-in for Eclipse, refer to
man valgrind .
Helgrind is a tool that allows you to detect synchronisation errors in C, C++ and Fortran programs that use POSIX pthreads. For more information about Helgrind, refer to http://valgrind.org/docs/manual/hg-manual.html.
Analyzing Helgrind Profile Results
All the synchronization errors found by Helgrind are displayed in the Valgrind view, which appears automatically after a profile run. Each displayed error can be expanded in the Valgrind view to display its stack trace.
In some cases, Helgrind can determine which section of the source code causes a reported error. Whenever this is the case, double-clicking on the stack trace of the reported error will open the related source file and place the cursor on the line responsible for the error. This stack trace view is similar to the view that the Memcheck plug-in provides.
Configuring a Helgrind Profile Run
To configure a Helgrind profile run, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu. In the Valgrind Options tab, navigate further to Helgrind Options.
![]()
The Helgrind Options tab allows you to configure the following options:
For more information about each Helgrind option in the Valgrind plug-in for Eclipse, refer to man valgrind, section 'HELGRIND OPTIONS'.
You can profile remote projects just as local ones. This can be useful when developing an application for a different architecture.
To run Valgrind remotely, right-click a remote c/c++ project and navigate to 'Profiling Tools', then 'Profile Configurations'. In the new window, double-click the Profile with Valgrind (remote) profile configuration.
Download Valgrind For Windows
In the main tab, click 'Browse' under 'C/C++ executable' to choose the binary that will be executed. The same tool configurations for local projects apply to remote ones.
After configuring the profile, click the Profile button to launch the profile. Results will be displayed in the same Valgrind view previously described. Encountering Errors
If the profiled application contains any errors or if any Valgrind options you selected result in an error, these errors will be reported in the Core Messages pane of the Valgrind View. The Memcheck tool outputs all of its profile results on this pane.
For other tools, it is possible to switch between the Core Messages pane and the tool's output in the Valgrind view menu.
How To Use ValgrindProfiling Child ProcessesHow To Download Valgrind On Mac High Sierra
To profile child processes during a profile run, enable the Trace children on exec option in the General Options tab (of the Valgrind Options tab). Memcheck's results will list the process ID (PID) for each reported error in the Valgrind view.
Massif, on the other hand, will present each process separately and allow you to switch between processes with the Select Process ID dropdown icon ( ) in the Valgrind view toolbar.
Cachegrind will report each PID separately as a top-level element in its output tree.
Valgrind Tutorial
Retrieved from 'http://wiki.eclipse.org/index.php?title=Linux_Tools_Project/Valgrind/User_Guide&oldid=409089'
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2020
Categories |