第 7 页 重要数据结构 gcov_var 2.6 重要数据结构 gcov_var
gcov_var 是个全局变量,其作用就是在 gcov/gcov-dump 程序运行期间保存操作的文件信息,例如,文件指针、某个 block 的 start/offset/length 、文件内容 buffer 等信息,定义如下。
/* Optimum number of gcov_unsigned_t's read from or written to disk. */
#define GCOV_BLOCK_SIZE ( 1 << 10="">
GCOV_LINKAGE struct gcov_var
{
FILE * file ;
gcov_position_t start ; /* Position of first byte of block */
unsigned offset ; /* Read/ write position within the block. */
unsigned length ; /* Read limit in the block. */
unsigned overread ; /* Number of words overread. */
int error ; /* < 0 overflow, > 0 disk error. */
int mode ; /* < 0 writing, > 0 reading */
#if IN_LIBGCOV
/* Holds one block plus 4 bytes, thus all coverage reads & writes
fit within this buffer and we always can transfer GCOV_BLOCK_SIZE
to and from the disk. libgcov never backtracks and only writes 4 or 8 byte objects. */
gcov_unsigned_t buffer [ GCOV_BLOCK_SIZE + 1 ];
#else
int endian ; /* Swap endianness. */
/* Holds a variable length block, as the compiler can write strings and needs to backtrack. */
size_t alloc ;
gcov_unsigned_t * buffer ;
#endif
} gcov_var ATTRIBUTE_HIDDEN ;
在 gcov-dump 程序中, sizeof( gcov_type )=sizeof( gcov_unsigned_t )=4 , sizeof(gcov_var) =40 。 gcov_var 的值一个例子可以参考 2.4 节,此处不再赘述。