understand source code of a C++ program written by someone else

T

TCMA

I am looking for some tools to help me understand source code of a
program written in C++ by someone else.
Are there any non-commercial, open source C or C++ tools to reverse
engineer C or C++ programs with source codes on linux?
i.e. It parses any sized C or C++ project to help reverse engineer,
document, draw UML diagram and understand it and thus maintain it
better.
 
I

Ivan Vecerina

TCMA said:
I am looking for some tools to help me understand source code of a
program written in C++ by someone else.
Are there any non-commercial, open source C or C++ tools to reverse
engineer C or C++ programs with source codes on linux?
i.e. It parses any sized C or C++ project to help reverse engineer,
document, draw UML diagram and understand it and thus maintain it
better.
As a free tool, try doxygen (www.doxygen.com).
It can generate hyperlinked HTML from source code, class hierarchy
graphs, called-by lists, and more...

hth,
Ivan
 
E

E. Robert Tisdale

TCMA said:
I am looking for some tools to help me understand source code of a
program written in C++ by someone else.
Are there any non-commercial, open source C or C++ tools to reverse
engineer C or C++ programs with source codes on linux?
i.e. It parses any sized C or C++ project to help reverse engineer,
document, draw UML diagram and understand it and thus maintain it
better.

No.
There is no tool that can make sense out of nonsense.
There are programs like Doxygen

http://www.doxygen.org/

that will automatically create documentation
from comments embedded in your source code
so that you can maintain your code an documentation together.
 
I

Ivan Vecerina

E. Robert Tisdale said:
No.
There is no tool that can make sense out of nonsense.
There are programs like Doxygen

http://www.doxygen.org/

that will automatically create documentation
from comments embedded in your source code
so that you can maintain your code an documentation together.

Just because this is easily misunderstood, I would like to insist
that doxygen can generate a lot of useful information, also from
code that does not contain any (doxygen) comments.
The output can still include:
- hyperlinked source code (click an identifier -> shows its definition)
- header dependencies (includes & included-by graphs)
- function call dependencies (links to all calls to a function)
- class hierarchies (graphs, links)
- index of namespaces, class names, etc...

There are IDEs that can provide some of the navigation interactively.
Nevertheless, doxygen generates valuable information (and even more
once you use doxygen-specific comments), expecially when reviewing
the structure of a program.


Regards,
Ivan
 
H

Howard

TCMA said:
I am looking for some tools to help me understand source code of a
program written in C++ by someone else.
Are there any non-commercial, open source C or C++ tools to reverse
engineer C or C++ programs with source codes on linux?
i.e. It parses any sized C or C++ project to help reverse engineer,
document, draw UML diagram and understand it and thus maintain it
better.

Some compilers have pretty good class browsers that will help. I'm not sure
about their ability to format the output for printers...you'd have to check.
But CodeWarrior (which I use) does a pretty good class tree diagram.

Rational Rose will do the job of creating UML from source, I think. (But
it's insanely expensive!)

Just a little (nit-picky) side note: source code doesn't require "reverse
engineering", since it's already source code. That term usually means
taking raw machine code and creating some form of assembler or source code
from it.

-Howard
 
D

David

I am looking for some tools to help me understand source code of a
program written in C++ by someone else.
Are there any non-commercial, open source C or C++ tools to reverse
engineer C or C++ programs with source codes on linux?
i.e. It parses any sized C or C++ project to help reverse engineer,
document, draw UML diagram and understand it and thus maintain it
better.

Any tool that you could acquire would only rearrange the facts
already laid down in the source you have. Nothing will help you
get at the meaning of the source until you decide to sit down and
explore it. It will take time. It took someone else time to
write it. You weren't there, so you'll have to make up your own
mental model. It doesn't have to agree with what the source or
what the original developer had in mind.

If it is functional, explore the various UI components. What
does it expose and what was the mental work model the develoer
laid out? Explore the source. Start at the beginning if you
can find it. Also explore various components and try to
understand what they may do. At some point the fragments of
a large jigsaw puzzle will appear and you'll figure out how the
the pieces fit together. You may find some parts you want to
change and others you may want to use later. Only after you've
understood what is there and what the mental work model is can
you then use that base to extend the model the way you'd like
it to be.

Have fun,

David
 
I

Ivan Vecerina

David said:
Any tool that you could acquire would only rearrange the facts
already laid down in the source you have. Nothing will help you
get at the meaning of the source until you decide to sit down and
explore it. It will take time. It took someone else time to
write it. You weren't there, so you'll have to make up your own
mental model. It doesn't have to agree with what the source or
what the original developer had in mind.

I mostly agree with your comment, but the usefulness of a
code browsing/analysis tool should not be dismissed.

A good code browser (IDE-integrated or e.g. doxygen-generated)
does help navigate through the code and connect bits and pieces
together. Getting an overview of class hierarchies and file
dependencies also can be invaluable in helping you create a
mental model of a piece of code.

If it is functional, explore the various UI components. What
does it expose and what was the mental work model the develoer
laid out? Explore the source. Start at the beginning if you
can find it. Also explore various components and try to
understand what they may do. At some point the fragments of
a large jigsaw puzzle will appear and you'll figure out how the
the pieces fit together. You may find some parts you want to
change and others you may want to use later. Only after you've
understood what is there and what the mental work model is can
you then use that base to extend the model the way you'd like
it to be.

Just one addition here: using a debugger and stepping through
code often is a good way to get an understanding of how things
work.
Also very important, as you go, is to add comments about the
design/function of the code you reviewed. Don't let yourself
or anyone else do this tedious analysis work again.


Cheers,
Ivan
 
I

Ivan Vecerina

olivier said:
message

what about umbrello ?

Found here: http://uml.sourceforge.net
I had never tried it. It looks like a nice UML modeler and code generator.
Thanks, I will look into it.

However, the original question was about extracting design information
from existing source code. Umbrello does not seem to have that capability.


Cheers,
Ivan
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top