铛没有在-g标志上生成调试信息 [英] Clang not generating debug info on -g flag

查看:42
本文介绍了铛没有在-g标志上生成调试信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows上使用clang v8.0.0时(从llvm预先构建的二进制文件中 )带有 -g -gline-tables-only 的源映射表未被gdb或lldb调试器接收.

When using clang v8.0.0 on Windows (from llvm prebuilt binaries) with -g or -gline-tables-only source map tables are not being aren't picked up by gdb or lldb debuggers.

包含 -g 标志文件的文件会增大大小(这是可以预期的),但gdb和lldb都没有选择源代码

Upon including -g flag file grows in size (which is to be expected) yet neither gdb nor lldb pickes the source up

使用gcc编译时(带有 -g 标志),调试器会检测到源文件.

When compiled with gcc though (with -g flag) source files are detected by debugger.

我尝试在macOS High Sierra( clang -v )上说这是 Apple LLVM版本的同一命令( clang -g< codefile> )10.0.0(clang-1000/10.44.4)),其中lldb正在获取源文件.因此,我猜想它已本地化到我的widows实例或用于Windows构建的llvm.

I have tried running the same command (clang -g <codefile>) on macOS High Sierra (clang -v says it is Apple LLVM version 10.0.0 (clang-1000/10.44.4)) where there source files are being picked up by lldb. So I guessed it is localized to my widows instance or llvm for windows build.

P.S.在Windows上 clang -v 的输出:

P.S. output of clang -v on windows:

clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

推荐答案

在Windows上,Clang不能自给(至少不是官方二进制文件).您需要安装GCC或MSVC才能运行.

On Windows, Clang is not self-sufficient (at least not the official binaries). You need to have either GCC or MSVC installed for it to function.

Target:x86_64-pc-windows-msvc 所示,默认情况下,您的Clang以某种与MSVC兼容的模式运行.从我收集的信息来看,这意味着使用标准库和MSVC安装提供的其他库,并大概以某种特定于MSVC的格式生成调试信息.

As Target: x86_64-pc-windows-msvc indicates, by default your Clang is operating in some kind of MSVC-compatible mode. From what I gathered, it means using the standard library and other libraries provided by your MSVC installation, and presumably generating debug info in some MSVC-specific format.

添加-target = x86_64-w64-windows-gnu 以在GCC兼容模式下进行构建.(如果您要构建的是32位而不是64位,请用 i686 替换 x86_64 ).这将使Clang使用标头&您的GCC安装提供的库以及调试信息应以与GCC兼容的方式生成.我可以使用MSYS2的GDB调试生成的二进制文件(这也是我的GCC安装所在的位置).

Add --target=x86_64-w64-windows-gnu to build in GCC-compatible mode. (If you're building for 32 bits rather than 64, replace x86_64 with i686). This will make Clang use headers & libraries provided by your GCC installation, and debug info should be generated in a GCC-compatible way. I'm able to debug resulting binaries with MSYS2's GDB (and that's also where my GCC installation comes from).

如果仅安装了GCC而不是MSVC,则仍必须使用此标志.

If you only have GCC installed and not MSVC, you still must use this flag.

我怎么知道这是正确的-target ?这就是MSYS2的Clang所使用的,我想他们知道他们在做什么.如果您不想每次都键入此标志,则可以用MSYS2的官方Clang代替它,但是我不确定这是否是最好的主意.
(我认为他们曾经提供一些补丁来增强与MinGW的兼容性,但现在官方二进制文件同样工作良好,除了需要指定目标.由于无法动态链接到工作环境,他们提供的某些版本也很容易崩溃,所有这些问题都来自于他们用MinGW构建Clang,而Clang似乎并没有很好地支持.为了捍卫自己的利益,他们正在积极维护其发行版,我认为他们甚至为Windows发行了libc ++,而官方发行版则没有.)

How do I know this is the right --target? This is what MSYS2's Clang uses, and I assume they know what they're doing. If you don't want to type this flag every time, you can replace the official Clang with MSYS2's one, but I'm not sure if it's the best idea.
(I think they used to provide some patches to increase compatibility with MinGW, but now the official binaries work equally well, except for the need to specify the target. Also, last time I checked their binary distribution was several GB larger, due to their inability to get dynamic linking to work. Also some of the versions they provided were prone to crashing. All those problems come from them building their Clang with MinGW, which Clang doesn't seem to support very well out of the box. In their defence, they're actively maintaining their distribution, and I think they even ship libc++ for Windows, which the official distribution doesn't do.)

这篇关于铛没有在-g标志上生成调试信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