Forum > Debugger

[Resolved] Debugging libraries

(1/2) > >>

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.

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.


--- Quote from: Thaddy 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.

--- End quote ---

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, you can add command line switches to the project options. BTW I never use Lazarus to build the RTL, but it is certainly possible.

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)


[0] Message Index

[#] Next page

Go to full version