Recent

Author Topic: How to debug Classes.pas ?  (Read 2813 times)

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
How to debug Classes.pas ?
« on: August 26, 2022, 06:19:37 pm »
I am debugging an application that uses my custom package (LPTK for the package name).
Since I am going down to LResources.pp "InitLazResourceComponent",
I need to see what going on Read.ReadRootComponent, but Lazarus doesn't go to that detail when i press F7.


Code: Pascal  [Select][+][-]
  1. function InitLazResourceComponent(Instance: TComponent;
  2.                                   RootAncestor: TClass): Boolean;
  3.  
  4.  
  5.   function InitComponent(ClassType: TClass): Boolean;
  6. ......
  7.  
  8.    try
  9.       //DebugLn('Form Stream "',ClassType.ClassName,'"');
  10.       //try
  11.       DestroyDriver:=false;
  12.       Reader := CreateLRSReader(Stream, DestroyDriver);
  13.       try
  14.         Reader.ReadRootComponent(Instance); <------- I want to debug down from here
  15.       finally
  16.         Driver := Reader.Driver;
  17.         Reader.Free;
  18.         if DestroyDriver then
  19.           Driver.Free;
  20.       end;
  21.       //except
  22.       //  on E: Exception do begin
  23.       //    DebugLn(Format(rsFormStreamingError,[ClassType.ClassName,E.Message]));
  24.       //    exit;
  25.       //  end;
  26.       //end;
  27.     finally
  28.       Stream.Free;
  29.     end;              
  30.  


So, my question is: How to allow debugging in Classes.pas (fpc) ?


There is no error, but debug step just skip that line  :o


--------------
Here is my spec
Lazarus: 2.3.0
Linux: UbuntuCinnamon
Target: Linux64/GTK2
VM: no.
Project Option: all default, with only "Dwarft with sets (-gw -godwarfsets).


Thanks for any answer  :)
« Last Edit: August 26, 2022, 06:24:27 pm by x2nie »
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

Thaddy

  • Hero Member
  • *****
  • Posts: 18337
  • Here stood a man who saw the Elbe and jumped it.
Re: How to debug Classes.pas ?
« Reply #1 on: August 26, 2022, 06:22:44 pm »
compile the rtl with debug info enabled.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: How to debug Classes.pas ?
« Reply #2 on: August 26, 2022, 06:26:44 pm »
compile the rtl with debug info enabled.


How? I can't find any package named "RTL"?

When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

Thaddy

  • Hero Member
  • *****
  • Posts: 18337
  • Here stood a man who saw the Elbe and jumped it.
Re: How to debug Classes.pas ?
« Reply #3 on: August 26, 2022, 06:38:18 pm »
compile the rtl with debug info enabled.


