[Python-Dev] Mixed Python/C debugging

26 views
Skip to first unread message

Skip Montanaro

unread,
Dec 1, 2019, 12:00:08 PM12/1/19
to python-dev Dev
Having tried comp.lang.python with no response, I turn here...

After at least ten years away from Python's run-time interpreter &
byte code compiler, I'm getting set to familiarize myself with that
again. This will, I think, entail debugging a mixed Python/C
environment. I'm an Emacs user and am aware that GDB since 7.0 has
support for debugging at the Python code level. Is Emacs+GDB my best
bet? Are there any Python IDEs which support C-level breakpoints and
debugging?

Thanks,

Skip
_______________________________________________
Python-Dev mailing list -- pytho...@python.org
To unsubscribe send an email to python-d...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/pytho...@python.org/message/L2KBZM64MYPXIITN4UU3X6L4PZS2YRTB/
Code of Conduct: http://python.org/psf/codeofconduct/

Dino Viehland

unread,
Dec 1, 2019, 9:37:51 PM12/1/19
to Skip Montanaro, python-dev
Python Tools for Visual Studio has supported mixed mode debugging for a while... I'm not sure if that support would have ever ended up in VS Code Python extension so it might be a windows only solution which might not help you much. 

Wes Turner

unread,
Dec 1, 2019, 11:53:27 PM12/1/19
to Skip Montanaro, python-dev Dev
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/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?

Fabio Zadrozny

unread,
Dec 2, 2019, 8:32:25 AM12/2/19
to Skip Montanaro, python-dev Dev
Hi Skip,

I just wanted to note that what I usually do in this case is having 2 debuggers attached.

i.e.: start one any way you want and then do an attach to from the other debugger -- in my case as I'm usually on the Python side I usually start the Python debugger and then do an attach to from the C++ IDE, but you can probably do it the other way around too :)

Sasha Kacanski

unread,
Dec 2, 2019, 10:54:14 AM12/2/19
to Fabio Zadrozny, Skip Montanaro, python-dev Dev
Same here, I do Pycharm and it is possible to add clion plugin and go through C code ...



--
Aleksandar Kacanski

Skip Montanaro

unread,
Dec 2, 2019, 11:02:59 AM12/2/19
to python-dev Dev
Thanks for the responses. I know there are multiple tools out there (to wit, Wes's response), but I'm really after what people actually use and find works. I apologize that wasn't clear. I did neglect to mention that my environment is Linux (specifically Ubuntu 18.04), so Windows-based solutions aren't likely to be workable for me.

For the time being, I've been working through one or two of the docs/tutorials about the parsing/compiler internals which focus on the C side, so gdb with curses display enabled (Ctrl-X a) and built-in PyObject support has been sufficient. I will eventually need mixed language debugging though. And, as an Emacs user, how this might play in that sandbox is of interest. 

Skip

Wes Turner

unread,
Apr 26, 2023, 7:55:07 AM4/26/23
to Skip Montanaro, python-dev Dev
Reply all
Reply to author
Forward
0 new messages