c++ - finstrument-functions-exclude-function-list 似乎无法正确处理逗号

标签 c++ gcc compilation instrumentation

尝试使用 finstrument-functions 进行编译并排除具有多个模板参数的模板函数,使用\方法转义逗号(如 exclude-file-list here 中所述)无法正确禁用检测传递的函数。

使用的 GCC 命令:

gcc -finstrument-functions -finstrument-functions-exclude-function-list='test<float\, int>' main.cpp -o a.out -O0

上面创建了一个带有“测试”功能的二进制文件。下面包含程序集片段和 main.cpp 文件

gcc -dumpversion 返回“6.2.0”,以上命令在 red hat enterprise linux 7.4 版上运行

main.cpp 的内容:

template<class T, class U>
T test(int a, T b){
    int res = 0;
    for(int i = 0; i < 1000; i++){
        res += i;
    }
    return(res);
}

int main(int argc, char** argv){
    float a = test<float, int>(argc, 1.0);
    return(0);
}

“测试”函数的 objdumped 输出:

000000000040059f <float test<float, int>(int, float)>:
  40059f:   55                      push   %rbp
  4005a0:   48 89 e5                mov    %rsp,%rbp
  4005a3:   48 83 ec 20             sub    $0x20,%rsp
  4005a7:   89 7d ec                mov    %edi,-0x14(%rbp)
  4005aa:   f3 0f 11 45 e8          movss  %xmm0,-0x18(%rbp)
  4005af:   48 8b 45 08             mov    0x8(%rbp),%rax
  4005b3:   48 89 c6                mov    %rax,%rsi
  4005b6:   bf 9f 05 40 00          mov    $0x40059f,%edi
  4005bb:   e8 70 fe ff ff          callq  400430 <__cyg_profile_func_enter@plt>
  4005c0:   c7 45 f8 00 00 00 00    movl   $0x0,-0x8(%rbp)
  4005c7:   c7 45 fc 00 00 00 00    movl   $0x0,-0x4(%rbp)
  4005ce:   81 7d fc e7 03 00 00    cmpl   $0x3e7,-0x4(%rbp)
  4005d5:   7f 11                   jg     4005e8 <float test<float, int>(int, float)+0x49>
  4005d7:   8b 55 f8                mov    -0x8(%rbp),%edx
  4005da:   8b 45 fc                mov    -0x4(%rbp),%eax
  4005dd:   01 d0                   add    %edx,%eax
  4005df:   89 45 f8                mov    %eax,-0x8(%rbp)
  4005e2:   83 45 fc 01             addl   $0x1,-0x4(%rbp)
  4005e6:   eb e6                   jmp    4005ce <float test<float, int>(int, float)+0x2f>
  4005e8:   8b 45 f8                mov    -0x8(%rbp),%eax
  4005eb:   66 0f ef c9             pxor   %xmm1,%xmm1
  4005ef:   f3 0f 2a c8             cvtsi2ss %eax,%xmm1
  4005f3:   f3 0f 11 4d e4          movss  %xmm1,-0x1c(%rbp)
  4005f8:   48 8b 45 08             mov    0x8(%rbp),%rax
  4005fc:   48 89 c6                mov    %rax,%rsi
  4005ff:   bf 9f 05 40 00          mov    $0x40059f,%edi
  400604:   e8 17 fe ff ff          callq  400420 <__cyg_profile_func_exit@plt>
  400609:   f3 0f 10 45 e4          movss  -0x1c(%rbp),%xmm0
  40060e:   c9                      leaveq 
  40060f:   c3                      retq

我预计测试函数不会被检测,但它是。有谁知道这是为什么吗?

Compiler explorer example

最佳答案

以防万一有人通过这种方式,这个和 finstrument-functions-exclude-function-list 不尊重函数的命名空间部分都是错误,我已经对两者提出了反对。希望尽快实现修复(目前正在处理一个)。

Namespace / class mishandling

Comma mishandling

关于c++ - finstrument-functions-exclude-function-list 似乎无法正确处理逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56494785/

相关文章:

c++ - 在由换行符分隔的字符串中查找特定文本

c++ - 在 GUI 运行时永久禁用 Qt 中的 shift?

java - 二维数组初始值设定项后跟方括号

scala - 编译后 SBT 应用任务

android - 尝试编译 AOSP 7.1.1 第 6 版时缺少 'libaudiopolicyservice_intermediates"?

c++ - 使用 TCP 发送 Iplimage 时出错

c++ - 崩溃,施工前使用它

c - 带减法的无符号字符溢出

c - 使用 gcc(resp.MinGW)编译器的 C 函数是否有最大数量的参数?

c++ - GCC 上的#pragma pack(push, n)/#pragma pack(pop) 和 __attribute__((__packed__, aligned(n) )) 之间有什么区别?