How? I can't find any package named "RTL"?
Then how did you install Freepascal and Lazarus? You need the sources. With fpcupdeluxe you will have the sources. rtl is not a package but the runtime library.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: How to debug Classes.pas ?
« Reply #4 on: August 26, 2022, 06:55:47 pm »
okay, I install lazarus & fpc from sourceforge *.deb.
Btw I can now recompile the rtl [1]
but it has error that I couldn't understand yet:
cannot create directory ‘../../rtl/units’: Permission denied
Code: [Select]
fathony@uc7m:/usr/share/fpcsrc/3.2.2/rtl$ make clean all LINKSMART=1  CREATESMART=1  DEBUG=1 OPTIMIZE=0  OPT="-gl -gw -godwarfsets -O-1"
/usr/bin/rm -f fpcmade.x86_64-linux Package.fpc ./ppas.sh script.res link.res 
/usr/bin/rm -f *.s *_ppas.sh ppas.sh ppaslink.sh
make -C linux clean
make[1]: Entering directory '/usr/share/fpcsrc/3.2.2/rtl/linux'
/usr/bin/rm -f ../../rtl/units/x86_64-linux/prt0.o ../../rtl/units/x86_64-linux/dllprt0.o ../../rtl/units/x86_64-linux/cprt0.o ../../rtl/units/x86_64-linux/gprt0.o ../../rtl/units/x86_64-linux/abitag.o
/usr/bin/rm -f ../../rtl/units/x86_64-linux/system.ppu ../../rtl/units/x86_64-linux/fpintres.ppu ../../rtl/units/x86_64-linux/si_prc.ppu ../../rtl/units/x86_64-linux/si_c.ppu ../../rtl/units/x86_64-linux/si_g.ppu ../../rtl/units/x86_64-linux/si_dll.ppu ../../rtl/units/x86_64-linux/uuchar.ppu ../../rtl/units/x86_64-linux/unixtype.ppu ../../rtl/units/x86_64-linux/ctypes.ppu ../../rtl/units/x86_64-linux/baseunix.ppu ../../rtl/units/x86_64-linux/strings.ppu ../../rtl/units/x86_64-linux/objpas.ppu ../../rtl/units/x86_64-linux/macpas.ppu ../../rtl/units/x86_64-linux/iso7185.ppu ../../rtl/units/x86_64-linux/extpas.ppu ../../rtl/units/x86_64-linux/syscall.ppu ../../rtl/units/x86_64-linux/unixutil.ppu ../../rtl/units/x86_64-linux/heaptrc.ppu ../../rtl/units/x86_64-linux/lineinfo.ppu ../../rtl/units/x86_64-linux/lnfodwrf.ppu ../../rtl/units/x86_64-linux/termio.ppu ../../rtl/units/x86_64-linux/unix.ppu ../../rtl/units/x86_64-linux/linux.ppu ../../rtl/units/x86_64-linux/initc.ppu ../../rtl/units/x86_64-linux/cmem.ppu ../../rtl/units/x86_64-linux/x86.ppu ../../rtl/units/x86_64-linux/ports.ppu ../../rtl/units/x86_64-linux/cpu.ppu ../../rtl/units/x86_64-linux/linuxvcs.ppu ../../rtl/units/x86_64-linux/sysutils.ppu ../../rtl/units/x86_64-linux/typinfo.ppu ../../rtl/units/x86_64-linux/math.ppu ../../rtl/units/x86_64-linux/charset.ppu ../../rtl/units/x86_64-linux/cpall.ppu ../../rtl/units/x86_64-linux/character.ppu ../../rtl/units/x86_64-linux/unixcp.ppu ../../rtl/units/x86_64-linux/getopts.ppu ../../rtl/units/x86_64-linux/errors.ppu ../../rtl/units/x86_64-linux/dl.ppu ../../rtl/units/x86_64-linux/dynlibs.ppu ../../rtl/units/x86_64-linux/types.ppu ../../rtl/units/x86_64-linux/sysconst.ppu ../../rtl/units/x86_64-linux/fpwidestring.ppu ../../rtl/units/x86_64-linux/cthreads.ppu ../../rtl/units/x86_64-linux/classes.ppu ../../rtl/units/x86_64-linux/fgl.ppu ../../rtl/units/x86_64-linux/rtlconsts.ppu ../../rtl/units/x86_64-linux/dos.ppu ../../rtl/units/x86_64-linux/cwstring.ppu ../../rtl/units/x86_64-linux/fpcylix.ppu ../../rtl/units/x86_64-linux/softfpu.ppu ../../rtl/units/x86_64-linux/sfpux80.ppu ../../rtl/units/x86_64-linux/ufloatx80.ppu ../../rtl/units/x86_64-linux/sfpu128.ppu ../../rtl/units/x86_64-linux/ufloat128.ppu ../../rtl/units/x86_64-linux/exeinfo.ppu ../../rtl/units/x86_64-linux/cp1250.ppu ../../rtl/units/x86_64-linux/cp1251.ppu ../../rtl/units/x86_64-linux/cp1252.ppu ../../rtl/units/x86_64-linux/cp1253.ppu ../../rtl/units/x86_64-linux/cp1254.ppu ../../rtl/units/x86_64-linux/cp1255.ppu ../../rtl/units/x86_64-linux/cp1256.ppu ../../rtl/units/x86_64-linux/cp1257.ppu ../../rtl/units/x86_64-linux/cp1258.ppu ../../rtl/units/x86_64-linux/cp437.ppu ../../rtl/units/x86_64-linux/cp646.ppu ../../rtl/units/x86_64-linux/cp737.ppu ../../rtl/units/x86_64-linux/cp775.ppu ../../rtl/units/x86_64-linux/cp850.ppu ../../rtl/units/x86_64-linux/cp852.ppu ../../rtl/units/x86_64-linux/cp855.ppu ../../rtl/units/x86_64-linux/cp856.ppu ../../rtl/units/x86_64-linux/cp857.ppu ../../rtl/units/x86_64-linux/cp860.ppu ../../rtl/units/x86_64-linux/cp861.ppu ../../rtl/units/x86_64-linux/cp862.ppu ../../rtl/units/x86_64-linux/cp863.ppu ../../rtl/units/x86_64-linux/cp864.ppu ../../rtl/units/x86_64-linux/cp865.ppu ../../rtl/units/x86_64-linux/cp866.ppu ../../rtl/units/x86_64-linux/cp869.ppu ../../rtl/units/x86_64-linux/cp874.ppu ../../rtl/units/x86_64-linux/cp3021.ppu ../../rtl/units/x86_64-linux/cp8859_1.ppu ../../rtl/units/x86_64-linux/cp8859_2.ppu ../../rtl/units/x86_64-linux/cp8859_3.ppu ../../rtl/units/x86_64-linux/cp8859_4.ppu ../../rtl/units/x86_64-linux/cp8859_5.ppu ../../rtl/units/x86_64-linux/cp8859_6.ppu ../../rtl/units/x86_64-linux/cp8859_7.ppu ../../rtl/units/x86_64-linux/cp8859_8.ppu ../../rtl/units/x86_64-linux/cp8859_9.ppu ../../rtl/units/x86_64-linux/cp8859_10.ppu ../../rtl/units/x86_64-linux/cp8859_11.ppu ../../rtl/units/x86_64-linux/cp8859_13.ppu ../../rtl/units/x86_64-linux/cp8859_14.ppu ../../rtl/units/x86_64-linux/cp8859_15.ppu ../../rtl/units/x86_64-linux/cp8859_16.ppu ../../rtl/units/x86_64-linux/cpkoi8_r.ppu ../../rtl/units/x86_64-linux/cpkoi8_u.ppu ../../rtl/units/x86_64-linux/unicodedata.ppu ../../rtl/units/x86_64-linux/unicodenumtable.ppu ../../rtl/units/x86_64-linux/syslinux.ppu ../../rtl/units/x86_64-linux/linux.ppu
/usr/bin/rm -f ../../rtl/units/x86_64-linux/math.rst ../../rtl/units/x86_64-linux/typinfo.rst ../../rtl/units/x86_64-linux/sysconst.rst ../../rtl/units/x86_64-linux/rtlconsts.rst
/usr/bin/rm -f fpcmade.x86_64-linux Package.fpc ./ppas.sh script.res link.res 
/usr/bin/rm -f *.s *_ppas.sh ppas.sh ppaslink.sh
make[1]: Leaving directory '/usr/share/fpcsrc/3.2.2/rtl/linux'
make -C linux all
make[1]: Entering directory '/usr/share/fpcsrc/3.2.2/rtl/linux'
/usr/bin/mkdir -p ../../rtl/units/x86_64-linux
/usr/bin/mkdir: cannot create directory ‘../../rtl/units’: Permission denied
make[1]: *** [Makefile:3390: ../../rtl/units/x86_64-linux] Error 1
make[1]: Leaving directory '/usr/share/fpcsrc/3.2.2/rtl/linux'
make: *** [Makefile:2037: linux_all] Error 2
fathony@uc7m:/usr/share/fpcsrc/3.2.2/rtl$




