Recent

Author Topic: Debug Package: projecttemplates  (Read 605 times)

Int3g3r

  • New Member
  • *
  • Posts: 41
Debug Package: projecttemplates
« on: November 21, 2025, 09:13:29 am »
Hello,

I would like to debug the package: projecttemplates.
How do I do that?
I have never created or debugged a package before.

I would like to see what happens when a new project is created from the templates.
I am interested in the following function (projecttemplates.pp):
Code: Pascal  [Select][+][-]
  1. procedure TProjectTemplate.GetFileList(Const Dir : String);
I would like to set breakpoints in it.

I have several folders and files in my template, but they are not copied even though I have entered “recurse=1” in project.ini.

Package -> Open Package (lpk) -> Options:
- Custom Options: “$(IDEBuildOptions)” is set
- Debugging -> Debug info: “Dwarf 2” is set
Then Use -> install.
After that, I opened projecttemplates.pp, set a breakpoint, file -> New -> from Template ....

Is this the right way to do it?

Many thanks in advance.
Int3g3r

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: Debug Package: projecttemplates
« Reply #1 on: November 21, 2025, 09:36:50 am »
You are trying to debug the package within the IDE? (As opposed to having your own project using the package)?

Which OS?

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

Yes, adding the debug info in the package options is correct as you describe it.

You should see the blue dots in the editor-gutter, to indicate that there is debug info.

I would also add -gw to menu Tools > Configure build Lazaurs : Custom options
That is not strictly necessary, but it ensure that packages like the LCL and the IDE itself get debug info => that can help sometimes.


After "Install" => you may want to restart the IDE. Not strictly necessary, but otherwise you need to check the filename for the IDE => compiling sometimes creates a lazarus.new.exe => and then you may be debugging the old lazarus.exe (on windows).

Mind, if your "lazarus" dir is write protected (usually the case on Linux), then the new lazarus executable will be in your primary config path (somewhere in your user folder), and you are debugging an old outdate IDE.




To debug the IDE (with the package / when its compiled with debug info)

1) Always use: Tools > build lazarus
If you just press F9 you may see the compiler running, but it will not call the linker to create the new exe, so without "Tools > build lazarus" you are debugging an old exe

2) Open ide/lazarus.lpi

3) Make sure the lazarus.exe has been recreated with the correct name in the lazarus folder (check the timestamp after the build)
- If you don't want to restart you can use "run > run params" to point to either lazarus.exe or lazarus.new.exe depending on what was created. (must be checked each time.
- if your lazarus folder is write protected, you need to find the lazarus.exe in the primary conf path, and use "run params" to point to that exe.

4) use F9/Run


Int3g3r

  • New Member
  • *
  • Posts: 41
Re: Debug Package: projecttemplates
« Reply #2 on: November 21, 2025, 10:51:06 am »
Quote
Which OS?
Windows 11 64x
Lazarus 4.99 FPC 3.3.1 (trunk)

Quote
You are trying to debug the package within the IDE? (As opposed to having your own project using the package)?
Yes, I am trying to debug the installed package with the currently running IDE.
Is that correct?

Quote
You should see the blue dots in the editor-gutter, to indicate that there is debug info.
I don't see any “blue dots” in the editor;
the breakpoints are red, if that's what you mean.

Quote
2) Open ide/lazarus.lpi
Why should I debug the IDE?
I just want to debug the package.
Do I have to open ide/lazarus.lpi to debug the package?


Should I change the profile to Debug IDE under Tools -> Configure Build Lazarus... -> Profile?
It is set currently to Normal IDE?

I open projtemplates.lpk(currently installed package) -> package -> open lpk file -> open in files tree -> projecttemplates.pp
The code is now displayed in Lazarus.
I set a breakpoint -> what now?
Do I have to recompile the entire IDE so that the breakpoint is used in the package?

Can you explain to me in simple steps how to debug installed packages?
I assume I'm doing something fundamentally wrong.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: Debug Package: projecttemplates
« Reply #3 on: November 21, 2025, 05:26:22 pm »
Quote
You should see the blue dots in the editor-gutter, to indicate that there is debug info.
I don't see any “blue dots” in the editor;
the breakpoints are red, if that's what you mean.
Once the debugger is running there should be
- little blue dots, one for each line that has source code
- the breakpoints should be red, with a "checkmark" ("V") symbol on them

But, that is once the debugger is running.


Quote
Quote
You are trying to debug the package within the IDE? (As opposed to having your own project using the package)?
Yes, I am trying to debug the installed package with the currently running IDE.
Is that correct?


Quote
2) Open ide/lazarus.lpi
Why should I debug the IDE?
I just want to debug the package.
Do I have to open ide/lazarus.lpi to debug the package?

A package on its own doesn't "run". Its not an application, there is no standalone *.exe for the package.

For projecttemplates the executable is the IDE.

So, yes, you need to debug the IDE.
You don't have to step through the IDE, or anything. You can (should be able to) set breakpoint directly in the code of the package.

Of course, what the package does will depend on what the IDE is calling on the package. So you may end up needing to look at that. (but that is maybe, maybe not).


Well, in theory, but I don't think its the way to go, you can write your own project, and simulate the IDE, and call the package yourself. But that isn't going to be practical. That would be a massive undertaking (since I expect projecttemplates wants to use the IDEINTF, and to simulate that, you need to write a huge amount of code) => So, opening lazarus.lpi it is.

If you compiled all of it correctly, then when you press F9 on the lazarus.lpi, and when the 2nd IDE opens, and you go back to the first IDE => then the blue dots should be there. And your breakpoints should show the "V" indicating they are active.


Quote
Should I change the profile to Debug IDE under Tools -> Configure Build Lazarus... -> Profile?
It is set currently to Normal IDE?
Yes, that will be the easiest.

Otherwise edit the custom options, and make sure they have at least
   -gw3

Or better
  -gw3   -O-1

IIRC the debug profile will also add range checks etc -Cr or -Criot or something like that. Ok to have, not making a difference for your case.


Quote
I open projtemplates.lpk(currently installed package) -> package -> open lpk file -> open in files tree -> projecttemplates.pp
The code is now displayed in Lazarus.
I set a breakpoint -> what now?
Do I have to recompile the entire IDE so that the breakpoint is used in the package?
You have to recompile the entire IDE when/if
- you change any options (in the package, or in other packages, or in the IDE, or in the Tools menu), e.g. optimization level, or debug info settings -O -gw .....
- If you changed any code (e.g. to test what the change will do)

And if you recompiled, check it replaced the lazarus.exe (timestamp should be updated to "now" / time of compilation), there should not be a lazarus.new.exe

Once you recompiled for the above, then you do not need to recompile for
- changing (setting, unsetting, properties) breakpoints


Quote
Can you explain to me in simple steps how to debug installed packages?
I assume I'm doing something fundamentally wrong.

First of all => I will assume you installed to C:\lazarus or to some folder that your user account has write access to.

1)
If you installed lazarus as admin, into c:\programs  or into some folder that you don't have write access with your normal user account => then it becomes a bit more complicated.

2)
- set debug info in the packag
- chose debug profiles in tools > config build laz

3)
Open ide/lazarus.lpi

4)
Recompile the IDE from the tools menu.
Check the lazarus.exe was updated => If it was, then you do *not* need to restart (you can if you want)
(more see below)

5)
run / F9

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

You may want to run the original Lazarus.exe as the one that acts as debugger.
E.g. if you make changes to the code, and you don't know they work, then you only want those changes in the "running IN debugger" lazarus IDE.
But you don't want the "running AS debugger" IDE to be affected.

In that case make a copy of lazarus.exe (e.g. lazarus-orig.exe).
Run lazarus-orig.exe (and ignore the "changed file name stuff" that comes up (if you need it open there is an option / cfg file / but I need to search...).

Then when you rebuild the IDE, it will change the lazarus.exe and when you debug it will run the lazarus.exe IN the debugger.

Int3g3r

  • New Member
  • *
  • Posts: 41
Re: Debug Package: projecttemplates
« Reply #4 on: November 24, 2025, 09:23:13 am »
Thanks for your help so far.

1) I am using an admin account.
2) See attachments
3) I opened ide/lazarus.lpi
4) If i try to compile lazarus.lpi (Run->Compile) i get follow message:
"The project has no compile command... Project -> ... -> Compiler commands"


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4673
  • I like bugs.
Re: Debug Package: projecttemplates
« Reply #5 on: November 24, 2025, 10:18:06 am »
The IDE must be built from Tools > Configure build Lazarus, as Martin mentioned.

BTW, the main logic in this package ProjTemplates is in unit ProjectTemplates which has minimal dependencies. No IdeIntf and no LCL.
You could create a temporary project and debug it directly from there. I remember doing that myself some years ago.

Anyway it is good to learn how to debug Lazarus IDE using Lazarus IDE. You will have 2 instances running which is confusing at the beginning. Just don't open too many IDE windows.
« Last Edit: November 24, 2025, 10:29:22 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12109
  • Debugger - SynEdit - and more
    • wiki
Re: Debug Package: projecttemplates
« Reply #6 on: November 24, 2025, 10:55:58 am »
4) If i try to compile lazarus.lpi (Run->Compile) i get follow message:

Pictures look correct.

As Juha said, Tools > Build.

And that is, if you change the source (any source, the IDE, or any package installed in it), then again Tools>Build.
(Pressing F9 (to debug) will (sometimes) do some compiling, but it will NOT replace the lazarus.exe, so the compiling will not have any effect. Only Tools>Build does)

 

TinyPortal © 2005-2018