diff --git a/m4/ax_code_coverage.m4 b/m4/ax_code_coverage.m4 index 93dfce3a..3d417f0f 100644 --- a/m4/ax_code_coverage.m4 +++ b/m4/ax_code_coverage.m4 @@ -140,7 +140,7 @@ AC_DEFUN([AX_CODE_COVERAGE],[ ]) dnl Build the code coverage flags - CODE_COVERAGE_CPPFLAGS="-DNDEBUG" + CODE_COVERAGE_CPPFLAGS="-DENABLE_COVERAGE_GCOV -DNDEBUG" CODE_COVERAGE_CFLAGS="-O0 -g -fprofile-arcs -ftest-coverage" CODE_COVERAGE_CXXFLAGS="-O0 -g -fprofile-arcs -ftest-coverage" CODE_COVERAGE_LDFLAGS="-lgcov" diff --git a/strace.c b/strace.c index bdfe1357..42650ab5 100644 --- a/strace.c +++ b/strace.c @@ -2512,6 +2512,10 @@ restart_tracee: return true; } +#ifdef ENABLE_COVERAGE_GCOV +extern void __gcov_flush(); +#endif + int main(int argc, char *argv[]) { @@ -2538,12 +2542,18 @@ main(int argc, char *argv[]) /* Child was killed by a signal, mimic that. */ exit_code &= 0xff; signal(exit_code, SIG_DFL); +#ifdef ENABLE_COVERAGE_GCOV + __gcov_flush(); +#endif raise(exit_code); /* Unblock the signal. */ sigset_t mask; sigemptyset(&mask); sigaddset(&mask, exit_code); +#ifdef ENABLE_COVERAGE_GCOV + __gcov_flush(); +#endif sigprocmask(SIG_UNBLOCK, &mask, NULL); /* Paranoia - what if this signal is not fatal?