Hi3559A

Hi3559A 跑valgrind开发步骤
一、下载valgrind源码

二、基于hisi toolchain,交叉编译valgrind
编译主机

4.15.0-34-generic #37~16.04.1-Ubuntu SMP Tue Aug 28 10:44:06 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

PC上编译命令

export LD=aarch64-himix100-linux-ld

export AR=aarch64-himix100-linux-ar

export CC=aarch64-himix100-linux-gcc

./configure --host=aarch64-himix100-linux --prefix=/home/huangxing/valgrind_install/

make -j4

make install

编译完成后,在valgrind_install中安装了以下文件。
simh@hxdl:~/valgrind_install$ tree -L 2
.
├── bin
│ ├── callgrind_annotate
│ ├── callgrind_control
│ ├── cg_annotate
│ ├── cg_diff
│ ├── cg_merge
│ ├── ms_print
│ ├── valgrind
│ ├── valgrind-di-server
│ ├── valgrind-listener
│ └── vgdb
├── include
│ └── valgrind
└── lib
├──-- pkgconfig
└──-- valgrind

将valgrind_install目录拷贝到nfs方式挂载的路径下。

三、海思板端执行:

export VALGRIND_LIB=’/home/simh/valgrind_install/lib/valgrind’
如果不执行上面的命令,会提示找不到memcheck!

cd /home/simh/valgrind_install/bin

./valgrind --help

此时会提示以下错误:
/home/simh/valgrind_install/bin # ./valgrind ls -l

19263 Memcheck, a memory error detector
19263 Copyright © 2002-2017, and GNU GPL’d, by Julian Seward et al.
19263 Using Valgrind-3.15.0.GIT and LibVEX; rerun with -h for copyright info
19263 Command: ls -l
19263
valgrind: Fatal error at startup: a function redirection
valgrind: which is mandatory for this platform-tool combination
valgrind: cannot be set up. Details of the redirection are:
valgrind:
valgrind: A must-be-redirected function
valgrind: whose name matches the pattern: strlen
valgrind: in an object with soname matching: ld-linux-aarch64.so.1
valgrind: was not found whilst processing
valgrind: symbols from the object with soname: ld-linux-aarch64.so.1
valgrind:
valgrind: Possible fixes: (1, short term): install glibc’s debuginfo
valgrind: package on this machine. (2, longer term): ask the packagers
valgrind: for your Linux distribution to please in future ship a non-
valgrind: stripped ld.so (or whatever the dynamic linker .so is called)
valgrind: that exports the above-named function using the standard
valgrind: calling conventions for this platform. The package you need
valgrind: to install for fix (1) is called
valgrind:
valgrind: On Debian, Ubuntu: libc6-dbg
valgrind: On SuSE, openSuSE, Fedora, RHEL: glibc-debuginfo
valgrind:
valgrind: Note that if you are debugging a 32 bit process on a
valgrind: 64 bit system, you will need a corresponding 32 bit debuginfo
valgrind: package (e.g. libc6-dbg:i386).
valgrind:
valgrind: Cannot continue – exiting now. Sorry.

此时的处理方法也比较简单,可以任选其一。

