143pi
Posts: 31
Joined: Sat Nov 14, 2015 6:25 pm

How to install Valgrind tool, will it work with raspbian?

Mon Nov 16, 2015 1:03 am

Hello everyone,

I want to check memory leaks in my program. I would link to know how to install Valgrind tool on Raspbian wheezy os..? Will it work on this OS. ? Please suggest me if you know any other methods/tools to check memory leaks.


Thank you

User avatar
rpdom
Posts: 15204
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: How to install Valgrind tool, will it work with raspbian

Mon Nov 16, 2015 5:40 am

sudo apt-get update ;#(this is just to update the software list)
sudo apt-get install valgrind

143pi
Posts: 31
Joined: Sat Nov 14, 2015 6:25 pm

Re: How to install Valgrind tool, will it work with raspbian

Mon Nov 16, 2015 10:43 am

I would like to know any other methods to check memory leaks in the program..

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23682
Joined: Sat Jul 30, 2011 7:41 pm

Re: How to install Valgrind tool, will it work with raspbian

Mon Nov 16, 2015 11:11 am

I wasn't able to get Valgrind working, but that was some time ago - it may have been fixed. But there are other memory tools available - I found one with a google search that found the problem i was looking for. Cannot remember the name of it though!
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: How to install Valgrind tool, will it work with raspbian

Mon Nov 16, 2015 12:19 pm

jamesh wrote:I wasn't able to get Valgrind working, but that was some time ago - it may have been fixed. But there are other memory tools available - I found one with a google search that found the problem i was looking for. Cannot remember the name of it though!
I recall getting it to work on my Pi2. I may be wrong, but it looked like it worked. I compiled it from source and since I'm using Ubuntu, it may have been compiled for v7.
There are 10 types of people: those who understand binary and those who don't.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23682
Joined: Sat Jul 30, 2011 7:41 pm

Re: How to install Valgrind tool, will it work with raspbian

Mon Nov 16, 2015 2:18 pm

kusti8 wrote:
jamesh wrote:I wasn't able to get Valgrind working, but that was some time ago - it may have been fixed. But there are other memory tools available - I found one with a google search that found the problem i was looking for. Cannot remember the name of it though!
I recall getting it to work on my Pi2. I may be wrong, but it looked like it worked. I compiled it from source and since I'm using Ubuntu, it may have been compiled for v7.
That's possible - it may be Arm11 that isn;t well supported on Valgrind.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

143pi
Posts: 31
Joined: Sat Nov 14, 2015 6:25 pm

Re: How to install Valgrind tool, will it work with raspbian

Thu Nov 19, 2015 9:28 pm

rpdom could you please tell me some steps to check with... explain in brief.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: How to install Valgrind tool, will it work with raspbian

Sun Nov 22, 2015 2:51 pm

143pi wrote:rpdom could you please tell me some steps to check with... explain in brief.
Valgrind works for me in Jessie, but not with all options that work on x86 debian. That's probably just because it's a somewhat older version though. Run 'valgrind --help' to see what's supported. You asked for valgrind on Wheezie, but I haven't tried. Sorry.

Code: Select all

sudo apt-get install valgrind
leakage.cpp:

Code: Select all

int main() {
	int *leak = new int[100];
	return 0;
}
Compile:

Code: Select all

g++ leakage.cpp -o leakage
Run valgrind:

Code: Select all

valgrind ./leakage
or:

Code: Select all

valgrind --leak-check=full ./leakage
Valgrind correctly reports 400 bytes lost.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

143pi
Posts: 31
Joined: Sat Nov 14, 2015 6:25 pm

Re: How to install Valgrind tool, will it work with raspbian

Tue Nov 24, 2015 8:34 pm

When I run valgrind --leak-check=full --show-leak-kinds=all ./a.out on raspberry pi2 ( 32 bit processor, Ubuntu-Mate OS )

==5739== LEAK SUMMARY:
==5739== definitely lost: 0 bytes in 0 blocks
==5739== indirectly lost: 0 bytes in 0 blocks
==5739== possibly lost: 355,811 bytes in 99 blocks
==5739== still reachable: 200,767 bytes in 1,037 blocks
==5739== of which reachable via heuristic:
==5739== newarray : 832 bytes in 16 blocks
==5739== suppressed: 0 bytes in 0 blocks
==5739==
==5739== For counts of detected and suppressed errors, rerun with: -v
==5739== ERROR SUMMARY: 22 errors from 9 contexts (suppressed: 0 from 0)

