Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help for generating tag files for source code

12 views
Skip to first unread message

prasanna bhat mavinkuli

unread,
Mar 28, 2005, 5:34:13 AM3/28/05
to
hi all,
I am a fresher to Linux. Actually I want to get a list
of all the function calls made in C, C++ source files.
we can obtain list of all function definitions in C/c++
source files using ctags. Any other utility available
on linux that can give the list of all function calls
invoked in source files?

thanks in advance
Prasanna Bhat Mavinkuli

Måns Rullgård

unread,
Mar 28, 2005, 6:17:34 AM3/28/05
to
boss...@yahoo.co.in (prasanna bhat mavinkuli) writes:

> hi all,
> I am a fresher to Linux. Actually I want to get a list
> of all the function calls made in C, C++ source files.
> we can obtain list of all function definitions in C/c++
> source files using ctags. Any other utility available
> on linux that can give the list of all function calls
> invoked in source files?

Check out cscope.

--
Måns Rullgård
m...@inprovide.com

Jens.T...@physik.fu-berlin.de

unread,
Mar 28, 2005, 2:59:06 PM3/28/05
to
prasanna bhat mavinkuli <boss...@yahoo.co.in> wrote:
> I am a fresher to Linux. Actually I want to get a list
> of all the function calls made in C, C++ source files.
> we can obtain list of all function definitions in C/c++
> source files using ctags. Any other utility available
> on linux that can give the list of all function calls
> invoked in source files?

Do you mean all functions that are referenced in the C code
or do you mean all functions that in a run of the program
are called? The latter is a question that can't be answered
generally, since what functions get invoked can depend on
how the program gets started or on external input it receives.
With something as simple as

#include <stdio.h>

void func_a( void ) {
printf( "Program was called with no arguments\n" );
}

void func_b( void ) {
printf( "Program was called with at least one argument\n" );
}

int main( int argc, char *argv[ ] ) {
if ( argc <= 1 )
func_a( );
else
func_b( );
return 0;
}

you already can't tell. But even the first question can be hard
to answer when function pointers are used. E.g.

#include <stdio.h>

void func_a( void ) {
printf( "Program was called with no arguments\n" );
}

void func_b( void ) {
printf( "Program was called with at least one argument\n" );
}

int main( int argc, char *argv[ ] ) {
void ( *f )( void );
f = argc <= 1 ? func_a : func_b;
f( );
return 0;
}

makes it hard to automatically detect if func_a() or func_b() are
actually used at all (here it's still rather obvious, but things
can get a lot more complicated). Moreover, a function can be defined
in one source file but only used from a different one. Even the
compiler can't find out then - gcc has the '-funused-function' option
to warn you about function that are declared as static but aren't used,
but that's as far as you can get with a compiler (since it always only
sees a single souce file). If e.g. a functions address is assigned to
a function pointer and this one is passed to a function in a different
C source file it's impossible to say what function is going to be in-
voked by just looking at source file where the function pointer is used
to call the function. Only the linker would be able to tell which of
the symbols it found in the object files are never used. So writing
such a tool would definitely not be simple and would need to know all
about the commands used to create the final executable. Your best
chance is probably using a profiler that creates a list of which func-
tion where called how often (and how much time was spent in the
functions). But, of course, if the flow of control in the program
depends on external input the list might differ from invocation to
invocation.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.T...@physik.fu-berlin.de
\__________________________ http://www.toerring.de

Joe Zeff

unread,
Mar 28, 2005, 6:56:13 PM3/28/05
to
On 28 Mar 2005 02:34:13 -0800, boss...@yahoo.co.in (prasanna bhat
mavinkuli) wrote:

>we can obtain list of all function definitions in C/c++
>source files using ctags.

..."we" as in those of us taking this class that want you do do our
homework for us?

--
Joe Zeff
The Guy With the Sideburns
"Always there are two, the BOFH and the PFY."
http://www.lasfs.org http://home.earthlink.net/~sidebrnz

0 new messages