问题描述
假设我们有以下超级简单的 Python 脚本:
Let's say we have the following mega-simple Python script:
...然后说,我想通过在 a=10
行放置一个断点来调试此脚本,然后单步执行该脚本.
... and say, I'd like to debug this script by placing a breakpoint at line a=10
, and then stepping through the script.
现在,我想为此使用 gdb
,因为我想调试可能作为共享对象(.so) 库 - 因此,理想情况下,我会在 Python 代码行上放置一个断点,然后进入"共享对象的 C 部分...(请注意,DebuggingWithGdb - PythonInfo Wiki 并没有明确说明这是可能的)
Now, I'd like to use gdb
for this, because I'd like to debug Python bindings that may come as a part of a shared object (.so
) library - hence, I'd ideally place a breakpoint on a Python code line, and then "step into" the C part of the shared object... (Note that DebuggingWithGdb - PythonInfo Wiki doesn't really explicitly state that this is possible)
问题是:gdb
本身无法真正识别断点,放置在 Python 脚本行:
The problem is: gdb
on its own cannot really recognize breakpoints, placed on a Python script line:
...虽然整个 Python 脚本确实在 gdb
中运行,但根本无法到达断点.
... and while the entire Python script does run within gdb
, the breakpoint is simply never reached.
所以 - 是我想要做的,完全可能使用 gdb
;如果没有,对于类似的东西,我还有什么其他选择?
So - is what I want to do, at all possible with gdb
; and if not, what other alternatives would I have for something similar?
推荐答案
非常有趣的问题.这是我的方法.创建signal_test.py
:
Very interesting question. Here's my approach. Create signal_test.py
:
然后就可以在gdb下运行了:
Then you can run it under gdb:
当你运行它时,它会一直运行到你调用 kill()
:
And when you run it, it will go until you reach the call to kill()
:
然后您可以查看回溯:
如果继续,程序的其余部分将正常运行.
If you continue on, the rest of the program will run normally.
相反,您可以在适当的框架中单步执行,直到找到您感兴趣的语句.您可能需要运行一个调试 Python 以使其更有意义.
You can, instead, step through in the appropriate frame until you reach the statement you're interested in. You're probably going to want to run a debugging Python for this to make much sense.
这篇关于调试:使用 gdb 单步执行 Python 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!