About extract call graph from C source code

Discussion in 'C Programming' started by Xing Xu, Jan 14, 2004.

  1. Xing Xu

    Xing Xu Guest

    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:
    Xing Xu, Jan 14, 2004
    #1
    1. Advertising

  2. 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:
    Douglas A. Gwyn, Jan 14, 2004
    #2
    1. Advertising

  3. [Note: F'up2 reduced to one group --- should've been done by OP...]

    In comp.lang.c.moderated Xing Xu <> 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 (-aachen.de)
    Even if all the snow were burnt, ashes would remain.
    --
    comp.lang.c.moderated - moderation address:
    Hans-Bernhard Broeker, Jan 17, 2004
    #3
  4. Luiz Henrique de Figueiredo, Jan 17, 2004
    #4
  5. In comp.lang.c Xing Xu <> 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/writings/clc/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:
    Christopher Benson-Manica, Jan 17, 2004
    #5
  6. Xing Xu

    John Guest

    >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:
    John, Jan 17, 2004
    #6
  7. Xing Xu

    James Antill Guest

    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 --
    Need an efficient and powerful string library for C?
    http://www.and.org/vstr/
    --
    comp.lang.c.moderated - moderation address:
    James Antill, Jan 17, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George Sakkis
    Replies:
    1
    Views:
    448
    Szabolcs Nagy
    Jan 29, 2007
  2. Dr Ann Huxtable

    Missing Graph.h and (Graph.lib) woes - any help

    Dr Ann Huxtable, Dec 21, 2004, in forum: C Programming
    Replies:
    6
    Views:
    648
    Dr Ann Huxtable
    Dec 21, 2004
  3. Jef Driesen
    Replies:
    3
    Views:
    2,540
    mlimber
    Jan 24, 2006
  4. Emilio Mayorga
    Replies:
    6
    Views:
    327
    Martien Verbruggen
    Oct 8, 2003
  5. Roy Smith

    Call graph analysis of perl source?

    Roy Smith, Nov 14, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    296
Loading...

Share This Page