Lazarus

Using the Lazarus IDE => General => Topic started by: julkas on September 21, 2019, 01:45:05 pm

Title: Call graph
Post by: julkas on September 21, 2019, 01:45:05 pm
How generate Call Graph - https://en.wikipedia.org/wiki/Call_graph and Dependency Graph - https://en.wikipedia.org/wiki/Dependency_graph in Lazarus?
Title: Re: Call graph
Post by: simone on September 21, 2019, 02:03:48 pm
I'm not sure to undestand your need. If you want to build a program with Lazarus that is able to generate flow charts and similar diagrams, as call graphs, I suggest to you the TEvsSimpleGraph component, available from https://github.com/taazz/EvsSimpleGraph or via Online Package Manager. It is very flexible and mature.

If you are searching for a tool that generates a static/run time call graph for a Lazarus program, I don't know if such a tool exists.
Title: Re: Call graph
Post by: zamtmn on September 21, 2019, 02:09:09 pm
https://forum.lazarus.freepascal.org/index.php/topic,38983.0.html
https://forum.lazarus.freepascal.org/index.php/topic,34040.0.html
Title: Re: Call graph
Post by: Martin_fr on September 21, 2019, 02:31:29 pm
The IDE has a unit dependency graph: Menu View > Unit dependencies
(and a package graph)

That is as far as it currently gets.

As for callgraph...
If you are on linux you can get a runtime call graph with kcachegrid and valgrind.
Title: Re: Call graph
Post by: valdir.marcos on September 21, 2019, 02:54:51 pm
I'm not sure to understand your need. If you want to build a program with Lazarus that is able to generate flow charts and similar diagrams, as call graphs, I suggest to you the TEvsSimpleGraph component, available from https://github.com/taazz/EvsSimpleGraph or via Online Package Manager. It is very flexible and mature.

If you are searching for a tool that generates a static/run time call graph for a Lazarus program, I don't know if such a tool exists.

https://forum.lazarus.freepascal.org/index.php/topic,38983.0.html
https://forum.lazarus.freepascal.org/index.php/topic,34040.0.html

The IDE has a unit dependency graph: Menu View > Unit dependencies
(and a package graph)

That is as far as it currently gets.

As for callgraph...
If you are on linux you can get a runtime call graph with kcachegrid and valgrind.
Interesting.
Title: Re: Call graph
Post by: julkas on September 21, 2019, 02:55:02 pm
As for callgraph...
If you are on linux you can get a runtime call graph with kcachegrid and valgrind.
I am on Windows. I need only compile time functions/procedures calls(deps).
Example -
Code: Pascal  [Select][+][-]
  1. unit u1;
  2.  
  3. function fun1();
  4. begin
  5. ...
  6.    x := fun2();
  7.    ...
  8.    y := fun3();
  9.    ...
  10. end;
  11.  
  12. function fun4();
  13. begin
  14. ...
  15.    z := fun2();
  16.    ...
  17.    w := fun3();
  18.    ...
  19. end;
  20.  
  21. function fun2();
  22. begin
  23.    ....
  24. end;
  25.  
  26. function fun3();
  27. begin
  28.    ....
  29. end;
  30.  
  31.  
Call graph for unit u1:
Code: Text  [Select][+][-]
  1. fun1
  2.    |
  3.    |---fun2
  4.    |---fun3
  5.  
  6. fun4
  7.    |
  8.    |---fun2
  9.    |---fun3
  10.  
  11. fun2
  12.  
  13. fun3
  14.  
I want XML, JSON or simple plain text repr. as above.
Title: Re: Call graph
Post by: Martin_fr on September 21, 2019, 03:27:14 pm
A few others. Not tested any of them... And they might be more for class structures....

https://sourceforge.net/projects/essmodelforlaza/
https://github.com/JuhaManninen/Laz-Model

Not a graph, but in the IDE you have: "Find Identifier references" (somewhere in the menu / also in the context menu)
It can find places where a function is called.
With virtual/overriden methods it may not find all....
Title: Re: Call graph
Post by: simone on September 21, 2019, 04:05:04 pm
As far as I know, none of the proposed tools is conceived to generate call graphs, i.e. graph that shows execution control flow. Pudgdb examines units dependencies. LazProfile is a performance profiler. EssModel and LazModel generates class diagram in UML style.
Title: Re: Call graph
Post by: zamtmn on September 21, 2019, 04:24:09 pm
LazProfiler has information about runtime procedure calls. It only needs to be taken out
Title: Re: Call graph
Post by: simone on September 21, 2019, 07:22:23 pm
I did not know PudGdb and I want to try it, but when I open the project, the IDE fails to download following packages: ag_graph, ag_vector, zobjectinspector. Where can I find them?
Title: Re: Call graph
Post by: zamtmn on September 21, 2019, 08:21:48 pm
https://forum.lazarus.freepascal.org/index.php/topic,34040.msg245712.html#msg245712  , but better https://github.com/zamtmn/pudgb/releases
Title: Re: Call graph
Post by: 440bx on September 21, 2019, 11:30:02 pm
How generate Call Graph and Dependency Graph
From the answers you've received above and, from my limited knowledge of Lazarus, I don't think Lazarus generates a procedure/function call graph for a program.

If you are familiar with AWK, it is fairly simple to generate the dependency sets from each function/procedure.  From the dependency sets it's trivial to generate a call graph and a dependency graph. 

There is one thing to be careful about, a topological sort is used to generate an ordered dependency graph, choose an algorithm that detects circular dependencies (most do) and handles them "gracefully" (some just stop, others can represent the cycle and continue sorting - the latter is obviously the kind of algorithm you want.)

Just FYI, way way back, TurboPower software had a product called Turbo Analyst which produced call graphs.  I don't know if that is one of the products they open sourced after they closed shop.  If it is available somewhere, it's likely it would need "improvements" to handle the FPC dialect but, for old Turbo Pascal code (circa TP6 and 7), it's likely to work without any changes.


Title: Re: Call graph
Post by: julkas on September 22, 2019, 10:49:16 am
Thanks all for replies.
I want simple and powerful static code analysis feature -
Quote
A call graph (also known as a call multigraph) is a control flow graph, which represents calling relationships between subroutines in a computer program. Each node represents a procedure and each edge (f, g) indicates that procedure f calls procedure g. Thus, a cycle in the graph indicates recursive procedure calls.
My code is not over complicated, so I will proceed manually.
Title: Re: Call graph
Post by: Thaddy on September 22, 2019, 12:08:02 pm
Note LazModel/EssModel works even on a Raspberry Pi with some slight adjustments:
The QueryInterface/_AddRef/_Release need to be explicitly cdecl on Linux and QueyInterface must be adapted to take constref instead of const for recent FPC versions.
Maybe Juha reads this?
Title: Re: Call graph
Post by: julkas on September 24, 2019, 06:04:17 pm
Something like here - https://www.peganza.com/products_pal.html
Title: Re: Call graph
Post by: marcov on September 24, 2019, 09:52:46 pm
valgrind/callgrind?
Title: Re: Call graph
Post by: julkas on September 25, 2019, 11:14:36 am
valgrind/callgrind?
Can valgrind/callgrind generate compile time (not run time) call graph/tree ?
Title: Re: Call graph
Post by: Thaddy on September 25, 2019, 11:23:33 am
Yes. (just proof)
But there are more than enough dependency scanners.
One of which is the parser and  lexer in the compiler itself. That happens to work....And you have the code... 8-)

fcl-passrc is almost just as good...
Title: Re: Call graph
Post by: zamtmn on September 25, 2019, 12:55:17 pm
No, callgrind works in runtime.
I have not met static analyzers for FPC. Only for delphi, and they don't work with modern FPC
Title: Re: Call graph
Post by: marcov on September 25, 2019, 03:35:05 pm
valgrind/callgrind?
Can valgrind/callgrind generate compile time (not run time) call graph/tree ?

Not that I know, but the initial post didn't mention that constraint.  Lazarus does not really contain much source code metrics tools. Peganza is about the only choice there.
Title: Re: Call graph
Post by: marcov on September 25, 2019, 03:35:45 pm
Not a graph, but in the IDE you have: "Find Identifier references" (somewhere in the menu / also in the context menu)
It can find places where a function is called.
With virtual/overriden methods it may not find all....

And or ifdefs...
Title: Re: Call graph
Post by: avra on October 03, 2019, 11:04:42 pm
How generate Call Graph - https://en.wikipedia.org/wiki/Call_graph and Dependency Graph - https://en.wikipedia.org/wiki/Dependency_graph in Lazarus?

Not in Lazarus, but with SciTools Understand:
https://scitools.com/clustered-call-graphs/
https://scitools.com/feature-category/dependency-analysis/
Title: Re: Call graph
Post by: julkas on October 12, 2019, 02:17:55 pm
How generate Call Graph - https://en.wikipedia.org/wiki/Call_graph and Dependency Graph - https://en.wikipedia.org/wiki/Dependency_graph in Lazarus?

Not in Lazarus, but with SciTools Understand:
https://scitools.com/clustered-call-graphs/
https://scitools.com/feature-category/dependency-analysis/
@avra Thanks.
TinyPortal © 2005-2018