it seem that a directory want to be created at root dir.  :P
What file is to be copied? I cant find "fpc", or rtl?


my fpc source & binary:



freePascalSourcePath: "/usr/share/fpcsrc/3.2.2",
binary: "/usr/bin/fpc",


[1] https://forum.lazarus.freepascal.org/index.php/topic,39255.msg268903.html#msg268903
« Last Edit: August 26, 2022, 06:59:31 pm by x2nie »
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: How to debug Classes.pas ?
« Reply #5 on: August 26, 2022, 07:11:09 pm »
next, with
Code: [Select]
sudo make clean all LINKSMART=1  CREATESMART=1  DEBUG=1 OPTIMIZE=0 

I got errors :


Code: [Select]

91 lines compiled, 0.0 sec
1 note(s) issued
/usr/bin/ppcx64 -XX -gl -O2 -Fi../inc -Fi../x86_64 -Fi../unix -Fix86_64 -FE. -FU../../rtl/units/x86_64-linux -Cg -gl -gw -godwarfsets -O-1 -dx86_64 -dDEBUG ../inc/sfpu128.pp
Compiling Debug Version
Note: DWARF debug information cannot be used with smart linking on this target, switching to static linking
Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling ../inc/sfpu128.pp
18799 lines compiled, 0.2 sec
1 note(s) issued
/usr/bin/ppcx64 -XX -gl -O2 -Fi../inc -Fi../x86_64 -Fi../unix -Fix86_64 -FE. -FU../../rtl/units/x86_64-linux -Cg -gl -gw -godwarfsets -O-1 -dx86_64 -dDEBUG ../inc/ufloat128.pp
Compiling Debug Version
Note: DWARF debug information cannot be used with smart linking on this target, switching to static linking
Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling ../inc/ufloat128.pp
91 lines compiled, 0.0 sec
1 note(s) issued
make[1]: Leaving directory '/usr/share/fpcsrc/3.2.2/rtl/linux'


