Track memory leaks and Memguard (solved? and some infos)

6 posts / 0 new
Last post
YesCop
YesCop's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2011-05-17 15:07
Track memory leaks and Memguard (solved? and some infos)

Hi Coders,

Well I would like to track some memory leaks in my C++ progs (uses of new and delete).
I tried the "include .h sources" like mem* (don't remember the names), i.e. include some redefinitions of new methods. Not useful here.

I tried to use memguard.
I use it by launching memguard -client name_of_prog (here jeu).

The output is written below :

4 buckets of 1024 used, max chain size 1, avg 1, total 4
512 bytes overhead caused by walls
1 MemHeaders allocated, that's 65504 bytes, 57008 bytes are free
526 allocations were tracked by this program, 522 are already freed
Task: [4] "jeu" (556706C0) -- 583AB040 = AllocVec(1064, 00001000)
LR 01923088 : "Kickstart/dos.library.kmod" offset 0000 segment 33844
CTR 6F8DC950 : "MemGuard" offset 0005 segment 8948
Task: [4] "jeu" (556706C0) -- 586DA040 = AllocVec(1064, 00001000)
LR 01923088 : "Kickstart/dos.library.kmod" offset 0000 segment 33844
CTR 6F8DC950 : "MemGuard" offset 0005 segment 8948
Task: [4] "jeu" (556706C0) -- 583AB9E0 = AllocVec(1064, 00001000)
LR 01923088 : "Kickstart/dos.library.kmod" offset 0000 segment 33844
CTR 6F8DC950 : "MemGuard" offset 0005 segment 8948
Task: [4] "jeu" (556706C0) -- 586DA9E0 = AllocVec(1064, 00001000)
LR 01923088 : "Kickstart/dos.library.kmod" offset 0000 segment 33844
CTR 6F8DC950 : "MemGuard" offset 0005 segment 8948

I have two questions.
First how can I use that output ? I tried to addr2line -e jeu -j .text adresss, but I have the classic ??:0 or the source line of thomas Frieden...
Second what are the use of parameters of memguard ?
I don't really understand them like PreSize and PostSize.

Thanks for your replies.
YesCop

EDIT:
I write here my last investigations and answers from Stephan, the author of Memguard.
The meaning of presize and post size is simple. It is just the size of extra allocated bytes (64 by default) before and after the asked allocated memory.
The goal is to test illegal memory access.


Task: [4] "jeu" (556706C0) -- 586DA9E0 = AllocVec(1064, 00001000)
LR 01923088 : "Kickstart/dos.library.kmod" offset 0000 segment 33844
CTR 6F8DC950 : "MemGuard" offset 0005 segment 8948

I will explain these lines.

556706C0 :
address of the task "jeu"

586DA9E0 = AllocVec(1064, 00001000) :
address of the allocated memory, 1064 bytes.

01923088 :
the link register.
from Stephan : "which usually holds the return address, points
to dos.library, so the allocation wasn't done by your program (it just
happened inside the context of your task/process)."

6F8DC950 :
From Stephan : "Counter register, just like the LR (link register), can be used to perform jumps to other addresses"

So, the LR line is associated to dos.library, the allocation is done by it.
I am happy because I have no memory leaks, I am a good coder :)
But I am worried about that allocation, it may appear that it is not always returned or is it just an illusion ?

YesCop
YesCop's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2011-05-17 15:07
Hi everybody, I see there

Hi everybody,

I see there are some viewers but no answer.
I am sure all the coders would want to know the answer so if Stephan (the author of memguard) is around, let him speak...

I hope I will have an answer.

YesCop

kas1e
kas1e's picture
Offline
Last seen: 3 months 5 days ago
Joined: 2010-11-30 15:30
??:0 mean that address are

??:0 mean that address are wrong , or just binary not have debug information. To make addr2line works at all, all your code (and all the objects, and final linking) should have -g option, which will put to the binary debug information for you (which, will be used by addr2line, to provide you line of source code). Not -ggdb and not others, but -g (other one can works, and can not works, depends).

Related to memguard: which addresses you spawn to addr2line ? LR ones or other ones ? Did you have -g for your binary at all ?

Menthos
Menthos's picture
Offline
Last seen: 12 years 12 months ago
Joined: 2011-04-18 10:38
It would be good to have some

It would be good to have some tutorials for how to debug applications in OS4. Walkero made a Blog here about getting started with programming. Who continues with how to use memguard and other tools to find bugs in the programs (yes, I want to know also about this)?

Tutorials on every aspect of OS4 development is something that is really lacking...

/M.Andersson, Viking Technology

YesCop
YesCop's picture
Offline
Last seen: 4 years 3 months ago
Joined: 2011-05-17 15:07
Hi, Thanks for your reply. I

Hi,

Thanks for your reply. I will test as soon as possible your solution.
And Menthos will be pleased.
I choose all adresses as I hadn't no solution at all... Despair....

See you soon,
YesCop

EDIT:

I had some time with no luck.
I compiled and linked with -g (I used -gstabs) with others parameters or alone (to see if some are intefering).
I used ALL the adresses, I always had the ??:0.
I could conclude as you wrote, all the address are fake. Memguard bug ?

The only informations I had are :
addr2line -e jeu --section=.text 33844
33844 segment adress in Kickstart line
/home/tfrieden/source/adtools/gcc-build/ppc-amigaos/libstdc++-v3/include/bits/locale_facets.tcc:90

addr2line -e jeu --section=.text 8948
8948 segment adress in Memguard line
/gcc/lib/gcc/ppc-amigaos/4.2.4/../../../../include/c++/4.2.4/ext/new_allocator.h:0

EDIT2:

Well I tested memguard with a prog created to test it.
I created some pointers, tab of pointers (int and a class).
I disabled some delete but Memguard didn't detect the memory links unlike Memguardian did.
I repeat my question, any of you and especially the author could explain how Memguard could be used to track memory leaks. If not, Memguard is useless because it seems to be the only program to resolve this kind of problem.

kas1e
kas1e's picture
Offline
Last seen: 3 months 5 days ago
Joined: 2010-11-30 15:30
@YesCop Sorry, i am not

@YesCop

Sorry, i am not professional with MemGuard, but just some notice:

-- As i know, memguard have different options, so with one you can catch something, with other are not. By default memguard can catch that and that, but without some flags in command line can't catch other moments.
-- 33844 address point on locale_facets.tcc:90 offset 0 - need to check that
-- 8948 address point on new_allocator.h:0 ofsset 5 - so let's try addr2line with 8948+5 = 894d, maybe it will point on exactly functon (like NEW), so you can check these ones in the source.

Try to write also mails directly to authors of memguard an memguardian, maybe you will have luck with it (Juha Niemimaki & Stephan Rupprecht). Also try to check DOCS/develop/kernel (or kind)in the SDK, there was some info about inbuild memguard-kind code in the kernel.debug.kmod.

Log in or register to post comments