??????1????????????????????????б?????????????????????????????????????????spec????????

 

1          sed -i '$ aexport LD_PRELOAD=/usr/local/bin/ccover_tool/gcov_out.so' /home/ads/.bash_profile
2          SPECFILE=`dirname $(gcc -print-libgcc-file-name)`/specs
3          gcc -dumpspecs >$SPECFILE
4          sed -i '/^*libgcc:/ { n; s/$/ -lgcov/; }' $SPECFILE
5          sed -i '/^*cc1:/ {n; s/$/ -fprofile-arcs -ftest-coverage/; }' $SPECFILE
6          sed -i '/^*cc1plus:/ {n; s/$/ -fprofile-arcs -ftest-coverage/; }' $SPECFILE

????(2)??Σ?????????????????????????exit()???dump???????????????????????kill -9 ??????????kill???

 

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#define SIMPLE_WAY
void sighandler(int signo)
{
#ifdef SIMPLE_WAY
exit(signo);
#else
extern void __gcov_flush();
// flush out gcov stats data
__gcov_flush();
// raise the signal again to crash process
raise(signo);
#endif
}
__attribute__ ((constructor))
void ctor()
{
int sigs[] = {
SIGILL?? SIGFPE?? SIGABRT?? SIGBUS??
SIGSEGV?? SIGHUP?? SIGINT?? SIGQUIT??
SIGTERM
};
int i;
struct sigaction sa;
sa.sa_handler = sighandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESETHAND;
for(i = 0; i < sizeof(sigs)/sizeof(sigs[0]); ++i) {
if (sigaction(sigs[i]?? &sa?? NULL) == -1) {
perror("Could not set signal handler");
}
}
}

??????????????.so
????gcov_out.so:gcov_out.c
????gcc -shared -fPIC gcov_out.c -o gcov_out.so
???????????export LD_PRELOAD=gcov_out.so
????(3)??????У???????к??????????????????????????????·????
????(4)????????????????????????????????????????????????????????к????????