Recent

Author Topic: [INFO] LazDebugUnit  (Read 3358 times)

JimD

  • Jr. Member
  • **
  • Posts: 62
[INFO] LazDebugUnit
« on: September 03, 2018, 05:44:38 am »
LazDebugUnit

Updated with v2.0 Methods and Examples
View or download from: https://github.com/jasc2v8/LazUnits
English only, Windows only, Unlicense (Public Domain)

Overview
DebugUnitMgr adds or removes a DebugForm to a Lazarus Project.
The DebugForm consists of the units debugform.pas and debugform.lfm.

Currently, debugging support for Free Pacal / Lasarus IDE has limited support on Windows.
In lieu of a fully functional debugger, the DebugForm enables debugging with "old school" methods.

Debug Example:
Code: Pascal  [Select][+][-]
  1. Debugln('Entering Function Add');
  2. Result:=Add(2,2);
  3. Debugln('Exit Function Add, check for exceptions, result should be 4, actual is: %n ', Result);

Methods
Code: Pascal  [Select][+][-]
  1. procedure Debugln(Arg1: Variant);
  2. procedure Debugln(Arg1, Arg2: Variant);
  3. procedure Debugln(Arg1, Arg2, Arg3: Variant);
  4. procedure Debugln(Arg1, Arg2, Arg3, Arg4: Variant);
  5. procedure Debugln(Arg1, Arg2, Arg3, Arg4, Arg5: Variant);
  6. procedure Debugln(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6: Variant);
  7. procedure Debugln(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7: Variant);
  8. procedure Debugln(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8: Variant);
  9.  
  10. procedure Debugln(Args: array of Variant);
  11.  
  12. procedure Debugln(Fmt:string; Args: array of Const);

Examples
Code: Pascal  [Select][+][-]
  1. Debugln('Unformatted output up to 8 Args of any Type:');
  2. Debugln('--------------------------------------------');
  3. Debugln(1,2,3,4,5,6,7,8);
  4. Debugln('binary=', %010);
  5. Debugln('boolean=', true);
  6. Debugln('decimal=', 10);
  7. Debugln('general=', 3.1415927);
  8. Debugln('hex=', $0010);
  9. Debugln('octal =', &0010);
  10. Debugln('scientific=', 1.9E6);
  11. Debugln('signed=', -100, ' or ', +100);
  12. Debugln('string=', 'the quick brown fox');
  13. Debugln('mixed bin=',%010,',bool=',true,',dec=',10,',gen=',3.1415927);
  14.  
  15. Debugln(LE+'Unformatted output with Array of Variant:');
  16. Debugln('-----------------------------------------');
  17. Debugln(['decimal', -1,true,3.1415,4,5]);
  18. Debugln(['T1=', true,',T2=',false,',T3=',01.23]);
  19.  
  20. Debugln(LE+'Formatted output with Array of Const:');
  21. Debugln('-------------------------------------');
  22. Debugln('boolean    =%s or %s', [BoolToStr(true,false), BoolToStr(true,true)]);
  23. Debugln('currency   =%m', [1000000.]);
  24. Debugln('decimal    =%d', [-1]);
  25. Debugln('float      =%f', [3.1415927]);
  26. Debugln('general    =%g', [3.1415927]);
  27. Debugln('hex        =%x', [-1]);
  28. Debugln('number     =%n', [1000000.]);
  29. Debugln('scientific =%e', [1.0e3]);
  30. Debugln('string     =%s', ['the quick brown fox']);
  31. Debugln('unsigned   =%u', [-1]);
  32. Debugln('mixed cur  =%m, dec=%d',[1000000., 10]);
  33. Debugln('mixed float=%f, num=%n',[3.1415927, 1000000.]);
« Last Edit: September 04, 2018, 07:26:51 am by jasc2v8 »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: [INFO] LazDebugUnit
« Reply #1 on: September 03, 2018, 06:47:16 am »
LazUtils package has units LazLoggerBase and LazLogger. There is DebugLn() with a more flexible syntax, taking any number of variant parameters.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

JimD

  • Jr. Member
  • **
  • Posts: 62
Re: [INFO] LazDebugUnit
« Reply #2 on: September 03, 2018, 04:05:08 pm »
JuhaManninen, Thank you for your excellent reply.

Yes, I experimented with LazLogger.  It will send output to a file or the command window if I uncheck "Win32 GUI application" in the project options.  In contrast, LazDebugUnit sends output to a form in a separate window.   I just find this easier to work with for my small projects, and I can save the text from the memo on the form easier than from the command window.  The DebugUnitMgr is a convenience utility that will add or remove the DebugUnit from the project.

I agree that the Debugln method in LazDebugUnit needs some work, and that is on my TODO list in the near future.

I also experimented with a several others, which were great but are suited for more complex projects:
http://lazarus-ccr.sourceforge.net/docs/fcl/eventlog/teventlog.html
http://lazarus-ccr.sourceforge.net/docs/fcl/dbugintf/
http://wiki.lazarus.freepascal.org/MultiLog
http://wiki.lazarus.freepascal.org/log4delphi

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: [INFO] LazDebugUnit
« Reply #3 on: September 03, 2018, 06:12:23 pm »
You can write your own subclass of lazlogger, just overriding
Code: Pascal  [Select][+][-]
  1.     procedure DoDbgOut(const {%H-}s: string); virtual;
  2.     procedure DoDebugLn(const {%H-}s: string); virtual;
  3.  
Put code in there to write to your form, and you can use the entire framework as it is, getting the result in your form.

Look at LazLoggerFile, if you need thread safety


Do your own unit based on LazLoggerBase, and add initilization
Code: Pascal  [Select][+][-]
  1. initialization
  2.   LazDebugLoggerCreator := @CreateYourDebugLogger;
  3.   RecreateDebugLogger;
  4.  
« Last Edit: September 03, 2018, 06:17:04 pm by Martin_fr »

JimD

  • Jr. Member
  • **
  • Posts: 62
Re: [INFO] LazDebugUnit
« Reply #4 on: September 04, 2018, 07:33:40 am »
Martin_fr,
Thank you for the pointers.
I do like the idea of leveraging what is already available.
I'll experiment with this.

All,
I updated the original post with the improved Debugln methods and examples from v2.0.
I'm doing this mostly for learning, not trying to re-invent the wheel here.
As always, constructive feedback is welcome.



 

TinyPortal © 2005-2018