squaresLab / BugZoo

Keep your bugs contained. A platform for studying historical software bugs.
https://squareslab.github.io/BugZoo
MIT License
67 stars 12 forks source link

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

Open ChrisTimperley opened 5 years ago

ChrisTimperley commented 5 years ago

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 commented 5 years ago

FYI @afsafzal

ChrisTimperley commented 5 years ago

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);
}
afsafzal commented 5 years ago

What do you mean? Do you mean __gcov_flush crashes?

ChrisTimperley commented 5 years ago

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 commented 5 years ago
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