3

I am using gcov with the option -a (--all-blocks) which from the manual:

When you use the -a option, you will get individual block counts

The original file:

#include <stdio.h>
#include "file1.h"

int max(int a , int b)
{
  int k = 0;
  if (a > b)
    return a;
  else
    return b;
}

The gcov file is the following:

    -:    0:Source:file1.c
    -:    0:Graph:file1.gcno
    -:    0:Data:file1.gcda
    -:    0:Runs:1
    -:    0:Programs:1
    -:    1:#include <stdio.h>
    -:    2:#include "file1.h"
    -:    3:
    -:    4:int max(int a , int b)
    1:    5:{
    1:    6:  int k = 0;
    1:    7:  if (a > b)
    1:    7-block  0
    1:    8:    return a;
    1:    8-block  0
    -:    9:  else
    1:   10:    return b;
$$$$$:   10-block  0
    1:   10-block  1
    -:   11:}
    -:   12:
    -:   13:

I couldn't find any information about the format of the output of the gcov. From the original code I can identify 3 basic blocks but gcov only numbers two and also in line 10 it identifies two blocks.

user847988
  • 984
  • 1
  • 16
  • 30

2 Answers2

2

Block numbers are local to a line. block 0 on line 7 means "block 0 of line 7" etc. You have block 1 only when a line has two or more blocks, as is the case with line 10.

The block number is shown on the last line of that block only.

Thus, your program has 4 blocks, two of them on line 10.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • can you identify the two blocks on line 10? and what does this sign mean "$$$$$" ? – user847988 Sep 02 '13 at 08:50
  • One block is the else part, the other is probably return-from-main (has no line of its own). $$$$$ marks blocks (not lines) that are not executed. – n. m. could be an AI Sep 02 '13 at 09:23
  • Hello! I am wondering if it was possible to map these "clumsy" source code level basic block representation back into GIMPLE code. Do you happen to how if it was feasible to do so? – lllllllllllll Jun 18 '20 at 09:16
0

The .gcov files contain the ‘:’ separated fields along with program source code. The format is execution_count:line_number:source line text Additional block information may succeed each line, when requested by command line option. The execution_count is ‘-’ for lines containing no code. Unexecuted lines are marked ‘#####’ or ‘====’, depending on whether they are reachable by non-exceptional paths or only exceptional paths such as C++ exception handlers, respectively. Given ‘-a’ option, unexecuted blocks are marked ‘$$$$$’ or ‘%%%%%’, depending on whether a basic block is reachable via non-exceptional or exceptional paths.

https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Invoking-Gcov.html

Nour
  • 2,099
  • 3
  • 17
  • 17