Hi,
Is there any tool that would do static detection (doesnt execute the
application) of dead code for C++ application.
Few tools do show which code flow would never get executed, but i am
looking for some tool which would detect any functions that are never
used at all? or any classes that are created but not instantiated.
This is required for an application which includes hundreds of C++
files and many classes.
Any help will be appreciated.
Thanks
Sanjay Raghani
|
|
0
|
|
|
|
Reply
|
sanjay.raghani (8)
|
8/1/2008 11:33:44 AM |
|
just to make the requirement more clear..
Following has been taken from coverity help which does have DEADCode
checker:
"The DEADCODE checker finds many instances of code that can never be
reached due to branches whose condition will always evaluate the same
way whenever the program is executed. This checker does not warn about
function-level dead code such as static functions which are never
called."
so here the requirement is to actually detect the code that is never
called. i think coverity/similar tools wont be of help here...
the reason i am looking for a tool is because the application is
pretty huge and includes hundreds of cpp files. Also the files have
been added since long.. so there will surely be lot of code that is
not used any more and could be removed..
On Aug 1, 4:33 pm, sanjay <sanjay.ragh...@gmail.com> wrote:
> Hi,
>
> Is there any tool that would do static detection (doesnt execute the
> application) of dead code for C++ application.
>
> Few tools do show which code flow would never get executed, but i am
> looking for some tool which would detect any functions that are never
> used at all? or any classes that are created but not instantiated.
>
> This is required for an application which includes hundreds of C++
> files and many classes.
>
> Any help will be appreciated.
>
> Thanks
> Sanjay Raghani
|
|
0
|
|
|
|
Reply
|
sanjay.raghani (8)
|
8/1/2008 11:45:02 AM
|
|
On Aug 1, 7:45=A0am, sanjay <sanjay.ragh...@gmail.com> wrote:
> just to make the requirement more clear..
>
> Following has been taken from coverity help which does have DEADCode
> checker:
> "The DEADCODE checker finds many instances of code that can never be
> reached due to branches whose condition will always evaluate the same
> way whenever the program is executed. This checker does not warn about
> function-level dead code such as static functions which are never
> called."
>
> so here the requirement is to actually detect the code that is never
> called. i think coverity/similar tools wont be of help here...
>
> the reason i am looking for a tool is because the application is
> pretty huge and includes hundreds of cpp files. Also the files have
> been added since long.. so there will surely be lot of code that is
> not used any more and could be removed..
I'm sorry, what you ask is impossible. No static analysis could tell
you which code may or may not be called during execution of the
program. You might as well as for a static analysis tool that tells
you whether a program will complete or not.
Joe C
|
|
0
|
|
|
|
Reply
|
joecook (150)
|
8/1/2008 12:24:49 PM
|
|
"sanjay" <sanjay.raghani@gmail.com> wrote in message
news:c81eb7e5-6744-471b-b183-e96268d47653@56g2000hsm.googlegroups.com...
> Hi,
>
> Is there any tool that would do static detection (doesnt execute the
> application) of dead code for C++ application.
>
> Few tools do show which code flow would never get executed, but i am
> looking for some tool which would detect any functions that are never
> used at all? or any classes that are created but not instantiated.
>
> This is required for an application which includes hundreds of C++
> files and many classes.
>
> Any help will be appreciated.
Best tool is the compiler. Just create a version of app and hide ( comment
out or remove source from makefile) functions definitions you think arent
used. If App links then function is unused.
You can also work the other way , gradually putting in the function
definitions that are used, or a combination of the two methods
regards
Andy Little
|
|
0
|
|
|
|
Reply
|
andy199 (808)
|
8/1/2008 12:52:21 PM
|
|
In article
<2d3e769b-9fc7-43e3-a6ba-8a99d6988272@w7g2000hsa.googlegroups.com>, sanjay
<sanjay.raghani@gmail.com> wrote:
> ...
> the reason i am looking for a tool is because the application is
> pretty huge and includes hundreds of cpp files. Also the files have
> been added since long.. so there will surely be lot of code that is
> not used any more and could be removed..
Use a compiler/linker combination which can do "dead stripping". A decent
compiler will optimize out things like
if ( 0 ) { /* ... */ }
and one that links only objects that are actually used will strip out
things like f() below.
// foo.cpp
static void f() { /* ... */ }
// ... following code never calls f
// ...
This sort of compiler/linker won't usually detect virtual functions never
called, though.
If you want code which could be called, but never is in practice, you'll
need a tool which keeps track of code that's used, then a data set which
exercises ALL functionality (including all possible errors).
|
|
0
|
|
|
|
Reply
|
blargg.h4g (301)
|
8/1/2008 1:16:50 PM
|
|
On Aug 1, 7:33=A0am, sanjay <sanjay.ragh...@gmail.com> wrote:
> Hi,
>
> Is there any tool that would do static detection (doesnt execute the
> application) of dead code for C++ application.
>
> Few tools do show which code flow would never get executed, but i am
> looking for some tool which would detect any functions that are never
> used at all? or any classes that are created but not instantiated.
>
> This is required for an application which includes hundreds of C++
> files and many classes.
>
> Any help will be appreciated.
>
> Thanks
> Sanjay Raghani
First, I suggest using Doxygen to get an overall feel of library
and file dependencies. Also, I'm pretty sure Doxygen will also
generate call graphs which I think is what your asking for.
Second, I suggest make a regression test suite *before* you
modify any code. With that, you can heavily modify your
project and have confidence that it still produces the same
results given the same inputs.
HTH
|
|
0
|
|
|
|
Reply
|
AnonMail2005 (245)
|
8/1/2008 1:36:33 PM
|
|
On Aug 1, 2:24 pm, joseph cook <joec...@gmail.com> wrote:
> On Aug 1, 7:45 am, sanjay <sanjay.ragh...@gmail.com> wrote:
> > just to make the requirement more clear..
> > Following has been taken from coverity help which does have DEADCode
> > checker:
> > "The DEADCODE checker finds many instances of code that can never be
> > reached due to branches whose condition will always evaluate the same
> > way whenever the program is executed. This checker does not warn about
> > function-level dead code such as static functions which are never
> > called."
> > so here the requirement is to actually detect the code that is never
> > called. i think coverity/similar tools wont be of help here...
> > the reason i am looking for a tool is because the application is
> > pretty huge and includes hundreds of cpp files. Also the files have
> > been added since long.. so there will surely be lot of code that is
> > not used any more and could be removed..
> I'm sorry, what you ask is impossible. No static analysis
> could tell you which code may or may not be called during
> execution of the program.
Yes and no. If the function is never referenced, it won't be
called. One simple solution for starters is to put each
function in a separate source file in a library, and see which
ones the linker picks up.
Of course, with virtual functions, it's somewhat harder. But
not always impossible.
> You might as well as for a static analysis tool that tells you
> whether a program will complete or not.
And... It's usually considered impossible in the general case,
but there are lots of special cases where it can be done.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34
|
|
0
|
|
|
|
Reply
|
james.kanze (9620)
|
8/1/2008 3:58:47 PM
|
|
|
6 Replies
44 Views
(page loaded in 0.178 seconds)
Similiar Articles: detecting leaks with purify in shared libraries - comp.unix ...> > On my solaris 10 box, I have a propriety application (no source code), > which dynamically ... any good tool to analyze memory corruption problem - comp.unix ... Check ... How best to detect duplicate values in a column? - comp.databases ...So given that this is *only* for an audit tool to use during or after a new-code ... When I write code that is becoming part of the application, I test that code to ... DICOM usage in MFC application - comp.os.ms-windows.programmer ...I want sample code. I see that there are tool available to do the above like "TIM" , "fpimage". But I don't want to use the tools. I have to write the application ... How can glClear cause application crashes? - comp.graphics.api ...If I remove this line of code, the application will run just fine. I'm still using glClear ... Tool like Purify and MemoryValidator, unfortunately, can't seem to find ... Documenting object-oriented MATLAB code - comp.soft-sys.matlab ...... would be very surpirsed if you find any automated tools. The key that makes Doxygen work for C ... object-oriented MATLAB code ... I'm writing a sizable application using ... Implementing a mangling tool - comp.lang.c++.moderatedSuch a tool would be very useful in various cases ... unfriendly, particularly if you want to port the application ... much C would a sea slug code if a sea slug could code C? Calling MATLAB from Visual Studio in a C program - comp.soft-sys ...> > Best Build the C code using the mex command line with the "-g" option. ... to build an Engine application, then ... DOS base btrieve application error in Windows XP DOS box - comp ...We are trying to run the DOS application in the DOS box under ... Worst case, try downloading a set of tools from http ... If you're running the code from Windows 3.1/98/98SE ... how to disassembly a .jar file? how to see what are the classes ...... sun.com/j2se/1.4.2/docs/tooldocs/tools.html Particularly the jar and javap tools. ... lot nar, if you want to be blown away by a good decompiler, that can find dead code ... instancename of current entity/architecture -- equivalent to C++ ...Using C and Assembly code: 64Bit Calling ... do, is to merge assembly code and C-co... ... > > So, reporting a dead link in NASM doc. Current link ... System V Application ... Tool to detect dead code in C++ application - C / C++Tool to detect dead code in C++ application. C / C++ Forums on Bytes. Automated Dead code detection in native C++ application on Windows ...I believe that it is impossible for a generic tool to find all the dead (e.g. unreachable code) in any arbitrary application with zero false positives (I think this would ... 7/22/2012 4:02:41 PM
|