据我所知,pdb无法识别源代码何时在"运行"之间发生了变化.也就是说,如果我正在调试,注意一个错误,修复该错误,并在pdb中重新运行程序(即不退出pdb),pdb将不会重新编译代码.即使pdb列出了新的源代码,我仍然会调试旧版本的代码.
那么,pdb是否在源更改时不更新已编译的代码?如果没有,有没有办法让它这样做?我希望能够留在单个pdb会话中以保持我的断点等.
FWIW,gdb会注意到它正在调试的程序在它下面发生变化,尽管只是重新启动该程序.这是我试图在pdb中复制的行为.
有没有人知道有一个让iPython作为解释器的python IDE?
使用标准解释器只会让我疯狂,因为我刚刚喜欢使用iPython及其提供的所有功能.说实话,我宁愿使用简单的文本编辑器+ ipython而不是IDE编写代码,但我喜欢能够通过点击鼠标等来设置断点,所以我想将两者结合起来.
对不起,如果有什么东西,这是常识.您可以提供的任何信息/提示非常感谢.谢谢!
可以在IPython+中设置断点,pdb如下所示:
run -d -b 150 file1.py
Run Code Online (Sandbox Code Playgroud)
这将打破第file1.py150行的执行.现在,如何在被调用的文件中设置断点file1.py?类似于以下内容:
run -d -b file2.py:106 file1.py
Run Code Online (Sandbox Code Playgroud)
在哪里file2.py导入和调用内部file1.py.
非常感谢.
$ ./runtests.py -v tests/managers/test_customer.py:CustomerManagerTest.test_register_without_subscription --ipdb
...
test_register_without_subscription (tests.managers.test_customer.CustomerManagerTest) ...
- TRACEBACK --------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/unittest/case.py", line 331, in run
testMethod()
File "*****/tests/managers/test_customer.py", line 198, in test_register_without_subscription
1/0
ZeroDivisionError: integer division or modulo by zero
--------------------------------------------------------------------------------
> *****/tests/managers/test_customer.py(198)test_register_without_subscription()
197 def test_register_without_subscription(self):
--> 198 1/0
199 ...
ipdb> import sys
ipdb> sys.exc_info()
(<type 'exceptions.AttributeError'>, AttributeError("Pdb instance has no attribute 'do_sys'",), <traceback object at 0x47eb908>)
ipdb>
Run Code Online (Sandbox Code Playgroud)
我找不到任何ipdb help显示当前异常的命令.
做import sys; print sys.exc_info()不起作用.
目前我这样做:
try:
do_something_that_raises_an_exception() …Run Code Online (Sandbox Code Playgroud) 我刚开始使用漂亮的PyCharm社区版IDE,并且不能做一个简单的事情,这是我常用的Python工作流程的一部分.
我已经启动了一个ipython控制台,我可以导入我的模块并以交互方式运行命令.在PyCharm中,当我执行一个函数调用时,它就像在一个单独的进程中运行一样执行.即使在执行完成之前,也可以使用控制台提示符.在PyCharm外部的shell中运行ipython,当发生异常时,我可以运行pdb的post mortem功能并调查问题:
import pdb;pdb.pm()
Run Code Online (Sandbox Code Playgroud)
我想在PyCharm中做同样的事情:当我在交互式调查问题时发生异常时,开始事后调试.
我试图从procmon解码以下调用堆栈行:
29 System.Management.Automation.ni.dll System.Management.Automation.ni.dll + 0x897a0a 0x7fee2ae7a0a C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a86698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,其中有一个NGEN-ed程序集:System.Management.Automation.ni.dll.我使用ngen createpdb为它创建了一个pdb文件:
PS> ngen createpdb c:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a86698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll c:\symbols\ngen
Successfully generated PDB for native assembly 'c:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a8698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll'.
PDB generated in directory c:\symbols\ngen\System.Management.Automation.ni.pdb a86698074f28597f1fc5ceabfed6fed61\
Run Code Online (Sandbox Code Playgroud)
_NT_SYMBOL_PATH变量中的符号路径是:
SRV*C:\symbols\ngen*;SRV*C:\symbols\dbg*http://referencesource.microsoft.com/symbols;SRV*C:\symbols\dbg*http://msdl.microsoft
Run Code Online (Sandbox Code Playgroud)
.COM /下载/符号
但我仍然可以看到没有为程序集加载新生成的符号文件:
PS a86698074f28597f1fc5ceabfed6fed6> dbh -n .\System.Management.Automation.ni.dll
verbose mode on.
DBGHELP: No header for .\System.Management.Automation.ni.dll. Searching for image on disk
DBGHELP: C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Manaa57fc8cc#\a86698074f28597f1fc5ceabfed6fed6\System.Management.Automation.ni.dll - OK
SYMSRV: C:\symbols\ngen\System.Management.Automation.pdb\6B8B8F14D0564CB893B6E84B43CAE67B1\System.Management.Automation.pdb - file not found
SYMSRV: C:\tools\diag\Debugging Tools for Windows\x64\sym\System.Management.Automation.pdb\6B8B8F14D0564CB893B6E84B43CAE67B1\System.Management.Automation.pdb - file not found
SYMSRV: C:\symbols\ngen\System.Management.Automation.pdb\6B8B8F14D0564CB893B6E84B43CAE67B1\System.Management.Automation.pdb not found
SYMSRV: …Run Code Online (Sandbox Code Playgroud) 在 pdb 模式下,我经常想进入一个函数。这是一个说明我可能会做的事情的情况。鉴于代码:
def f(x):
print('doing important stuff..')
result = g(x) + 2
return result
def g(x):
print('some cool stuff going on here, as well')
0 / 0 # oops! a bug
return x + 5
Run Code Online (Sandbox Code Playgroud)
现在,假设我在print('doing important stuff...')和之间设置了一个断点result = g(x) + 2。所以现在,f(x)看起来像这样:
def f(x):
print('doing important stuff..')
__import__('pdb').set_trace() # or something similar..
result = g(x) + 2
return result
Run Code Online (Sandbox Code Playgroud)
然后,我调用该函数f(x)用x=5,期待得到一个结果12。当被调用时,我最终在f. 命中n会给我错误(在这种情况下是 ZeroDivisionError)。现在,我想以g(x) …
我正在寻找用leaderpMacvim中的键击插入一行代码的方法
我想插入以下代码行:
import pdb; pdb.set_trace()
Run Code Online (Sandbox Code Playgroud)
可能不是python土地中前所未闻的代码行
我正在通过PDB(Python调试器)运行一些python代码.当我设置并随后点击断点时,我可以使用以下方法检查局部变量:
(Pdb) locals()
Run Code Online (Sandbox Code Playgroud)
这打印出一个很好的名称,在我暂停的当前范围内的局部变量的值对.完善!
我还可以使用PDB where命令查看堆栈跟踪,结果如下所示:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
<string>(1)<module>()
.../main.py(116)<module>()
-> run()
.../main.py(104)run()
-> res = quicksort(res)
> .../main.py(68)quicksort()
-> if len(v) <= 1:
Run Code Online (Sandbox Code Playgroud)
在这个示例输出中,我暂停了quicksort()函数调用的run()函数.
到现在为止还挺好.
如果我可以quicksort()通过调用来检查函数的局部变量,locals()我怎样才能类似地检查run()函数的局部变量?
换句话说,我如何检查嵌套在调用堆栈中的函数的局部变量?
重要说明:我不要想continue或step成run()检查局部变量.我想检查(从我当前的,暂停的角度来看)run()当前嵌套在调用堆栈中的堆栈框架中的局部变量.