Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare execution paths of same code under different inputs

Tags:

c++

execution

I'm debugging a very complex C++ function that gives me some unexpected results under some inputs. I'd like to compare code executions under different input so that I find out what part causes me bug. The tool that can compare code execution paths is what I am looking for. Please let me know if such a tool exists. Or otherwise if there's some techniques I can employ to do the same thing?

To describe my problem concretely, here I'm using a contrived example.

Say this is the function in pseudocode,

double payTax(double income)
{
   if (income < 10000)
      return noTax();
   else if ( 10000 < income < 30000)
      return levelOneTax();
   else if (30000 < income < 48000)
      return levelTwoTax();
   else  
      return levelThreeAboveTax();
}

Given input 15000, the function computes the correct amount of tax, but somehow input 16000 gives an erroneous tax amount. Supposedly, input 15000 and 16000 would cause the function to go through exactly the same execution paths; on the other hand, if they go different paths, then something must have gone wrong within the function. Therefore, a tool that compares execution paths would reveal enough information that could help me quickly identify the bug. I'm looking for such a tool. Preferably compatible with Visual Studio 2010. It would be better if such a tool also keeps values of variables.

P.S. debugging is the last thing I want to do because the code base I am working with is much much bigger and complex than the trivial payTax example.

Please help. Thanks.

like image 728
Shuo Avatar asked Dec 09 '12 19:12

Shuo


1 Answers

The keywords you are looking for is "code coverage" or "coverage analysis" or "code coverage analysis".

Which tool you use will naturally depend on the rest of your environment.

like image 123
Yakk - Adam Nevraumont Avatar answered Oct 25 '22 04:10

Yakk - Adam Nevraumont