debugger icon indicating copy to clipboard operation
debugger copied to clipboard

ENH: Mixed Python/C debugging (GDB,)

Open westurner opened this issue 6 years ago • 2 comments

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.

  • Multiple attached debuggers
  • Multiple sidecars? This list is from voltron:
    • Registers
    • Disassembly
    • Stack
    • Memory
    • Breakpoints
    • Backtrace
  • Log to the notebook

westurner avatar Dec 13 '19 23:12 westurner

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/[email protected]/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 avatar Dec 13 '19 23:12 westurner

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

  • What will it take to connect GDB to DAP? With multiple attached debuggers?
    • Which (Python?) to GDB bridge would be easiest to connect?
      • ptvsd uses gdb for Python-only debugging, AFAIU?
        • [ ] ptvsd will probably only ever support Python? If so, ptvsd will not solve for mixed Python/C debugging (with GDB,)
        • presumably the jupyter/debugger plan is to first work with ptvsd and then support other DAP-compatible tools?
        • [ ] ptvsd does not yet support ARM https://github.com/microsoft/ptvsd/issues/1674
        • https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/ lists a number of DAP debug adapters for various languages and LLDB
  • Not that this is necessary list of features, but what can DAP handle? (Please advise regarding this list)
    • [ ] Registers
    • [ ] Disassembly
    • [ ] Stack
    • [ ] Memory
    • [x] Breakpoints
    • [x] Backtrace
    • [x] Variables

westurner avatar Dec 14 '19 01:12 westurner