AVX-512 - 使用英特尔 SDE 调试应用程序不起作用

问题描述

我正在尝试使用 Intel® Software Development Emulator 在模拟 cpu 上调试 AVX-512 指令,但在设置断点后它无法正常工作。我关注了这篇博文:Debugging Emulated Code on Linux*

在窗口 #1:

~$ g++ -g -O0 -mavx512f main.cpp -o main # compile main.cpp file
~$ sde -debug -- ./main # enable debugging

Application stopped until continued from debugger.
Start GDB,then issue this command at the (gdb) prompt:
target remote :54105

在窗口 #2

# run debugger
~$ gdb ./main 
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
copyright (C) 2020 Free Software Foundation,Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY,to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions,please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.

For help,type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./main...

# set target "target remote :portnumber"
(gdb) target remote :54105  
Remote debugging using :54105
warning: remote target does not support file transfer,attempting to access files from local filesystem.
Reading symbols from /lib64/ld-linux-x86-64.so.2...
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
0x00007fa7bbbcc100 in ?? () from /lib64/ld-linux-x86-64.so.2

# suspend program at main function
(gdb) break main   
Breakpoint 1 at 0x2c9c: file /home/borrow/source/repos/se-test/main.cpp,line 165.

# start program execution from the beginning of the program
(gdb) run        
The "remote" target does not support "run".  Try "help target" or
"continue".

# step to next line of code
(gdb) step        
Cannot find bounds of current function

# continue executing until next break point
(gdb) c         
Continuing.
warning: Probes-based dynamic linker interface Failed.
Reverting to original interface.
[Inferior 1 (Remote target) exited normally]

在窗口 #2:如你所见

gdb run 应该运行一个程序,但它不起作用。 gdb c 也应该运行到下一个断点,但会执行程序并终止。此命令给了我以下警告消息:

警告:基于探针的动态链接器接口失败。

在窗口 #1:程序运行并结束(不停止)。

程序代码如下所示:

//  main.cpp
#include <immintrin.h>

const int N=64;
int64_t srcA[N] = {0};
int64_t srcB[N] = {0};
int64_t dst[N] = {0};


void foo()
{
    __m512i result,B,C;
    for ( int i=0; i<N; i+=8 ){
        B =  _mm512_loadu_si512(&srcA[i]);
        C =  _mm512_loadu_si512(&srcB[i]);
        result = _mm512_add_epi64(B,C);
        _mm512_storeu_si512(&dst[i],result);
    }
}
 
int main() {
     ...
     foo();
     ...
}

我尝试使用 gdb 在没有 SDE 模拟器的情况下运行 AVX2 代码,并且成功了。首先,我在带有 SDE 的模拟 cpu 上启动它,它失败了。我该如何解决这个问题?

解决方法

PIE 可执行文件似乎已损坏
(已在 Arch GNU/Linux 上使用 GCC 10.2、GDB 10.1、SDE 8.33 确认。)

使用 g++ -O2 -fno-pie -no-pie -g -march=skylake-avx512 构建,一切正常。 (我不得不运行 gdb ./a.out 而不是裸 GDB;否则,即使连接到远程,它也无法找到正确的文件。)

$ g++ -O2 -march=skylake-avx512 -no-pie -fno-pie -g  avx512.cpp
$ /opt/sde-external-8.33.0-2019-02-07-lin/sde64 -debug -- ./a.out
Application stopped until continued from debugger.
Start GDB,then issue this command at the (gdb) prompt:
  target remote :59783

然后在另一个终端标签中

$ gdb ./a.out
...
(gdb)   target remote :59783
warning: remote target does not support file transfer,attempting to access files from local filesystem.
Reading symbols from /lib64/ld-linux-x86-64.so.2...
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
0x00007f4f7033b090 in _start () from /lib64/ld-linux-x86-64.so.2
(gdb) b main
Breakpoint 1 at 0x401050: file avx512.cpp,line 29.
(gdb) b foo
Breakpoint 2 at 0x401190: file avx512.cpp,line 14.
(gdb) c
Continuing. 
Breakpoint 1,main () at avx512.cpp:23
(gdb) layout asm
(copy-paste of some of the disassembly window)
│B+ 0x401120 <_Z3foov>              xor    eax,eax
│   0x401122 <_Z3foov+2>            nop    WORD PTR [rax+rax*1+0x0]
│  >0x401128 <_Z3foov+8>            vmovdqu64 zmm1,ZMMWORD PTR [rax+0x404260]
│   0x401132 <_Z3foov+18>           add    rax,0x40
│   0x401136 <_Z3foov+22>           vpaddq zmm0,zmm1,ZMMWORD PTR [rax+0x404420]
│   0x401140 <_Z3foov+32>           vmovdqu64 ZMMWORD PTR [rax+0x404020],zmm0
│   0x40114a <_Z3foov+42>           cmp    rax,0x200
│   0x401150 <_Z3foov+48>           jne    0x401128 <_Z3foov+8>
│   0x401152 <_Z3foov+50>           vzeroupper
│   0x401155 <_Z3foov+53>           ret
(gdb) layout src

asm 级和源级调试都可以正常工作,在使用 avx512fintrin.h(又名 stepi)时进入 si 中的内在“函数”等等。


没有单独指定文件名与远程连接:

$ gdb
(gdb)  target remote :46879
Remote debugging using :46879 warning: No executable has been specified and target does not support determining executable automatically.  Try using the "file" command.
0x00007f0f85830090 in ?? ()
(gdb)

(如果我的 .gdbinit 包含 layout reg(全屏终端 TUI 模式)很重要的话,IDK。它工作时很好,但有些问题。)


或者作为 PIE 可执行文件的超级hacky 解决方法,我还能够在 main 的顶部放置一个延迟循环,让您有机会在 SDE 完成执行您的程序之前附加然后控制 C。

然后我可以设置断点并开始单步执行。 (大概 sleepread 系统调用会起作用)。源代码级调试似乎仍然失败,但我能够使用 layout reg 调试 asm。在附加并点击 control-C 后,我使用带有复制粘贴地址的 set $rip = ... 退出 _mm_pause() 循环。