linux代码工具tag,gcov-dump原理分析_Linux平台代码覆盖率测试

第 16 页 LINES tag: tag_lines() 函数

3.4 LINES tag: tag_lines() 函数static void

tag_lines ( const char * filename ATTRIBUTE_UNUSED ,

unsigned tag ATTRIBUTE_UNUSED , unsigned length ATTRIBUTE_UNUSED )

{

if ( flag_dump_contents )

{

unsigned blockno = gcov_read_unsigned ();

char const * sep = NULL ;

while ( 1 )

{

gcov_position_t position = gcov_position ();

const char * source = NULL ;

unsigned lineno = gcov_read_unsigned ();

if ( ! lineno )//lineno=0 时才会执行该 clause ,因此 lineno=0 即为以后的新的文件的标志

{

source = gcov_read_string ();// 该函数读取 length(4 字节 ) 和 length 个 words(4*length 字节 )

if ( ! source )//source 即为文件名,没有源文件了,就退出

break ;

sep = NULL ;

}

if ( ! sep )//sep=NULL 才会执行该 clause ,那么什么时候会为 NULL 呢?——就是新的文件开始,实际上就是 lineno=0

{

printf ( "/n" );

print_prefix ( filename , 0 , position );

printf ( "/tblock %u:" , blockno );

sep = "" ;

}

if ( lineno )

{

printf ( "%s%u" , sep , lineno );

sep = ", " ;

}

else

{

printf ( "%s`%s'" , sep , source );//lineno=0 时,输出该文件名,之后 sep= " : "

sep = ":" ;

}

}

}

}

输出格式:

block blockno:'filename':lineno1, lineno2, ...

例如: block 1:'test.c':4, 7, 9

其中,前面的 block 为提示信息。同上,需要注意前导符或者输出位置。

3.5 COUNTER tag: tag_counters() 函数static void

tag_counters ( const char * filename ATTRIBUTE_UNUSED ,

unsigned tag ATTRIBUTE_UNUSED , unsigned length ATTRIBUTE_UNUSED )

{

static const char *const counter_names [] = GCOV_COUNTER_NAMES ;

unsigned n_counts = GCOV_TAG_COUNTER_NUM ( length );

printf ( " %s %u counts" ,

counter_names [ GCOV_COUNTER_FOR_TAG ( tag )], n_counts );

if ( flag_dump_contents )

{

unsigned ix ;

for ( ix = 0 ; ix != n_counts ; ix ++ )

{

gcov_type count ;

if ( ! ( ix & 7 ))// 如果 counter 较多,则每 8 个 1 行输出,且按 0 , 8 , 16 , ... 输出序号

{

printf ( "/n" );

print_prefix ( filename , 0 , gcov_position ());

printf ( "/t/t%u" , ix );// 输出序号

}

count = gcov_read_counter ();// 读取该 counter ,读取 8 字节,但返回 4 字节

printf ( " " );

printf ( HOST_WIDEST_INT_PRINT_DEC , count );

}

}

}

关于 GCOV_TAG_COUNTER_NUM 和 GCOV_COUNTER_FOR_TAG ,请参考源代码。

counter 的名字定义如下。/* A list of human readable names of the counters */

#define GCOV_COUNTER_NAMES         {"arcs ", "interval", "pow2", "single", "delta"}

输出格式:

arcs n counts //arcs 即为 counter 的名字,如上

0 counter0 counter1 ... counter7// 每 8 个 1 行输出,前面的 0 表示序号

8 counter8 counter9 ... counter15// 前面的 8 表示序号

...

同上,需要注意前导符或者输出位置。

3.6 OBJECT/PROGRAM SUMMARY tag: tag_summary() 函数static void

tag_summary ( const char * filename ATTRIBUTE_UNUSED ,

unsigned tag ATTRIBUTE_UNUSED , unsigned length ATTRIBUTE_UNUSED )

{

struct gcov_summary summary ;

unsigned ix ;

/***** initialize all members with 0 *****/

memset( & summary , 0 , sizeof ( summary ));

unsigned count = gcov_read_summary ( & summary );// 读取该 summary

printf ( " checksum=0x%08x" , summary .checksum );

/* for (ix = 0; ix ! = GCOV_COUNTERS; ix++) *//* 原来的代码 */

for ( ix = 0 ; ix < count ; ix ++ )/* 应该如此修改 */

{

printf ( "/n" );

print_prefix ( filename , 0 , 0 );

printf ( "/t/tcounts=%u, runs=%u" , summary .ctrs [ ix ] .num , summary .ctrs [ ix ] .runs );

printf ( ", sum_all=" HOST_WIDEST_INT_PRINT_DEC , ( HOST_WIDEST_INT ) summary .ctrs [ ix ] .sum_all );

printf ( ", run_max=" HOST_WIDEST_INT_PRINT_DEC , ( HOST_WIDEST_INT ) summary .ctrs [ ix ] .run_max );

printf ( ", sum_max=" HOST_WIDEST_INT_PRINT_DEC , ( HOST_WIDEST_INT ) summary .ctrs [ ix ] .sum_max );

}

}

