Valgrind移植

2020-10-18 12:00:13

Valgrind移植與使用教學

原始碼版本:valgrind-3.16.1.tar.bz2

ubutun版本:20.04

交叉編譯鏈:arm-none-linux-gnueabi-

交叉編譯命令介紹:

configure設定說明說明
–build執行程式碼編譯的主機
–host程式最終要執行的主機
–target用build主機上的編譯器,編譯一個新的編譯器( 如gcc),這個新的編譯器將來編譯出來的其他程式將執行在target指定的系統上
–prefix指定編譯出來的版本存放路徑,預設放在「/usr /local/bin」
CC CXX CPP交叉編譯器設定CC=arm-none-linux-gnueabi-cc CPP=arm-none-linux-gnueabi-cpp CXX=arm-none-linux-gnueabi-g++

安裝步驟:

編譯linux版本

1.解壓並執行valgrind自動make指令碼

vmuser@vmuser-virtual-machine:tar jxvf valgrind-3.16.1.tar.bz2
vmuser@vmuser-virtual-machine:~/valgrind-3.16.1$ sudo apt-get install automake
vmuser@vmuser-virtual-machine:~/valgrind-3.16.1$ ./autogen.sh

2.configure

vmuser@vmuser-virtual-machine:~/valgrimakend-3.16.1$ mkdir install 
vmuser@vmuser-virtual-machine:~/valgrind-3.16.1$ ./configure --prefix=/home/vmuser/valgrind-3.16.1/install/

3.make

vmuser@vmuser-virtual-machine:~/valgrimakend-3.16.1$ make
vmuser@vmuser-virtual-machine:~/valgrimakend-3.16.1$ make install

編譯ARM版本

1.編譯之前先make clean

2.修改 configure 檔案:

vmuser@vmuser-virtual-machine:~/valgrimakend-3.16.1$ mkdir install_arm
vmuser@vmuser-virtual-machine:~/valgrimakend-3.16.1$ ./configure --host=arm-linux CC=arm-none-linux-gnueabi-cc CPP=arm-none-linux-gnueabi-cpp CXX=arm-none-linux-gnueabi-g++ --prefix= --prefix=/home/vmuser/valgrind-3.16.1/install_arm/

報錯

checking host system type... arm-unknown-linux-gnu
checking for a supported CPU... no (arm)
configure: error: Unsupported host architecture. Sorry

修改configure 把armv7a* 改為 arm* 再次設定configure

vmuser@vmuser-virtual-machine:~/valgrimakend-3.16.1$ ./configure --host=arm-linux CC=arm-none-linux-gnueabi-cc CPP=arm-none-linux-gnueabi-cpp CXX=arm-none-linux-gnueabi-g++ --prefix= --prefix=/home/vmuser/valgrind-3.16.1/install_arm/

//注意:–prefix=/mnt指定的目錄要與開發板上放置的目錄一致,不然執行valgrind時可能會出現「valgrind: failed to start tool ‘memcheck’ for platform ‘arm-Linux’: No such file or directory」錯誤。

3.編譯安裝

vmuser@vmuser-virtual-machine:~/valgrimakend-3.16.1$ make
vmuser@vmuser-virtual-machine:~/valgrimakend-3.16.1$ make install

4.移植到arm開發板

將/home/vmuser/valgrind-3.16.1/install_arm/目前下檔案複製到arm同級目錄下;

將/home/vmuser/valgrind-3.16.1/install_arm/bin/valgrind檔案複製到/bin目錄下。

root@freescale /home/vmuser/valgrind-3.16.1$ valgrind --help
usage: valgrind [options] prog-and-args

  tool-selection option, with default in [ ]:
    --tool=<name>             use the Valgrind tool named <name> [memcheck]

  basic user options for all Valgrind tools, with defaults in [ ]:
    -h --help                 show this message
    --help-debug              show this message, plus debugging options
    --help-dyn-options        show the dynamically changeable options
    --version                 show version
    -q --quiet                run silently; only print error msgs
    -v --verbose              be more verbose -- show misc extra info
    --trace-children=no|yes   Valgrind-ise child processes (follow execve)? [no]
    --trace-children-skip=patt1,patt2,...    specifies a list of executables
                              that --trace-children=yes should not trace into
    --trace-children-skip-by-arg=patt1,patt2,...   same as --trace-children-skip=
                              but check the argv[] entries for children, rather
                              than the exe name, to make a follow/no-follow decision
    --child-silent-after-fork=no|yes omit child output between fork & exec? [no]
    --vgdb=no|yes|full        activate gdbserver? [yes]
                              full is slower but provides precise watchpoint/step
    --vgdb-error=<number>     invoke gdbserver after <number> e