"Debug" Linux ultra-strong memory detection Tool Valgrind
Content Introduction
- What is Valgrind?
- Use of Valgrind
- Valgrind Detailed Tutorials
1. What is Valgrind?
Valgrind is a set of Linux, open source code (GPL
V2) A collection of simulation debugging tools. The valgrind consists of the kernel and other kernel-based debugging tools.
The kernel is similar to a framework (framework) that simulates a CPU environment and provides services to other tools, while other tools are similar to plug-ins (plug-in) that use the services provided by the kernel to perform a variety of specific memory debugging tasks.
The architecture of the Valgrind is as follows:
Valgrind includes some of the following tools:
Memcheck: This is the most widely used tool in Valgrind, a heavyweight memory checker that discovers the vast majority of memory error usage in development, such as using uninitialized memory, using freed memory, memory access, and so on.
Callgrind: It is used primarily to check for problems that occur during function calls in the program.
Cachegrind: It is primarily used to check for problems with cache usage in the program.
Helgrind: It is primarily used to check for competition problems in multithreaded programs.
Massif: It is used primarily to check for problems that occur in the stack usage in the program.
Extension: You can use the functionality provided by the core to write your own specific memory debugging tools.
2. Use of Valgrind
In order to make the errors found by valgrind more accurate, such as being able to locate the source line, it is recommended to add the-G parameter at compile time, and compile the optimization option, select O0, although this will reduce the execution efficiency of the program.
Here is the example program file named: test.c, the compiler selected for GCC.
Generating an executable program
gcc -g -O0 test.c -o test
After generating the executable program test, how can I use Valgrind to generate the memory log file? Generally this is used:
valgrind --leak-check=full --log-file=test_valgrind.log --num-callers=30 ./test
The test_valgrind.log behind--log-file is the name of the log file that is specified for generation.
The 60 behind--num-callers is the number of trace lines generated for each error record. 30 is arbitrarily set, if not specified, the default is 12 lines seemingly (there may be some tracking line is not shown).
--leak-check=full indicates that a detailed memory leak detector is turned on.
3. Valgrind Detailed Tutorials
For a detailed tutorial, see this article:
Applying Valgrind to discover memory problems with Linux programs
I am Shenmon, an embedded software engineer struggling in Paris, France.
The current work is Android embedded and app development.
Love life, like swimming, a little understanding of cooking.
Linux Exploration
"Debug" Linux ultra-strong memory Detection Tool Valgrind