一种新的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)


9bFWZRy1  2015-08-08 07:40:39 From 188.143.234.155

Whoever wrote this, you know how to make a good artelci.


EffereeJego  2020-04-20 22:27:02 From 127.0.0.1

play online casino big fish casino free casino slot games


EffereeJego  2020-04-25 12:42:15 From 127.0.0.1

slots free http://onlinecasinogamespcx.com/ - casino real money online casino bonus world class casino slots online casino games


EstillaspiltCow  2020-04-26 02:19:16 From 127.0.0.1

slots for real money online casino slots world class casino slots slot games http://onlinecasinosw.com/ - vegas casino slots


EstillaspiltCow  2020-04-26 23:06:13 From 127.0.0.1

free slots games free slots games online gambling


EstillaspiltCow  2020-04-27 20:00:43 From 127.0.0.1

http://onlinecasinosw.com/ online casino bonus http://onlinecasinosw.com/ - slots games free vegas slots online


EffereeJego  2020-05-06 11:35:09 From 127.0.0.1

casino play slots free play casino free casino games online


EstillaspiltCow  2020-05-09 06:16:41 From 127.0.0.1

online casino games http://casinorealmoneyfdr.com/ - free slots online slot games real casino slots


EstillaspiltCow  2020-05-16 03:55:19 From 127.0.0.1

cbd pure http://buycbdoil11.com/ - hemp oil hemp oil medterra cbd


EstillaspiltCow  2020-05-17 07:01:47 From 127.0.0.1

hemp cbd http://buycbdoil11.com/ - cbd oil cbd capsules buy hemp oil cbd oil for dogs