Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable memleak option in gdb for linux

I am trying to see which process which is causing a memory leak, and dump the heap which is causing it to see what is the issue.

Which command do I use in gdb to set the memory leak on and check the heap?

I tried:

(gdb) check -leaks

checkpoint: can't find fork function in inferior.

(gdb) help info heap

Undefined info command: "heap".  Try "help info".

(gdb) help info leaks 

Undefined info command: "leaks".  Try "help info".
like image 512
user862833 Avatar asked Feb 08 '13 14:02

user862833


People also ask

How do I enable Kmemleak?

kmemleak can be enabled in the kernel configuration under Kernel hacking > Memory Debugging. I used to turn it off by default and enable it on demand by passing kmemleak=on to the kernel command line. If some leaks occur before kmemleak is initialized you may need to increase the “early log entries” value.

How do I enable GDB?

Go to your Linux command prompt and type “gdb”. Gdb open prompt lets you know that it is ready for commands. To exit out of gdb, type quit or q.


1 Answers

Valgrind is your answer as people have pointed out. Normally, Valgrind will only report errors at the end of your program's execution. You can link Valgrind with GDB (vgdb) to dump Valgrind stats during a program's execution while it's running under GDB.

Refer to a similar question asked:

Dumping contents of lost memory reported by Valgrind

like image 65
Forhad Ahmed Avatar answered Sep 28 '22 08:09

Forhad Ahmed