* * *

Author Topic: Debug Lazarus sources step by step  (Read 1033 times)

s73

  • Newbie
  • Posts: 4
Debug Lazarus sources step by step
« on: November 01, 2016, 04:06:00 pm »
I have error with

Code: Pascal  [Select]
  1. var
  2.   f: TField;
  3.   v: variant;
  4. begin
  5. ...
  6.         v := f.Value;
  7.  
where f is TinyInt ASE field (byte): v contains negative value ($FFFFFFVV). To trace error I should somehow trace into GetFieldValue. I've tried rebuild Lazarus with profile "Debug IDE" (it seems gives me only memory usage), tried to open LCL, LCLBase and FCL (Open Loaded Package, Open, there already "Generate debugging" checked, tried both "automatic" or "Dwarf with sets"), compiled, rebuilded Lazarus - but still can't trace into Lazarus DB code.
Can someone provide step by step "How to" to do that? Lazarus 1.6 for Win64. Thanks.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2761
  • I like bugs.
Re: Debug Lazarus sources step by step
« Reply #1 on: November 01, 2016, 05:50:13 pm »
How did you try to trace Lazarus DB code? Debugging should work when you have built Lazarus with profile "Debug IDE".
Just open the ide\lazarus.lpi project and debug it as any project. It is briefly explained here:
 http://wiki.freepascal.org/Extending_the_IDE#Debugging_the_IDE

You can also use GDB directly. When debugging a Lazarus instance using another Lazarus instance, you must pay attention to which window belongs to which instance.
Anyway, that is how I often debug the IDE.
An alternative way is to add DebugLn() calls to the source and look at their output. It is the best way for debugging mouse event handlers because mouse may stop working in the IDE after a breakpoint.

howardpc

  • Hero Member
  • *****
  • Posts: 2058
Re: Debug Lazarus sources step by step
« Reply #2 on: November 01, 2016, 06:58:09 pm »
still can't trace into Lazarus DB code.

It may be that your fpc is not built with debug info.
To do that see, for example, this thread
http://forum.lazarus.freepascal.org/index.php/topic,20335.msg117259.html#msg117259

s73

  • Newbie
  • Posts: 4
Re: Debug Lazarus sources step by step
« Reply #3 on: November 02, 2016, 12:56:24 pm »
How did you try to trace Lazarus DB code? Debugging should work when you have built Lazarus with profile "Debug IDE".
Just open the ide\lazarus.lpi project and debug it as any project. It is briefly explained here:
 http://wiki.freepascal.org/Extending_the_IDE#Debugging_the_IDE
It is not clear for me is this profile "Debug IDE" to exactly debug IDE (environment) or is it as Delphi's compiler option "Use debug .dcus" that allows to step into Delphi sources. I guess this option to exactly debug IDE, not IDE environment that allows to debug Lazarus/FPC sources. What I want is to trace errors I have with some types of fields under FPC (Byte fields, BCD etc that works under Delphi but fails with errors under FPC).

s73

  • Newbie
  • Posts: 4
Re: Debug Lazarus sources step by step
« Reply #4 on: November 02, 2016, 01:36:41 pm »
It may be that your fpc is not built with debug info.
To do that see, for example, this thread
http://forum.lazarus.freepascal.org/index.php/topic,20335.msg117259.html#msg117259
So I have in fpc\3.0.0\source\packages\fcl-db\ several makefiles. To rebuild with debug information I should do exactly what?

When I trying to build as suggested I have
Quote
D:\lazarus\fpc\3.0.0\source\packages>make OPT=-g
MAKE Version 5.41  Copyright (c) 1987, 2014 Embarcadero Technologies, Inc.
Error makefile 14: Command syntax error
...
or
Quote
D:\lazarus\fpc\3.0.0\source\packages>d:\lazarus\fpc\3.0.0\bin\x86_64-win64\make OPT=-g
d:/lazarus/fpc/3.0.0/bin/x86_64-win64/make -C fpmkunit bootstrap
make[1]: Entering directory `D:/lazarus/fpc/3.0.0/source/packages/fpmkunit'
d:/lazarus/fpc/3.0.0/bin/x86_64-win64/gmkdir.exe -p units_bs/x86_64-win64
d:/lazarus/fpc/3.0.0/bin/x86_64-win64/ppcx64.exe src/fpmkunit.pp -n -Fu../../rtl -FUunits_bs/x86_64-win64 -Fu../paszlib/src -Fu../hash/src -Fi../paszlib/src   -Fi../fcl-process/src/win -Fu../fcl-process/src -Fi../fcl-process/src/win64 -Fi../fcl-process/src/dummy -Fu../libtar/src -g
Fatal: Can't find unit system used by fpmkunit
Fatal: Compilation aborted
make[1]: *** [bootstrap] Error 1
make[1]: Leaving directory `D:/lazarus/fpc/3.0.0/source/packages/fpmkunit'
make: *** [fpmake.exe] Error 2
« Last Edit: November 02, 2016, 02:13:57 pm by s73 »

