valgrind在Hi3559A上的尝试

simonhuang 2018-10-24 14:39:45 9380

下载valgrind源码

两种方式(任选其一)
1)登录http://valgrind.org/downloads/ 下载压缩包

2)git clone git://sourceware.org/git/valgrind.git

基于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 (C) 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 $(OSDRV_DIR)/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 (C) 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

打开工具试验:
kcachegrind

声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包 点赞 收藏 评论 打赏
评论
1个
内容存在敏感词
手气红包
  • 2024-06-01 15:49:55
    回复
    build.sh脚本 ./configure \ --prefix="/home/valgrind_install" \ CC=/opt/public/gcc/hisi-linux/x86-arm/aarch64-mix410-linux/bin/aarch64-mix410-linux-gcc \ CXX=/opt/public/gcc/hisi-linux/x86-arm/aarch64-mix410-linux/bin/aarch64-mix410-linux-g++ \ CPP=/opt/public/gcc/hisi-linux/x86-arm/aarch64-mix410-linux/bin/aarch64-mix410-linux-cpp \ AR=/opt/public/gcc/hisi-linux/x86-arm/aarch64-mix410-linux/bin/aarch64-mix410-linux-ar \ RANLIB=/opt/public/gcc/hisi-linux/x86-arm/aarch64-mix410-linux/bin/aarch64-mix410-linux-ranlib \ --target=aarch64-mix410-linux \ --host=aarch64-mix410-linux \ --program-prefix=hisi- 运行: ./build.sh make -j8 sudo make install 安装之后,把valgrind_install拷贝到海思的板子里面去, 然后在板子上运行 export VALGRIND_LIB='/home/valgrind_install/lib/valgrind' ./hisi-valgrind --help 出现错误,找不到memcheck valgrind: failed to start tool 'memcheck' for platform 'arm64-linux': No such file or directory valgrind的版本为valgrind-3.23.0
相关专栏
关于作者
simonhuang

simonhuang

暂无个性签名~

原创2
阅读1.4w
收藏0
点赞0
评论2
打赏用户 0
我要创作
分享技术经验,可获取创作收益
分类专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
simonhuang
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区