delphijedi-code-library

Delphi JCL Debug missing stack frame entries for JDBG


I use following code to dump stack frame at the moment of an exception:

...
var
  FTraceList: TStringList;
...
procedure TTraceForm.LogException(ExceptObj: TObject; ExceptAddr: Pointer; IsOS: Boolean);
begin
...
StackList := JclCreateStackList(false, 0, Caller(0, false));
try
  FTraceList.Add('');
  FTraceList.Add('Stack trace at the moment of the exception:');
  StackList.AddToStrings(FTraceList, true, true, true, true);
finally
  Stacklist.Free;
end;
end;

But it behaves differently in Debug and Release mode.

For an intended exception (exception for testing purposes) in main form's OnKeyDown when compiling in Debug mode (Delphi debug info) the result is:

Stack trace at the moment of the exception:
(00591276){Main.exe     } [00992276] DlgTraceException.TTraceForm.LogException (Line 162, "DlgTraceException.pas" + 55) + $4
(0058B8FF){Main.exe     } [0098C8FF] JclDebug.JclCreateStackList + $17
(00591281){Main.exe     } [00992281] DlgTraceException.TTraceForm.LogException (Line 162, "DlgTraceException.pas" + 55) + $F
(00582AE3){Main.exe     } [00983AE3] JclHookExcept.TNotifierItem.DoNotify + $43
(00582CCB){Main.exe     } [00983CCB] JclHookExcept.DoExceptNotify + $CF
(00582DAD){Main.exe     } [00983DAD] JclHookExcept.HookedExceptObjProc + $1D
(0000606F){Main.exe     } [0040706F] System.@HandleAnyException + $33
(00598DE3){Main.exe     } [00999DE3] Main.TMainForm.FormKeyDown (Line 658, "Main.pas" + 2) + $7

And this I get in Release mode (JCL debug info added to binary with JCL Debug Expert):

Stack trace at the moment of the exception:
(0053BA27){Main.exe     } [0093CA27] DlgTraceException.TTraceForm.LogException + $377
(00536427){Main.exe     } [00937427] JclDebug.JclCreateStackList + $17
(0053BA32){Main.exe     } [0093CA32] DlgTraceException.TTraceForm.LogException + $382
(0052D60B){Main.exe     } [0092E60B] JclHookExcept.TNotifierItem.DoNotify + $43
(0052D7F3){Main.exe     } [0092E7F3] JclHookExcept.DoExceptNotify + $CF
(0052D8D5){Main.exe     } [0092E8D5] JclHookExcept.HookedExceptObjProc + $1D
(0000606F){Main.exe     } [0040706F] System.@HandleAnyException + $33

In second case FormKeyDown entry is missing. Is there somebody who knows why this is happening? I would like to know the entire stack trace in release mode as well.


Solution

  • After playing a bit with compiler options (toggling them on and off) I could isolate the cause. The stack frame has been optimized out. When I turned Optimization off the FormKeyDown call was recorded even in Release mode. The Stack Frames generation option mentioned in comments above did not influence the results.

    Of course I'll keep optimizations on in release mode. It will be harder to find the cause of the exception but there is other info about it JCL debug provides which should be (hopefully) sufficient to find the cause of the exception.