it seem as no error, but still can't debug the "CLASSES.pp" :-\
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11811
  • Debugger - SynEdit - and more
    • wiki
Re: How to debug Classes.pas ?
« Reply #6 on: August 26, 2022, 07:30:57 pm »
You need to build your own FPC.  (at least all other approaches will just over complicate it).

The easiest is to use FpcUpDeluxe. Build you fpc with the option  -gw3
But you already done it with "make". (not sure if you need a make install)


Then change lazarus to use the newly build fpc, and recompile your project.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: How to debug Classes.pas ?
« Reply #7 on: August 26, 2022, 08:33:07 pm »
I did it. (checkout fpc git & compile via FPCUPdelux 2.2.ok for x86-linux-gtk2)


but how to set the "-gw3" ?
Because I still can't debug the Classes.pas


When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11811
  • Debugger - SynEdit - and more
    • wiki
Re: How to debug Classes.pas ?
« Reply #8 on: August 26, 2022, 08:46:30 pm »
-gw3 => "FPC Options"


ok you are on Linux, that can complicate things a bit.

On Windows all happens inside the folder in which the fpc exe resides
On Linux the location of the fpc exe has little impact....



there likely is an /etc/fpc.cfg
And even if you use a different fpc exe, it will find that config. And that config points to the original ppu, which don't have debug info


You can check by compiling your project (or an dummy project) with -va

Also, fpc will call ppc....
And it will find the ppc from the global PATH.
Though the correct fpc/ppc don't really matter, as long as they all are the same version, and can read each others ppu.

Maybe check if fpc/ppc takes a parameter which fpc.cfg to use.


Then it depends how permanent a solution you seek.

For occasional debugs, you could copy your new fpc.exe into /etc/  (or use -va on the normal fpc, to find where it is / there is a possible location in the home folder too)


For something more permanent, and to have diff fpc versions. It's a bit more work.
And I have to check my own install, how I did it ...

(IIRC fpcupdeluxe can generate some batch/sh files that change PATH and whatever - but I never played with that)

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: How to debug Classes.pas ?
« Reply #9 on: August 26, 2022, 10:03:05 pm »
"-va" doesn't help.  :o


but yes, there is usage of old fpc, even when I change both fpc & fpc-source dir into FPCUPdelux fpc dir.


Now, after uninstalling old fpc via those installer *.deb, I have problem on running this fresh application:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var a : tlist;
  3. begin
  4.   a := TList.create(); <---- want to debug classes.pas from here
  5. end;
  6.  
  7.  
         


