jupyterlab / debugger

A visual debugger for Jupyter notebooks, consoles, and source files
BSD 3-Clause "New" or "Revised" License
562 stars 43 forks source link

ENH: Mixed Python/C debugging (GDB,) #284

Open westurner opened 4 years ago

westurner commented 4 years ago

Users can do [mixed mode] debugging with GDB (and/or other debuggers) and log the session in a notebook; in particular in order to teach.

westurner commented 4 years ago

This is spawned from #274 "Possibility to support ipykernel" (re: implementing support in ipykernel that may already partially exist in the spyder kernel (which is derived from ipykernel))

Your question is specifically about IDEs with support for mixed-mode debugging (with gdb), so I went looking for an answer:

https://wiki.python.org/moin/DebuggingWithGdb (which is not responsive and almost unreadable on a mobile device) links to https://fedoraproject.org/wiki/Features/EasierPythonDebugging , which mentions the py-list, py-up and py-down, py-bt, py-print, and py-locals GDB commands that are also described in https://devguide.python.org/gdb/

https://wiki.python.org/moin/PythonDebuggingTools Ctrl-F "gdb" mentions: DDD, pyclewn (vim), trepan3k (which is gdb-like and supports breaking at c-line and also handles bytecode disassembly)

Apparently, GHIDRA does not have a debugger but there is a plugin for following along with gdb in ghidra called https://github.com/Comsecuris/gdbghidra , which may or may not be useful.

https://github.com/Comsecuris/gdbghidra/blob/master/data/gdb_ghidra_bridge_client.py (zero dependencies)

https://github.com/Mistobaan/pyclewn hasn't been updated in years, but may have useful bits for implementing mixed-mode debugging in other non-vim IDEs.

https://reverseengineering.stackexchange.com/questions/1392/decent-gui-for-gdb lists a number of GUIs for GDB; including voltronnn:

There's Voltron, which is an extensible Python debugger UI that supports LLDB, GDB, VDB, and WinDbg/CDB (via PyKD) and runs on macOS, Linux and Windows. For the first three it supports x86, x86_64, and arm with even arm64 support for lldb while adding even powerpc support for gdb. https://github.com/snare/voltron

https://developers.redhat.com/blog/2017/11/10/gdb-python-api/ describes the GDB Python API.

https://pythonextensionpatterns.readthedocs.io/en/latest/debugging/debug_in_ide.html#writing-a-c-function-to-call-any-python-unit-test may be helpful.

Does DDD support mixed-mode debugging? https://www.gnu.org/software/ddd/manual/html_mono/ddd.html

Essentially, for IDE support, AFAIU, the basic functionality is:

  • set breakpoints: b c-file.c:123
  • step through them while seeking-to and highlighting the current breakpoint
  • provide one or more panes for executing GDB commands within the current or other frames

The GDB Python API docs: https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html

The devguide gdb page may be the place to list IDEs with support for mixed-mode debugging of Python and C/C++/Cython specifically with gdb?

Sorry to just dump this here (this probably isn't the correct issue); but I put all that together the other day and thought it may be useful for implementing (mixed mode) debugging. "Mixed Python/C debugging" https://mail.python.org/archives/list/python-dev@python.org/thread/L2KBZM64MYPXIITN4UU3X6L4PZS2YRTB/#Z3S2RAXRIHAWT6JEOXEBPPBTPUTMDZI7

Other mentions in the thread include Emacs + GDM, PyCharm + clion, and routinely having 2+ debuggers attached. I haven't had a chance to look. Does the current debugger protocol handle multiple concurrent debugging flows?

(cc'd here (for the last time))

westurner commented 4 years ago

https://github.com/jupyter/jupyter_client/issues/446 "Supporting the Debug Adapter Protocol" (DAP)