一种新的python局部调试手法

Comments(26)


Posted on 2014-01-28 12:47:57 python


我们都知道,python里面可以用pdb来调试代码。但是pdb往往不大好用。有时候调试代码往往在多重条件里面,直接用pdb需要下条件断点,设定复杂的条件。

一个简单的办法就是这么干。

__import__('pdb').set_trace()

但是有的时候,连这个出现的条件都不满足。例如,代码必须在一个受限环境中运行,很难拿到console,或者其他林林总总的毛病。这时候,我们还有一招秘技。

import pdb, socket
s = socket.socket()
s.connect(('127.0.0.1', 8888))
f = s.makefile()
pdb.Pdb(stdin=f, stdout=f).set_trace()

在连接到的目标端口上,提前用nc做好监听,就可以在触发断点的时候直接连接上来调试。

前一篇: golang: 类型转换和类型断言 后一篇: GDB调试Go程序

Captcha:
验证码

Email:

Content: (Support Markdown Syntax)


WilliamShato  2022-10-30 16:59:00 From 127.0.0.1

свадьба дочери видео. виагра дешево спб danalite.ru ебётся с лошадью онлайн видео онлайн видео


JosephDew  2022-11-05 19:58:29 From 127.0.0.1

online colleges north carolina auto insurance bakersfield ca point of sale software for mac


FelipePar  2022-11-10 20:07:04 From 127.0.0.1

criminal defense houston https://uhod-za-kozhej-posle-leta.blogspot.com church newsletter software


Eugenepoito  2022-11-14 00:41:33 From 127.0.0.1

марс картинки заказать попперс с доставкой смотреть хип-хоп батлы русских реперов


APPALPFAP  2022-12-10 17:43:08 From 127.0.0.1

FES was produced and administered to the patient as described earlier 14, 28 stromectol dosis They also address the benefits of exercise pages 27 29


JalsJoill  2023-02-18 20:25:18 From 127.0.0.1

Hence, naturally occurring antioxidants such as flavonoids have been viewed as promising chemotherapeutic drugs for the management of cancer without causing damage to normal cells 12 propecia success rate