Enable coverage when strace is self terminated by signal
The data collected by -fprofile-arcs during program run is saved on program exit. When program is terminated by signal, the data is not saved. However, libgcov provides an interface to dump the data at runtime. * m4/ax_code_coverage.m4 (AX_CODE_COVERAGE): Add -DENABLE_COVERAGE_GCOV to CODE_COVERAGE_CPPFLAGS. * strace.c [ENABLE_COVERAGE_GCOV] (__gcov_flush): New prototype. (main) [ENABLE_COVERAGE_GCOV]: Call __gcov_flush() before raise() and sigprocmask() calls that might cause program termination.
This commit is contained in:
parent
ae1b07bc2a
commit
556edf91e3
@ -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"
|
||||
|
10
strace.c
10
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?
|
||||
|
Loading…
Reference in New Issue
Block a user