简体   繁体   English

如何在 Visual Studio 或 CLion 调试器中单步执行 ispc 源文件?

[英]How to step through ispc source files in Visual Studio or CLion debugger?

I'm getting started with ispc (Intel SPMD Program Compiler), and I'm able to compile and run the examples provided with the distribution.我开始使用ispc (英特尔 SPMD 程序编译器),并且能够编译和运行随分发提供的示例。 What I'd like to do next is to be able to step through an .ispc file inside the Visual Studio (or CLion) debugger.我接下来想做的是能够单步执行 Visual Studio(或 CLion)调试器中的.ispc文件。

According to the documentation , the ispc compiler can be instructed to emit debugging symbols with the -g option.根据文档,可以使用-g选项指示ispc编译器发出调试符号。 I've added that to the provided CMakeLists.txt , but I can't seem to get Visual Studio to actually step into an ispc function.我已将其添加到提供的CMakeLists.txt中,但我似乎无法让 Visual Studio 真正进入 ispc function。

For example, I set a breakpoint in the simple example here: https://github.com/ispc/ispc/blob/master/examples/simple/simple.cpp#L49例如,我在这里的simple示例中设置了一个断点: https://github.com/ispc/ispc/blob/master/examples/simple/simple.cpp#L49

When clicking "step into", I'd expect Visual Studio to step into the definition of that function, here: https://github.com/ispc/ispc/blob/master/examples/simple/simple.ispc#L35 .单击“进入”时,我希望 Visual Studio 能够进入该 function 的定义,此处为: https://github.com/ispc/ispc/blob/master/examples/simple/simple.ispc#L35 Instead, Visual Studio steps over and continues on with simple.cpp .相反,Visual Studio 会跳过并继续使用simple.cpp

I suspect that Visual Studio either can't locate the debugging symbols generated by the ispc compiler, and/or doesn't know that those symbols are associated with the simple.ispc file.我怀疑 Visual Studio 要么找不到ispc编译器生成的调试符号,和/或不知道这些符号与simple.ispc文件相关联。

I found this blog post from last year which says, among other things:我发现去年的这篇博文除其他外说:

The latest version of ispc (1.9.2) supports limited debugging with Visual Studio.最新版本的 ispc (1.9.2) 支持使用 Visual Studio 进行有限调试。 Examining struct's with bool's doesn't seem to work, the locals window is very iffy but more or less works.用布尔值检查结构似乎不起作用,当地人 window 非常有问题,但或多或少有效。 Single stepping works.单步工作。 Profiling works but seems a little iffy.分析工作,但似乎有点不确定。

So it seems clear that this is possible;所以很明显这是可能的; I just don't know enough about how compilers, debuggers, and IDEs interact to make this happen.我只是不太了解编译器、调试器和 IDE 如何交互以实现这一点。 Does anyone know how to accomplish this?有谁知道如何做到这一点?

Running Windows 10 (v1903) with Visual Studio 2017 (v15.9.17)使用 Visual Studio 2017 (v15.9.17) 运行 Windows 10 (v1903)

$ ispc --version
Intel(r) SPMD Program Compiler (ispc), 1.12.0 (build date Aug 15 2019, LLVM 8.0.0)
Supported Visual Studio versions: Visual Studio 2015 and later.

It turns out that I added the -g flag in the wrong place.事实证明,我在错误的位置添加了-g标志。

The ISPC examples include a "master" CMake file that has a bunch of common options, called AddISPCExample.cmake . ISPC 示例包括一个“主”CMake 文件,该文件具有一系列常用选项,称为AddISPCExample.cmake This file is executed for every example.该文件针对每个示例执行。 Each example also includes its own CMakeLists.txt with its own options.每个示例还包含自己的CMakeLists.txt和自己的选项。 I originally modified AddISPCExample.cmake by adding the following line:我最初通过添加以下行修改AddISPCExample.cmake

    # add debug flag
    target_compile_options(${example_NAME} PRIVATE -g)

After more closely examining the build output, it turns out that this caused the -g flag to be added to the MSVC compiler's flags for simple.exe ([2/3] command below), instead of to the ispc compiler's flags for simple.ispc ([1/3] command below):在更仔细地检查构建 output 之后,事实证明这导致-g标志被添加到 MSVC 编译器的simple.exe标志(下面的 [2/3] 命令),而不是simple.ispc (下面的 [1/3] 命令):