When I run valgrind --leak-check=full --show-leak-kinds=all ./a.out on VM Ubuntu OS ( 64 bit intel i5 processor)

==1607== LEAK SUMMARY:
==1607== definitely lost: 0 bytes in 0 blocks
==1607== indirectly lost: 0 bytes in 0 blocks
==1607== possibly lost: 728 bytes in 18 blocks
==1607== still reachable: 249,075 bytes in 892 blocks
==1607== of which reachable via heuristic:
==1607== newarray : 832 bytes in 16 blocks
==1607== suppressed: 0 bytes in 0 blocks
==1607==
==1607== ERROR SUMMARY: 18 errors from 18 contexts (suppressed: 0 from 0)
==1607== ERROR SUMMARY: 18 errors from 18 contexts (suppressed: 0 from 0)

1) Are there any memory leaks/corruption in my code..?
2) What does error summary indicate..?

fredkerr
Posts: 2
Joined: Fri Feb 02, 2018 11:32 pm

Re: How to install Valgrind tool, will it work with raspbian?

Fri Feb 02, 2018 11:35 pm

Hello,

I'll look for more "valgrind" posts, but I seem to get the same complaints on every program I run:

This example is from a simple hello.cpp:

==10238== Conditional jump or move depends on uninitialised value(s)
==10238== at 0x401B230: index (in /lib/arm-linux-gnueabihf/ld-2.24.so)
==10238== Uninitialised value was created by a stack allocation
==10238== at 0x4001AA0: handle_ld_preload (in /lib/arm-linux-gnueabihf/ld-2.24.so)

Thanks,
Fred

Heater
Posts: 13342
Joined: Tue Jul 17, 2012 3:02 pm

Re: How to install Valgrind tool, will it work with raspbian?

Fri Feb 02, 2018 11:57 pm

You might want to try using the clang/llvm compiler instead of GCC.
https://clang.llvm.org/

Then you can use clang's memory leak detector:
https://clang.llvm.org/docs/LeakSanitizer.html

Which is a lot better than valgrind.

To be honest, I'm don't recall if I have ever tried LeakSanitizer on a Pi. Generally I develop C/C++ code on a PC and then build and run it on a Pi or whatever. But it's worth an experiment I think.

jahboater
Posts: 4685
Joined: Wed Feb 04, 2015 6:38 pm

Re: How to install Valgrind tool, will it work with raspbian?

Sat Feb 03, 2018 8:34 am

Heater wrote:
Fri Feb 02, 2018 11:57 pm
You might want to try using the clang/llvm compiler instead of GCC.
https://clang.llvm.org/

Then you can use clang's memory leak detector:
https://clang.llvm.org/docs/LeakSanitizer.html

Which is a lot better than valgrind.

To be honest, I'm don't recall if I have ever tried LeakSanitizer on a Pi. Generally I develop C/C++ code on a PC and then build and run it on a Pi or whatever. But it's worth an experiment I think.
GCC supports the same sanitizers.
Use: -fsanitize=leak

From man gcc:-
"Enable LeakSanitizer, a memory leak detector. This option only matters for linking of
executables and the executable is linked against a library that overrides "malloc" and
other allocator functions. See
<https://github.com/google/sanitizers/wi ... kSanitizer> for more
details. The run-time behavior can be influenced using the LSAN_OPTIONS environment
variable. The option cannot be combined with -fsanitize=thread."

Heater
Posts: 13342
Joined: Tue Jul 17, 2012 3:02 pm

Re: How to install Valgrind tool, will it work with raspbian?

Sat Feb 03, 2018 9:40 am

GCC has been catching up with clang in the sanitizer department then.

Excellent. When did that happen ?

jahboater
Posts: 4685
Joined: Wed Feb 04, 2015 6:38 pm

Re: How to install Valgrind tool, will it work with raspbian?

Sat Feb 03, 2018 9:48 am

Heater wrote:
Sat Feb 03, 2018 9:40 am
GCC has been catching up with clang in the sanitizer department then.

Excellent. When did that happen ?
I don't know, a few releases ago. Copied from clang!

Return to “General discussion”