2

Originally posted on stackoverflow, but they indicated this question would be a better fit for here. https://stackoverflow.com/questions/52928683/show-all-possible-paths-from-a-specific-function

For a specific debugging approach, I would need to know all possible callstack from a C++ function. So if function a would look like this:

int Calculator::calculateResult(int a, int b) const
   {
   if (a > 0 && b > 0)
      return calculatePositiveResult(a,b)

   else if (a < 0)
      return calculateNegativeFirst(a,b)

   else if (b < 0)
      return calculateNegativeSecond(a,b)

   }

I would expect a result like: Option 1:

calculateResult(int a, int b)
--> calculatePositiveResult(a,b)

--> calculateNegativeFirst(a,b)

--> calculateNegativeSecond(a,b)

Option 2:

calculateResult(int a, int b)

--> calculatePositiveResult(a,b)

calculateResult(int a, int b)

--> calculateNegativeFirst(a,b)

calculateResult(int a, int b)

--> calculateNegativeSecond(a,b)

Both are fine. The output would need to be some kind of text output. Are there any open source libraries or freeware which can do this? There should be no limit to the depth of the callstack, and probably recursion should be detected. So I am looking for some kind of static code analyzer, which can take the functionname as an input and show all possible paths. Besides writing the program myself, is there already something out there which I can use?

Note: I want to use this on a quite large codebase, multiple millions of lines

  • Maybe you can do something with the REFERENCES_RELATION in doxygen. – albert Oct 22 '18 at 13:02
  • Do you also want the converse - all possible stacks that leas to this function being called? – Mawg says reinstate Monica Oct 23 '18 at 10:22
  • Have you considered using Doxygen, which can show this diagrammatically? IIRC, the Eclipse CDT IDE can also show "call trees". If you Google for images using search term doxygen call tree, you will see what I mean. What format are you after? – Mawg says reinstate Monica Oct 23 '18 at 10:27
  • The issue is that our codebase is quite large and complex. I am basicly looking for a program which allows to check if a path exists. If it exists, it should be able to show it. Just displaying all paths is not an option i'm afraid – Houbie Nov 2 '18 at 8:08

Your Answer

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

Browse other questions tagged or ask your own question.