我最近一直在使用pybind11,现在我已经掌握了它的诀窍,我对它感到非常兴奋。这是一件很棒的作品。执行pybind11的工具难题的最后一部分是调试部分。我已经使用下面的指南让命令行调试和lldb一起工作:
我花了一些时间尝试使用Visual代码进行调试,但效果有限。第一个问题是,为了设置附加配置,需要指定python可执行文件(而不是进程id)。我不知道如果您有多个active python进程,这是如何工作的,这种情况经常发生。
抛开这一点,我设置了一个启动配置来指向ipython可执行文件,这是最方便使用的东西。当我尝试开始调试时,我得到以下信息:

有人能解释一下吗?
如果我将可执行文件更改为普通Python,则可以在Debug控制台中得到以下内容:
Could not initialize Python interpreter - only native expressions will be available.
Launching: /Users/andy/anaconda3/envs/SciPy37/bin/python但是,如果转到终端窗口,我可以成功地输入Python表达式,并触发代码中设置的断点。万岁!但还有一个问题。当我的一个扩展需要加载另一个dylib时,它就找不到它。
>>> import block_test
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/andy/Dropbox (Personal)/Developer/AudioDev/GenericDSP/Common/SciPy/BlockTest/build/block_test.cpython-37m-darwin.so, 2): Symbol not found: _vDSP_vsmul
Referenced from: /Users/andy/Dropbox (Personal)/Developer/AudioDev/GenericDSP/Common/SciPy/BlockTest/build/block_test.cpython-37m-darwin.so
Expected in: flat namespace
in /Users/andy/Dropbox (Personal)/Developer/AudioDev/GenericDSP/Common/SciPy/BlockTest/build/block_test.cpython-37m-darwin.so这就说明了because_vDSP_vsmul是Apple加速库的一部分。但我不明白的是,当我使用本文开头提到的命令行调试技术时,我没有这个问题。显然,这与如何发现dylibs有关,但为什么这与命令行的情况不同呢?
在这些问题上提供任何帮助都是很好的。让这些调试工具在Visual代码中运行是Python和C++之间绝对惊人的互操作性的缺失之处
发布于 2020-05-26 01:33:16
我想出了如何将进程调试附加到Visual代码与iPython和上。launch.json中的以下代码可以工作:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "path_to/bin/python",
"args": [],
"cwd": "${workspaceFolder}/build"
},
{
"name": "Debug Attach",
"type": "lldb",
"request": "attach",
"program": "path_to/bin/python",
"processId": "${command:pickProcess}",
"MIMode": "gdb"
},
]
}首先,在尝试开始调试之前,在终端窗口中启动IPython,以便您可以附加一个进程。
最初,我在VSC上遇到了问题,抱怨在json文件中没有一个“程序”条目,这在附加到进程时似乎无关紧要。事实上,它可能是完全不相关的,但是你必须添加它才能让事情开始工作。我还没有尝试为程序参数添加一个虚假的条目,看看这个值是否重要。
另一个细节--有时VSC中的断点似乎没有启用,创建它们时会得到一个未填充的圆圈,而不是一个红色的点。但似乎你无论如何都会撞到断点。但是,根据我以前的经验,在附加到过程之后,最好在测试的iPython中导入包,以获得最佳的结果。
发布于 2020-09-15 18:55:35
我无意中发现了这一点,因此我发布了如何将VS代码配置为能够进入调试Python脚本时加载的共享库(.so)?,而不必附加到已经运行的调试器上,而是能够从VSCode内部启动gdb:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch 1123",
"type": "cppdbg",
"request": "launch",
"program": "/usr/bin/python3",
"args": ["${file}"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}通过这个launch.json设置,我能够逐步完成设置断点的C++代码,并调试C++代码。但是,正如前面的SO注释中提到的那样,我不确定在调试会话期间是否存在在python和C/C++代码之间流动的方法。如果试图在python文件上放置断点,我也会“在创建它们时得到一个未填充的圆圈,而不是一个红点”。
发布于 2020-11-03 14:59:54
我在使用LLDB的macOS 10.14.5中实现这一点有问题。对我起作用的是为VS代码安装"vadimcn.vscode-lldb“扩展名,配置如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "attach",
"name": "Attach pid",
"pid": "${command:pickProcess}", // use ${command:pickProcess} to pick other users' processes,
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"stopOnEntry": true,
"env": {
"PYTHONPATH": "${workspaceFolder}/build"
}
},
{
"type": "lldb",
"request": "launch",
"name": "LLDB Python",
"program": "/usr/local/bin/python3",
"args": [
"${file}"
],
"cwd": "${workspaceFolder}",
"stopOnEntry": false,
"env": {
"PYTHONPATH": "${workspaceFolder}/build"
},
},
]
}要么用lldb (LLDB Python)启动python,要么我首先启动python调试会话(Python: Current File),然后我可以将它附加到(Attach pid)。第二个选项的好处是能够在python和C++中设置断点。
https://stackoverflow.com/questions/61490100
复制相似问题