Recent

Author Topic: unit ProjectDescriptorTypes;  (Read 1079 times)

Aruna

  • Hero Member
  • *****
  • Posts: 795
unit ProjectDescriptorTypes;
« on: March 05, 2026, 02:01:13 am »
The call chain is:

User clicks: Project  --> New Project. What would be the best way to see the call trace for this function please?

Code: Pascal  [Select][+][-]
  1. function TProjectApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;

What I want to know is: suppose I have a function somewhere in the code base, and I need to find out who or what is calling it—how can I trace that back?

No amount of grepping has allowed me to pin-point where in the code this is called.  What am I missing? Is there a standard recommended way to to do this?

dsiders

  • Hero Member
  • *****
  • Posts: 1596
Re: unit ProjectDescriptorTypes;
« Reply #1 on: March 05, 2026, 02:24:15 am »
The call chain is:

User clicks: Project  --> New Project. What would be the best way to see the call trace for this function please?

Code: Pascal  [Select][+][-]
  1. function TProjectApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;

What I want to know is: suppose I have a function somewhere in the code base, and I need to find out who or what is calling it—how can I trace that back?

No amount of grepping has allowed me to pin-point where in the code this is called.  What am I missing? Is there a standard recommended way to to do this?

I don't know what you're looking for... but the obvious ones are:

Code: Bash  [Select][+][-]
  1. ide/lazbuild.lpr:    if ProjectDesc.InitProject(Result)<>mrOk then begin
  2. ide/main.pp:    if ProjectDesc.InitProject(Result)<>mrOk then begin
  3. ide/main.pp:      FallbackProjectDesc.InitProject(Result);
  4.  

Aruna

  • Hero Member
  • *****
  • Posts: 795
Re: unit ProjectDescriptorTypes;
« Reply #2 on: March 05, 2026, 03:16:43 am »
The call chain is:

User clicks: Project  --> New Project. What would be the best way to see the call trace for this function please?

Code: Pascal  [Select][+][-]
  1. function TProjectApplicationDescriptor.InitProject(AProject: TLazProject): TModalResult;

What I want to know is: suppose I have a function somewhere in the code base, and I need to find out who or what is calling it—how can I trace that back?

No amount of grepping has allowed me to pin-point where in the code this is called.  What am I missing? Is there a standard recommended way to to do this?

I don't know what you're looking for... but the obvious ones are:

Code: Bash  [Select][+][-]
  1. ide/lazbuild.lpr:    if ProjectDesc.InitProject(Result)<>mrOk then begin
  2. ide/main.pp:    if ProjectDesc.InitProject(Result)<>mrOk then begin
  3. ide/main.pp:      FallbackProjectDesc.InitProject(Result);
  4.  
Thank you Don much appreciated. This helps a lot!

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12303
  • Debugger - SynEdit - and more
    • wiki
Re: unit ProjectDescriptorTypes;
« Reply #3 on: March 05, 2026, 09:41:17 am »
The call chain is:

User clicks: Project  --> New Project. What would be the best way to see the call trace for this function please?

For future cases, you can always run the IDE itself in the debugger, and set a breakpoint, and use the call stack window.