1) 更改osdrv的makefile,将hirootfs_prepare中的这句话注释掉。
pushd ( O S D R V D I R ) / p u b / (OSDRV_DIR)/pub/ (OSDRVDIR)/pub/(PUB_ROOTFS); $(OSDRV_CROSS)-strip ./lib/*; popd

2)直接到/opt/hisi-linux/x86-arm/aarch64-himix100-linux/target/lib中取libc-2.24.so(not stripped), 重新制作rootfs。

至此,algrind应该可以在海思平台上运行了,

cd /home/simh/valgrind_install/bin
./valgrind ls -l
/home/simh/valgrind_install/bin # ./valgrind ls -l
7215 Memcheck, a memory error detector
7215 Copyright © 2002-2017, and GNU GPL’d, by Julian Seward et al.
7215 Using Valgrind-3.15.0.GIT and LibVEX; rerun with -h for copyright info
7215 Command: ls -l
7215
total 2608
-rw------- 1 root root 150158 Oct 24 10:50 callgrind.out.2646
-rw------- 1 root root 476590 Oct 24 10:51 callgrind.out.2661
-rw------- 1 root root 150110 Oct 24 10:51 callgrind.out.2689
-rw------- 1 root root 508277 Oct 24 10:52 callgrind.out.2694
-rw------- 1 root root 509620 Oct 24 10:53 callgrind.out.2735
-rw------- 1 root root 93369 Oct 24 10:52 callgrind.out.2737
-rwxr-xr-x 1 1000 1000 42184 Oct 23 17:38 callgrind_annotate
-rwxr-xr-x 1 1000 1000 12677 Oct 23 17:38 callgrind_control
-rwxr-xr-x 1 1000 1000 32174 Oct 23 17:38 cg_annotate
-rwxr-xr-x 1 1000 1000 10422 Oct 23 17:38 cg_diff
-rwxr-xr-x 1 1000 1000 238632 Oct 23 17:38 cg_merge
-rwxr-xr-x 1 1000 1000 24402 Oct 23 17:38 ms_print
-rwxr-xr-x 1 1000 1000 76888 Oct 23 17:38 valgrind
-rwxr-xr-x 1 1000 1000 104024 Oct 23 17:38 valgrind-di-server
-rwxr-xr-x 1 1000 1000 39072 Oct 23 17:38 valgrind-listener
-rwxr-xr-x 1 1000 1000 168088 Oct 23 17:38 vgdb
7215
7215 HEAP SUMMARY:
7215 in use at exit: 775 bytes in 8 blocks
7215 total heap usage: 98 allocs, 90 frees, 66,501 bytes allocated
7215
7215 LEAK SUMMARY:
7215 definitely lost: 32 bytes in 2 blocks
7215 indirectly lost: 112 bytes in 1 blocks
7215 possibly lost: 0 bytes in 0 blocks
7215 still reachable: 631 bytes in 5 blocks
7215 suppressed: 0 bytes in 0 blocks
7215 Rerun with --leak-check=full to see details of leaked memory
7215
7215 For counts of detected and suppressed errors, rerun with: -v
7215 ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

valgrind正常运行了。

第四步数据分析

valgrind在板端运行生成的数据可以通过pc端的工具进行分析。

举例来说:
如果使用callgrind工具,会生成callgrind.out.pid文件,可以通过kcachegrind工具分析,或者通过gprof2dot.py工具进行分析。

gprof2dot.py可以在以下链接下载:
https://github.com/jrfonseca/gprof2dot

使用示例:
gprof2dot.py -f callgrind ./callgrind.out.2735 | dot -Tpng -o ps_report.png

不过valgrind官网推荐使用kcachegrind工具。

Callgrind
Callgrind, by Josef Weidendorfer, is an extension to Cachegrind. It provides all the information that Cachegrind does, plus extra information about callgraphs. It was folded into the main Valgrind distribution in version 3.2.0. Available separately is an amazing visualisation tool, KCachegrind, which gives a much better overview of the data that Callgrind collects; it can also be used to visualise Cachegrind’s output.

可以下载kcachegrind源码,按照source中的README,编译,安装,比较简单。
kcachegrind源码下载链接:
http://kcachegrind.sourceforge.net/html/Download.html

编译,安装命令:

mkdir build

cd build

cmake …

Note:
执行cmake时遇到错误:
simh@hxdl:~/Downloads/kcachegrind-0.7.4/build$ cmake …
CMake Error at /usr/share/cmake-3.5/Modules/FindKDE4.cmake:111 (message):
ERROR: cmake/modules/FindKDE4Internal.cmake not found in
/home/huangxing/.kde/share/apps;/usr/share/kde4/apps
Call Stack (most recent call first):
CMakeLists.txt:5 (find_package)

sudo apt install kdelibs5-dev kdebase-apps
之后再执行cmake没有报错。

make

sudo make install

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值