了解gcov文件中的块 [英] Understanding blocks in gcov files

查看:77
本文介绍了了解gcov文件中的块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解gcov工具的输出.使用-a选项运行它很有意义,并且想了解块覆盖率选项.不幸的是,很难理解这些障碍物是做什么的以及为什么不使用它们.下面是输出.

I'm trying to understand the output of the gcov tool. Running it with -a options makes sense, and want to understand the block coverage options. Unfortunately it's hard to make sense of what the blocks do and why they aren't taken. Below is the output.

我曾经在我的计算器程序中运行过一次添加功能.我不知道为什么它显示为block0.

I have run add function in my calculator program once. I have no clue why it shows block0.

        -:    0:Source:calculator.c
        -:    0:Graph:calculator.gcno
        -:    0:Data:calculator.gcda
        -:    0:Runs:1
        -:    0:Programs:1
        -:    1:#include "calculator.h"
        -:    2:#include <stdio.h>
        -:    3:#include <stdlib.h>
        -:    4:
        1:    5:int main(int argc, char *argv[])
        1:    5-block  0
        -:    6:{
        -:    7:    int a,b, result;
        -:    8:    char opr;
        -:    9:
        1:   10:    if(argc!=4)
        1:   10-block  0
        -:   11:    {
    #####:   12:        printf("Invalid arguments...\n");
    $$$$$:   12-block  0
    #####:   13:        return -1;
        -:   14:    }
        -:   15:
        -:   16:    //get values
        1:   17:    a = atoi(argv[1]);
        1:   18:    b = atoi(argv[3]);
        -:   19:
        -:   20:    //get operator
        1:   21:    opr=argv[2][0];
        -:   22:
        -:   23:    //calculate according to operator
        1:   24:    switch(opr)
        1:   24-block  0
        -:   25:    {
        1:   26:        case '+':
        1:   27:            result = add_(a, b);
        1:   27-block  0
        -:   28:
        1:   29:            break;
    #####:   30:        case '-':
    #####:   31:            result=sub_(a,b);
    $$$$$:   31-block  0
    #####:   32:            break;
    #####:   33:        case '_':
    #####:   34:            result=multiply_(a,b);
    $$$$$:   34-block  0
    #####:   35:            break;
    #####:   36:        case '/':
    #####:   37:            result = div_(a,b);
    $$$$$:   37-block  0
    #####:   38:        default:
    #####:   39:            result=0;
    #####:   40:            break;
    $$$$$:   40-block  0
        -:   41:    }
        -:   42:
        1:   43:    if(opr=='+' || opr=='-' || opr=='_'|| opr== '/')
        1:   43-block  0
    $$$$$:   43-block  1
    $$$$$:   43-block  2
    $$$$$:   43-block  3
        1:   44:        printf("Result: %d %c %d = %d\n",a,opr,b,result);
        1:   44-block  0
        -:   45:    else
    #####:   46:        printf("Undefined Operator...\n");
    $$$$$:   46-block  0
        -:   47:
        1:   48:    return 0;
        1:   48-block  0
        -:   49:}
        -:   50:
        -:   51:/**
        -:   52: * Function to add two numbers
        -:   53: */
        1:   54:float add_(float num1, float num2)
        1:   54-block  0
        -:   55:{
        1:   56:    return num1 + num2;
        1:   56-block  0
        -:   57:}
        -:   58:
        -:   59:/**
        -:   60: * Function to subtract two numbers
        -:   61: */
    #####:   62:float sub_(float num1, float num2)
    $$$$$:   62-block  0
        -:   63:{
    #####:   64:    return num1 - num2;
    $$$$$:   64-block  0
        -:   65:}
        -:   66:
        -:   67:/**
        -:   68: * Function to multiply two numbers
        -:   69: */
    #####:   70:float multiply_(float num1, float num2)
    $$$$$:   70-block  0
        -:   71:{
    #####:   72:    return num1 * num2;
    $$$$$:   72-block  0
        -:   73:}
        -:   74:
        -:   75:/**
        -:   76: * Function to divide two numbers
        -:   77: */
    #####:   78:float div_(float num1, float num2)
    $$$$$:   78-block  0
        -:   79:{
    #####:   80:    return num1 / num2;
    $$$$$:   80-block  0
        -:   81:}

如果有人知道如何解密块信息,特别是第5、12、13、43、64行,或者知道任何有关其含义的详细文档,我将不胜感激.

If anyone knows how to decipher the block info, specially lines 5,12,13,43 ,64 or knows of any detailed documentation on what it all means, I'd appreciate the help.

推荐答案

每个块都由一行标记,该行的行号与该块的最后一行相同,并且该分支中的分支和调用的数目相同.使用一对花括号({})创建一个块.第5行标志着主块的开始...然后提到了我提到的每个分支或函数调用块的编号...现在,您的if语句具有四个条件,这意味着将有4个附加块被标记为0,1,2,3 ..所有未执行的块都标记为$$$,在这里是正确的,因为您必须传递"+"作为参数,因此程序永远不会采用其他运算符的路径,因此块1,2,3标记为$$$$$.

Each block is marked by a line with the same line number as the last line of the block and the number of branch and calls in the block. A block is created using a pair of curly braces({}). Line 5 marks the beginning of main block...then as I mentioned for every branch or function call block number is mentioned...Now your if statement has four conditions that means there will be 4 additional blocks which are labeled as 0,1,2,3..All the blocks which are not executed are marked $$$$$, which is true here as you must have passed '+' as the argument so the program never takes the path of other operators and hence block 1,2,3 are marked as $$$$$.

希望这会有所帮助.

这篇关于了解gcov文件中的块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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