Introduction to valgrind and cross-compiling and running on ARM
Reference blog: https://blog.csdn.net/dengcanjun6/article/details/54958359
Reference blog: https://blog.csdn.net/longbei9029/article/details/78626004?locationNum=1&fps=1
Reference blog: https://blog.csdn.net/qq_29350001/article/details/53780697
Valgrind is a software development tool for memory debugging, memory leak detection, and performance analysis.
The original author of Valgrind was Julian Seward, who won the second Google-O'Reilly Open Source Code Award in 2006 for his work developing Valgrind.
Valgrind is free software under the terms of the GNU General Public License.
There are many online about the specific use of valgrind. Here are some problems in the process of cross-compilation and use on ARM.
1. Download and compile preparation
wget http://valgrind.org/downloads/valgrind-3.12.0.tar.bz2
tar xvf valgrind-3.12.0.tar.bz2
cd valgrind-3.12.0
sudo apt-get install automake
./autogen.sh
2. Cross-compile and
modify configure: armv7*) to armv7*|arm)
./configure --host=arm-linux CC=arm-none-linux-gnueabi-gcc CPP=arm-none-linux-gnueabi-cpp CXX=arm-none-linux-gnueabi-g++ --prefix=/opt/valgrind-3.12.0
make
make install
The generated valgrind in the /opt/valgrind-3.12.0 directory includes 4 folders: bin, include, lib, share
The directory specified by --prefix=/opt/valgrind-3.12.0 should be the same as the directory placed on the development board, otherwise, "valgrind: failed to start tool 'memcheck' for platform 'arm-linux': No" may appear when running valgrind such file or directory" error.
3. Run
Copy the valgrind directory in the installation directory to the /opt/valgrind-3.12.0 directory on the target board through tftp, and modify the execution permission in the bin directory.
chmod -R +x /opt/valgrind-3.12.0/bin/
At this point, when running valgrind in the bin directory, the following error message will appear:
valgrind: failed to start tool 'memcheck' for platform 'arm-linux': Permission denied
Solution:
export VALGRIND_LIB="/opt/valgrind-3.12.0/lib/valgrind"
chmod -R +x /opt/valgrind-3.12.0/lib/valgrind/
You can check the code on ARM for memory leaks, etc.
4. Troubleshooting
1.出现“valgrind: failed to start tool ‘memcheck’ for platform ‘arm-linux’: No such file or directory”错误。
Many tutorials on the Internet say to pay attention to the installation directory after the --prefix should be consistent with the development board platform directory. For example, if I compile it on ubuntu x64 and install it to the /opt/valgrind-3.12.0 directory, then we will put the entire valgrind-3.12 .0 directory is copied to the development board, then it must be copied to the /opt directory of the development board, and some problems may indeed be solved. But in fact, the essential problem is that when valgrind is executed , the lib library of valgrind is not found ! ! !
Solution: You can see that there is a layer of directory valgrind under lib. At this time, we add a line to the /etc/profile file of the development board
export VALGRIND_LIB=/opt/valgrind-3.12.0/lib/valgrind
Of course, we can also configure some system paths in PATH="/usr/bin:/usr/sbin:/bin:/sbin:/app/bin:/opt/valgrind-3.12.0/bin" (according to you PATH path in your profile), just add the red part behind, execute source /etc/profile, you can use it as a valgrind command
Execute valgrind --tool=memcheck --leak-check=full ./test
2. The following error occurs when executing valgrind ls -l:
The above error is because a LIB is also required under Ubuntu: libc6-dbg
Run: sudo apt-get install libc6-dbg to install libc6-dbg
Then run again: valgrind ls -l