如何在macOS Mojave中使用lldb调试C代码?

时间:2019-02-12 20:21:27

标签: macos debugging gdb

我在Linux中使用gdb,但是现在我切换到Mac,并且阅读到lldb是Apple设备中gdb的替代品。但是,当我尝试使用lldb时出现错误(我也尝试过gdb,但它不能将文件识别为可执行文件)。当我尝试使用它时,出现以下错误:

sanad@Sanads-MBP  ~/Desktop/cppLab  lldb ./a.out         ✔  623  01:43:54
(lldb) target create "./a.out"
Traceback (most recent call last):
  File "", line 1, in 
  File "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python/lldb/__init__.py", line 98, in 
    import six
ImportError: No module named six
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'run_one_line' is not defined

…以及另外十多个类似的NameErrors,直到输出以以下结尾:

Current executable set to './a.out' (x86_64).
(lldb)

1 个答案:

答案 0 :(得分:0)

lldb链接到System Python.framework,并且只能加载与该Python库一起构建的其他python模块。事实证明,如果您不明确告诉Python在哪里找到Python模块,Python的工作方式将与它在PATH中找到的“ python”二进制文件并排。因此,如果您安装了另一个python并将其放在PATH中,则lldb的python将尝试加载实际上无法正确加载的Python模块。当前的解决方法是清除您要从中运行lldb的任何终端窗口中的PATH环境变量中手动安装的Python

该问题最近已得到修复(llvm.org上的r356819),并将在不久的将来纳入Xcode版本。