2

I am debugging a bug in C++ code that I did not write. I know that between location A and B in the source, something happened to produce this unexpected output. This is often the only information I have to begin with.

It occurred to me that most of the time I spend on tracking down bugs is not trying to comprehend logic, but rather trying to identify the possible routes between A and B. Is there a tool out there to do this for me?

Specifics:

  • Works with C++ source code
  • Provides information of all possible paths from A to B that is specified in code
  • Does not require usage of breakpoints. I.e. it can analyse the code without running it
  • (Preferably) a small application
  • "preferably a small application"? It has to contain a full C++ parser and analysis engine. "Small" is not the right adjective here. – Ira Baxter Mar 21 '17 at 11:28
  • Use any of the many free all tree programs and ignore the parts you don't want. That's the quickest & simplest way. – Mawg Mar 22 '17 at 9:14
1

I doubt you are going to a tool that does exactly what you want out of the box. You can collect this information from a C++ "parser" that knows how to resolve C++ names fully (that means a full C++ front end).

Our DMS Software Reengineering Toolkit with its C++ Front End can provide this information.

The pair comprise a full-blown C++ parsing and static analysis engine, which can compute control-flows (which OP wants) and dataflows (which OP does not need) and call graphs. See the control/data flow SVG sample at the site page.

With that control flow information, OP could code a control flow graph walk starting at "point A" and finding different routes to "point B". This will be a quite straightforward depth-first search in the control flow graph if points A and B are in the same function. If they are in different functions fA and fB, he will need to find some shared caller-parent S of fA and fB, such that S calls fA, and then trace the control flow path from A to B across the call graph. This is more complicated but is probably only a few pages of code if you know what you are doing. It is should be obvious that learning how to use a tool such as DMS is not something you do in afternoon; anything that can handle C++ is already very sophisticated and handles tons of details.

Summary:

  • Full parser for various C++ dialects including GCC and MS, up through C++14 (with C++17 in the works)
  • Builds function local control (and dataflow) graphs
  • Can build call tree
  • Requires custom code to extract facts of interest about C++ programs

You can probably customize Clang or GCC to do this too, but I suspect it is not an easy task, and you'll face the same kind of learning curve problem you would face with DMS, for the same reasons. GCC has a reputation for being very hard to work with. I have no experience with Clang; I don't think it computes control flow graphs on C++ code, but rather on the LLVM back end, so you'd have to compute control flow on LLVM graphs and then backtrace into the C++ source code.

0

You can try CppDepend to track all the possible paths between A and B. The DSM and the dependency graph are provided to understand the dependencies between two or many elements.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.