???????????????

????1. ???????

??????????????????????????????????Щ?????м????????????????(Basic Block)?????????(Basic Block Graph)???и?????(line coverage)?? ?????????(branch coverage)???

??????????(Basic Block)??”A basic block is a sequence of instructions with only entry and only one exit. If any one of the instructions are executed?? they will all be executed?? and in sequence from first to last.” ???????????????????????????????????????????????????????У????????????;

???????????(Basic Block Graph)??????????????????????????????????????????????????????????? ????????????????????????????????(arc)??????????????????????????????????????????鵱???????????????????е????л????鹹?????????????????????????(Basic Block Graph)???????????в???BB??arc????д???????????????е?BB?????е?arc????д???;

??????????????????Ч??????????????????????????????鱻???е????;?????λ?????????????????Ч????;

?????и?????(line coverage)?????????Ч????????е?????е????;

?????????????(branch coverage)?????ж??????????????2??????????????????????????з?????????????????????????????????(condition coverage)????????????????????ж???????????и????????

????2. gcc/g++ ???????

????gcc?????????????????????????????????????2?????(-ftest-coverage -fprofile-arcs )????????????????? *.gcno ??????????????????????????“????????”?????????????2???*.gcda????????????gcov??????????????????????

????-ftest-coverage

????Produce a notes file that the gcov code-coverage utility (see gcov—a Test Coverage Program) can use to show program coverage. Each source file’s note file is called auxname.gcno. Refer to the -fprofile-arcs option above for a description of auxname and instructions on how to generate test coverage data. Coverage data matches the source files more closely if you do not optimize.

???????????????????????????.gcno???(note file)????????????????????????????????????????????????????;

????-fprofile-arcs

????Add code so that program flow arcs are instrumented. During execution the program records how many times each branch and call is executed and how many times it is taken or returns. When the compiled program exits it saves this data to a file called auxname.gcda for each source file. The data may be used for profile-directed optimizations (-fbranch-probabilities)?? or for test coverage analysis (-ftest-coverage). Each object file’s auxname is generated from the name of the output file?? if explicitly specified and it is not the final executable?? otherwise it is the basename of the source file. In both cases any suffix is removed (e.g. foo.gcda for input file dir/foo.c?? ordir/foo.gcda for output file specified as -o dir/foo.o). See Cross-profiling.

???????????????????????????й?????????????в?????????????????????????libgcov.a?????а?????????????????????*.gcda????????;

????????????????????????????2????????????????g++ -S??????????????Rectangle.s ?? Rectangle_cc.s (????–coverage???)?????????£?

????g++ -c -o Rectangle.s Rectangle.cpp -g -Wall -S

????g++ -c -o Rectangle_cc.s Rectangle.cpp -g -Wall –coverage -S

????vimdiff Rectangle.s ?? Rectangle_cc.s???????

?????????????????????????????gcc?????2???????????????????????

???????????????????磬????????gcno/gcda?????????????ο? @livelylittlefish ???????£?GCC Coverage???????-.gcda/.gcno?????????????(http://blog.csdn.net/livelylittlefish/article/details/6448885)??