【问题标题】:finstrument-functions-exclude-function-list appears to not handle commas properlyfinstrument-functions-exclude-function-list 似乎无法正确处理逗号
【发布时间】:2019-10-22 23:43:31
【问题描述】:

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

使用的 GCC 命令:

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

上面创建了一个带有“测试”功能的二进制文件。汇编 sn-p 和 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

【问题讨论】:

  • 嗨@Scheff,逗号需要转义,否则gcc会将其后的所有内容视为单独的函数子字符串,因此如果我将“test”替换为“test",由于子字符串“test
  • 不错的收获。我没有尝试使用“test”,得出了错误的结论。 :-(

标签: c++ gcc compilation instrumentation


【解决方案1】:

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

Namespace / class mishandling

Comma mishandling

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-10
    • 2015-10-14
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-27
    相关资源
    最近更新 更多