我需要gcov
在我正在处理的共享库上执行一些测试覆盖.
问题是libtool
将目标文件重命名为my-name.c
,libmylib_la-my-name.lo
并且gcov
无法处理该转换.每次运行它时,cannot open notes file
都会生成错误.
如果我手动重命名my-name.c
到libmylib_la-my-name.c
后构建gcov
工作正常,所以没有其他问题,除了文件名截断.
试图提供一个最小的工作示例,我发现文件名修改只在lib..._la_CFLAGS
设置时(以及设置为空值时)发生.
cat <<EOT > configure.ac
AC_INIT(sample,0.0.1)
AC_CONFIG_SRCDIR(configure.ac)
AM_INIT_AUTOMAKE(foreign)
LT_INIT
AC_PROG_CC
AC_CONFIG_FILES(Makefile)
AC_OUTPUT
EOT
cat <<EOT > Makefile.am
lib_LTLIBRARIES=libsample.la
libsample_la_SOURCES=sample.c
# The following line triggers the filename mangling (libsample_la-sample.lo instead of sample.lo)
libsample_la_CFLAGS=
EOT
touch sample.c && autoreconf -if && ./configure && make
Run Code Online (Sandbox Code Playgroud)
有没有办法避免libtool操作的文件名修改或让我们gcov
理解文件名修改方案?
假设我从外部库中获得以下类型:
union foreign_t {
struct {
enum enum_t an_enum;
int an_int;
} header;
struct {
double x, y;
} point;
};
Run Code Online (Sandbox Code Playgroud)
假设以下代码片段在不同平台和不同编译器上按预期工作是否安全?
struct pair_t {
double x, y;
};
union foreign_t foreign;
struct pair_t *p_pair;
p_pair = (struct pair_t *) &foreign;
p_pair->x = 1234;
p_pair->y = 4321;
/* Expected result: (1234, 4321) or something like that */
printf("(%lf, %lf)", foreign.point.x, foreign.point.y);
Run Code Online (Sandbox Code Playgroud)
按照严格的别名建议,我做了以下测试:
#include <stdint.h>
#include <stdio.h>
int main()
{
uint16_t word = 0xabcd;
uint8_t tmp;
struct {
uint8_t low; …
Run Code Online (Sandbox Code Playgroud)