FullDebugMode_DLL_TestApp.dpr 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // JCL_DEBUG_EXPERT_INSERTJDBG ON
  2. program FullDebugMode_DLL_TestApp;
  3. {$APPTYPE CONSOLE}
  4. {$R *.res}
  5. {$stackframes on}
  6. uses
  7. System.SysUtils;
  8. const
  9. {$if SizeOf(Pointer) = 8}
  10. FullDebugModeLibraryName = 'FastMM_FullDebugMode64.dll';
  11. {$else}
  12. FullDebugModeLibraryName = 'FastMM_FullDebugMode.dll';
  13. {$ifend}
  14. const
  15. MaxEntries = 20;
  16. SkipFrames = 0;
  17. TextBufSize = 64 * 1024;
  18. var
  19. LReturnAddresses: array[0..MaxEntries - 1] of NativeUInt;
  20. LTextBuffer: array[0..TextBufSize - 1] of AnsiChar;
  21. {Procedures exported by the DLL that should be tested.}
  22. procedure GetFrameBasedStackTrace(AReturnAddresses: PNativeUInt;
  23. AMaxDepth, ASkipFrames: Cardinal); external FullDebugModeLibraryName;
  24. procedure GetRawStackTrace(AReturnAddresses: PNativeUInt;
  25. AMaxDepth, ASkipFrames: Cardinal); external FullDebugModeLibraryName;
  26. function LogStackTrace(AReturnAddresses: PNativeUInt; AMaxDepth: Cardinal;
  27. ABuffer: PAnsiChar): PAnsiChar; external FullDebugModeLibraryName;
  28. procedure TestFrameBasedStackTrace;
  29. begin
  30. FillChar(LReturnAddresses, SizeOf(LReturnAddresses), 0);
  31. FillChar(LTextBuffer, SizeOf(LTextBuffer), 0);
  32. GetFrameBasedStackTrace(@LReturnAddresses, MaxEntries, SkipFrames);
  33. LogStackTrace(@LReturnAddresses, MaxEntries, @LTextBuffer);
  34. WriteLn(LTextBuffer);
  35. end;
  36. procedure TestRawStackTrace;
  37. begin
  38. FillChar(LReturnAddresses, SizeOf(LReturnAddresses), 0);
  39. FillChar(LTextBuffer, SizeOf(LTextBuffer), 0);
  40. GetRawStackTrace(@LReturnAddresses, MaxEntries, SkipFrames);
  41. LogStackTrace(@LReturnAddresses, MaxEntries, @LTextBuffer);
  42. WriteLn(LTextBuffer);
  43. end;
  44. procedure RunTest;
  45. begin
  46. TestFrameBasedStackTrace;
  47. TestRawStackTrace;
  48. end;
  49. begin
  50. try
  51. RunTest;
  52. ReadLn;
  53. except
  54. on E: Exception do
  55. Writeln(E.ClassName, ': ', E.Message);
  56. end;
  57. end.