My program crashes when start with OpenCPPCoverage

May 20, 2016 at 10:12 AM
Edited May 20, 2016 at 10:14 AM
Hi,

I find a strange problem that my program would crash after doing certain operations when start with OpenCppCoverage. But when it is running by itself, no problems will happen.

I tried to debug the crash, but when I use Visual Studio to attach to my program started with "OpenCppCoverage", it reports “Unable to attach to the process. A debugger is already attached". I believe visual studio show this message because OpenCppCoverage itself is implemented as a debugger. So I feel a little hard to debug the crash reason.

Any suggestions on how to debug this crash issue?


Thanks,
Frank
Coordinator
May 22, 2016 at 8:38 PM
Hi,

You are right, OpenCppCoverage uses the same API as a debugger.

First, please check your program is not compiled in release. OpenCppCoverage not yet supports optimized code.

When an application crashes, OpenCppCoverage shows an error message. Can you post it?

Hope that help,

OpenCppCoverage
May 23, 2016 at 2:34 AM
Thanks for the reply. Yes I always use your tools to get code coverage result for my program compiled in release... Actually after turn off the compile optimization (use "/od" instead of "/oi"), and related link optimization, I believe the code coverage analysis result should be same with debug build. My program is a large program that will use many 3rd party dlls. And the program will use release 3p dlls if built with release mode which will run much faster than debug build which uses debug 3p dlls. So in simple words, my program is built in release mode with compile and link optimization turned off on local dlls, but not on 3rd party dlls.

I find 98% of the workflows are running without problems invoked by OpenCppCoverage. Also I can get the correct code coverage result. But there are several workflows which will finally lead to crash. The error code usually looks like follows:

*** Unhandled exception code: 3221225477: EXCEPTION_ACCESS_VIOLATION

I will try use the debug build to see if the crash still happens, will update to you after that.



Thanks,
Frank
May 23, 2016 at 10:29 AM
Hi,

I doubled checked this problem using debug build. What shocked me is... the program will crash directly on debug even without the use of OpenCppCoverage. I had never run into such kind of cases that a program is running well on Release, but crashes on Debug build. I will go on look into the problem to find the real cause.

Anyway, thanks for the good guidance!



Thanks,
Frank
Coordinator
May 28, 2016 at 10:02 AM
Hi,

There is a known issue in release with switch / case. See https://opencppcoverage.codeplex.com/workitem/13 for more information.

Let me know if you have any issue when running OpenCppCoverage with your application in debug mode.

OpenCppCoverage
Coordinator
Feb 26 at 11:14 AM
Hello,

OpenCppCoverage 0.9.6 has a flag --optimized_build to support optimized build.

Let me know if you have any problems.

OpenCppCoverage.
Mar 6 at 6:07 AM
Hi,

Thanks for providing this flag to enable us to run code coverage using an optimized build. I will definitely have a try.

However by looking at the command-line documentation, I see following descriptions:

-optimized_build

.........

You can see surprising coverage results when the target is compiled with optimization because there can be a big difference between the source code and the generated code.

........


Does that mean the code coverage results could be a little inaccurate due to optimization of the code? I am more keen on the accuracy of code coverage, so if the result is not accurate enough, I would rather run code coverage by removing the build optimization. (use /Od instead of /O1, /O2).
Mar 8 at 8:09 AM
Edited Mar 8 at 9:02 AM
Hi,

I tried using the optimized_build flag and find most coverage information is correct. But some coverage information are still questionable, like:

a. In a function, the final "return" statement sometimes shown as NOT covered while other lines are covered.
FuncA ( )
{
XXCmd* pCmd = new XXCmd(this, pContext);   // This line is shown covered
return pCmd;   // This line is shown as NOT covered.
}

Later I find not only the "return" statement could be shown as NOT covered, normal statement such as follow example could also be shown as NOT covered:
if(point.get() == 0) // This line is shown as covered
{
point.reset(...);    // This line is shown as covered
line.reset(...);      // This line is shown as NOT covered
arc.reset(...);      // This line is shown as NOT covered
}


b. The "else if" statement is shown as NOT covered, but the "{ }"block next to "else if" is shown as covered. (Also sometimes, not all times)

else if(curves.size() == 2) // This line is shown as NOT covered
{
 createLinearCurve(..)    // This line is shown as covered.
}

c. Some functions are shown as NOT coverable, but actually they should be shown as NOT covered.

What I mean here is some functions have no color shown (Neither Green, nor Red). Usually I am thinking of this as this part of the code cannot be covered. Like commented code, etc. But I did see some functions should be able to be covered or not covered, but they are now shown as NOT coverable.

But in general, I see about 90% of the coverage is shown correct, so I am still happy with this option introduced. I only want to know are the 3 mentioned cases considered as correct under optimized build? Can we make some improvements to fix them?
Coordinator
Mon at 12:48 PM
Hello,
You can see surprising coverage results when the target is compiled with optimization because there can be a big difference between the source code and the generated code.
You should have the same behavior as if you try to debug an optimized code. If you can put a breakpoint on a line in an optimized code, OpenCppCoverage should be able to consider this line too.

If you run OpenCppCoverage with --verbose, you can see in the log which lines are ignored by the option --optimized_build (Search for "Optimized build support ignores line").

There is one known issue as explained in the documentation: "In rare cases, this heuristic can exclude a valid line when you rethrow an exception in a catch block."

I hope this will help,

OpenCppCoverage