Difference between revisions of "Valgrind"

[quality revision] [unchecked revision]
m
 


Template:ArticleMainWriter

Template:ArticleApprovedVersion


1 Article purpose[edit]

This article provides the basic information needed to start using the Linux application tool: valgrind[1].

2 Introduction[edit]

The following table provides a brief description of the tool, as well as its availability depending on the software packages:

Yes: this tool is either present (ready to use or to be activated), or can be integrated and activated on the software package.

No: this tool is not present and cannot be integrated, or it is present but cannot be activated on the software package.

Tool STM32MPU Embedded Software distribution STM32MPU Embedded Software distribution for Android™
Warning white.png Warning
STM32MPU Embedded Software distribution for Android™ is no more supported by ST. You can contact our ST partner, Witekio, who can help you to port and maintain it on STM32MP15 platform.
Name Category Purpose Starter Package Developer Package Distribution Package Starter Package Developer Package Distribution Package
valgrind Monitoring tools valgrind[1] is an instrumentation framework for building dynamic analysis tools. Some Valgrind tools can automatically detect many memory management and threading bugs, and profile your programs in detail.

This is tool for Linux application analysis.

Yes Yes Yes
Under construction.png Coming soon

3 Installing the trace and debug tool on your target board[edit]

3.1 Using the STM32MPU Embedded Software distribution[edit]

valgrind is installed by default and ready to be used with all STM32MPU Embedded Software Packages.

 which valgrind
/usr/bin/valgrind

valgrind is integrated in weston image distribution through openembedded-core package: openembedded-core/meta/recipes-core/packagegroups/packagegroup-core-tools-profile.bb.

VALGRIND = "valgrind"
...
RDEPENDS_${PN} = "\
   ${PROFILETOOLS} \
   ${LTTNGUST} \
   ${LTTNGTOOLS} \
   ${LTTNGMODULES} \
   ${BABELTRACE} \
   ${SYSTEMTAP} \
   ${VALGRIND} \
   "

3.2 Using the STM32MPU Embedded Software distribution for Android™[edit]

Under construction.png Coming soon

4 Getting started[edit]

Valgrind is designed to be as non-intrusive as possible. It works directly with existing executables/applications. It does not require to recompile, relink, or otherwise modify the program to be checked.

Here is a simple way to invoke valgrind:

 valgrind [valgrind-options] <Program><Program> [Prog_Args]

valgrind can be started without [valgrind-options]. More options can be turned on afterward, according the proposals provided in valgrind first-pass result.

Analysis is done during all phase of the program execution: program start, program run and program stop.

5 To go further[edit]

5.1 Example[edit]

  • Example of program analysis without any issue detected:
 valgrind /usr/local/bin/fooProg 
 ==351== Memcheck, a memory error detector
 ==351== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
 ==351== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
 ==351== Command: /usr/local/bin/fooProg
 ==351== 
 push_led application example started...
 Monitoring line 13 on /dev/gpiochip0
 ^C...push_led application example exit.
 ==351== 
 ==351== HEAP SUMMARY:
 ==351==     in use at exit: 0 bytes in 0 blocks
 ==351==   total heap usage: 2 allocs, 2 frees, 4,116 bytes allocated
 ==351== 
 ==351== All heap blocks were freed -- no leaks are possible
 ==351== 
 ==351== For counts of detected and suppressed errors, rerun with: -v
 ==351== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 3)
  • Example of program analysis with memory leak issue detected (i.e. missing memory-freeing):
 valgrind /usr/local/bin/fooProg
 ==360== Memcheck, a memory error detector
 ==360== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
 ==360== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
 ==360== Command: /usr/local/bin/fooProg
 ==360== 
 push_led application example started...
 Monitoring line 13 on /dev/gpiochip0
 ^C...push_led application example exit.
 ==360== 
 ==360== HEAP SUMMARY:
 ==360==     in use at exit: 20 bytes in 1 blocks
 ==360==   total heap usage: 2 allocs, 1 frees, 4,116 bytes allocated
 ==360== 
 ==360== LEAK SUMMARY:
 ==360==    definitely lost: 0 bytes in 0 blocks
 ==360==    indirectly lost: 0 bytes in 0 blocks
 ==360==      possibly lost: 0 bytes in 0 blocks
 ==360==    still reachable: 20 bytes in 1 blocks
 ==360==         suppressed: 0 bytes in 0 blocks
 ==360== Rerun with --leak-check=full to see details of leaked memory
 ==360== 
 ==360== For counts of detected and suppressed errors, rerun with: -v
 ==360== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 3)

