Python 虚拟环境中的 lldb

lldb in a Python virtal environment

我倾向于使用大量虚拟环境,尤其是 Python。我在特定虚拟环境中有一些代码 运行 并且包含一些 C++ 代码。此代码核心转储,我想使用 lldb 对其进行调试。

不过,我明白了

; lldb a.out -c core.17915
Core file '/path/core.17915' (x86_64) was loaded.
Process 0 stopped
* thread #1: tid = 0, 0x0000000000559689 

[...] ← lots of irrelevant data for this question.

(lldb) frame variable
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named lldb.embedded_interpreter
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'run_one_line' is not defined

zsh: segmentation fault (core dumped)  lldb a.out -c core.17915

我可以在虚拟环境外导入 lldb 运行ning,但不能在虚拟环境中导入。我不希望将所有系统模块都添加到虚拟环境中,因为这样一开始就破坏了拥有虚拟环境的意义。

如何在我的虚拟环境中加载 lldb 模块?

问题源于这样一个事实,即虚拟环境默认情况下不会复制系统范围内安装的模块。这就是虚拟环境的重点。但是,在开发环境中,需要其中一些模块。因此,在 tox.ini 中,我调用了一个执行 post 设置工作的脚本(通过 commands)。在那个脚本中,我有

lib_python_path="/usr/lib64/python2.7"
dst="$VIRTUAL_ENV/lib/python2.7/site-packages"
…
# Copy lldb, iff it exists.
if [ -d "${lib_python_path}/site-packages/lldb" ]
then
    ln -f -s ${lib_python_path}/site-packages/lldb ${dst}
fi

这似乎可以解决问题。

我怀疑 "lots of irrelevant data for this question" 中的内容可能相关。 ;)

你能编译一个像

这样的简单程序吗
$ echo "int main () { }" > /tmp/a.c
$ clang -g -o /tmp/a.out /tmp/a.c
$ lldb -x /tmp/a.out
(lldb) br s -n main
(lldb) r
(lldb) fr v

(或 gcc,随便)。那样有用吗?如果这不起作用,那么您安装 lldb 的方式有些奇怪。如果确实有效,请找出这两个示例之间的不同之处。