Then i got a strange error:
Fatal: Cannot find system used by fcllaz. Make sure all ppu files of a package are in its output directory. ppu in wrong directory=/usr/local/lib/fpc/3.2.2/units/x86_64-linux/rtl/system.ppu..

That dir (/usr/local/lib/fpc) is actually doesn't exist any more. WHat shall do?
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: How to debug Classes.pas ?
« Reply #10 on: August 26, 2022, 10:04:52 pm »
Okay, Its may time to install lazarus via fpcupdeluxe  ;D
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11811
  • Debugger - SynEdit - and more
    • wiki
Re: How to debug Classes.pas ?
« Reply #11 on: August 26, 2022, 10:39:01 pm »
"-va" doesn't help.  :o

Should have been more detailed.

-va produces tons of output. You need to copy it (all of it, not just the part the IDE shows), and look through it.

It will tell you for every file where it
- looks for it
- found it (or didn't)

Then you can see, if and which files come from the old install. And with that knowledge you can track down whatever setting or config file is still wrong.


---------------

The issue that "fpc" is looking for "ppc..." in the global path....
If you do not cross compile configure the IDE with the ppc... in the fpc field. So fpc is skipped

Then use -va to find a spot to place the fpc.cfg.
Make sure the fpc.cfg has the correct paths.
You can recreate it with (whatever pathes you have)
  fpcmkcfg -d basepath=/home/nnnnn/fpcinstall/lib/fpc/3.2.0  fpc.cfg

If you don't have a global config at all
https://www.freepascal.org/docs-html/user/userap1.html
says you can do
  fpc @path/to/fpg.cfg
(not tested // also maybe ppc @fpc.cfg)

If needs must, write a shell script to execute fpc, and call that from the IDE.




fpcupdeluxe promises to have its own way to solve all this.
But I haven't used it on linux, so I don't know the details.


Having more than one fpc install on a linux box, unfortunately seems to be one of the more tricky endeavours.


x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: How to debug Classes.pas ?
« Reply #12 on: August 26, 2022, 10:48:58 pm »
okay.


I just remove all fpc (all folsder such in /usr/lib/fpc etc)


Now I can't compile lazarus via command line, as same error as when it is trying compiled via fpcupdeluxe:


« Last Edit: August 26, 2022, 10:50:33 pm by x2nie »
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11811
  • Debugger - SynEdit - and more
    • wiki
Re: How to debug Classes.pas ?
« Reply #13 on: August 26, 2022, 11:10:01 pm »
Search for the fpc.cfg file....

It is not enough to prevent access to the old ppu => it needs access to the new ppu (of the rtl). And the locations of those are read from the fpc.cfg file.

Make an empty "program foo; begin end."
and compile from the commandline with -va

grep for fpc.cfg

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: How to debug Classes.pas ?
« Reply #14 on: August 27, 2022, 05:04:26 am »
Awesome @Martin_fr !
I ran this on therminal :
Code: [Select]
/fpcupdeluxe/fpc/bin/x86_64-linux/fpc ./prog.lpr  -va

Code: [Select]
[0.000] Macro defined: REGCALL
[0.000] Configfile search: /home/fathony/.fpc.cfg
[0.000] Configfile search: /home/fathony/fpcupdeluxe/fpc/bin/etc/fpc.cfg
[0.000] Configfile search: /etc/fpc.cfg
[0.000] Reading options from file /etc/fpc.cfg <------------------------------ YEAH !!!
[0.000] Hint: Start of reading config file /etc/fpc.cfg
[0.000] interpreting file option "#"
[0.000] interpreting file option "# Config file generated by fpcmkcfg on 19-8-22 - 20:01:23"
[0.000] interpreting file option "# Example fpc.cfg for Free Pascal Compiler"
[0.000] interpreting file option "#"

I found which fpc.cfg being used: /etc/fpc.cfg
Actually I have deleted that file too, but somehow it is recreated (by, maybe fpcupdeluxe?)


Now, after editing the "/etc/fpc.cfg" file, replace all occured old dir into new dir,
I can compile with correct fpc.


Okay, I am going to debug the classes.pp with lazarus ...

« Last Edit: August 27, 2022, 05:06:33 am by x2nie »
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

 

TinyPortal © 2005-2018