The text highlighted in orange green in the above valgrind report suggests to turn on more options in order to focus on the reported issue.

6 References[edit]


  • Useful external links
Document link Document Type Description
Quick start User guide Official site
Wikipedia Wiki Documentation from Wikipedia
<noinclude>

{{ArticleBasedOnModel|[[Trace and debug tools article model]]}}
{{ArticleMainWriter|Jean-PhilippeR}}

{{ ArticleApprovedVersion | Jean-PhilippeR | Jean-ChristopheT | No previous approved version  | BrunoB - 08Oct'18 - 9114 | 10Oct'18 }}

[[Category:Linux monitoring tools]]</noinclude>


== Article purpose ==
This article provides the basic information needed to start using the Linux application tool: '''valgrind'''<ref name=valgrinddotorg/>.

== Introduction ==
{{:Trace_and_debug_tools_assignment_table_template}}<onlyinclude>

 | [[Valgrind|valgrind]]
 | [[:Category:Monitoring tools|Monitoring tools]]
 | style="text-align:left;" | '''valgrind'''<ref name=valgrinddotorg>http://valgrind.org/</ref>  is an instrumentation framework for building dynamic analysis tools. Some Valgrind tools can automatically detect many memory management and threading bugs, and profile your programs in detail.<br>

This is tool for Linux application analysis.
 | {{Y}} || {{Y}} || {{Y}}
 | colspan="3" | {{UnderConstruction}}
 |-</onlyinclude>

 |}

== Installing the trace and debug tool on your target board ==

=== Using the STM32MPU Embedded Software distribution ===
'''valgrind''' is installed by default and ready to be used with all STM32MPU  Embedded Software Packages. 
 {{Board$}} which valgrind
 /usr/bin/valgrind

'''valgrind''' is integrated in weston image distribution through openembedded-core package: ''openembedded-core/meta/recipes-core/packagegroups/packagegroup-core-tools-profile.bb''.
 VALGRIND = "valgrind"
 ...
 RDEPENDS_${PN} = "\
    ${PROFILETOOLS} \
    ${LTTNGUST} \
    ${LTTNGTOOLS} \
    ${LTTNGMODULES} \
    ${BABELTRACE} \
    ${SYSTEMTAP} \
    {{green|'''${VALGRIND}'''}} \
    "

=== Using the STM32MPU Embedded Software distribution for Android&trade; ===
{{UnderConstruction}}

== Getting started ==
Valgrind is designed to be as non-intrusive as possible. It works directly with existing executables/applications. It does not require to recompile, relink, or otherwise modify the program to be checked.

Here is a simple way to invoke valgrind:
 {{Board$}} valgrind {{orangeHighlightParam|[''valgrind-options''] <''Program''>''<Program>'' [''Prog_Args'']}}

valgrind can be started without [valgrind-options]. More options can be turned on afterward, according the proposals provided in valgrind first-pass result.

{{highlight|Analysis is done during all phase of the program execution: program start, program run and program stop.}}

== To go further ==
=== Example ===
* Example of program analysis without any issue detected:<br>

 {{Board$}} valgrind /usr/local/bin/fooProg 
  ==351== Memcheck, a memory error detector
  ==351== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
  ==351== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
  ==351== Command: /usr/local/bin/fooProg
  ==351== 
  push_led application example started...
  Monitoring line 13 on /dev/gpiochip0
  ^C...push_led application example exit.
  ==351== 
  ==351== '''HEAP SUMMARY''':
  ==351==     in use at exit: {{green|0 bytes in 0 blocks}}
  ==351==   total heap usage: {{green|2 allocs, 2 frees,}} 4,116 bytes allocated
  ==351== 
  ==351== {{green|All heap blocks were freed -- no leaks are possible}}
  ==351== 
  ==351== For counts of detected and suppressed errors, rerun with: -v
  ==351== '''ERROR SUMMARY''': {{green|0 errors from 0 contexts}} (suppressed: 6 from 3)

