Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > About extract call graph from C source code

Reply
Thread Tools

About extract call graph from C source code

 
 
Xing Xu
Guest
Posts: n/a
 
      01-14-2004
Hi guiders,

sorry , since I don't know which group suit for this question,I just post this
question at these group.

As we know , we can get the run-time call graph by some proved tools .
now I have a problem about the extract call graph from statice C source code
, not from binary.

I have try to use cscope and write some perl script for it .
but final I find If there are have the function piont call or function
defined by macro , cscope have some problem to parse the source code .
At last I find I almost write a C language parser for it just like a compiler
Unfortuntaly I am not good at area .

Are there have another reliable ways or tools to extract call graph
from source code ?

Thanks

Xing
--
comp.lang.c.moderated - moderation address: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Douglas A. Gwyn
Guest
Posts: n/a
 
      01-14-2004
Xing Xu wrote:
> I have try to use cscope and write some perl script for it .
> but final I find If there are have the function piont call or function
> defined by macro , cscope have some problem to parse the source code .


Try preprocessing the source first (cc -E on Unix) then give
the result to cscope.
--
comp.lang.c.moderated - moderation address: (E-Mail Removed)
 
Reply With Quote
 
 
 
 
Hans-Bernhard Broeker
Guest
Posts: n/a
 
      01-17-2004
[Note: F'up2 reduced to one group --- should've been done by OP...]

In comp.lang.c.moderated Xing Xu <(E-Mail Removed)> wrote:

> I have try to use cscope and write some perl script for it.


There's now a KDE GUI for cscope, called kscope, which has a calltree
extractor based on cscope ouput. You may want to use that, instead of
rolling your own. It's at http://kscope.sourceforge.net/

> but final I find If there are have the function piont call or function
> defined by macro, cscope have some problem to parse the source code.


Indeed, use of function pointers does throw cscope off track quite
reliably ;-(. The problem can be reduced considerably by always using
typedefs for function pointer types, to avoid extra parentheses inside
the parentheses of a function definition, i.e. you should have

typedef int (*t_fp)(char);
void somefunction(t_fp function_pointer_argument);

instead of

void somefunction (int (*function_pointer_argument)(char));

You'll still get an incomplete call graph, though, since use of
function pointers generally makes static analysis impossible. cscope
won't log passing of a function foo() as an argument to function bar()
as a call to foo().

I'm not sure I understand what you mean by "function defined by
macro". Cscope does not run its input through the C preprocessor, so
it can't expand macros. If your function definition is entirely
hidden inside a macro call like the "DEFUN" convention in Emacs source
code, that means cscope's parser won't catch it. You'ld have to
extend cscope's parser yourself to do that, and I'm not even sure it
can be done inside the given framework.

> Are there have another reliable ways or tools to extract call graph
> from source code ?


None that I know of, at least not if the source code is obfuscated by
heavy use of macros the tool doesn't know about. You could run the
tools on preprocessed sources, but that may well create as many new
problems as it solves given ones.

--
Hans-Bernhard Broeker ((E-Mail Removed)-aachen.de)
Even if all the snow were burnt, ashes would remain.
--
comp.lang.c.moderated - moderation address: (E-Mail Removed)
 
Reply With Quote
 
Luiz Henrique de Figueiredo
Guest
Posts: n/a
 
      01-17-2004
In article <(E-Mail Removed)>, Xing Xu <(E-Mail Removed)> wrote:
>
>Are there have another reliable ways or tools to extract call graph
>from source code ?


Try cflow at ftp://ftp.tecgraf.puc-rio.br/pub/lhf/cflow.tar.gz .
--
comp.lang.c.moderated - moderation address: (E-Mail Removed)
 
Reply With Quote
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      01-17-2004
In comp.lang.c Xing Xu <(E-Mail Removed)> wrote:

> sorry , since I don't know which group suit for this question,I just
> post this question at these group.

(linewrap adjusted)
> (snip cscope question>


In the likely case that you don't get all the information you need
from here, the following URL has suggestions for alternate groups to
post to:

http://www.msu.edu/~pfaffben/writing...off-topic.html

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
--
comp.lang.c.moderated - moderation address: (E-Mail Removed)
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      01-17-2004
>As we know , we can get the run-time call graph by some proved tools .
>now I have a problem about the extract call graph from statice C source code
>, not from binary.

.....
>
>Are there have another reliable ways or tools to extract call graph
>from source code ?


Try doxygen www.doxygen.org

In the config you can tell it you're using C. I've not tried it with
'tricky' code (fn pointers and the like) so don't know how far you'll
get there but as far as static calls goes it's fine.

cheers,
--
John
--
comp.lang.c.moderated - moderation address: (E-Mail Removed)
 
Reply With Quote
 
James Antill
Guest
Posts: n/a
 
      01-17-2004
On Wed, 14 Jan 2004 01:39:21 +0000, Xing Xu wrote:

> Are there have another reliable ways or tools to extract call graph from
> source code ?


There are a few, smatch http://smatch.sourceforge.net/ is probably the
closest to a real compiler (unsurprisingly).

--
James Antill -- (E-Mail Removed)
Need an efficient and powerful string library for C?
http://www.and.org/vstr/
--
comp.lang.c.moderated - moderation address: (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Boost Graph Library to create very large graph Almoni C++ 0 01-17-2010 05:13 AM
[Boost.Graph] graph.vertices property creates new objects George Sakkis Python 1 01-29-2007 11:09 PM
Help with initialization of graph (Boost Graph Library) Jef Driesen C++ 3 01-24-2006 01:44 PM
Missing Graph.h and (Graph.lib) woes - any help Dr Ann Huxtable C Programming 6 12-21-2004 11:15 AM
GD::Graph: "mixed" graph doesn't recognize "area" graph type Emilio Mayorga Perl Misc 6 10-08-2003 02:14 AM



Advertisments