- Make sure to compile with debug info, and O1: In "Tools > Configure build Lazarus" remove any existing -O2 or -O3, than add -O-1 -gw3 (or -O- -gw3  / for using gdb make it -gw instead of -gw3) and rebuild the IDE. (and restart / restart is not always needed, but sometimes)
- You must build via "Tools" menu. "Compile", "Build", "Run", etc from the "Run" menu will not create a new lazarus executable (they may do some compiling, but it will not change the executable.
- Open Project: ide/lazarus.lpi
- Set breakpoint
- Run

n7800

  • Hero Member
  • *****
  • Posts: 683
  • Lazarus IDE contributor
    • GitLab profile
Re: unit ProjectDescriptorTypes;
« Reply #4 on: March 05, 2026, 09:27:11 pm »
What I want to know is: suppose I have a function somewhere in the code base, and I need to find out who or what is calling it—how can I trace that back?

No amount of grepping has allowed me to pin-point where in the code this is called.  What am I missing? Is there a standard recommended way to to do this?


Find Identifier References

In theory, there's a reference search function, that you can call in three ways:
* Menu > Search > Find Identifier References
* Editor context menu > Find > Find Identifier References
* [Ctrl+Shift+I]

It should take into account the visibility of identifiers, and, for example, not confuse the class property "test" with the global variable "test". Be sure to specify the search scope as "in all open packages and projects". However, due to numerous specifics (e.g. conditional compilation directives), it may miss some occurrences.


Find In Files

Therefore, a more reliable and "recommended" method is to use file search:
* Menu > Search > Find In Files
* Editor context menu > Find > Find In Files
* [Ctrl+Shift+F]

When working with IDE code, it's best to set the search folder to "C:\lazarus" or use the "$LazarusDir()\" macro. I have several IDEs installed, and this really helps avoid confusion.

Depending on what you're searching for, this may return a lot of unnecessary results, but it usually works well enough. You should inspect all results anyway.

Aruna

  • Hero Member
  • *****
  • Posts: 795
Re: unit ProjectDescriptorTypes;
« Reply #5 on: March 06, 2026, 11:05:47 pm »
The call chain is:

User clicks: Project  --> New Project. What would be the best way to see the call trace for this function please?

For future cases, you can always run the IDE itself in the debugger, and set a breakpoint, and use the call stack window.

- Make sure to compile with debug info, and O1: In "Tools > Configure build Lazarus" remove any existing -O2 or -O3, than add -O-1 -gw3 (or -O- -gw3  / for using gdb make it -gw instead of -gw3) and rebuild the IDE. (and restart / restart is not always needed, but sometimes)
- You must build via "Tools" menu. "Compile", "Build", "Run", etc from the "Run" menu will not create a new lazarus executable (they may do some compiling, but it will not change the executable.
- Open Project: ide/lazarus.lpi
- Set breakpoint
- Run
Hi Martin many thanks. When I went to "Tools > Configure build Lazarus"  then selected "Debug IDE" under "Profile to build" it gave me many options. Screenshot attached shows this. Shall I try using these?
Or delete all and use what you gave -O-1 -gw3?

What I need is the source code file where "Project > New Project ..." is so I can set a break pointg on that line??

Aruna

  • Hero Member
  • *****
  • Posts: 795
Re: unit ProjectDescriptorTypes;
« Reply #6 on: March 06, 2026, 11:08:52 pm »
What I want to know is: suppose I have a function somewhere in the code base, and I need to find out who or what is calling it—how can I trace that back?

No amount of grepping has allowed me to pin-point where in the code this is called.  What am I missing? Is there a standard recommended way to to do this?


Find Identifier References

In theory, there's a reference search function, that you can call in three ways:
* Menu > Search > Find Identifier References
* Editor context menu > Find > Find Identifier References
* [Ctrl+Shift+I]

It should take into account the visibility of identifiers, and, for example, not confuse the class property "test" with the global variable "test". Be sure to specify the search scope as "in all open packages and projects". However, due to numerous specifics (e.g. conditional compilation directives), it may miss some occurrences.


Find In Files

Therefore, a more reliable and "recommended" method is to use file search:
* Menu > Search > Find In Files
* Editor context menu > Find > Find In Files
* [Ctrl+Shift+F]

When working with IDE code, it's best to set the search folder to "C:\lazarus" or use the "$LazarusDir()\" macro. I have several IDEs installed, and this really helps avoid confusion.

Depending on what you're searching for, this may return a lot of unnecessary results, but it usually works well enough. You should inspect all results anyway.
Thank you n7800. Ctrl+Shift+I really helps. One last question if I want to see the code where "Project > New Project ..." is on the main top-level menu how do I find this file. Have been trying for a long while with nil success,

n7800

  • Hero Member
  • *****
  • Posts: 683
  • Lazarus IDE contributor
    • GitLab profile
Re: unit ProjectDescriptorTypes;
« Reply #7 on: March 07, 2026, 01:46:45 am »
- Make sure to compile with debug info, and O1: In "Tools > Configure build Lazarus" remove any existing -O2 or -O3, than add -O-1 -gw3 (or -O- -gw3  / for using gdb make it -gw instead of -gw3) and rebuild the IDE. (and restart / restart is not always needed, but sometimes)
- You must build via "Tools" menu. "Compile", "Build", "Run", etc from the "Run" menu will not create a new lazarus executable (they may do some compiling, but it will not change the executable.
- Open Project: ide/lazarus.lpi
- Set breakpoint
- Run
Hi Martin many thanks. When I went to "Tools > Configure build Lazarus"  then selected "Debug IDE" under "Profile to build" it gave me many options. Screenshot attached shows this. Shall I try using these?
Or delete all and use what you gave -O-1 -gw3?

What I need is the source code file where "Project > New Project ..." is so I can set a break pointg on that line??

Overall, it's fairly easy to use the "Debug" profile, it also includes other useful options like range checks and the like.

As far as I know, specifying "-O-"/"-O1" is optional, but it's better for step-by-step debugging. If you retype them, please note that char case is important.

As for "-gw"/"-gw3" I personally don't know - Martin is more knowledgeable about debugging, especially on Linux.

... than add -O-1 -gw3 ...

By the way, I think "-O-1" is a typo and meant "-O1".

n7800

  • Hero Member
  • *****
  • Posts: 683
  • Lazarus IDE contributor
    • GitLab profile
Re: unit ProjectDescriptorTypes;
« Reply #8 on: March 07, 2026, 01:52:22 am »
... In "Tools > Configure build Lazarus" remove any existing -O2 or -O3, than add -O-1 -gw3 (or -O- -gw3  / for using gdb make it -gw instead of -gw3) and rebuild the IDE ...

Martin, did you insist on removing "-O2"/"-O3" just for the sake of "cleanliness"? Am I correct in remembering that they are being redefined and the last one listed is being adopted? So, adding "-O-" to the end is enough?

n7800

  • Hero Member
  • *****
  • Posts: 683
  • Lazarus IDE contributor
    • GitLab profile
Re: unit ProjectDescriptorTypes;
« Reply #9 on: March 07, 2026, 02:01:39 am »
One last question if I want to see the code where "Project > New Project ..." is on the main top-level menu how do I find this file. Have been trying for a long while with nil success,

Finding the code for an open window is actually very easy, there's an old trick with the context help editor:

Open the window you need (or focus it) and press [Ctrl+Shift+F1]. In the dialog box that opens, click "Open ..." button. The unit will open directly in the Source Editor!

For your question, you should see the "ide\newprojectdlg.pp" unit.

 

TinyPortal © 2005-2018