Page 1 of 1

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

Posted: Mon Nov 16, 2015 1:03 am
by 143pi
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

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

Posted: Mon Nov 16, 2015 5:40 am
by rpdom
sudo apt-get update ;#(this is just to update the software list)
sudo apt-get install valgrind

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

Posted: Mon Nov 16, 2015 10:43 am
by 143pi
I would like to know any other methods to check memory leaks in the program..

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

Posted: Mon Nov 16, 2015 11:11 am
by jamesh
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!

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

Posted: Mon Nov 16, 2015 12:19 pm
by kusti8
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.

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

Posted: Mon Nov 16, 2015 2:18 pm
by jamesh
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.

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

Posted: Thu Nov 19, 2015 9:28 pm
by 143pi
rpdom could you please tell me some steps to check with... explain in brief.

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

Posted: Sun Nov 22, 2015 2:51 pm
by panik
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.

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

Posted: Tue Nov 24, 2015 8:34 pm
by 143pi
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..?

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

Posted: Fri Feb 02, 2018 11:35 pm
by fredkerr
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

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

Posted: Fri Feb 02, 2018 11:57 pm
by Heater
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.

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

Posted: Sat Feb 03, 2018 8:34 am
by jahboater
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."

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

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

Excellent. When did that happen ?

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

Posted: Sat Feb 03, 2018 9:48 am
by jahboater
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!