Linux valgrind 移植到ARM-Linux


 一、Cross-Compile/交叉编译

(1)下载及解压Valgrind-3.11

(2)修改confirure

  将armv7*)修改为armv7*|arm*)

(3)执行configure

./configure CC=arm-linux-gcc CPP=arm-linux-cpp CXX=arm-linux-g++  --host=arm-linux --prefix=/opt/valgrind/lib

注意:CC=arm-linux-gcc,之所以没有像有些博客上写的、用了绝对路径,是因为「我已经将arm-linux-gcc 软链接/soft-linke 到了实际的gcc」。

(4)make

(5)make install

二、移植到ARM开发板

注意:make install之后,编译生成的bin/和lib/目录存放在PC上的/opt/valgrind/lib目录下。将此目录下的bin/和lib/目录单独「复制/Copy」出来,不要Copy share/和include/目录,因为文件有点大,而且include/和share/这两个目录在开发板上没有用。

  在ARM开发板上建立「目录-/opt/valgrind/lib/valgrind/」,将上面刚刚编译得到的lib/目录下的文件(.so, .a 等)放到左边提到的这个目录(/opt/valgrind/lib/valgrind)中。

注意:上面这个步骤非常关键,如果放错位置,在运行程序valgrind的时候,会提示「failed to start 'memcheck' : No such file or directory」。

三、ARM上配置使用

1、Error:在运行「./valgrind ls」的时候依然碰到了一个错误,出现在「vgdb」。错误提示是:

[::]root@freescale ~/valgrind/valgrind/bin$ ./valgrind ls
[::]==== Memcheck, a memory error detector
[::]==== Copyright (C) -, and GNU GPL'd, by Julian Seward et al.
[::]==== Using Valgrind-3.11. and LibVEX; rerun with -h for copyright info
[::]==== Command: ls
[::]====
[::]==== error writing bytes to shared mem /tmp/vgdb-pipe-shared-mem-vgdb--by-root-on-???

在网页failure to run on armv6 following the armv6 legacy patches suggested by bug 276897找到了一个暂时的方法,就是临时禁用「vgdb」。

[::]root@freescale ~/valgrind/valgrind/bin$ ./valgrind --vgdb=no ls
[::]==== Memcheck, a memory error detector
[::]==== Copyright (C) -, and GNU GPL'd, by Julian Seward et al.
[::]==== Using Valgrind-3.11. and LibVEX; rerun with -h for copyright info
[::]==== Command: ls
[::]====
[::]ERROR: ld.so: object '/opt/valgrind/lib/valgrind/vgpreload_core-arm-linux.so' from LD_PRELOAD cannot be preloaded: ignored.
[::]ERROR: ld.so: object '/opt/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so' from LD_PRELOAD cannot be preloaded: ignored.
[::]==== Conditional jump or move depends on uninitialised value(s)
[::]==== at 0x4909C98: index (in /lib/libc-2.11..so)
[::]====
[::]==== Conditional jump or move depends on uninitialised value(s)
[::]==== at 0x4909D90: strcmp (in /lib/libc-2.11..so)
[::]==== by 0x4910377: strcoll_l (in /lib/libc-2.11..so)
[::]====
[::]==== Conditional jump or move depends on uninitialised value(s)
[::]==== at 0x4909D98: strcmp (in /lib/libc-2.11..so)
[::]==== by 0x4910377: strcoll_l (in /lib/libc-2.11..so)

2、LD_PRELOAD错误

[::]ERROR: ld.so: object '/opt/valgrind/lib/valgrind/vgpreload_core-arm-linux.so' from LD_PRELOAD cannot be preloaded: ignored.

上述的错误,经过检查,发现:「/opt/valgrind/lib/valgrind」缺少一些「.so/共享动态库」。重新编译「Valgrind」,并且用「arm-linux-strip」将文件进行精简,顺利复制。程序也顺利运行。

四、Valgrind简介

1、Valgrind是什么?

2、Valgrind能做什么?

