svperbeast / mem_trace

traces memory allocation/deallocation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bash:

$ LD_PRELOAD=<mem_trace.so path> <your program>

or

% export LD_PRELOAD=<mem_trace.so path>

% run your program

after checking the report, reset LD_PRELOAD.

% export LD_PRELOAD=

output:

$ cat mem_trace.out
[0xb7ff72ed]	malloc 5 byte(s) lost.
[0xb7f01000]	__strdup
[0x8048406]	func (test.c:7)
[0x8048432]	main (test.c:24)
[0xb7ea0685]	__libc_start_main

addr2line doesn't exist:

* To examine caller address

Linux:

$ ./tp
malloc: using trace hooks..ok
free: using trace hooks..ok
caller addr: 0x8048411

$ gdb ./tp
...
(gdb) dissassemble 0x8048411
Dump of assembler code for function main:
0x080483f4 <main+0>:	lea    0x4(%esp),%ecx
0x080483f8 <main+4>:	and    $0xfffffff0,%esp
0x080483fb <main+7>:	pushl  -0x4(%ecx)
0x080483fe <main+10>:	push   %ebp
0x080483ff <main+11>:	mov    %esp,%ebp
0x08048401 <main+13>:	push   %ecx
0x08048402 <main+14>:	sub    $0x14,%esp
0x08048405 <main+17>:	movl   $0x20,(%esp)
0x0804840c <main+24>:	call   0x804832c <malloc@plt>  <--- HERE!
0x08048411 <main+29>:	mov    %eax,-0x8(%ebp)         <--- mem_trace.so report
...

SunOS:

$ LD_PRELOAD=./mem_trace.so ./tp
malloc: using trace hooks..ok
free: using trace hooks..ok
caller addr: 0x10698

% gdb ./tp
...
(gdb) disass main
Dump of assembler code for function main:
0x00010688 <main+0>:    save  %sp, -120, %sp
0x0001068c <main+4>:    st  %i0, [ %fp + 0x44 ]
0x00010690 <main+8>:    st  %i1, [ %fp + 0x48 ]
0x00010694 <main+12>:   mov  0x20, %o0
0x00010698 <main+16>:   call  0x20808 <malloc@plt>  <--- mem_trace.so report
...

About

traces memory allocation/deallocation


Languages

Language:C 100.0%