By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

About extract call graph from C source code

P: n/a
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: cl**@plethora.net
Nov 14 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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: cl**@plethora.net
Nov 14 '05 #2

P: n/a
[Note: F'up2 reduced to one group --- should've been done by OP...]

In comp.lang.c.moderated Xing Xu <so****@163.com> 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 (br*****@physik.rwth-aachen.de)
Even if all the snow were burnt, ashes would remain.
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 14 '05 #3

P: n/a
In article <cl****************@plethora.net>, Xing Xu <so****@163.com> 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: cl**@plethora.net
Nov 14 '05 #4

P: n/a
In comp.lang.c Xing Xu <so****@163.com> 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: cl**@plethora.net
Nov 14 '05 #5

P: n/a
>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: cl**@plethora.net
Nov 14 '05 #6

P: n/a
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 -- ja***@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/
--
comp.lang.c.moderated - moderation address: cl**@plethora.net
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.