(1)「badapp.c」

 #include <stdlib.h>

 void f(void)
{
int* x = malloc( * sizeof(int));
x[] = ;     // problem 1: heap block overrun
} // problem 2: memory leak -- x not freed int main(void)
{
f();
return ;
}

(2)

[::]<valgrind/bin/valgrind --vgdb=no --leak-check=full ./bad1pp1
[::]==== Memcheck, a memory error detector
[::]==== Copyright (C) -, and GNU GPL'd, by Julian Seward et al.
[::]==== Using Valgrind-3.11. and LibVEX; rerun with -h for copyright info
[::]==== Command: ./bad1pp1
[::]====
[::]connect fail. ip:10.167.13.207, strlen(ip):. File:main.c, Line:
[::]Internet Fail. File: main.c, Line:
[::]==== Invalid write of size
[::]==== at 0x8414: f (badapp1.c:)
[::]==== by 0x842F: main (badapp1.c:)
[::]==== Address 0x496f050 is bytes after a block of size alloc'd
[::]==== at 0x483481C: malloc (in /opt/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
[::]====
[::]====
[::]==== HEAP SUMMARY:
[::]==== in use at exit: bytes in blocks
[::]==== total heap usage: allocs, frees, bytes allocated
[::]====
[::]==== bytes in blocks are definitely lost in loss record of
[::]==== at 0x483481C: malloc (in /opt/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)
[::]====
[::]==== LEAK SUMMARY:
[::]==== definitely lost: bytes in blocks
[::]==== indirectly lost: bytes in blocks
[::]==== possibly lost: bytes in blocks
[::]==== still reachable: bytes in blocks
[::]==== suppressed: bytes in blocks
[::]====
[::]==== For counts of detected and suppressed errors, rerun with: -v
[::]==== ERROR SUMMARY: errors from contexts (suppressed: from )

3、Valgrind工作原理?

4、谁开发的Valgrind?

Julian Seward, from Cambridge, UK.

5、Valgrind的名称来源

From Nordic mythology. Originally (before release) the project was named Heimdall, after the watchman of the Nordic gods. He could "see a hundred miles by day or night, hear the grass growing, see the wool growing on a sheep's back" (etc). This would have been a great name, but it was already taken by a security package "Heimdal".

Keeping with the Nordic theme, Valgrind was chosen. Valgrind is the name of the main entrance to Valhalla (the Hall of the Chosen Slain in Asgard). Over this entrance there resides a wolf and over it there is the head of a boar and on it perches a huge eagle, whose eyes can see to the far regions of the nine worlds. Only those judged worthy by the guardians are allowed to pass through Valgrind. All others are refused entrance.

It's not short for "value grinder", although that's not a bad guess.

参考:Where does the name 'Valgrind' come from?

6、如何利用Valgrind结果?


参考:

1、应用 Valgrind 发现 Linux 程序的内存问题

2、Valgrind 基础

3、Valgrind Frequently Asked Questions

4、Valgrind官网

5、Valgrind Guide

6、Valgrind Quick Start

在ARM Linux 使用 Valgrind的更多相关文章

  1. linux下valgrind的使用概述

    Valgrind简介: Valgrind是动态分析工具的框架.有很多Valgrind工具可以自动的检测许多内存管理和多进程/线程的bugs,在细节上剖析你的程序.你也可以利用Valgrind框架来实现 ...

  2. Linux下Valgrind的使用概述 来源:Linux社区 作者:dndxhej

    本地使用情况,在Ubantu系统上编写的测试性能: 1,下载:sudo apt-get install valgrind; 2,验证是否安装成功:试着valgrind ls -l来检测是否正常工作: ...

  3. ARM Linux Qt 5.x.x 无标题栏

    /********************************************************************************* * ARM Linux Qt 5. ...

  4. 构建 ARM Linux 4.7.3 嵌入式开发环境 —— BusyBox 构建 RootFS

    上一篇我们已经成功将 ARM Linux 4.7.3 的内核利用 U-BOOT 引导了起来.但是细心的你会发现,引导到后面,系统无法启动,出现内核恐慌 (Kernel Panic). 原因是找不到文件 ...

  5. 构建 ARM Linux 4.7.3 嵌入式开发环境 —— U-BOOT 引导 Kernel

    经过若干天的反复测试,搜索.终于成功利用 Qemu 在 u-boot 下引导 ARM Linux 4.7.3 内核.如下详细解释整个构建过程. 准备环境 运行环境:Ubuntu 16.04 需要的虚拟 ...

  6. ARM Linux 3.x的设备树(Device Tree)

    http://blog.csdn.net/21cnbao/article/details/8457546 宋宝华 Barry Song <21cnbao@gmail.com> 1.     ...

  7. ARM Linux启动代码分析

    前言 在学习.分析之前首先要弄明白一个问题:为什么要分析启动代码? 因为启动代码绝大部分都是用汇编语言写的,对于没学过或者不熟悉汇编语言的同学确实有一定难度,但是如果你想真正深入地学习Linux,那么 ...

  8. ARM Linux 3.x的设备树(Device Tree)

    1. ARM Device Tree起源 Linus Torvalds在2011年3月17日的ARM Linux邮件列表宣称“this whole ARM thing is a f*cking pai ...

  9. ARM Linux从Bootloader、kernel到filesystem启动流程

    转自:http://www.veryarm.com/1491.html ARM Linux启动流程大致为:bootloader ---->kernel---->root filesyste ...

随机推荐

  1. 如何获取、下载、安装fortran编译工具ifort

    今天接触到ifort,不知如何下载安装.遂GOOGLE之,很多文章给出连接并表示说在网页上下载即可.可往往事与愿违,新的问题是:链接已经失效:获取ifort的办法又不同了: 于是,我探索到新的获取安装 ...

  2. iOS设备的硬件适配 (关于armv6, armv7, armv7s ) <转>

    <转> http://blog.csdn.net/smking/article/details/8148702 1.OpenGL ES版本支持   iPhone:iPhone 3G以下(包 ...

  3. Ⅴ.spring的点点滴滴--引用其他对象或类型的成员

    承接上文 引用其他对象或类型的成员 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class Person { public string Name { ...

  4. ABAP程序相互调用--SUBMIT

    (1) 调用其他程序: * Trigger the IDOC SUBMIT zpcppmd001_idoc AND RETURN. (2) 调用其他程序参数传递参数: *当被调用的程序的屏幕有输入参数 ...

  5. 我这个IOS渣渣又来写随笔了

    我这个渣渣又来写了,哎,今天看了一篇大神面试别人的文章,感觉还有很遥远的路要走,不过没关系,还年轻,才入ios两个月,我相信自己的学习能力,加油! 博客园会是我成长的见证!

  6. 【JavaScript】出现即使设置了ID也获取不到的可能原因与window.onload

    有时候.在JavaScript中.即使设置了ID也有可能出现document.getElementById()获取不到的情况,然后你就開始想document是否写错之类的.事实上根本就不是你的代码的大 ...

  7. 微软正式提供Visual Studio 2013正式版下载(附直接链接汇总)

    转自 http://www.iruanmi.com/visual-studio-2013/ 微软已经向MSDN订阅用户提供了Visual Studio 2013正式版镜像下载,只是非MSDN用户能够在 ...

  8. Android开发书籍推荐

    当你看到这些文字时,那么恭喜你,你可能选择了一个无限可能的方向. Android,Google出品,信誉保证,你值得深入研究. 学习一样新事物或许有多种方式,报培训班,看视频,向高手请教等等,但一本好 ...

  9. C# 算速表达式

              public object ComputeExpression(string expression)         {             var result = new  ...

  10. [置顶] android LBS的研究与分享(附PPT)

    早上起床后想想以前的工作有什么可以分享的... 两年前,前公司在做一个陌生人交友的社交软件(比陌陌还早),需要研究LBS的相关工作(这里面主要研究的是Google定位)... 一.简要调研结果 很多 ...