Recent

Author Topic: [Resolved] Debugging libraries  (Read 1635 times)

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
[Resolved] Debugging libraries
« on: May 28, 2022, 08:57:02 am »
Hi all,

here is one of my long-running questions and my top issue where I'd love to see a future enhancement of the Lazarus/FPC ecosystem:

Is there a reasonably convenient and safe to use way to build my program and individual FCL and LCL libraries from Lazarus with the "debug" flag set, so next time I step through my code I can step into the source?

As far as I know, there are arcane ways to compile the whole LCL and FCL with debug. I have also found, by coincidence, that including a LCL or FCL source file in my project and recompiling the project set to "debug" configuration lets me step into that library. Recompiling Lazarus with debug is also rumoured to help. I am however not wuite sure which effects this has on my exercutable as well as other projects I do currentlyx have under development.

What I have already tried (On Windows, mostly)

- Do a second install of Lazarus (using FPUpDeluxe) with the debug flag set. My intention was to have two Lazarus'ses/FPCs with the same version number, one with debug, and one without, and load the source code in either one. For some reason this never worked like intended.

- I found unit object code in my user's directory, specifically in %appdata%\Lazarus, and it doesn't seem to distinguish between debug and no debug. Probably this "common" unit storage spoiled my "two installation" attempt

- I suspect that messing with two Lazarus Installations and libraries intransparently having been compiled with or without debug may pose a risk that debug information may inadvertadly remain linked in a program executable which does somehow make it into a shipped version.

What do you think? Did I miss somethig? Are there reasonable ways available giving me what I think is a very basic feature of an IDE: a quick way to include/exclude debugging information into all or part of an executable for debugging, but also a mechanism to guarantee that after some easy measure, say, after a "Build all" with debug turned off, the resulting executable is 100% debug free, but other projects under development are not affected in any way?

For hobbyist use what I found out so far about this topic this may suffice. I think I read through the Lazarus Wiki about debugging throughly, but this topic doesn't seem to be covered. For professional use I feel there needs to be a bit more. I am willing to contribute to the wiki, as soon as I have pulled together sufficient knowledge, but I need your guidance for that task.

Thnx, Armin.

« Last Edit: May 30, 2022, 02:39:07 pm by Nimral »
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Debugging libraries
« Reply #1 on: May 28, 2022, 10:02:23 am »
That are not arcane ways, it is the ONLY way just like in any other programming language. You should simply recompile the rtl/fcl/lcl with debug info enabled.
It is possible to store the debug info externally, though. (-Xg)
That will give you a slightly better idea of the size of your binaries before you compile for release.
I have always debug and release versions installed, even the compiler itself. That's how it works, no way around it.
« Last Edit: May 28, 2022, 10:05:46 am by Thaddy »
Specialize a type, not a var.

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Re: Debugging libraries
« Reply #2 on: May 28, 2022, 04:03:14 pm »
That are not arcane ways, it is the ONLY way just like in any other programming language. You should simply recompile the rtl/fcl/lcl with debug info enabled.

There doesn't happen to be any switch or hack within the Lazarus many project options which let me rebuild the fcl and/or lcl along with the project, given they are included in the project, and depending on the current debug/release config?

Armin.



Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Debugging libraries
« Reply #3 on: May 28, 2022, 04:32:44 pm »
Armin, you can add command line switches to the project options. BTW I never use Lazarus to build the RTL, but it is certainly possible.
Specialize a type, not a var.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Debugging libraries
« Reply #4 on: May 28, 2022, 07:48:06 pm »
For the LCL there are various ways.

1) Your can open the package(s) LCL, LCLBase and any other, and in the package-options set the generate debug-info.
(IIRC you may even be able to set up build modes and have them follow the procject / but I haven't don, so I don't know)

2) You can add "custom options" in "Configure build Lazarus". They should be honoured by many of the packages.
You do not need to rebuild the IDE, just save this.

3) IMHO, most convenient: "Additions and Overrides"
(see wiki for documentation)
You can in your project settings (and therefore individually for each project) add options for your choice of packages.
So for debug info you add -O-1 -gw3 (or -gw -godwarfsets)  and if you want -Criot -Sa -gt ...
And you can toggle this by build-modes.



For the the rtl and packages in the FPC installation, you need to build your own fpc from scratch.

Well fpc-packages can in some cases be copied, and recompiled on their own.
This works if (and works only if) no other FPC package depends on the package you rebuild. (Or if you copy and rebuild all dependent packages)

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Re: Debugging libraries
« Reply #6 on: May 29, 2022, 10:03:04 am »
Thnx Avra!

Nice script you got there, but what is it supposed to do? It doesn't seem to take any parameters, so while showing how to use "make" to rebuild fpc it does not help turning on  or off debugging. Did I miss something?

Think it does also contain a little glitch:

Code: Pascal  [Select][+][-]
  1. c:
  2. cd c:\Prg\Lazarus\TrunkAll\fpcsrc
  3.  

should, IMHO, read

Code: Pascal  [Select][+][-]
  1. cd /d %FPCUPDELUXEDIR%\fpcsrc
  2.  

Armin
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Debugging libraries
« Reply #7 on: May 29, 2022, 01:21:18 pm »
Nice script you got there, but what is it supposed to do? It doesn't seem to take any parameters, so while showing how to use "make" to rebuild fpc it does not help turning on or off debugging.
There is always space for improvement. You can see that -j %THREADS% FPMAKEOPT="-T %THREADS%" was used as a parameter on several places. You can make it a new environment variable and make parameters also configurable. Then deciding whether you want debugging or not would be a piece of cake.

Think it does also contain a little glitch
Nice catch. Feel free to fix it. If you don't, then I will when I find some time.
« Last Edit: May 29, 2022, 01:24:40 pm by avra »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Re: Debugging libraries
« Reply #8 on: May 29, 2022, 03:45:15 pm »
Hi Avra,

I didn't mean to despise your script, I just don't think it resolves my problem.

IMHO a real "solution" to the problem needs to integrate seamlessly with Lazarus's build ecosystem, it should follow the "debug" and "release" config setting, and also be able to detect the last build mode of the FCL so it does not rebuild if there isn't any need to do so.

For now I have found a working solution by - once again - installing a second Lazarus through fpcupdeluxe with debugging for LCL and FCL turned on, this will do for my purposes. I suspect I found the reason why this didn't work when I tried last year:

In fpcdeluxe's "Advanced settings" (--> see attachment), in the "Options Override" section to the right of the field to input options, there is a "Debug" checkbox. I suspect that I probably had checked the checkboxes only, and that this alone did probably not produce the desired results. I entered  -g -gw2 -O- now (like suggested in the wiki) and it seems to work now.

 :-* Anyone here who can explain what the "Debug" checkboxes are good for, and how they work in conjunction with what can be entered in the input fields? :-*

Armin.

P.S. I leave the honour of correcting the glitch to the author.
« Last Edit: May 29, 2022, 07:11:49 pm by Nimral »
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

 

TinyPortal © 2005-2018