473,513 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tool to detect dead code in C++ application

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
Aug 1 '08 #1
6 7743
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.comwrote:
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
Aug 1 '08 #2
On Aug 1, 7:45*am, sanjay <sanjay.ragh...@gmail.comwrote:
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
Aug 1 '08 #3

"sanjay" <sa************@gmail.comwrote in message
news:c8**********************************@56g2000h sm.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

Aug 1 '08 #4
In article
<2d**********************************@w7g2000hsa.g ooglegroups.com>, sanjay
<sa************@gmail.comwrote:
...
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).
Aug 1 '08 #5
On Aug 1, 7:33*am, sanjay <sanjay.ragh...@gmail.comwrote:
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
Aug 1 '08 #6
On Aug 1, 2:24 pm, joseph cook <joec...@gmail.comwrote:
On Aug 1, 7:45 am, sanjay <sanjay.ragh...@gmail.comwrote:
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:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Aug 1 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2985
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
0
3271
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool including SourceOffSite, SourceAnyWhere and VSS Remoting This article makes a detailed...
19
6766
by: lihua | last post by:
Hi, Group! I got one question here: We all know that fclose() must be called after file operations to avoid unexpected errors.But there are really cases when you forget to do that!Just like...
4
3828
by: Frank Meng | last post by:
Hi. I am trying a csharp sample from http://www.codeproject.com/csharp/socketsincs.asp . (Sorry I didn't post all the source codes here, please get the codes from above link if you want to try)....
0
1444
by: Namratha Shah \(Nasha\) | last post by:
Hi All, We have almost covered all the .NET Framework Tools except a few, which we will cover in the coming days. Today we will are going to check out a tool called as mscorcfg.msc. This is a...
10
1555
by: PJ6 | last post by:
I've read some of the posts on this subject but let me add this little twist to the subject's question- I can appreciate the utility of doing screen caps off of other websites with PSP or PhotoShop...
0
868
by: RadoMaster | last post by:
Hi, The last time browsing the internet for an answer, i saw somewhere here a thread talking about a profiling and tracing tool. i wanted to check the performance of my .NET application because...
9
16048
by: SeC | last post by:
Hi. Is there any way to detect if application is being killed by 'End Process' via Task Manager ?
8
1425
by: =?Utf-8?B?S2Vsdmlu?= | last post by:
Hi all, I am writing an application to detect the dead pixel of LCD panel by using visual C++ (MFC). My flow is follow: 1. Display a dialog with a start button. When the user press the start...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.