Unix/Linux/Perl Tool to determine if function is defined but not called ?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Unix/Linux/Perl Tool to determine if function is defined but not called ?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Unix/Linux/Perl Tool to determine if function is defined but not called ?  
bakul.joshi@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-17-06 07:57 AM

Is there a tool to determine whether a function is defined but not
being called in a program?The program can be in any
language(C/Perl/Unix)..I studied the nm tool that does the profiling of
the object file but that gives all the functions that are defined
(whether or not they are called in the file)...






[ Post a follow-up to this message ]



    Re: Unix/Linux/Perl Tool to determine if function is defined but not called ?  
Andrei Voropaev


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-17-06 07:57 AM

On 2006-03-17, bakul.joshi@gmail.com <bakul.joshi@gmail.com> wrote:
> Is there a tool to determine whether a function is defined but not
> being called in a program?The program can be in any
> language(C/Perl/Unix)..I studied the nm tool that does the profiling of
> the object file but that gives all the functions that are defined
> (whether or not they are called in the file)...

Assuming you are talking about C. Probably you'll like the ctags
program. Not only you can see if some function is used at all, but you
can also see at which specific place(s) it is used.
http://ctags.sourceforge.net/

Well, if you want to find all the functions that are not used, then
probably you'll have to write a script that gets the list of all defined
functions (maybe from nm output) and then uses ctag to do the checking

--
Minds, like parachutes, function best when open





[ Post a follow-up to this message ]



    Re: Unix/Linux/Perl Tool to determine if function is defined but not called ?  
Simon Elliott


Report This Message To A Moderator Edit/Delete Message


 
03-17-06 12:50 PM

On 17/03/2006, bakul.joshi@gmail.com wrote:

> Is there a tool to determine whether a function is defined but not
> being called in a program?The program can be in any
> language(C/Perl/Unix)..I studied the nm tool that does the profiling
> of the object file but that gives all the functions that are defined
> (whether or not they are called in the file)...

Lint will do this (eg http://www.gimpel.com/html/flex.htm) but might be
overkill if you only want to find unused functions.

The map files produced by one of the W32 linkers I use (BCB) can be
used to work out which functions have been called. Can you do something
similar with gcc?

--
Simon Elliott    http://www.ctsn.co.uk





[ Post a follow-up to this message ]



    Re: Unix/Linux/Perl Tool to determine if function is defined but not called ?  
Ben C


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-17-06 10:55 PM

On 2006-03-17, Simon Elliott <> wrote:[vbcol=seagreen]
> On 17/03/2006, bakul.joshi@gmail.com wrote:
> 

I use nm, grep for the capital Ts, filter that a bit with something,
feed it to cscope -L -3, and look for empty strings coming back.

Unused static functions will get you a compiler warning on gcc.





[ Post a follow-up to this message ]



    Re: Unix/Linux/Perl Tool to determine if function is defined but not called ?  
Waldek Hebisch


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-18-06 01:53 AM

bakul.joshi@gmail.com wrote:
> Is there a tool to determine whether a function is defined but not
> being called in a program?The program can be in any
> language(C/Perl/Unix)..I studied the nm tool that does the profiling of
> the object file but that gives all the functions that are defined
> (whether or not they are called in the file)...
>

There is no general solution, the problem is unsolvable (it is equivalent
to well known halting problem). If you limit yourself to a "static" language
like C, then it is possible to get partial answer which in practice may be
good enough. For example, if you compile program using gcc-4.0 and give
it '-O2' option, then gcc will remove provably "useless" functions (and
variables). So if you compile twice once using '-O0' option and once
using '-O2' and compare what nm gives you you will see unused functions.
Note that this does not work for global functions -- gcc sees only one
file and can not tell if global functions are used.

Another possiblility is to use program like gprof and gcov: they will
tell you which functions were used dureing given program run. While
function not used in one run may be used in another run, this can give
you a list of suspects worth closer examination.

--
Waldek Hebisch
hebisch@math.uni.wroc.pl





[ Post a follow-up to this message ]



    Re: Unix/Linux/Perl Tool to determine if function is defined but not called ?  
Ben C


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-18-06 01:53 AM

On 2006-03-17, Ben C <spamspam@spam.eggs> wrote:
> On 2006-03-17, Simon Elliott <> wrote: 
>
> I use nm, grep for the capital Ts, filter that a bit with something,
> feed it to cscope -L -3, and look for empty strings coming back.
>
> Unused static functions will get you a compiler warning on gcc.

Oh and I forgot to mention, this will miss functions assigned to
variables and called indirectly. If you think there might be some of
those, it's a bit harder, but you can do something similar but with
cscope -L -0. Deciding if the indirected functions are actually called
is harder still...

There are such things as "dead code removing linkers", I think gcc may
have an option for this, that would probably be the most reliable thing
to use really.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:25 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register