>------ Rebuild started: Project: CMakeLists, Configuration: Debug ------
Build started 14-Nov-19 6:40:58.
RunExternalTool:
  [1/3] cmd.exe /C "cd /D "C:\Users\Daniel\CMakeBuilds\7d280c73-3384-fd31-a5a6-63248b2e8dd4\build\x64-Debug (default)\simple" && C:\bin\ispc.exe C:/Users/Daniel/Downloads/ispc-v1.12.0-windows/examples/simple/simple.ispc -O2 --target=sse2 --arch=x86-64 -h "C:/Users/Daniel/CMakeBuilds/7d280c73-3384-fd31-a5a6-63248b2e8dd4/build/x64-Debug (default)/simple/simple_ispc.h" -o "C:/Users/Daniel/CMakeBuilds/7d280c73-3384-fd31-a5a6-63248b2e8dd4/build/x64-Debug (default)/simple/simple_ispc.obj""
  [2/3] C:\PROGRA~2\MICROS~1\2017\ENTERP~1\VC\Tools\MSVC\1416~1.270\bin\HostX64\x64\cl.exe  /nologo /TP  -Isimple /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1   /fp:fast /Oi -g /showIncludes /Fosimple\CMakeFiles\simple.dir\simple.cpp.obj /Fdsimple\CMakeFiles\simple.dir\ /FS -c C:\Users\Daniel\Downloads\ispc-v1.12.0-windows\examples\simple\simple.cpp
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\cl : Command line warning D9002: ignoring unknown option '-g'
  [3/3] cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=simple\CMakeFiles\simple.dir --manifests  -- C:\PROGRA~2\MICROS~1\2017\ENTERP~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo simple\simple_ispc.obj simple\CMakeFiles\simple.dir\simple.cpp.obj  /out:simple\simple.exe /implib:simple\simple.lib /pdb:simple\simple.pdb /version:0.0  /machine:x64 /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
  LINK : simple\simple.exe not found or not built by the last incremental link; performing full link

Instead, I modified the simple example's CMakeLists.txt by adding the -g flag:相反,我通过添加-g标志修改了简单示例的CMakeLists.txt

set (ISPC_FLAGS -O2 -g)

This causes the -g flag to be passed to the ispc compiler's command line (in [2/3] below):这会导致-g标志被传递到 ispc 编译器的命令行(在下面的 [2/3] 中):

>------ Build started: Project: CMakeLists, Configuration: Debug ------
Build started 14-Nov-19 6:44:17.
RunExternalTool:
  [1/3] cmd.exe /C "cd /D "C:\Users\Daniel\CMakeBuilds\7d280c73-3384-fd31-a5a6-63248b2e8dd4\build\x64-Debug (default)\simple" && C:\bin\ispc.exe C:/Users/Daniel/Downloads/ispc-v1.12.0-windows/examples/simple/simple.ispc -O2 -g --target=sse2 --arch=x86-64 -h "C:/Users/Daniel/CMakeBuilds/7d280c73-3384-fd31-a5a6-63248b2e8dd4/build/x64-Debug (default)/simple/simple_ispc.h" -o "C:/Users/Daniel/CMakeBuilds/7d280c73-3384-fd31-a5a6-63248b2e8dd4/build/x64-Debug (default)/simple/simple_ispc.obj""
  [2/3] C:\PROGRA~2\MICROS~1\2017\ENTERP~1\VC\Tools\MSVC\1416~1.270\bin\HostX64\x64\cl.exe  /nologo /TP  -Isimple /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1   /fp:fast /Oi /showIncludes /Fosimple\CMakeFiles\simple.dir\simple.cpp.obj /Fdsimple\CMakeFiles\simple.dir\ /FS -c C:\Users\Daniel\Downloads\ispc-v1.12.0-windows\examples\simple\simple.cpp
  [3/3] cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=simple\CMakeFiles\simple.dir --manifests  -- C:\PROGRA~2\MICROS~1\2017\ENTERP~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo simple\simple_ispc.obj simple\CMakeFiles\simple.dir\simple.cpp.obj  /out:simple\simple.exe /implib:simple\simple.lib /pdb:simple\simple.pdb /version:0.0  /machine:x64 /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
  LINK : simple\simple.exe not found or not built by the last incremental link; performing full link

Build succeeded.

Now, setting a breakpoint and stepping into the ispc file works (although the UI is a bit wonky):现在,设置断点并进入 ispc 文件是可行的(尽管 UI 有点不稳定):

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM