问:如何在 x86 ubuntu 机器上为 ARM 交叉编译 valgrind?
问问题
291 次
1 回答
3
这是一个独立的过程,假设您在 x86_64 Ubuntu Linux 机器上构建。如果不是这种情况,只需为您的 Linux 发行版中可用的目标安装交叉编译器arm-none-linux-gnueabihf
,确保它在您的路径中,并相应地修改configure
命令。
在 PC 端:
# downloading/installing toolchain
wget https://developer.arm.com/-/media/Files/downloads/gnu-a/10.2-2020.11/binrel/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=d0b90559-3960-4e4b-9297-7ddbc3e52783&la=en&hash=985078B758BC782BC338DB947347107FBCF8EF6B
sudo mkdir -p /opt/arm/10
sudo tar Jxf gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf.tar.xz -C /opt/arm/10
# downloading/extracting valgrind
wget https://sourceware.org/pub/valgrind/valgrind-3.16.1.tar.bz2
tar jxf valgrind-3.16.1.tar.bz2
# building
export PATH=/opt/arm/10/gcc-arm-10.2-2020.11-x86_64-arm-none-linux-gnueabihf/bin:$PATH
mdkir valgrind
cd valgrind
../valgrind-3.16.1/configure --host=arm-none-linux-gnueabihf --prefix=$(pwd)/valgrind-3.16.1-arm-none-linux-gnueabihf
make all install
在 Orangepi 上:
将valgrind-3.16.1-arm-none-linux-gnueabihf
目录及其子目录的内容从您的 PC 复制到您的 Orangepi 的 /usr/local 目录中。
安装libc6-dbg
(假设您在 Orangepi 上运行 Ubuntu 或 Debian):apt-get install libc6-dbg
使用此处提供的程序进行测试:
wget http://cs.ecs.baylor.edu/~donahoo/tools/valgrind/test.c
gcc -o test -g test.c
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./test
==2034== Memcheck, a memory error detector
==2034== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2034== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==2034== Command: ./test
==2034==
==2034==
==2034== FILE DESCRIPTORS: 3 open at exit.
==2034== Open file descriptor 2: /dev/ttyS0
==2034== <inherited from parent>
==2034==
==2034== Open file descriptor 1: /dev/ttyS0
==2034== <inherited from parent>
==2034==
==2034== Open file descriptor 0: /dev/ttyS0
==2034== <inherited from parent>
==2034==
==2034==
==2034== HEAP SUMMARY:
==2034== in use at exit: 35 bytes in 2 blocks
==2034== total heap usage: 3 allocs, 1 frees, 47 bytes allocated
==2034==
==2034== 16 bytes in 1 blocks are definitely lost in loss record 1 of 2
==2034== at 0x484A4B0: malloc (vg_replace_malloc.c:307)
==2034== by 0x1087DB: main (test.c:15)
==2034==
==2034== 19 bytes in 1 blocks are definitely lost in loss record 2 of 2
==2034== at 0x484A4B0: malloc (vg_replace_malloc.c:307)
==2034== by 0x1087BB: main (test.c:8)
==2034==
==2034== LEAK SUMMARY:
==2034== definitely lost: 35 bytes in 2 blocks
==2034== indirectly lost: 0 bytes in 0 blocks
==2034== possibly lost: 0 bytes in 0 blocks
==2034== still reachable: 0 bytes in 0 blocks
于 2021-02-02T14:55:19.760 回答