Using Valgrind on ARM Linux

Publisher:科技舞者Latest update time:2020-01-13 Source: eefocusKeywords:ARM  Linux  Valgrind Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Linux valgrind ported to ARM-Linux


 1. Cross-Compile


(1) Download and unzip Valgrind-3.11


(2) Modify the configuration


  Change armv7*) to armv7*|arm*)


(3) Execute configure


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


Note: CC=arm-linux-gcc. The reason why I didn’t use an absolute path like some blogs say is because I have soft-linked arm-linux-gcc to the actual gcc.


(4)make


(5)make install


2. Porting to ARM Development Board


Note: After make install, the bin/ and lib/ directories generated by the compilation are stored in the /opt/valgrind/lib directory on the PC. Copy the bin/ and lib/ directories in this directory separately, and do not copy the share/ and include/ directories, because the files are a bit large, and the include/ and share/ directories are not used on the development board.


  Create a "directory - /opt/valgrind/lib/valgrind/" on the ARM development board, and put the files (.so, .a, etc.) in the lib/directory just compiled above into the directory mentioned on the left (/opt/valgrind/lib/valgrind).


Note: The above step is very important. If you put it in the wrong place, when running the valgrind program, it will prompt "failed to start 'memcheck': No such file or directory".


3. Configuration and use on ARM


1. Error: When running "./valgrind ls", an error still occurred in "vgdb". The error prompt is:


[12:58:19]root@freescale ~/valgrind/valgrind/bin$ ./valgrind ls           

[12:58:19]==5978== Memcheck, a memory error detector

[12:58:19]==5978== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.

[12:58:19]==5978== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info

[12:58:19]==5978== Command: ls

[12:58:19]==5978== 

[12:58:20]==5978== error writing 36 bytes to shared mem /tmp/vgdb-pipe-shared-mem-vgdb-5978-by-root-on-???


A temporary solution was found on the webpage failure to run on armv6 following the armv6 legacy patches suggested by bug 276897, which is to temporarily disable "vgdb".


[12:54:55]root@freescale ~/valgrind/valgrind/bin$ ./valgrind --vgdb=no ls 

[12:54:55]==5976== Memcheck, a memory error detector

[12:54:55]==5976== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.

[12:54:55]==5976== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info

[12:54:55]==5976== Command: ls

[12:54:55]==5976== 

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

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

[12:54:57]==5976== Conditional jump or move depends on uninitialised value(s)

[12:54:57]==5976==    at 0x4909C98: index (in /lib/libc-2.11.1.so)

[12:54:57]==5976== 

[12:54:58]==5976== Conditional jump or move depends on uninitialised value(s)

[12:54:58]==5976==    at 0x4909D90: strcmp (in /lib/libc-2.11.1.so)

[12:54:58]==5976==    by 0x4910377: strcoll_l (in /lib/libc-2.11.1.so)

[12:54:58]==5976== 

[12:54:58]==5976== Conditional jump or move depends on uninitialised value(s)

[12:54:58]==5976==    at 0x4909D98: strcmp (in /lib/libc-2.11.1.so)

[12:54:58]==5976==    by 0x4910377: strcoll_l (in /lib/libc-2.11.1.so)


 2. LD_PRELOAD error


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


After checking the above error, I found that: "/opt/valgrind/lib/valgrind" lacks some ".so/shared dynamic libraries". I recompiled "Valgrind" and used "arm-linux-strip" to simplify the files and copied them successfully. The program also ran smoothly.


4. Introduction to Valgrind


1. What is Valgrind?


2. What can Valgrind do?


(1)「badapp.c」


 1 #include

 2 

 3 void f(void)

 4 {

 5  int* x = malloc(10 * sizeof(int));

 6  x[10] = 0;            // problem 1: heap block overrun

 7 }                         // problem 2: memory leak -- x not freed

 8 

 9 int main(void)

10 {

11  f();

12  return 0;

13 }


(2)


[15:20:06][15:20:06]==8399== Memcheck, a memory error detector

[15:20:06]==8399== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.

[15:20:06]==8399== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info

[15:20:06]==8399== Command: ./bad1pp1

[15:20:06]==8399== 

[15:20:07]connect fail. ip:10.167.13.207, strlen(ip):13. File:main.c, Line:696

[15:20:07]Internet Fail. File: main.c, Line: 2469

[15:20:08]==8399== Invalid write of size 4

[15:20:08]==8399==    at 0x8414: f (badapp1.c:6)

[15:20:08]==8399==    by 0x842F: main (badapp1.c:11)

[15:20:08]==8399==  Address 0x496f050 is 0 bytes after a block of size 40 alloc'd

[15:20:08]==8399==    at 0x483481C: malloc (in /opt/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)

[15:20:08]==8399== 

[15:20:08]==8399== 

[15:20:08]==8399== HEAP SUMMARY:

[15:20:08]==8399==     in use at exit: 40 bytes in 1 blocks

[15:20:08]==8399==   total heap usage: 1 allocs, 0 frees, 40 bytes allocated

[15:20:08]==8399== 

[15:20:08]==8399== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1

[15:20:08]==8399==    at 0x483481C: malloc (in /opt/valgrind/lib/valgrind/vgpreload_memcheck-arm-linux.so)

[15:20:08]==8399== 

[15:20:08]==8399== LEAK SUMMARY:

[15:20:08]==8399==    definitely lost: 40 bytes in 1 blocks

[15:20:08]==8399==    indirectly lost: 0 bytes in 0 blocks

[15:20:08]==8399==      possibly lost: 0 bytes in 0 blocks

[15:20:08]==8399==    still reachable: 0 bytes in 0 blocks

[15:20:08]==8399==         suppressed: 0 bytes in 0 blocks

[15:20:08]==8399== 

[15:20:08]==8399== For counts of detected and suppressed errors, rerun with: -v

[15:20:08]==8399== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 11 from 5)


3. How does Valgrind work?


4. Who developed Valgrind?


Julian Seward, from Cambridge, UK.


5. The origin of the name 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.

Keywords:ARM  Linux  Valgrind Reference address:Using Valgrind on ARM Linux

Previous article:ARM series STM32F103RCT6 development
Next article:ARM S3C2410 Learning Notes

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号