Difference between revisions of "Valgrind"
[quality revision] | [quality revision] |
(→Using the STM32MPU Embedded Software distribution for Android™)
|
(Merge articles)
|
Contents
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:
: this tool is either present (ready to use or to be activated), or can be integrated and activated on the software package.
: 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™
|
||||||||
---|---|---|---|---|---|---|---|---|---|---|
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. |
![]() |
![]() |
![]() |
![]() |
![]() ![]() |
![]() |
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]
3.2.1 Distribution Package[edit]
valgrind source code module is available Distribution Package in external/valgrind
.
- To compile it (ensure the build environment is correctly set):
- Check valgrind binary is available in system image:
- Push the binary and dependencies (libraries) to the remote target file system:
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> [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.
![]() |
Below information is related to the Android™ distribution
Android™ also propose a web page [2] about valgrind usage. Especially for using valgrind on an Android™ application. |
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 green in the above valgrind report suggests to turn on more options in order to focus on the reported issue.
6 References[edit]
- ↑ 1.01.1 http://valgrind.org/
- ↑ Use AddressSanitizer (ASan) for Android: https://source.android.com/devices/tech/debug/valgrindasan
- Useful external links
Document link | Document Type | Description |
---|---|---|
Quick start | User guide | Official site |
Wikipedia | Wiki | Documentation from Wikipedia |
== 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}} | {{N}} || {{N}} || {{Y}}N}}<ref>Use AddressSanitizer (ASan) for Android: https://source.android.com/devices/tech/debug/asan</ref> |-</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: <code>''openembedded-core/meta/recipes-core/packagegroups/packagegroup-core-tools-profile.bb''</code>. VALGRIND = "valgrind" ... RDEPENDS_${PN} = "\ ${PROFILETOOLS} \ ${LTTNGUST} \ ${LTTNGTOOLS} \ ${LTTNGMODULES} \ ${BABELTRACE} \ ${SYSTEMTAP} \ {{green|'''${VALGRIND}'''}} \ " === Using the STM32MPU Embedded Software distribution for Android™ === ====Distribution Package==== '''valgrind''' source code module is available Distribution Package in <code>''external/valgrind''</code>. *To compile it (ensure the build environment is correctly set): {{PC$}} cd $ANDROID_BUILD_TOP {{PC$}} mma valgrind *Check valgrind binary is available in system image: {{PC$}} ls out/target/product/{{HighlightParam|''<BoardId>''}}/system/bin/valgrind *Push the binary and dependencies (libraries) to the remote target file system: # Remount first the target file system with write access {{PC$}} adb root; adb remount {{PC$}} adb push out/target/product/{{HighlightParam|''<BoardId>''}}/system/bin/valgrind /system/bin/ {{PC$}} adb shell mkdir /system/lib/valgrind {{PC$}} adb push out/target/product/{{HighlightParam|''<BoardId>''}}/system/lib/valgrind/* /system/lib/valgrind/ {{PC$}} adb shell sync == == 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 {{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. {{highlight|Analysis is done during all phase of the program execution: program start, program run and program stop.}} {{Android| Android™ also propose a web page <ref>https://source.android.com/devices/tech/debug/valgrind</ref> about valgrind usage. {{Highlight|Especially for using valgrind on an Android™ application.}} }} == 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== {{HighlightParam|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 {{HighlightParam|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 |} {{ ArticleBasedOnModel | Trace and debug tools article model }} {{ PublicationRequestId | 9114 | 08Oct'18 }} [[Category:Linux monitoring tools]]
Line 10: | Line 10: | ||
This is tool for Linux application analysis. |
This is tool for Linux application analysis. |
||
| {{Y}} || {{Y}} || {{Y}} |
| {{Y}} || {{Y}} || {{Y}} |
||
− | | {{N}} || {{N}} || {{ |
+ | | {{N}} || {{N}} || {{N}}<ref>Use AddressSanitizer (ASan) for Android: https://source.android.com/devices/tech/debug/asan</ref>
|
|- |
|- |
||
</onlyinclude> |
</onlyinclude> |
||
Line 34: | Line 34: | ||
{{green|'''${VALGRIND}'''}} \ |
{{green|'''${VALGRIND}'''}} \ |
||
" |
" |
||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Getting started == |
== 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. |
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. |
||
Line 60: | Line 43: | ||
{{highlight|Analysis is done during all phase of the program execution: program start, program run and program stop.}} |
{{highlight|Analysis is done during all phase of the program execution: program start, program run and program stop.}} |
||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== To go further == |
== To go further == |