Tools for analyzing C++ codebase [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Which tools would be most useful for analyzing a C++ codebase?
What do they cost?
Can we manage with free and trial software, or are there commercial software that is good and that we really should to pay for?
The main object would be to get an understanding of quality - memory issues etc, also to understand the code (For spotting architectural problems for example), perhaps coding standards.
Primarily statical analysis, but we are hoping to be able to run the code.
Think it needs to be "robust in the sense that it should work with code for arcane compilers.

The best free tool is your compiler's warning errors, I always use them at maximum level. The first goal should be a clean build without any cheating (eg. disabling or casting away not-understood warnings).
Visual C++ has built in Code Analysis which is good for catching some bugs and Win32 API misuse, but it's not included in the free version and is (obviously) Windows-specific. This used to be an internal Microsoft tool called Prefast - analogous to FxCop in .Net.
PC-Lint is good, but verbose and not free. If you can get a config file to trap 'useful things' and ignore the noise, that would be a big plus. Again this is for Windows, but I know there are versions for other platforms.

Take a look at:
http://www.cppdepend.com/
and a good many others:
http://www.chris-lott.org/resources/cmetrics/
http://www.locmetrics.com/alternatives.html

I've heard very good things about Valgrind. "automatically detect many memory management and threading bugs, and profile your programs in detail"

The number one stink in programs is code duplication.
You can use clone detectors to find duplicates. Many clone detectors compare just text lines for exact matches; other compare token streams and will find almost-exact matches where the differences are just changed identifiers. You can use our CloneDR to find duplication in which arbitrary langauge structures are inserted or removed, using the langauge grammar as a guide. CloneDR works for large C++ systems, as well as many other languages. At the link you can find typical clone detection reports.
A popular broad-spectrum static checker is PCLint. This checks for a variety of common coding errors predefined by the tool. I don't know how well it handles "arcane" (compilers) dialects of C++.
If you want to define custom checks, you need a full C++ front end parser and the ability to configure your checks arbitrarily. Our DMS Software Reengineering Toolkit is an engine that can be configured to accomplish this. DMS's C++ front end can be configured to handle "arcane" C++ dialects, but already covers ANSI, GCC3 and GCC4, MS Visual Studio 7 and 2005. Because DMS is a program transformation engine, it can even be used to "improve" the code quality by replacing poor constructs with better ones.
While not static analysis, test coverage tools for measuring how well you've tested your code are very helpful in assessing your code quality. Just because all your tests pass, doesn't mean you've tested well; unexercised code arguably can have any/all variety of problems.

Theres CCCC: http://cccc.sourceforge.net/ -- result of a research project on metrics.
To tell the truth, I've not found much benefit in such things. What do you hope to get?

You could try out Vigilant Sentry, which analyzes C and C++ and looks for advanced errors in your software. This includes memory or resources leaks, and crash causing memory corruption, among other things.
The small business edition is currently only $795 (by far the cheapest on the market for the value) and the enterprise is $4995. Good luck finding what you need.

Related

Code checking as-you-type C++ [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Visual Studio is capable of reporting errors and warnings "as you type" in the Error List View;
Is there any C++ IDE for Linux capable of behaving as Visual Studio does (With the same level of speed/accuracy)?
This boosts the speed of the development drastically.
If you know IntelliSense in the C# IDE then you're not too far from a C++ IDE that implements this, the Visual C++ IDE does this as well. Modeling this feature as a JIT compiler isn't very accurate, it is simply the front-end of a C++ compiler. Minus the back-end, the code generator, that doesn't happen until you actually build the project.
Sounds simple, it is nonetheless a pretty non-trivial thing to do well. Primary implementation problems are doing it fast enough, in the background while the programmer is typing. And dealing with code that is almost always in an uncompilable state since the programmer is busy editing. Common front-ends in regular C++ compilers are not typically fit for that job. They are not fast enough and don't particularly deal with uncompilable code all that well, often generating a flurry of additional uninteresting errors that were induced by a single mistake.
Microsoft used to use their own parser to do this but gave up on it. The Edison Design Group are the specialists in this kind of tooling, famous for one for being the only ones that ever created a C++ compiler that completely implemented the C++03 language specification. EDG just sells the front-end, they leave the back-end to the implementer. VS2010 was the first VS version that started using EDG's. Not entirely trouble-free btw, in a few corner cases the EDG parser disagrees with the Visual C++ compiler.
This feature is not otherwise widely available. It is just plain expensive and hard to maintain, especially with the rapid changes in C++ as of late. Last I heard (been a while), EDG asks you to plunk down $50,000 before they even start talking to you, there probably is a royalty payment involved as well. It surely costs Microsoft a wholeheckofalot more, they also need to support the C++/CLI and C++/CX language extensions. Well, that's what you're paying for.
KDevelop, QtCreator, XCode and many other editors offer this feature. And more will come, as nowadays it's rather trivial to implement in some way based on Clang.

How to parse C++ source in Python? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
We want to parse our huge C++ source tree to gain enough info to feed to another tool to make diagrams of class and object relations, discern the overall organization of things etc.
My best try so far is a Python script that scans all .cpp and .h files, runs regex searches to try to detect class declarations, methods, etc. We don't need a full-blown analyzer to capture every detail, or some heavy UML diagram generator - there's a lot of detail we'd like to ignore and we're inventing new types of diagrams. The script sorta works, but by gosh it's true: C++ is hard to parse!
So I wonder what tools exist for extracting the info we want from our sources? I'm not a language expert, and don't want something with a steep learning curve. Something we low-brow blue-collar programmer grunts can use :P
Python is preferred as one of the standard languages here, but it's not essential.
I'll simply recommend Clang.
It's a C++ library-based compiler designed with ease of reuse in mind. It notably means that you can use it solely for parsing and generating an Abstract Syntax Tree. It takes care of all the tedious operator overloading resolution, template instantiation and so on.
Clang exports a C-based interface, which is extended with Python Bindings. The interface is normally quite rich, but I haven't use it. Anyway, contributions are welcome if you wish to help extending it.
You could check out GccXML and OpenC++, as well as doxygen.
Can you run a preprocessing step? Doxygen parses most C++ syntax and creates xml with all the relationships. Compilers also create debug databases (typically dwarf format from gcc and codeview format from MSC).
From what you say of our requirements, Tony's answer of GccXML will probably be the best option. If that doesn't work, you could try to generate an outline of your program with cscope or ctags, and then work your way to the info you want from it's output.
You asked for tools that can extract information from C++.
Our DMS Software Reengineering Toolkit is configurable compiler technology for building custom analyzers. It has a full C++ Front End with a preprocesser, full C++ parsing with AST construction (including capture of comments), and full symbol table. These could be used to extract such structural information, and export it to whatever you want to process it.
EDIT: One of the comments is that there are only 3 full C++ parsers in the world. I suspect more; surely IBM has one that works. DMS's C++ front end has been used in anger on large applications in both MS Visual Studio and on GNU C++ source codes, so it might reasonably qualify, too :-}
I've had good experience with PLY:
http://www.dabeaz.com/ply/
But this requires some experience with lex and yacc
If you can bring yourself to run this analysis using a Windows-platform application, save yourself a lot of time and trouble, and spend $200 on Enterprise Architect by Sparx Systems (I have no affiliation with this company, just a satisfied customer). (Note: this should not be confused with Microsoft's own "Enterprise Architect" bundle for Visual Studio.)
EA can reverse-engineer a number of languages, including C++, C, Java, and Python, generating some very nice UML class diagrams. (EA comes in a number of different packages, Desktop is the cheapest but you have to by Professional, the 2nd cheapest, to get the code engineering feature included.) I also like the integration between the generated class diagrams and sequence diagramming, where you can drag a line between object lifelines and a menu of defined methods is presented to you based on the class definition of the target object. At my former consulting business, we used this tool quite a bit to develop system architectural proposals which we then included as part of our project bid (just copy/paste the diagram into a Word doc). It wont take long to make back your $200.

Seeking a true "tool-chain" [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I just posted this as part of a reply to a question about the "best" bug-tracking software...
Well, a tool on its own is just a tool. And while all speak of a toolchain, most just mean a loose collection of tools. Why not look for a problem tracker that "plays well with other children"? That is to say, interfaces well with your IDE, your build tool, your version control system ...
In fact, I think I'll go now and ask a question about the best linked toolchain ...
So, any comments? I would prefer replies for developing C/C++ on Linux and using FOSS (but don't let that prevent you posting Windows based answers if you think that it would help someone else). We don't need a complete chain, but maybe a few groups of linked tools are still better than totally separate "links" in the chain)
I use
Eclipse - for coding and debugging, also its plug-ins for
Doxygen for auto code-documentation
Splint and CppCheck for static code analysis
CppUnit for automated testing
Bugzilla, et all for bug tracking
CVS, Subversion, etc, for version control
Hudson - for automated builds, with plug-ins for
Doxygen for auto code-documentation
CppCheck for static code analysis
CppUnit for automated testing
Bugzilla, et all for bug tracking
CVS, Subversion, etc, for version control
I seem to be missing a tool for project management which interfaces with other "links" in the toolchain. How complete can we make it, end to end, and is there a "best" chain (or, at least, one with the most links)?
Edit: Let's not forget requirements tracking and project planning & tracking - end Edit
And has anyone every diagrammed the relationship between various tools (i.e., which interfaces to which, and in which direction; which can export in the import format of another, etc)?
G'day,
In my experience, I have found that trying to come up with a "definitive" tool chain can cause problems.
One of the worst is that it tends to force people into the "everything looks like a nail" approach to projects. That is, You've done the work to select the tools you think are suitable and you now have your tool suite.
In my experience, it is very difficult to get people to change their "canonical set" of tools for other projects once that tool set has been selected and annointed as such.
I've been doing this for over twenty years now in a variety of projects that ranged from on-board submarine sonar simulators to air-traffic control display systems to helicopter control systems. Even within the same company, different projects need different tool sets to address the various problems that are going to be encountered.
You might think that once you've selected a tool for a particular purpose then you can re-use that tool for all projects, e.g. your selection of BugZilla for bug tracking. But what if there is no suitable SMTP server available because you've got a distributed team and your mail server is internal, locked down, secure, for example.
I'd suggest that it would be better to establish a suite of possible tools from which you can select your project's tool suite from. For example, adding Trac or FogBuzz as a possible bug tracking mechanism.
A lot of things can affect your choice of tools. Off the top of my head I've got:
geographical distribution of teams,
internal lock down, i.e. no public access, of servers e.g. email, source repository, test platform, etc,
having to interface to some existing system because of a desire to reuse aspects of that system, e.g. previous teams had had VisualSourceSafe inflicted upon them,
customer insistence on the use of a particular platform,
the management team for a new project having requirements that differ from the previous management team for regular management type reports,
etc.
Having a suite of possibilities minimises the effect of "trying to squeeze a square peg into a round hole".
Anyway, you might find that you're able to trim down your suite of possibilities after a while because you can demonstrate a successful approach and so get enough traction within the company for the support of doing things the way you've previously done them.
HTH
I think the Unix philosophy militates against these kinds of tightly integrated toolchains. It's no accident that Eclipse, the first thing you mention, came from the Java world. Unix (and by extension, Linux) tends to believe less in things called "plugins" and more in sets of tools that share data stored in flat text files.
By "project management" I'm not sure if you mean something like Make or something to keep track of your team's progress. If you mean something like Make, the Unix world sorely needs a reusable Make that supports "smart recompilation" and will work with multiple compilers. The closest thing is Glenn Fowler's nmake, but that's not very close.
Regarding integrate toolsets more generally,
The best set of tools I've seen are the Advanced Software Technology tools built at AT&T. There's a most excellent book Practical Reusable Unix Software, free to download, which describes the state of play circa 1995. Since then the toolset has only gotten better and richer, but to get an overview of what the hell is going on, you really need the book. These guys started with the Unix group at Bell Labs, and what they've created is not so much a toolchain but a way of life. Joe Bob says check it out.
The other ubiquitous element in many Unix toolchains is (and this is likely to make you laugh or puke) Emacs. Although Emacs Lisp is not anyone's favorite way to write plugins or extensions, sheer accumulation over time has made Emacs into a very rich, powerful programming environment—and it talks to all sorts of other tools. I'm into simplicity, not complexity, so I try to keep to shallow water, but if you're serious about investigating toolchains for Unix, it's something to know about.
I'm looking forward to seeing more answers to your question.
Well its not FOSS but Rational supplies a complete tool chain (except for the compilers!),
You get IDEs, Class diagrams, use cases, requirements tracking, test tools, problem logging tools which integrate well all for a few thousand (or hundreds of) dollars.
None (aprt from the modeling tools) is best of breed, but, they are all pretty good and integrate well with each other.
Disclaimer:-
My "toolset" of choice is vim,make, ddd, gmail and a moleskin notebook for modeling.

What tools exist for comparing C++ code to coding guidelines? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
There exist tools for comparing code against a custom specified set of coding guidelines/standards for a variety of languages (rather than pure static analysis for common defects). Examples include FxCop for .Net code and CheckStyle for Java, but I was wondering what examples people know of in the C++ world.
An existing question was asked regarding free tools which provided examples like Vera but I was also wondering about commercial tools that may be available.
A tool used by us was CodeWizard from Parasoft. But I think the new version is called "Parasoft C++ Test". From the homepage:
Static analysis of code for
compliance with user-selected coding
standards
Graphical RuleWizard
editor for creating custom coding
rules
Static code path simulation
for identifying potential runtime
errors
Automated code review with a
graphical interface and progress
tracking
Automated generation and
execution of unit and component-level
tests
Flexible stub framework
Full support for regression testing
Code coverage analysis with code
highlighting
Runtime memory error
checking during unit test execution
Full team deployment infrastructure
for desktop and command line usage
The full list that I managed to generate:
PRQA's QA C++
Parasoft's C++Test
MS Visual Studio Team System seems to have some functionality but it's hard to tell via their website.
GrammaTech CodeSonar
Coverity Extend
The last two provide some functionality but not particularly customisable ones:
Klocwork Insight
Rational PurifyPlus
DISCLAIMER: Working on this tool is my day job.
I'm obviously biased, but one of the main features of QA C++ is Coding Standard enforcement. For example we do JSF++ and MISRA C++ enforcement. You can read more about this here.
astyle is a common Unix tool that reformats source to a specified style. It supports most C-like languages. I know of no similar commercial tools.
I was also wondering about commercial tools that may be available.
Visual Studio Team System Edition 2005/2008 does have some such stuff. They also have a facility to enforce a set of rules on a whole team. Check it out.
I do not know whether you looking for a tool with built-in rules or want to validate against your custom rules. If it is the second, you may find it useful to implement searches for undesirable patterns based on regexp. Depending on your needs, Metrix++ http://metrixplusplus.sourceforge.net/ may offer helpful framework.

Is there a working C++ refactoring tool? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
Does anybody know a fully featured refactoring tool for C++ that works reliably with large code bases (some 100.000 lines)?
I tried whatever i can find again and again over the last years: SlickEdit, Eclipse CDT. They all were not at all usable.
SUMMARY:
I took time and evaluated "Visual Assist X" as well as "Refactor for C++". Both have some impressing features, but both as well are far from perfect. Extracting a large block of code usually is not done satisfying without manual modifications - and therefore does not pay off.
"Visual Assist X" has nice features such as much more complete autocompletition etc. But it leads to so much flickering and slows down much at certain points.
By my opinion therefore the answer is: "No, there is no production ready refactoring tool for C++"
UPDATE March 2015
As for hdoghmens reply today i tried Resharper for C++.
His link
https://www.jetbrains.com/resharper/ does not say anything about C++. But i found Resharper C++ that was announced more than a year ago here:
https://www.jetbrains.com/resharper/features/cpp.html
I gave it a try with VC2010 using a code base of 20MB.
Test 1: Extract Method:
results in a Resharper exception. No source code changed.
Test 2: Extract Method with different source:
Works fine
Test 3: Change signature of extracted function: Results in broken C++ code:
bool myclass::do_work123(<unknown long Color>int& Filled*&, long, int&)
Maybe thats why C++ its not listed on the main page.
By my opinion the answer to this question still is "NO".
Visual Assist and Visual Studio make dealing with large codebases much easier. Visual assist is good at tracking down how a class or member is used and is more effective at renaming it without false positives than search and replace.
I find Visual Assist X with Visual Studio very useful. Another choice is Refactor for C++.
I expect clang will significantly change the landscape of C++ refactoring tools out there over the next couple of years. It's an open-source, modular compiler that exposes an API for parsing and semantically analyzing C++ code. IDEs and other tools will be able to use this API rather than doing the difficult work of writing their own parser and semantic analyzer.
Google already made a large-scale refactoring tool using clang.
Mozilla has their own refactoring tool named Pork (Wiki, Developer Wiki). Here is the blog of the developer behind Pork. From what I've read Pork was successfully used in refactorings at Mozilla.
Pork should help if you come from *nix land, for Visual Studio I too recommend Visual Assist.
Our DMS Software Reengineering Toolkit is a transformation engine designed to carry out complex transforms over large bodies of code, including C++. It has been used to make reliable changes on systems of millions of lines of code. It operates by using compiler-accurate langauges analyzers and transformers.
It has a full C++ parser with name and type resolution, builds ASTs of code, can apply procedural or source-to-source transformations (with C++ surface syntax) to revise those trees, and regenerate compilable output with comments preserved. (Edit: 7/1/2011: Now does C++1X to the extent we understand the standard :)
It has been used on large scale reengineering projects, including C++ component re-architecting, and 100% fully automated translations between langauges.
You can read about this at the website.
DMS is also used to build arbitrary source analysis tools. Examples include clone detection, test coverage, smart difference (comparision of source code structures and abstract editing operations rather than lines with simple insert and delete), etc.
What it is not (presently) is an interactive refactoring tool. We believe that to do most refactorings well, you need deep control and data fow analyses. DMS has generic machinery to support this, and that machinery is implemented for C, COBOL and Java at this point, with C++ being next in line. This is a tough job. You won't see a lot of serious C++ refactoring tools from anybody until this kind of problem has been solved well.
First you need a full C++ parser :-}
EDIT 7/5/2011: Looks like we are going to take a run at the interactive version. We have won a Department of Energy Phase I SBIR to investigate how to do this. See http://science.energy.gov/sbir/awards-and-general-stats/fy-2011/phase-i-by-state/?p=1#tx (Look for Semantic Designs under "Texas").
Don't expect a result in a hurry; this is just the start of 3 phase multi-year program to get to a tool.
EDIT 8/11/2011: First progress... we now handle all of C++0x and OpenMP directives.
EDIT 1/4/2012: Does full control flow analysis of C++ code.
EDIT 9/15/2014: Now have C++14 front end parser/transformation engine well in hand. Even does rename pretty reliably at this point :-}
If you're using emacs, try Xrefactory . It supports method extraction, renaming of classes/functions/variables and insert/delete/move parameters.It also has very good/fast code completion engine.
Currently I can't recommend any refactoring tool for C++, certainly not for large code bases of 100k lines and above. I've been hoping this will change, like the OP, and I hope one day there will be something. I fear that the language itself might have to change significantly before we see any really good tools.
btw, has SlickEdit dropped its refactoring features?
I recommend to try rtags if you use emacs and haven't tried it yet (there is also a package for vim available). It is a clang based client/server application that indexes C/C++ code, with these features included:
go to definition/declaration
find all references, go to next/previous
rename symbol
integration with clang’s “fixits”
I decided to give it a try after watching this talk which introduced rtags (and emacs) for me.
(I have to say that I went this far only after my QtCreator failed to rename some symbols properly, which is a show-stopper for my using this great IDE for now)
Besides what is supported by rtags, I also need some additional neat features, including:
create function definition/prototype
extract function
create getter/setter methods
For these, I recommend to use a semantic-refactor package for emacs (not sure if there are alternatives for vim)
Generally, clang based tools looks very promising. If you are interested in more information about clang tools for C++ refactoring, including for projects with large codebase, there are some great talks by Chandler Carruth.
The DMS software rengineering toolkit does this I think. It is a code transformation engine, designed for large scale and handles C++. Have no idea how elegant the output is though.
The problem are C++ templates. As of 2019 I'm not aware of any refactoring tool that supports C++ templates. I've tried VS2019, VisualAssist, Clion, QtCreator.
Consider example:
#include <iostream>
struct foo { void print() {} };
struct bar { void print() {} };
template <typename T>
void call_print(T&& v) { v.print(); }
void print() {}
int main()
{
call_print(foo{});
call_print(bar{});
return 0;
}
If I run Rename Refactoring on foo::print, bar::print should be also renamed automatically. Because they are linked through call_print function template instantiations.
One surely has to mention Klocwork as a commercial code refactoring suite. It does look very promising when you go through the demo video.
Definetely Resharper Ultimate is the way to go. Happiness guaranteed :)
In Beta version as of march 2015.
Sorry to only find this question so late. My students and assistants work on C++ refactoring since about 2006. Most of CDTs refactoring infrastrucure was built by my team at IFS institute of software. since a couple of years we provide Cevelop our version of CDT with support for C++ code modernization refactorings etc. Cevelop can work with large code bases, if workspace is set up correctly. Free available at https://cevelop.com
If you are using Visual C++ (Express Edition is free), you can use Visual Assist from www.wholetomato.com (link to the C++ refactoring features).
It has a 30 day trial period and we have found it to be faster and more feature-full that the built-in intellisense in the Visual C++ product itself.
If your looking to reengineer your codebase: MOOSE. But that's a large collection of analysis and reengineering tools, not an editor.
There is now a C++ refactoring extension for Visual Studio 2013 from Microsoft:
http://visualstudiogallery.msdn.microsoft.com/164904b2-3b47-417f-9b6b-fdd35757d194
CLion looks very promising.
Disclaimer: I've not tried it yet as I need to convert my projects to CMake format in order to use it.
I recommend you try Lattix. It allows you to analyze large C/C++ codebases to discover the archtecture, identify problematic dependencies, and re-engineer the code to improve modularity and reduce technical debt. Lattix also provides a number of algorithms to help in the refactoring process. These algorithms help you figure out how to move elements from one part of the hierarchy to another, to break cycles and to move subsystems so that the coupling and cohesion of subsystems can be improved. Here are the results of Lattix analyzing the Android Kernel (1.6 million LOC of C/C++).
Full disclosure: I work for Lattix
I found the following plugin for Visual Studio 2013:
Visual C++ Refactoring by Microsoft.
It is just a simple rename tool but it works flawlessy. It adds the following context menu after right-clicking on a symbol: