c++ - 截至 2017 年的 clang 5.0 pdb 支持

标签 c++ windows visual-studio clang pdb

这里解释说 clang 现在知道如何生成 .pdb 文件(http://blog.llvm.org/2017/08/llvm-on-windows-now-supports-pdb-debug.html)。

据我所知,至少 clang 与 Microsoft 链接器现在预计会生成与 msvc 工具链生成的文件等效的 .pdb 文件。

此处解释了如何使用主流 Visual Studio 2017 调试“外部”二进制文件,即不是使用项目/解决方案构建的二进制文件 (https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-debug-an-executable-not-part-of-a-visual-studio-solution)。

我用 clang -g main.c -o main.exe 编译了一个简单的 hello world 应用程序,它按预期生成了一个 .pdb 文件。

但是,当我尝试进入它时,Visual Studio 提示 .pdb 文件不包含行号信息。

相比之下,使用 cl/EHsc/Zi main.c 编译允许使用 Visual Studio 正常调试。

我目前正在尝试了解 clang 生态系统是否已经足以在 Windows 上进行开发,如果有人能解释一下,我将不胜感激:

  1. stable clang 和 msvc 生成的 .pdb 文件有什么区别?
  2. 在这方面,linklld 之间有什么区别吗?
  3. clang 6.0 会发生变化吗?

最佳答案

这对我有用:

clang -g -gcodeview main.c -o main.exe

选项-gcodeview 告诉Clang 在Microsoft 的CodeView format 中生成调试信息。 . 然后 Visual Studio 可以毫无问题地读取生成的 .pdb

另一种选择是使用 clang-cl,您可以将 /Zi 传递给它,或者 MIEngine ,这应该允许您在 Visual Studio 中使用非 CodeView 调试信息。 不过,我还没有尝试过这两种方法。


郑重声明,这是我的 ma​​in.c:

#include <stdio.h>

int main() {
    getc(stdin); // pause to allow attaching the debugger
    return 0;
}

我用了Clang 6.0.0 .

关于c++ - 截至 2017 年的 clang 5.0 pdb 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47858889/

相关文章:

android - 如何在不发疯的情况下使用 ARM DS-5 在 eclipse 中调试 Android native 库?

c++ - 调试断言失败!表达式 : _BLOCK_TYPE_IS_VALID

c# - C#程序保持不变的错误级别

visual-studio - 在 VS2010 中将目标更改为 x86

visual-studio - 如何在 Visual Studio 中启用 'Locals' 选项卡?

c++ - 在矩阵中寻找邻域

c++ - 标识符在初始化时未定义

Windows 批处理脚本 : substring calculation

sql - 从数据源名称获取实例名称

c# - 无法将 Type 1 隐式转换为 Type 1