【问题标题】:clang 5.0 pdb support as of 2017截至 2017 年的 clang 5.0 pdb 支持
【发布时间】:2017-12-17 19:56:05
【问题描述】:

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

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

这里解释了如何使用主流 Visual Studio 2017 调试“外部”二进制文件,即不是使用项目/解决方案 (https://docs.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-cl.exe
  • 愚蠢的问题:如果您已经在 Windows 上并且可以访问 Visual Studio,为什么不直接使用 Visual Studio?

标签: c++ windows visual-studio clang pdb


【解决方案1】:

这对我有用:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 2014-01-04
    • 2015-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多