是否可以使用lldb调试gcc编译的程序,或者使用gdb调试clang编译的程序? [英] Is it possible to debug a gcc-compiled program using lldb, or debug a clang-compiled program using gdb?

查看:25
本文介绍了是否可以使用lldb调试gcc编译的程序,或者使用gdb调试clang编译的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(前言:我对 C/C++ 还很陌生,我真的不知道在本机代码中调试实际上是如何工作的.)

(Preface: I'm pretty new to C/C++ and I don't really know how debugging in native code actually works.)

一些消息来源说 gdb 和 lldb 可以调试 任何编译为机器码.其他人说要使用 gdb 进行调试,您必须在 gcc 使用 -g 标志.gcc 本身的文档表明这是可选的,事实上如果您使用它,它可能会导致调试器出现问题 gdb.Clang 还有一个 -g 标志,文档基本上只是说生成调试信息".

Some sources say that gdb and lldb can debug any program compiled to machine code. Others say that to debug with gdb you must compile in gcc with the -g flag. The documentation for gcc itself suggests this is optional, and that in fact if you use it, it can cause problems for debuggers other than gdb. Clang also has a -g flag and the documentation basically just says "Generate debug information."

那么这些调试器是否仅限于它们自己的工具链(GNU 和 LLVM),或者它们在某种程度上独立于所使用的编译器?

So are these debuggers restricted to their own toolchains (GNU and LLVM), or are they somehow independent of the compiler used?

推荐答案

理论上你应该能够使用 lldb 调试 GCC 构建的程序,以及使用 gdb 调试 LLVM 构建的程序.在这两种情况下,您都应该使用 -g 进行编译.

In theory you should be able to debug a GCC-built program with lldb and an LLVM-built program with gdb. In both cases you should compile with -g.

这是因为两个编译器都生成相同格式的目标文件(例如,在 Linux 上,两者都会生成 ELF 文件DWARF 调试信息)并且两个调试器都知道如何解析该格式.

This is because both compilers generate object files in the same format (e.g., on Linux, both will generate ELF files with DWARF debug info) and both debuggers know how to parse that format.

实际上,两个编译器都会将一些数据推送到只有它们各自的调试器知道如何使用的调试信息中.然而:

In practice, both compilers push some data into the debug info that only their respective debugger knows how to consume. However:

  1. LLVM 生成的数据不应以任何方式阻碍 gdb.
  2. GCC 生成的数据不应妨碍 lldb,但如果确实如此,您可以专门 要求 gcc 不要添加非标准数据.例如,在 Linux 上,使用 -gdwarf-2 而不是 -g 应该只生成符合标准的 DWARF.
  1. LLVM-generated data should not hinder gdb in any way.
  2. GCC-generated data should not hinder lldb, but if it does you can specifically ask gcc to not add non-standard data. For example, on Linux, using -gdwarf-2 over -g should only generate standard-compliant DWARF.

请注意,您也可以在没有调试信息的情况下调试程序(不使用 -g 编译),但您将仅限于调试器中的低级信息 - 汇编代码、内存和寄存器 -并且将无法看到高级构造,例如行号、函数名称、变量名称及其内容之间的映射等.

Notice that you can also debug programs without debug info (not compiled with -g), but you'll be limited to low-level information in the debugger - assembly code, memory and registers - and will not be able to see high level constructs such as line numbers, function names, mapping between variable names and their content, etc.

这篇关于是否可以使用lldb调试gcc编译的程序,或者使用gdb调试clang编译的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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