交叉编译Valgrind

交叉编译Valgrind

1.Valgrind

1.1 下载valgrind

官网 http://valgrind.org/downloads/  下载源码包

tar xvf valgrind-3.15.0.tar.bz2

cd valgrind-3.15.0

apt-get install automake

./autogen.sh

1.2 修改configure文件

armv7*) 改成 armv7*|arm)

1.3 编译

sudo ./configure --host=arm-linux-gnueabihf --prefix=/usr/local/valgrind CC=arm-linux-gnueabihf-gcc CPP=arm-linux-gnueabihf-cpp CXX=arm-linux-gnueabihf-g++

make -j14       //根据自己的CPU核心数来选,不然编译有点久

make install


–prefix=/usr/local/valgrind指定的目录要与开发板上放置的目录一致,不然运行valgrind时可能会出现“valgrind: failed to start tool ‘memcheck’ for platform ‘arm-linux’: No such file or directory”错误。

1.4 裁剪

rm -r  /usr/local/valgrind/shared
rm -r  /usr/local/valgrind/include

精简/usr/local/valgrind/lib/valgrind目录,精简后如下.

32bit-core-valgrind-s1.xml   32bit-sse.xml                arm-with-vfpv3.xml
32bit-core-valgrind-s2.xml   arm-core-valgrind-s1.xml     default.supp
32bit-core.xml               arm-core-valgrind-s2.xml     getoff-arm-linux
32bit-linux-valgrind-s1.xml  arm-core.xml                 memcheck-arm-linux
32bit-linux-valgrind-s2.xml  arm-vfpv3-valgrind-s1.xml    vgpreload_core-arm-linux.so
32bit-linux.xml              arm-vfpv3-valgrind-s2.xml    vgpreload_memcheck-arm-linux.so
32bit-sse-valgrind-s1.xml    arm-vfpv3.xml
32bit-sse-valgrind-s2.xml    arm-with-vfpv3-valgrind.xml

1.5 拷贝valgrind到开发板

直接把/usr/local/valgrind拷贝到网关

把工具添加到/etc/profile

#valgrind
export PATH=/usr/local/valgrind/bin:$PATH

1.6 报错说 ld-linux.so.3 不是debug版本

valgrind ls -l
 ==1298== Memcheck, a memory error detector
 ==1298== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
 ==1298== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
 ==1298== Command: ls -l
 ==1298== 

 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:      memcpy
 valgrind:  in an object with soname matching:   ld-linux.so.3
 valgrind:  was not found whilst processing
 valgrind:  symbols from the object with soname: ld-linux.so.3
 valgrind:  

正常能被debug的库长这样子,valgrind就是靠监听系统malloc的库的debug信息分析内存泄露的,所以一定要debug版本
在这里插入图片描述

网上找了一大圈,都是

  • 查看网关glibc版本
  • 下载对应版本 glibc-2.19.tar.bz2
  • 编译configure
  • 安装
  • 替换 ld-2.19.so \ libc-2.19.so 这两个文件

我编译了,替换以后虽然当时可以用,但重启后文件系统崩了!!!

Freeing init memory: 312K
/sbin/init: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
Kernel panic - not syncing: Attempted to kill init!
[] (unwind_backtrace+0x0/0x138) from [] (dump_stack+0x20/0x24)
[] (dump_stack+0x20/0x24) from [] (panic+0x78/0x194)
[] (panic+0x78/0x194) from [] (complete_and_exit+0x0/0x2c)
[] (complete_and_exit+0x0/0x2c) from [] (do_group_exit+0x5c/0xb4)
[] (do_group_exit+0x5c/0xb4) from [] (__wake_up_parent+0x0/0x30)
[] (__wake_up_parent+0x0/0x30) from [] (ret_fast_syscall+0x0/0x30)

最后想了一下,文件系统的库,不就是从交叉编译工具里面来的嘛,
最后从交叉编译工具里面找到了两个库,换进去完事了

cp ~/mint/am3352-arm-linux-gcc/gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux/arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf/

参考https://blog.csdn.net/qq_34743935/article/details/105682653
参考https://www.valgrind.org/downloads/

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
交叉编译valgrind可以按照以下步骤进行操作: 1. 首先,确保你已经正确配置了交叉编译环境,并且已经安装了交叉编译工具链。 2. 下载valgrind的源代码,并解压缩。 3. 进入valgrind源代码目录,执行以下命令进行配置: ``` ./configure --host=<目标平台> --prefix=<安装路径> ``` 其中,`<目标平台>`是你要交叉编译的目标平台,比如arm-linux,`<安装路径>`是你要安装valgrind的路径。 4. 执行make命令进行编译: ``` make ``` 5. 编译完成后,执行make install命令进行安装: ``` make install ``` 6. 在目标板上设置valgrind的环境变量,可以通过在/etc/profile文件中添加以下内容: ``` export PATH=<安装路径>/bin:$PATH export VALGRIND_LIB=<安装路径>/lib/valgrind ``` 注意将`<安装路径>`替换为你实际的安装路径。 7. 保存/etc/profile文件,并执行以下命令使环境变量生效: ``` source /etc/profile ``` 这样,你就可以在目标板上使用交叉编译valgrind了。请注意,根据你的具体情况,可能需要根据错误提示进行一些额外的配置或调整。 #### 引用[.reference_title] - *1* *2* [Valgrind交叉编译(踩坑)](https://blog.csdn.net/weixin_41791581/article/details/127290653)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [交叉编译Valgrind](https://blog.csdn.net/Reasonss/article/details/111218224)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

交叉编译之王 hahaha

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值