Recent

Author Topic: Help debugging Lazarus IDE  (Read 1646 times)

Alex.Machado

  • New Member
  • *
  • Posts: 35
Help debugging Lazarus IDE
« on: October 18, 2024, 04:50:04 am »
Hi all,

I'm translating a package from Delphi to Lazarus. The work is done but I have a very weird thing happening.

The final version of my package works, I can see all components installed into the Lazarus IDE, but when I drop a control on my form, the unit where the control is declared is included in the uses clause, but the control itself is not included in the source code (e.g. right below the form declaration we should expect the line "myWidget1: TMyWidget;" to be included).
This problem happens with the final release version of the package (built with -Ur) but doesn't happen when I build/install it from the sources.

I'm tring to find what's causing it and debugging the IDE itself.
I found the unit SourceFileManager.pas which seems to be the one that I was looking for but I couldn't determine the exact method that is responsible for writing the newly added component to the PAS and LFM files. Seems that this is written to the files during an Application.OnIdle event (involving message dispatching and such) which makes the debugging experience as pleasant as a root canal treatment.

Anyone knows exactly where the newly added component is written to the PAS and LFM files?

Any tips that could save me long hours fighting the debugger are welcome.

Thanks in advance

 
« Last Edit: October 18, 2024, 04:56:15 am by Alex.Machado »

Alex.Machado

  • New Member
  • *
  • Posts: 35
Re: Help debugging Lazarus IDE
« Reply #1 on: October 18, 2024, 06:16:35 am »
Partially responding my own question:

The component declaration is written inside method: TEventsCodeTool.CompleteComponent, unit EventCodeTool.pas.

The mystery behind why it works only when I build/install my package from the sources remains. Need more (lots of) debugging, unfortunately.

n7800

  • Full Member
  • ***
  • Posts: 199
Re: Help debugging Lazarus IDE
« Reply #2 on: October 18, 2024, 11:24:38 pm »
What does the "-Ur" option even give? I see its description, but I don't really understand its purpose:
Quote
-U     Unit options:
      -Un        Do not check where the unit name matches the file name
      -Ur        Generate release unit files (never automatically recompiled)
      -Us        Compile a system unit

Usually, a special build mode is used for release (there is a built-in "Release" in the project options), which includes many options, but this is not there.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10670
  • Debugger - SynEdit - and more
    • wiki
Re: Help debugging Lazarus IDE
« Reply #3 on: October 18, 2024, 11:50:31 pm »
I don't know the answer to your question (which part of the code to dig into...).

But there are companies selling closed source packages => so it should work.

Which version of Lazarus have you tried?
You should at least try 3.6 an "git main" (currently named 4.99, former 3.99).

If you source compile with older Lazarus, you can even try an older 2.x version, just to see there is no regression in Lazarus.

---
Also when you test, I assume you remove the sources. Make sure the package and ppu files remain in there place. I do not know if it does have an impact. But at least test it...

Alex.Machado

  • New Member
  • *
  • Posts: 35
Re: Help debugging Lazarus IDE
« Reply #4 on: October 18, 2024, 11:53:55 pm »
Hi n7800,

As I understand the -Ur option should be used in case of packages where the source code is not released (e.g. trial/evaluation versions of commercial packages).

At least this was the main recommendation in this thread:

https://forum.lazarus.freepascal.org/index.php?topic=47582.0

Cheers

Alex.Machado

  • New Member
  • *
  • Posts: 35
Re: Help debugging Lazarus IDE
« Reply #5 on: October 19, 2024, 12:03:23 am »
I don't know the answer to your question (which part of the code to dig into...).

But there are companies selling closed source packages => so it should work.

Which version of Lazarus have you tried?
You should at least try 3.6 an "git main" (currently named 4.99, former 3.99).

If you source compile with older Lazarus, you can even try an older 2.x version, just to see there is no regression in Lazarus.

---
Also when you test, I assume you remove the sources. Make sure the package and ppu files remain in there place. I do not know if it does have an impact. But at least test it...


Hi Martin_fr,

I'm using Lazarus 3.4 + FPC 3.2.2 installed with latest FpcDeluxe on Win64. I didn't try 3.6 yet (I intend to).

I'll try your recommendation and see what I get.

Thanks for that

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10670
  • Debugger - SynEdit - and more
    • wiki
Re: Help debugging Lazarus IDE
« Reply #6 on: October 19, 2024, 12:31:02 am »
Also, you can always set a breakpoint in SynEdit.BeginUndoBlock or similar. That should be called when the IDE makes changes. So then you can see where the call come from.

Alex.Machado

  • New Member
  • *
  • Posts: 35
Re: Help debugging Lazarus IDE
« Reply #7 on: October 19, 2024, 11:51:06 pm »
Hi again

I found where it's failing but I don't actually understand why it fails

There is an exception being raised inside method TFindDeclarationTool.FindIdentifierInUsesSection (unit FindDeclarationTool.pas, line 8317), more specifically, here:

Code: Pascal  [Select][+][-]
  1.    
  2.     if (not Result) and (MissingUnit<>nil) then begin
  3.       // identifier not found and there is a missing unit
  4.       if FindMissingFPCUnits and Assigned(FOnRescanFPCDirectoryCache) then
  5.       begin
  6.         AnUnitName := LowerCase(AnUnitName);
  7.         if FFindMissingFPCUnits=nil then
  8.           FFindMissingFPCUnits := TFindIdentifierInUsesSection_FindMissingFPCUnit.Create;
  9.         if not FFindMissingFPCUnits.IsInResults(AnUnitName) // don't rescan twice
  10.         and FFindMissingFPCUnits.Find(AnUnitName, DirectoryCache) then
  11.         begin
  12.           FOnRescanFPCDirectoryCache(Self);
  13.           Result := FindIdentifierInUsesSection(UsesNode, Params, False);
  14.         end else
  15.           RaiseUnitNotFound;  <<<<-------------------- Exception HERE
  16.       end else
  17.         RaiseUnitNotFound;
  18.     end;
  19.  

I'm not familiar with this code and what it does.

The unit where the component is declared is already added to the source code at this stage. The only task pending is adding

MyWidget1: TMyWidget1;

to the source code (and also include it in the LFM file). I'm not sure why it's necessary for the Lazarus IDE to "FindMissingFPCUnits".

Anyone familiar with this code can give me some directions? What can be done about this?

Kind regards,

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10670
  • Debugger - SynEdit - and more
    • wiki
Re: Help debugging Lazarus IDE
« Reply #8 on: October 20, 2024, 11:04:12 pm »
I am not the expert on this...

As for the exception. When codetool inserts the unit, the in order to keep working on the unit it desires to know what idents are defined in that unit (in the interface part). Well, technically it needs that, when it needs to lookup any identifier that is not declared in that unit.
Code: Pascal  [Select][+][-]
  1. var a: TMyTypeFromOtherUnit;
TMyTypeFromOtherUnit could have several declarations in several units. The codetool needs to go through the uses, and for each unit make sure that it is not in there, before going to the next.

....

Some hear-say that I found way down memory lane....

It might be that codetool can find some of that from ppu. Afaik a ppu probably has the names of stuff in your interface. Because if another unit refers to it, then the compiler must be able to find it.

Even if it's a ppu, if I use it in my unit, then my unit can use anything from it's interface. Just as if it was source. Only I can't get it human readable.

So, if my memory is right there, then codetool could work, if it finds the ppu (and if it indeed knows how to read it).

For that codetool would probably still need a package. That package still needs to say, I have that unit, and the ppu must be in the configure path (it should be by default if you compiled the unit from source before, and only removed the pas files).
Mind, then that if you are using the latest trunk fpc, maybe the ppu format is not compatible.

Or maybe I am entirely wrong.... Sorry, but I only got those breadcrumbs.

TRon

  • Hero Member
  • *****
  • Posts: 3791
Re: Help debugging Lazarus IDE
« Reply #9 on: October 20, 2024, 11:21:48 pm »
What does the "-Ur" option even give? I see its description, but I don't really understand its purpose:
It's purpose is to instruct the compiler to not build the unit from source (and go with the compiled (ppu) file).

One of the situations where that can be helpful (besides that what was already mentioned) is that sometimes the compiler runs into a situation that a checksum for a unit has changed. A checksum change is indication for the compiler to rebuild the unit (and all its dependencies). For this all the corresponding source-code has to be available (which isn't always the case).

Providing -Ur tries to circumvent the situation and not react on such a checksum change.

There are actually quite some bug-report s on that issue because such an issue prevents the Lazarus IDE from being build (e.g. one of its dependencies). Providing the -Ur switch is most of the times able to circumvent that issue (if not then there is seriously somethings amiss).
I do not have to remember anything anymore thanks to total-recall.

Alex.Machado

  • New Member
  • *
  • Posts: 35
Re: Help debugging Lazarus IDE
« Reply #10 on: October 23, 2024, 08:42:37 am »
I am not the expert on this...

As for the exception. When codetool inserts the unit, the in order to keep working on the unit it desires to know what idents are defined in that unit (in the interface part). Well, technically it needs that, when it needs to lookup any identifier that is not declared in that unit.
Code: Pascal  [Select][+][-]
  1. var a: TMyTypeFromOtherUnit;
TMyTypeFromOtherUnit could have several declarations in several units. The codetool needs to go through the uses, and for each unit make sure that it is not in there, before going to the next.

....

Some hear-say that I found way down memory lane....

It might be that codetool can find some of that from ppu. Afaik a ppu probably has the names of stuff in your interface. Because if another unit refers to it, then the compiler must be able to find it.

Even if it's a ppu, if I use it in my unit, then my unit can use anything from it's interface. Just as if it was source. Only I can't get it human readable.

So, if my memory is right there, then codetool could work, if it finds the ppu (and if it indeed knows how to read it).

For that codetool would probably still need a package. That package still needs to say, I have that unit, and the ppu must be in the configure path (it should be by default if you compiled the unit from source before, and only removed the pas files).
Mind, then that if you are using the latest trunk fpc, maybe the ppu format is not compatible.

Or maybe I am entirely wrong.... Sorry, but I only got those breadcrumbs.

Hi Martin_fr

thanks for your effort trying to help my (almost lost) case :-)

I was in this saga debugging Lazarus IDE trying to find why the installation of my package was kind of failing (although it was buildling/installing just fine).

It happens that I could find a way to make it work. The details are in this other thread here:
 
https://forum.lazarus.freepascal.org/index.php/topic,68965.msg534268.html#msg534268

Another user gave some insights why Lazarus needs to go into the details of the unit that declares a specific component, which seems logical, but I lack knowledge on Lazarus code to say more than this.

Anyway, I'm happy that it worked now. Soon we will have another major Delphi library fully ported to Lazarus.

Cheers,

 

TinyPortal © 2005-2018