Valgrind is an instrumentation framework for building dynamic analysis tools. It comes with a set of tools, each of which performs some kind of debugging, profiling, or similar task that helps you improve your programs.
Valgrind's architecture is designed to be modular, so new tools can be created easily without disturbing the existing structure.
Before starting work, there are two pieces of information that you must read, that is, the platform and tool overview. Although Baidu has checked some, it is not as accurate as the official one:
Platform support, my ARM-v7 is supported
http://valgrind.org/info/platforms.html
Tool Overview:
http://valgrind.org/info/tools.html
Many useful tools are provided as standard.
Memcheck is a memory error detector. It can help you make your programs, especially those written in C and C++, more correct.
Cachegrind is a cache and branch prediction profiler. It can help you make your program run faster.
Callgrind is a call graph generating cache profiler. It has some overlap with Cachegrind, but also collects some information that Cachegrind does not.
Helgrind is a thread error detector. It can help you make your multithreaded programs more correct.
DRD is also a thread error detector. It is similar to Helgrind, but uses different analysis techniques, so may find different problems.
Massif is a heap profiler. It can help you make your program use less memory.
DHAT is a different type of heap analyzer. It helps you understand issues with block lifespan, block utilization, and layout inefficiencies.
SGcheck is an experimental tool that detects overflows of the stack and global arrays. Its functionality is complementary to that of Memcheck: SGcheck finds problems that Memcheck cannot, and vice versa.
BBV is an experimental SimPoint Basic Block Vector generator. It is useful for people doing computer architecture research and development.
The official explanation is:
Memcheck detects memory management problems, primarily for C and C++ programs. Memcheck runs programs about 10-30 times slower than normal
Cachegrind runs your program about 20-100 times slower than normal.
Massif runs programs 20 times slower than normal
1. Download source code
http://valgrind.org/
2 After decompression, configure:
./configure --prefix=/home/sun/share/install --host=arm-buildroot-linux-uclibcgnueabi
Configuration error:
checking for a supported CPU... no (arm)
configure: error: Unsupported host architecture. Sorry
Check the official website homepage and find that ARM-LINUX is supported
It runs on the following platforms: X86/Linux, AMD64/Linux, ARM/Linux, ARM64/Linux, PPC32/Linux, PPC64/Linux, PPC64LE/Linux, S390X/Linux, MIPS32/Linux, MIPS64/Linux, X86/Solaris, AMD64/Solaris, ARM/Android (2.3.x and later), ARM64/Android, X86/Android (4.0 and later), MIPS32/Android, X86/Darwin and AMD64/Darwin (Mac OS X 10.12).
Modify the configure file:
Change armv7a* to arm* and configure again without error
before fixing:
After modification:
3. Compile
make -j4
make install
Four directories will be generated: bin lib share include
4. My board space is very small, so I need to delete unnecessary tools and only leave the memory check tool.
You need to delete the files in the lib/valgrind directory and the entire share directory, and finally reduce it to about 12M:
sun@machine:~/share/install$ du -sh bin include/ lib/
520K bin
2.1M include/
10M lib/
All files in the streamlined lib/valgrind directory:
Copy code
32bit-core-valgrind-s1.xml 32bit-sse.xml arm-with-vfpv3.xml
32bit-core-valgrind-s2.xml arm-core-valgrind-s1.xml default.supp
32bit-core.xml arm-core-valgrind-s2.xml getoff-arm-linux
32bit-linux-valgrind-s1.xml arm-core.xml memcheck-arm-linux
32bit-linux-valgrind-s2.xml arm-vfpv3-valgrind-s1.xml vgpreload_core-arm-linux.so
32bit-linux.xml arm-vfpv3-valgrind-s2.xml vgpreload_memcheck-arm-linux.so
32bit-sse-valgrind-s1.xml arm-vfpv3.xml
32bit-sse-valgrind-s2.xml arm-with-vfpv3-valgrind.xml
Copy code
File information with the name containing ARM-LINUX:
sun@machine:~/share/install/lib/valgrind$ file *arm-linux*
getoff-arm-linux: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, with debug_info, not stripped
memcheck-arm-linux: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
vgpreload_core-arm-linux.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped
vgpreload_memcheck-arm-linux.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped
5. Requirements for the operating environment:
http://valgrind.org/docs/manual/dist.readme-packagers.html
View Code
Five important points are mentioned:
Copy code
1 - If your toolchain (compiler, linker) supports lto, using the configure option --enable-lto=yes will produce a smaller/faster valgrind
2 - Do not use a completely stripped Linux distribution /lib/ld.so. (For example, the getoff-arm-linux above links to /lib/ld-uClibc.so.0, which requires that /lib/ld-uClibc.so.0 in the root directory of our development board must be not stripped)
3 The directory running on the development board must be exactly the same as the directory specified by --prefix =
4 - Do not strip debug information from lib/valgrind/$platform/vgpreload*.so (such as vgpreload_core-arm-linux.so and vgpreload_memcheck-arm-linux.so above must be not stripped)
5 - Do not strip symbols from lib/valgrind/* in the installation tree. (e.g. getoff-arm-linux and memcheck-arm-linux above must be not stripped)
Copy code
The 4th and 5th items require that any file in the lib/valgrind/ directory must be not stripped to ensure the reliability of the program.
Put all the streamlined directories into the specified directory of the development board (that is, the directory with --prefix=/home/sun/share/install). If you forget which directory you compiled in, please check lib/pkgconfig/valgrind.pc
The file contains an absolute path description: such as prefix=/home/sun/share/install
sun@machine:~/share/install/lib/pkgconfig$ cat valgrind.pc
prefix=/home/sun/share/install
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/valgrind
arch=arm
os=linux
platform=arm-linux
valt_load_address=0x58000000
Name: Valgrind
Description: A dynamic binary instrumentation framework
Version: 3.14.0
Requires:
Libs: -L${libdir}/valgrind -lcoregrind-arm-linux -lvex-arm-linux -lgcc
Cflags: -I${includedir}
Generally, it can run successfully. Occasionally, it cannot run after adb push. If you have confirmed that the path on the development board is exactly the same as the path specified by prefix, but still report the following error:
valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No such file or directory
Then you need to specify the path to the library:
VALGRIND_LIB=/home/sun/share/install/lib ./valgrind /home/sun/share/install/bin/valgrind --help
If it works, set it to the environment variable. It is only valid in the current terminal. If you open another terminal, you need to set it again. If the terminal is closed or the board is restarted, you also need to set it again:
export VALGRIND_LIB=/home/test/valgrind/lib/valgrind
After setting, you can run it directly./valgrind/home/sun/share/install/bin/valgrind --help can be successfully run
./valgrind/home/sun/share/install/bin/valgrind ls reports an error
The error message is: Internal error, valgrind segmentation error exited
After several days of back and forth, the cross tool chain was rebuilt and the error still occurred with the new version of uclibc.
After replacing the kernel version, the error still occurs
Changing to several older versions of valgrind still reports errors
Finally, I checked valgrind's support for the platform's CPU architecture again, and found that I had missed important information due to negligence at the beginning.
current
Valgrind supports the following platforms:
x86/Linux: up to SSSE3 included, but no higher - no SSE4, AVX, AVX2. This target is now in maintenance mode..
AMD64/Linux: includes AVX2. This is the primary development target, and tends to be well supported.
PPC32/Linux, PPC64/Linux, PPC64LE/Linux: Including Power8.
S390X/Linux: Supported.
ARM/Linux: Supported since ARMv7.
ARM64/Linux: ARMv8 support.
MIPS32/Linux, MIPS64/Linux: Supported.
X86/Solaris, AMD64/Solaris, X86/illumos, AMD64/illumos: Supported since Solaris 11.
X86/Darwin (10.10, 10.11), AMD64/Darwin (10.10, 10.11): Supported.
ARM/Android, ARM64/Android, MIPS32/Android, X86/Android: supported.
On Linux, you must be running kernel 3.0 or later, and glibc 2.5.X or later. On Mac OS X, you must be running 10.9.x or later.
Transplantation Program
Valgrind 3.X has infrastructure to support multiple platforms. A platform is a specific (CPU, OS) pairing, such as x86/Linux or AMD64/Linux.
A lot of effort goes into maintaining each port, more than most other programs. Valgrind is fragile because it works at a very low level. Also, each platform port has CPU-specific code, OS-specific code, and platform-specific code, and it's hard to test all the combinations.
Therefore, we can only justify support for widely used platforms. Unlike NetBSD or GCC, we are not interested in having Valgrind work on every platform in the known universe: the maintenance burden would be too high. Therefore, porting Valgrind to a different platform is not just a technical exercise: you also need to make a convincing case that the effort is worthwhile and that the port will be properly supported, at least for the foreseeable future.
Windows is not under consideration, as porting to it would require so many changes that it would almost be a separate project. (However, Valgrind + Wine could be done with some effort.) Also, non-open source operating systems are difficult to work with; being able to see the OS and associated (libc) source code makes things easier. However, Valgrind can be used in conjunction with Wine, which means that it is possible to run Windows programs under Valgrind.
Previous article:How to build an ARM cross-compilation environment under Linux
Next article:Cross-compile Python-2.7.13 to ARM (aarch32) platform
Recommended ReadingLatest update time:2024-11-16 12:43
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- First day of work in 2021
- TL335x-EVM development board processor, FLASH, RAM, FRAM
- DSP2812 CMD detailed configuration example
- 【ESP32-Korvo Review】 01 Unboxing Experience
- PCB circuit board heat dissipation tips
- Exposed! Another unfinished semiconductor project: defrauding state-owned land and refusing to return it! Using the name of chips to engage in real estate?
- How to configure C2000 to enter low power mode
- Basic concepts of amplifier circuits and three basic connections
- Does the material of the transformer determine the operating frequency of the transformer?
- CV2880 simple datasheet