简体   繁体   中英

pydev debugger usage as a python module

pydev debugger is a python debugger used by pydev and pycharm . It seems much more powerful than pdb . Its code is available ( https://github.com/fabioz/PyDev.Debugger ), and it is easy to install through pip. The package name is pydevd .

However, there is no information on how to use it from python code (outside of pydev or pycharm IDE). The documentation is completely lacking.

Does anyone know how to use it? I would like to do something like that:

import pydevd

pdd = pydevd.debug("python myscript.py")

pdd.set_break_point(file="myscript.py", lineno=12)
pdd.start()
pdd.read_variable("a")
pdd.continue()

well, I agree that the docs are lacking, but the idea is mostly that you'd use it from within the IDE, not programmatically.

The only public API you should use programmaticallyis pydevd.settrace() , which is the API which will setup a breakpoint at the place it's put programmatically (meaning the debugger will stop at that line -- the same effect of having pdb.set_trace() -- and that same API will also connect to the frontend for remote debugging if it's still not connected (ie: http://www.pydev.org/manual_adv_remote_debugger.html -- code: https://github.com/fabioz/PyDev.Debugger/blob/a4a58179dab9f9fb93559066f0ef22ac59c59e04/pydevd.py#L1065 ).

Now, currently the only frontends are PyDev and PyCharm, there's no frontend that gives you a command line... the whole communication happens by connecting to a thread in the debugger backend through a socket (again, there are no real docs, but the code should be easy to read on what the socket accepts and the protocol is pretty simple: https://github.com/fabioz/PyDev.Debugger/blob/a4a58179dab9f9fb93559066f0ef22ac59c59e04/_pydevd_bundle/pydevd_process_net_command.py ).

There are unit-tests in pure-python code which exercise that (ie: connect to a debugger, and issue commands through sockets -- https://github.com/fabioz/PyDev.Debugger/blob/a4a58179dab9f9fb93559066f0ef22ac59c59e04/tests_python/debugger_unittest.py ), so, it shouldn't be that hard to actually do a command-line frontend to it -- it's just that no one had interest on it until now, but if someone would like to contribute a command-line frontend to PyDev.Debugger, it'd be welcome ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM