You are not logged in.

#1 2010-09-29 21:33:10

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Application to visualize program flow

I'm looking for an easier way to "visualize" what is going on in the source code of a large project, in regards to function calls, method calls, and classes.

For example, a source directory of a project will have a bunch of files, like this:

...
anim.c
character.c
direction.c
game.c
input.c
main.c
player.c
resources.c
room.c
screen.c
...

If I didn't know anything about this project, if I wanted to try to understand how it works it would be difficult to start.

Does anyone know of an application that will read source code and display a tree-like output of the program flow? For example, maybe like this:

main() [main.c]
-> create_game() [game.c]
-> reset_timer() [timer.c]
-> update_game() [game.c]
---> update_world() [world.c]
---> is_game_over() [game.c]
---> ...
-> draw_game() [game.c]
---> draw_world() [world.c
---> ...
-> destroy_game() [game.c]
...

How about for classes and method calls?

I don't care if it's GUI or CLI, or what programming language it's for. I think a program like this would be incredibly useful, especially in the FOSS community, and would be surprised if something doesn't already exist. tongue

Offline

#2 2010-09-29 21:59:13

codycarey
Member
Registered: 2009-08-21
Posts: 154

Re: Application to visualize program flow

If you just want to generate source code graphs look into Doxygen [extra/doxygen], but if you want to see the flow as it's running you'll need a debugger like gdb.

EDIT: http://www.stack.nl/~dimitri/doxygen/

Last edited by codycarey (2010-09-29 22:00:26)

Offline

#3 2010-09-29 23:01:54

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Application to visualize program flow

Thank you, I remember hearing about Doxygen but had forgotten about it. I installed it and am reading about how to use it. You wouldn't happen to know how to make it do what I was asking, would you? big_smile

I am interested in source code parsing, not parsing a running application.

Offline

#4 2010-10-01 10:33:51

joven
Member
Registered: 2010-03-27
Posts: 19

Re: Application to visualize program flow

I've never found an app that automatically does this. When I want to do what you are describing, I use a UML tool to basically take notes as I read the code. This piece calls that piece. This class subclasses that class. It doesnt take long for the bigger picture to start emerging. Using UML to do this helps a lot because I dont need to remember anything as I go.

Offline

#5 2010-10-01 10:34:42

joven
Member
Registered: 2010-03-27
Posts: 19

Re: Application to visualize program flow

I should also note that in my experience doxygen is great at displaying structure not runtime behavior.

Offline

#6 2010-10-01 13:39:58

Google
Member
From: Mountain View, California
Registered: 2010-05-31
Posts: 484
Website

Re: Application to visualize program flow

Offline

#7 2010-10-02 21:15:40

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Application to visualize program flow

Google wrote:

ptrace?

I want to learn what happens in the source code, not at run time. I don't think ptrace (or strace) can do that. Even if it did, I'd only be able to learn about how a function is called after finding a way to get the running application to call it.

joven wrote:

I've never found an app that automatically does this. When I want to do what you are describing, I use a UML tool to basically take notes as I read the code. This piece calls that piece. This class subclasses that class. It doesnt take long for the bigger picture to start emerging. Using UML to do this helps a lot because I dont need to remember anything as I go.

You described my situation very well. I, too, try to make notes like that when reading the source code of a project.

I'm very surprised there isn't a program that does this automatically. I may have found an idea for my next personal project. wink

Offline

#8 2010-10-02 21:21:24

SanskritFritz
Member
From: Budapest, Hungary
Registered: 2009-01-08
Posts: 1,928
Website

Re: Application to visualize program flow

[offtopic] joven Which UML program are you using?


zʇıɹɟʇıɹʞsuɐs AUR || Cycling in Budapest with a helmet camera || Revised log levels proposal: "FYI" "WTF" and "OMG" (John Barnette)

Offline

#9 2010-10-02 21:25:50

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Application to visualize program flow

SanskritFritz wrote:

[offtopic] joven Which UML program are you using?

I don't even know what exists besides Dia. tongue

Last edited by drcouzelis (2010-10-02 21:26:24)

Offline

#10 2010-10-02 21:27:45

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,294

Re: Application to visualize program flow

I guess this would not so tough with explicit function calls, but what about cases where functions are passed by reference and those references are stored for later use.  Here I think of things such as call back functions or references to pseudo-objects in toolkits like Gtk. 

I realize your example is for C.  This gets uglier with C++ where the function that actually gets called is determined at run time as a function of inheritance.

It gets really ugly in languages that use the reflective paradigm where they can actually change their structure at runtime (Python Lua, Lisp, Ruby, etc...)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#11 2010-10-02 21:39:58

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Application to visualize program flow

ewaller wrote:

I guess this would not so tough with explicit function calls, but what about cases where functions are passed by reference and those references are stored for later use.  Here I think of things such as call back functions or references to pseudo-objects in toolkits like Gtk.

The easiest thing to do would be to report that a function named "function_ptr_var" (or whatever the variable is called) was called. This makes sense to me.

ewaller wrote:

I realize your example is for C.  This gets uglier with C++ where the function that actually gets called is determined at run time as a function of inheritance.

I would report the name of the method and the class type of the variable that called it.

ewaller wrote:

It gets really ugly in languages that use the reflective paradigm where they can actually change their structure at runtime (Python Lua, Lisp, Ruby, etc...)

I don't know enough about these languages. Maybe someone else has an idea.

Offline

#12 2010-10-03 01:54:48

codycarey
Member
Registered: 2009-08-21
Posts: 154

Re: Application to visualize program flow

Well, another option is to use IDA Pro. They offer a free version for Windows, but there isn't a native Linux equivalent of it I believe. However, their standard and advanced versions which cost money do have native Linux versions. Of course, that means shelling out like $500-$1000 depending on what you get.

Do some googling to find out how well the free version works in Wine/VMs. Personally I own a standard copy of IDA Pro, it's just worth it. If you ever plan to rip apart software it has no competition.

Offline

#13 2010-10-03 14:14:49

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Application to visualize program flow

It looks like IDA Pro is used to watch the flow of a running application, which isn't what I'm looking for. Can it parse a directory of source code and report the flow of function calls?

Offline

#14 2010-10-07 05:14:35

tousborne
Member
Registered: 2007-12-01
Posts: 5

Re: Application to visualize program flow

It's probably not everything you're hoping for, but GNU cflow might be of some use.  It's also in the AUR.

http://www.gnu.org/software/cflow/
http://aur.archlinux.org/packages.php?ID=1085

Offline

#15 2010-10-07 05:59:34

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Application to visualize program flow

tousborne wrote:

It's probably not everything you're hoping for, but GNU cflow might be of some use.

Thank you, yes, that is exactly what I was looking for! I had never heard of cflow before.

I did an Internet search. Apparently cflow is a "call graph generator". This page lists others, including KCachegrind, codeviz, egypt, gprof, and pycallgraph. I will start trying them out.

https://secure.wikimedia.org/wikipedia/ … generators

This pretty much answers my question. After I try some out, if I find one I really like I might mention it here in this thread.

Thanks everyone!

Offline

#16 2010-10-07 13:10:42

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Application to visualize program flow

cflow - For C programs. Nice and simple.

KCacheGrind - Uses the "callgrind" application. I couldn't find callgrind in the Arch repositories or the AUR, so I gave up.

codeviz - For C and C++ programs. I got it to produce a beautiful PNG tree of all of my function calls. I probably won't use it. A graphical tree output isn't so useful to me, and it was a bit tricky to actually setup and use. (for example, it requires a patched version of GCC)

egypt - For C programs. Super duper simple concept, but requires some setup to use. I couldn't figure out how to configure and run it.

gprof - Part of the GNU Binary Utilities. A little too low level for what I was looking for.

pycallgraph - For Python programs. I didn't try it.

doxygen - Is able to create documentation for anything in the world, including your car. I wish someone could tell me, "Type this doxygen command to create a call graph", but until that happens, I just can't seem to figure it out.

cflow is definitely my favorite. I will do some post processing to the output to remove any functions that I didn't write.

EDIT: Someone did a similar "review" to mine here, along with mentioning more programs to try out: http://grok2.tripod.com/code_comprehension.html

Last edited by drcouzelis (2010-10-07 13:13:45)

Offline

#17 2010-10-07 13:50:58

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Application to visualize program flow

drcouzelis wrote:

I couldn't find callgrind in the Arch repositories or the AUR, so I gave up.

Because it's not an independent program.

valgrind --tool=callgrind ...

Offline

#18 2010-10-07 23:53:05

duquesnc
Member
Registered: 2008-12-10
Posts: 94
Website

Re: Application to visualize program flow

AFAIK, doxygen has a wizard easy to use. They you just run doxygen...

Offline

#19 2010-10-25 12:50:51

joven
Member
Registered: 2010-03-27
Posts: 19

Re: Application to visualize program flow

SanskritFritz wrote:

[offtopic] joven Which UML program are you using?

Sorry for the delay in answer. I use a commercial tool called MagicDraw. Its awesome. I've used it for 6 or 7 years and highly recommend it. I'm a heavy UML user and have never seen another tool I would replace it with. The personal edition, which is all I have ever needed, is $149 so its not going to break the bank either. Well worth the money.

Offline

Board footer

Powered by FluxBB