* Example of program analysis with memory leak issue detected (i.e. missing memory-freeing):<br>

 {{Board$}} valgrind /usr/local/bin/fooProg
  ==360== Memcheck, a memory error detector
  ==360== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
  ==360== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
  ==360== Command: /usr/local/bin/fooProg
  ==360== 
  push_led application example started...
  Monitoring line 13 on /dev/gpiochip0
  ^C...push_led application example exit.
  ==360== 
  ==360== '''HEAP SUMMARY''':
  ==360==     in use at exit: {{red|20 bytes in 1 blocks}}
  ==360==   total heap usage: {{red|2 allocs, 1 frees,}} 4,116 bytes allocated
  ==360== 
  ==360== '''LEAK SUMMARY''':
  ==360==    definitely lost: 0 bytes in 0 blocks
  ==360==    indirectly lost: 0 bytes in 0 blocks
  ==360==      possibly lost: 0 bytes in 0 blocks
  ==360==    {{red|still reachable: 20 bytes in 1 blocks}}
  ==360==         suppressed: 0 bytes in 0 blocks
  ==360== {{orangeHighlightParam|Rerun with --leak-check{{=}}full to see details of leaked memory}}
  ==360== 
  ==360== For counts of detected and suppressed errors, rerun with: -v
  ==360== '''ERROR SUMMARY''': 0 errors from 0 contexts (suppressed: 6 from 3)
The text highlighted in {{orange|orangeHighlightParam|green}} in the above valgrind report suggests to turn on more options in order to focus on the reported issue.

== References ==<references />


* Useful external links
{|
! scope=col | Document link
! scope=col | Document Type
! scope=col | Description
|-
| [http://valgrind.org/docs/manual/quick-start.html Quick start]
| User guide
| Official site
|-
| [https://en.wikipedia.org/wiki/Valgrind Wikipedia]
| Wiki
| Documentation from Wikipedia
|}
Line 51: Line 51:
   
 
Here is a simple way to invoke valgrind:
 
Here is a simple way to invoke valgrind:
  {{Board$}} valgrind {{orange|[''valgrind-options''] <''Program''> [''Prog_Args'']}}
+
  {{Board$}} valgrind {{HighlightParam|[''valgrind-options''] ''<Program>'' [''Prog_Args'']}}
   
 
valgrind can be started without [valgrind-options]. More options can be turned on afterward, according the proposals provided in valgrind first-pass result.
 
valgrind can be started without [valgrind-options]. More options can be turned on afterward, according the proposals provided in valgrind first-pass result.
Line 100: Line 100:
 
   ==360==    {{red|still reachable: 20 bytes in 1 blocks}}
 
   ==360==    {{red|still reachable: 20 bytes in 1 blocks}}
 
   ==360==        suppressed: 0 bytes in 0 blocks
 
   ==360==        suppressed: 0 bytes in 0 blocks
   ==360== {{orange|Rerun with --leak-check{{=}}full to see details of leaked memory}}
+
   ==360== {{HighlightParam|Rerun with --leak-check{{=}}full to see details of leaked memory}}
 
   ==360==  
 
   ==360==  
 
   ==360== For counts of detected and suppressed errors, rerun with: -v
 
   ==360== For counts of detected and suppressed errors, rerun with: -v
 
   ==360== '''ERROR SUMMARY''': 0 errors from 0 contexts (suppressed: 6 from 3)
 
   ==360== '''ERROR SUMMARY''': 0 errors from 0 contexts (suppressed: 6 from 3)
The text highlighted in {{orange|orange}} in the above valgrind report suggests to turn on more options in order to focus on the reported issue.
+
The text highlighted in {{HighlightParam|green}} in the above valgrind report suggests to turn on more options in order to focus on the reported issue.
   
 
== References ==
 
== References ==