UPX completely messes up leak report
Posted: Tue Jan 19, 2021 8:30 pm
I started to experiment with MadExcept in my home projects - mainly to be able to fill the stack trace of exception objects. As I accomplished that, I looked into the leak reporting - FastMM shipped with Delphi is really crippled, it's nice to have a stack trace.
All is working fine. Debug or Release config, my test leak shows up just fine... until I UPX the executable. I left a leak in a frame constructor to check and after UPX, objects do not even show up anymore (only GetMem and UnicodeString) and they point to a unit initialization stack rather than a button click -> frame constructor.
For home, I prohibited MadExcept to adjust project clauses, complier and linker options or conditional defines. I have a small unit which acts as a wrapper for MadExcept, it is added as the first unit in the project:
Unit uMyMadExcept;
Interface
This is my first experience with MadExcept, especially by not using the package directly. Can someone assist me in pointing out where my logic is flawed?
Thanks!
All is working fine. Debug or Release config, my test leak shows up just fine... until I UPX the executable. I left a leak in a frame constructor to check and after UPX, objects do not even show up anymore (only GetMem and UnicodeString) and they point to a unit initialization stack rather than a button click -> frame constructor.
For home, I prohibited MadExcept to adjust project clauses, complier and linker options or conditional defines. I have a small unit which acts as a wrapper for MadExcept, it is added as the first unit in the project:
Unit uMyMadExcept;
Interface
Code: Select all
Uses MadExcept;
Type
TLeakDetectedMethod = Reference To Procedure(Const inLeakText: String);
Var
OnLeakDetected: TLeakDetectedMethod;
Procedure EnableLeakChecking;
Implementation
Uses System.SysUtils;
Procedure EnableLeakChecking;
Begin
WaitForCleanExitProcess(True);
ShowNoLeaksWindow(False);
ShowLeakProgressWindow(False);
SetChildLeakFiltering(True);
StartLeakChecking;
End;
Function GetExceptionStackInfoProc(P: PExceptionRecord): Pointer;
Var
stacktrace: String;
Begin
stacktrace := GetCrashStackTrace(True);
Result := StrAlloc(Length(stacktrace));
StrCopy(Result, PChar(stacktrace));
End;
Function GetStackInfoStringProc(Info: Pointer): String;
Begin
Result := PChar(Info);
End;
Procedure CleanUpStackInfoProc(Info: Pointer);
Begin
StrDispose(PChar(Info));
End;
Initialization
OnLeakDetected := nil;
Exception.GetExceptionStackInfoProc := GetExceptionStackInfoProc;
Exception.GetStackInfoStringProc := GetStackInfoStringProc;
Exception.CleanUpStackInfoProc := CleanUpStackInfoProc;
{$IFDEF DEBUG}
EnableLeakChecking;
{$ENDIF}
Finalization
Exception.GetExceptionStackInfoProc := nil;
Exception.GetStackInfoStringProc := nil;
Exception.CleanUpStackInfoProc := nil;
If Assigned(OnLeakDetected) Then
Begin
OnLeakDetected(MadExcept.GetLeakReport);
StopLeakChecking;
End;
End.
Thanks!