Tools to reverse engineer C++ ( i.e. to view C++ c

2019-04-14 00:26发布

问题:

I have a large body of hand-written C++ source (i.e. WebKit and other open source).

I want a tool which will:

  • Let me see the inter-class relationships for each and any class:
    • Containment relationships: i.e. which other classes contain this class, or are contained by it (the header files declare templated smart pointer types as member data)
    • Declared dependencies (i.e. use of the type in method signatures; though I can see this pretty well using 'find in files')
    • Subclass and superclass hierarchies
  • Run on Windows or Linux (or even a web-based solution)
  • Preferably have a UI (or is that too much to ask?)
  • Optionally be a plugin in an IDE

Unlike the related question, C++ to UML (Reverse engineer / Round-trip engineering), I do NOT need it to:

  • Parse the definitions/implementation (the cpp and c files)
  • Support editing or 'round-tripping' the source

Instead, parsing the type declarations in the application and system headers (including template types and typedefs) would be enough. I have lists of all the header files.

I'd prefer it, if it could handle preprocessor definitions (especially #include and #if), but I can preprocess if that's necessary; and/or give it make or project files in various formats.

回答1:

You could always use doxygen, it'll give you full documentation on your set of header (inheritance, usage, ...) It can also generate graphs out of the class hierarchy.



回答2:

another possibility is to customize your own tool, by extending an existing C++ compiler

There are two compilers which you could extend:

  • LLVM & Clang (but I can't help, because I don't know much them).
  • GCC (version 4.6 please) is extensible thru plugins or by coding a MELT extension MELT is a high-level domain specific language to extend the GCC compiler; it is easier to code your extension in MELT than a plugin in C. [I am the main author of MELT]

Extending GCC is in my (biased) view the good way to do it. But I do admit that (even with t he help of MELT) it is non-trivial, because you need to partly understand GCC main internal representations (Gimple, Tree) and internal passes. (I guess that you have same issue with LLVM/Clang: to extend it you need to understand it).

GCC extensions (in MELT) or plugins (in C) are mostly working on the Gimple representations (after template expansion).

If interested in using MELT, feel free to ask more to me.

Some costly proprietary tools exist, like e.g. coverity - but there are so expensive that I have no idea of what they are able to do.