BugZoo icon indicating copy to clipboard operation
BugZoo copied to clipboard

Coverage information is not always flushed for C/C++ programs that seg. fault

Open ChrisTimperley opened this issue 7 years ago • 5 comments

See: https://github.com/ChrisTimperley/genprog-tse-2012-bugs/pull/3

Related: https://stackoverflow.com/questions/20250400/how-can-i-use-gcov-even-when-a-segmentation-fault-happens

Also affects https://github.com/ChrisTimperley/genprog-tse-2012-bugs/pull/2 and https://github.com/ChrisTimperley/genprog-tse-2012-bugs/pull/1

ChrisTimperley avatar Oct 27 '18 18:10 ChrisTimperley

FYI @afsafzal

ChrisTimperley avatar Oct 27 '18 18:10 ChrisTimperley

Interestingly, the signal handler below crashes once again (for certain kinds of seg. fault) when the call to __gcov_flush is made.

extern void __gcov_flush(void);
void bugzoo_sighandler(int sig){
        __gcov_flush();
        fprintf(stderr, "no bueno");
        exit(1);
}

ChrisTimperley avatar Oct 30 '18 14:10 ChrisTimperley

What do you mean? Do you mean __gcov_flush crashes?

afsafzal avatar Oct 30 '18 14:10 afsafzal

What do you mean? Do you mean __gcov_flush crashes?

Exactly.

If the call to __gcov_flush is removed, no bueno is printed to the stderr, as expected.

ChrisTimperley avatar Oct 30 '18 14:10 ChrisTimperley

void gflush(){
  fprintf(stderr, "flushing...\n");
  // __gcov_flush();
  fprintf(stderr, "flushed!\n");
}
void bugzoo_sighandler(int sig){
  fprintf(stderr, "no bueno\n");
  exit(1);
}
void bugzoo_ctor (void) __attribute__ ((constructor));
void bugzoo_ctor (void) {
  if (atexit(gflush) != 0)
    fprintf(stderr, "failed to register gflush\n");

The program above exits with code 1 and produces the following output:

no bueno
flushing...
flushed!

shell returned 1

When the call to __gcov_flush is uncommented, the following output is produced:

no bueno
flushing...
Segmentation fault (core dumped)

shell returned 139

ChrisTimperley avatar Oct 30 '18 15:10 ChrisTimperley