| View previous topic :: View next topic |
| Author |
Message |
Dimitry Timokhov Guest
|
Posted: Wed Apr 11, 2007 1:01 am Post subject: FastMM and strange stack |
|
|
Hi, everone.
1) Short introduction
I'm using features of FastMM very intensive to find out my own errors and
memory leaks. Of course to do it i use FullDebugMode.
I notice that sometime stack has unexpected functions. But if i use my own
mind to find out the source of the error then i could use sophisticated way
of thinking to eliminate unexpected functions in displayed stack. In one
word - every time i receive the error report from FastMM i could find out
the source of the problem.
2) Situation
I decided to use generated report for automatic processing.
3) Problem
If unexpected functions present in stack then it is a real problem to use
automatic processing.
4) Example
This code
////////////// PROGRAM
{$o-}
program StackProblem;
uses
FastMM4,
StackProblemUnit in 'StackProblemUnit.pas';
begin
Test1();
end.
////////////// UNIT
{$o-}
unit StackProblemUnit;
interface
procedure Test2();
procedure Test1();
implementation
procedure Test2();
begin
TObject.Create();
end;
procedure Test1();
var
O: TObject;
begin
O := TObject.Create();
O.Free();
Test2();
end;
end.
generates this stack
Stack trace of when this block was allocated (return addresses):
402E0E [FastMM4Messages.pas][System][System.@GetMem][138]
40323B [FastMM4Messages.pas][System][System.TObject.NewInstance][138]
40338E [FastMM4Messages.pas][System][System.@ClassCreate][138]
403270 [FastMM4Messages.pas][System][System.TObject.Create][138]
403259 [FastMM4Messages.pas][System][System.TObject.FreeInstance][138]
////////// Why is there this function?
4033D9 [FastMM4Messages.pas][System][System.@ClassDestroy][138] //////////
Why is there this function?
403292 [FastMM4Messages.pas][System][System.TObject.Destroy][138] //////////
Why is there this function?
408148 [StackProblemUnit.pas][StackProblemUnit][StackProblemUnit.Test2][9]
40816C [StackProblemUnit.pas][StackProblemUnit][StackProblemUnit.Test1][17]
4090E9
I had seen similar behaviour in another situations.
5) Question
It would be great to know for sure - where the problem is. Why cannot FastMM
create correct stack?
a) Is it consequence of Windows architecture?
b) OR it is consequence of Delphi code generation?
c) OR Is it problem of FastMM?
I'm not good in asm and in system programing. Therefore i cannot find out
the answer myself.
Thank u a lot!
--
Regards,
Dimitry Timokhov |
|
| Back to top |
|
 |
Pierre le Riche Guest
|
Posted: Wed Apr 11, 2007 8:11 am Post subject: Re: FastMM and strange stack |
|
|
Hi Dimitry,
| Quote: | It would be great to know for sure - where the problem is. Why cannot
FastMM create correct stack?
|
Stack tracing is an inexact science. What the stack tracer does is examine
stack entries below the current stack top and from that try to figure out
the sequence of calls that lead up to that point. It is not 100% accurate,
but you can get good results with a little help from the compiler: If you
switch on "Use Stack Frames" in Compiler Options and disable the
"RawStackTraces" option in FastMM you should get better stack traces (at the
cost of slower code).
Regards,
Pierre |
|
| Back to top |
|
 |
Dimitry Timokhov Guest
|
Posted: Thu Apr 12, 2007 11:44 pm Post subject: Re: FastMM and strange stack |
|
|
Thank you, Pierre.
I've just tested your advice.
I notice that many of unexpected functions are disappeared. But i notice
that some of *expected* functions are also disappeared.
Am i right saying that there is no way to get exact stack?
--
Regards,
Dimitry Timokhov
| Quote: | Stack tracing is an inexact science. What the stack tracer does is examine
stack entries below the current stack top and from that try to figure out
the sequence of calls that lead up to that point. It is not 100% accurate,
but you can get good results with a little help from the compiler: If you
switch on "Use Stack Frames" in Compiler Options and disable the
"RawStackTraces" option in FastMM you should get better stack traces (at
the cost of slower code). |
|
|
| Back to top |
|
 |
Hallvard Vassbotn Guest
|
Posted: Fri Apr 13, 2007 12:50 am Post subject: Re: FastMM and strange stack |
|
|
"Dimitry Timokhov" <timokhov (AT) gmail (DOT) com> wrote:
| Quote: | But i notice that some of *expected* functions are also disappeared.
|
The Delphi compiler has an issue with the "Use Stack Frames" option - it
does not always generate one for small and simple functions.
| Quote: | Am i right saying that there is no way to get exact stack?
|
Short answer: Yes. |
|
| Back to top |
|
 |
Dimitry Timokhov Guest
|
Posted: Fri Apr 13, 2007 1:02 am Post subject: Re: FastMM and strange stack |
|
|
| Quote: | The Delphi compiler has an issue with the "Use Stack Frames" option - it
does not always generate one for small and simple functions.
|
Yea, sure u are right - i have mentioned that for simple functions like B:
function A(): Integer; begin ....end;
function B(): Integer; begin Result := A(); end;
Delphi doesn't generates stack frame.
| Quote: | Am i right saying that there is no way to get exact stack?
Short answer: Yes.
 |
---
Regards,
Dimitry |
|
| Back to top |
|
 |
|