输出格式:

checksum=0x51924f98

counts=5, runs=1, sum_all=12, run_max=10, sum_max=10

同上,也需要注意前导符或者输出位置。

其中, gcov_read_summary 函数是修改后的函数,在 " Linux 平台代码覆盖率测试 -GCC 如何编译生成 gcov/gcov-dump 程序及其 bug 分析 " 一文没有列出该修改后的函数,其实这篇文章中的 bug 与该函数有关。此处列出其代码。GCOV_LINKAGE unsigned

gcov_read_summary ( struct gcov_summary * summary )

{

unsigned ix ;

struct gcov_ctr_summary * csum ;

summary - >checksum = gcov_read_unsigned (); /***** checksum is a words (4Bytes) *****/

/***** that is, a summry is 32Bytes (sizeof(gcov_type)=4) or 20Bytes (sizeof(gcov_type)=8) *****/

for ( csum = summary - >ctrs , ix = GCOV_COUNTERS_SUMMABLE ; ix -- ; csum ++ )

{

csum - >num = gcov_read_unsigned (); /***** 4Bytes *****/

csum - >runs = gcov_read_unsigned (); /***** 4Bytes *****/

csum - >sum_all = gcov_read_counter (); /***** 8Bytes , but return 4Bytes *****/

csum - >run_max = gcov_read_counter (); /***** 8Bytes , but return 4Bytes *****/

csum - >sum_max = gcov_read_counter (); /***** 8Bytes , but return 4Bytes *****/

}

return GCOV_COUNTERS_SUMMABLE ; /* zubo modified to return the nubmer */

}

gcov_summary 及 gcov_ctr_summary 结构的定义可参考源代码或者 " Linux 平台代码覆盖率测试工具 GCOV 相关文件分析 " 。

4. 小结

本文详细叙述了 gcov-dump 程序的结构和实现原理。也从中学习了其处理各种 tag 用到的 callback 方法,如果你想深入跟踪或学习 gcc 源码,请注意 callback 的使用,因为 gcc 源码中大量地使用了 callback 。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/405710.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

关于 CFileDialog 对话框多选功能的一个问题

From: http://www.vckbase.com/document/viewdoc/?id1544 最近有位读者来信指出&#xff1a;《在线杂志》第26期中有一篇文章&#xff1a;“再谈 CFileDialog 对话框的定制”&#xff0c;其例子程序有一个bug。如果多选时选中的文件过多&#xff0c;那么后面选中的文件将无效…

React开发(217):vs code出现‘npm’

npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写&#xff0c;如果包括路径&#xff0c;请确保路径正确&#xff0c;然后再试一次。 所在位置 行:1 字符: 1 解决 以管理员身份打开vs code

java类内存中只能运行一个实例对象

方法&#xff1a;构造方法私有化(private) public class TestClass { private static TestClass obj new TestClass (); //私有构造方法   private TestClass () {        }   public static TestClass getInstance() {     return obj ;   } } 使用&#xff…

linux winrar 安装目录,WinRAR 5.61发布,提供Linux版本下载,附安装方法

压缩及解压缩工具WinRAR 5.61已经发布下载&#xff0c;提供WinRAR (32/64 bit) 5.61、RAR 5.61 for Linux、RAR for Android、RAR 5.61 for Mac OS X、RAR 5.61 for FreeBSD安装包下载。WinRAR 5.61是一款流行的压缩工具&#xff0c;它支持鼠标播放及外壳扩展功能&#xff0c;支…

JAVASCRIPT 提示信息 主要是使用了获取控件的位置进行定位

JAVASCRIPT 提示信息 主要是使用了获取控件的位置进行定位 <% Page Language"C#" AutoEventWireup"true" CodeBehind"DCS_SubmitNewRequest.aspx.cs" Inherits"BAF.DCS.Web.DCS_SubmitNewRequest" %> <!DOCTYPE html PUBL…

luceda ipkiss教程 53:在版图上加中文

要在版图上加中文&#xff0c;如&#xff1a; 可以通过如下方法实现&#xff1a; 首先&#xff0c;可以在ppt中加入文本框&#xff0c;在文本框中输入想要加到版图上的中文内容&#xff0c;如&#xff0c;复旦大学&#xff0c;并将文本框存为windows位图。 其次&#xff0c;通…

同时打开多个VC工程

操作流程如下&#xff1a; 在系统资源管理器->文件夹选项->选择dsw文件-> 高级->open with->编辑->把“使用DDE”前面的勾取消 点击确定&#xff0c;OK。已经设置OK.

QtCreator 如何将开发的程序打包成exe

一、前言 在QtCreator中开发好应用程序后&#xff0c;想发布成exe可执行程序&#xff0c;在其他电脑可以运行&#xff0c;按照以下步骤即可。QtCreator在安装的时候会自带部署器windeployqt&#xff0c;利用windeployqt抽出相应的DLL即可。 二、具体步骤 1&#xff1a;将开发…

MS SQLService中的*= 及 =*

今天看到数据库中的存储过程中&#xff0c;有* &#xff0c;于是百度了一下&#xff0c;原来这个SQL2000以前的左连接&#xff0c;以后的版本中开启兼容也是可以用的。 于是拿出来在系统中的表中测试了一下果然如此 例&#xff1a; 有用户表D_user及公司代码表d_organization 其…

Oracle 外部表

-- -- Oracle 外部表 -- 外部表只能在Oracle 9i 之后来使用。简单地说&#xff0c;外部表&#xff0c;是指不存在于数据库中的表。通过向Oracle提供描述外部表的元数据&#xff0c;我们 可以把一个操作系统文件当成一个只读的数据库表&#xff0c;就像这些数据存储在一个普通数…

LED32*32点阵书写屏设计方案

一、引言 目前LED显示屏都是采用字模软件生成好的字节序列然后进行显示&#xff0c;而LED点阵书写屏是一种无需通过字模软件编码即可给LED显示屏提供显示信息的一种新的交互方案&#xff0c;通过光敏二极管或光敏三极管在屏幕上捕获LED点阵的驱动信号&#xff0c;从而反馈至控制…

(C++)浅谈using namespace std

1、<iostream>和<iostream.h> 在你的编译器include文件夹里面可以看到&#xff0c;二者是两个文件&#xff0c;里面的代码是不一样的。 后缀为.h的头文件c标准已经明确提出不支持了&#xff0c;早些的实现将标准库功能定义在全局空间里&#xff0c;声明在带.h后缀的…

lpr命令linux下未找到,linux – LPR命令无法识别CUPS打印机

我有一个杯子服务器,上面配置了一台共享打印机.它可以毫无问题地打印测试页.printername (Idle, Accepting Jobs, Shared)Description: descLocation:Driver: Zebra ZPL Label Printer (grayscale, 2-sided printing)Connection: socket://172.20.50.26Defaults: job-sheetsnon…

Qt如何将数据保存成CSV文件

一、csv文件 csv文件是逗号分隔值&#xff08;Comma-Separated Values&#xff0c;CSV&#xff09;文件的缩写&#xff0c;其文件以纯文本形式存储表格数据&#xff08;数字和文本&#xff09;&#xff0c;各个字段用逗号进行分割&#xff0c;采用回车进行换行。由于采用纯文本…

windows 2003负载均衡故障切换

准备一个vip realserver 1 realserver 2 server1&#xff1a; IP:192.168.1.3 掩码:255.255.255.0 网关:192.168.1.254 server2: IP:192.168.1.4 掩码:255.255.255.0 网关:192.168.1.254   在server1上通过NLB管理器建立集群: 虚拟IP:192.168.1.111 掩码:255.255.255.0 网关:…

SecureCRT日志配置

SecureCRT设置 日志文件名&#xff1a; D:\Embedded\SecureCRT\SessionLog\%S__%Y-%M-%D_%h%m.log 连接时&#xff1a; [%Y%M%D %h:%m:%s] 在每行: [%h:%m:%s]

linux6添加chkconfig管理,10、14 Linux系统服务管理工具-chkconfig

chkconfig --listchkconfig --level 3 network offchkconfig --level 345 network offchkconfig --del networkchkconfig --add networkchkconfig工具crond、iptables、firewalld、nginx、httpd、mysql等等&#xff0c;都属于服务。chkconfig工具&#xff0c;在centos6和之前的…