如何找到使用dlopen()打开的库的覆盖范围? [英] How to find the coverage of a library opened using dlopen()?

查看:180
本文介绍了如何找到使用dlopen()打开的库的覆盖范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++库(.so),该库由另一个应用程序使用dlopen()打开。但是我需要在使用gcov在应用程序中运行时找到该库的代码覆盖率。可能吗?如果是,该怎么办?



如果没有,该如何解决?

解决方案

是。可以生成由 dlopen 加载的共享库的覆盖范围。



1)使用标志 -fprofile-arcs -ftest-coverage

$ b $编译共享库b

2)编译使用 dlopen 和标志 -fprofile-arc -ftest-coverage



3)lcov生成 .info 文件



< pre class = lang-sh prettyprint-override> lcov --capture --rc lcov_branch_coverage = 1-目录路径/to/.gcda-输出文件coverage.info

4)生成html

  genhtml coverage.info --branch-coverage --output-directory out 


I have a C++ library (.so) which is opened using dlopen() by another application. But I need to find the code coverage of this library while run within the application using gcov. Is it possible? If yes, how can it be done?

If not, how can the issue be resolved?

解决方案

Yes. Coverage of shared library loaded by dlopen can be generated.

1) compile shared library with flags -fprofile-arcs -ftest-coverage

2) compile program that using dlopen with flags -fprofile-arc -ftest-coverage

3) lcov to generate .info file

lcov --capture --rc lcov_branch_coverage=1 --directory path/to/.gcda --output-file coverage.info 

4) generate html

genhtml coverage.info --branch-coverage --output-directory out 

这篇关于如何找到使用dlopen()打开的库的覆盖范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