Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

Using gcov with shared objects used by executable

I am trying to generate coverage report for my project. the .gcno files are generated as expected for the shared object code files, but when I run the executable (which uses the shared object generated), .so is also present in same location as executable but .gcda files for shared object doesnot get generated whereas .gcda files for executable code is generated as expected. Is there something wrong in approach? PLEASE ADVISE

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Its possible to get coverage for shared libarary. i tried simple hello application profiling with gcov with shared library concept ,im able to get code coverage. let take two files hello.c and extlib.c

First compile extlib.c

#include <stdio.h>

extern void print(const char* p, ...);

void print(const char* p, ...) {
    printf("%s World!
", p);

}

gcc -shared -fPIC extlib.c -o libext.so -ftest-coverage -fprofile-arcs

here will get extlib.gcno libextlib.so

next link it to main hello program //hello.c extern void print(const char*, ...);

int main() {
    print("Hello");
}

gcc hello.c -L./ -lextlib -o test -ftest-coverage -fprofile-arcs

after this hello.gcno file. execute ./test

After execution will get extlib.gcda and hello.gcda

using gcov *.c can check coverage.

so my suggestion try some simple file in your project individually compiling it with gcov profiling.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...