howardpc

  • Hero Member
  • *****
  • Posts: 2058
Re: Debug Lazarus sources step by step
« Reply #5 on: November 02, 2016, 05:17:00 pm »
I don't have a current working Windows setup to test on, and give you a step-by-step.
However I can point out one obvious problem, and warn about another.
You have Delphi installed, and Embarcadero's make.exe is in your system path.
You'll have to reset the system path with a command line instruction like
  path=path-to-fpc-binutils
(or however it should be written on Windows).

Also, I seem to remember that running the make.exe that is provided with a Windows fpc installation can fail if you work with makefiles on a drive other than c: (You're using d:, for instance). I don't know if that is still an issue or not, but it certainly was in the past because some of the required binutils choked if you presented them with files not on the c: drive.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2761
  • I like bugs.
Re: Debug Lazarus sources step by step
« Reply #6 on: November 02, 2016, 05:54:10 pm »
It is not clear for me is this profile "Debug IDE" to exactly debug IDE (environment) or is it as Delphi's compiler option "Use debug .dcus" that allows to step into Delphi sources. I guess this option to exactly debug IDE, not IDE environment that allows to debug Lazarus/FPC sources.
It allows you to debug all Lazarus sources, including LCL and other packages.
For debugging FPC's source you must compile it with debug info, too.
Sometimes it is easy to copy some FPC library code and debug it as part of your project, but it may not work in this case.

s73

  • Newbie
  • Posts: 4
Re: Debug Lazarus sources step by step
« Reply #7 on: November 10, 2016, 01:16:22 pm »
So I made as described in http://wiki.freepascal.org/Installing_Lazarus#Installing_Free_Pascal_under_Windows from sources with some fixes:
makefpc.bat
Code: Pascal  [Select]
  1. @echo on
  2. set myroot=c:\freepascal
  3. set myFPC=%myroot%\fpc\3.0.1
  4. set mybinutils=%myroot%\binutils
  5. set PATH=%mybinutils%\i386-win32;%mybinutils%\i386-win32\binw32;
  6. cd %myFPC%
  7. rd /s /q  %myfpc%\examples
  8. make clean all OPT="-glw2" install INSTALL_PREFIX=%myFPC% PP=%mybinutils%\ppc386.exe DATA2INC=%myFPC%\utils\data2inc.exe
makelaz.bat
Code: Pascal  [Select]
  1. set myroot=c:\freepascal
  2. set myFPC=%myroot%\fpc\3.0.1
  3. set mybinutils=%myroot%\binutils
  4. set PATH=%mybinutils%;%mybinutils%\i386-win32\binw32;%myFPC%\bin\i386-win32;
  5. cd %myroot%\laz
  6. make clean all OPT="-glw2"
Everything built with debug enabled OPT="-glw2" but I still can't trace into for example "Field.AsBytes := value". When I open fields.inc in code editor I can see there blue circles to set breakpoints, but they do not works there.
Code: Pascal  [Select]
  1. procedure TBlobField.SetAsBytes(const AValue: TBytes);
  2. var
  3.   Len : Integer;
  4. begin <- breakpoint
  5.   with GetBlobStream(bmWrite) do <- breakpoint
  6.     try
  7.       Len := Length(AValue);
  8.       if Len > 0 then
  9.         WriteBuffer(AValue[0], Len);
  10.     finally
  11.       Free;
  12.     end;
  13. end;
  14.  
from
Code: Pascal  [Select]
  1.             if FieldObj is TBlobField then
  2.               FieldObj.AsBytes := Value
  3.  
« Last Edit: November 10, 2016, 01:18:26 pm by s73 »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus