[Python-Dev] What's the best way to debug python3 source code?

"Martin v. Löwis" martin at v.loewis.de
Mon Jun 18 08:16:07 CEST 2012


> What's the best way to debug python3 source code?
> To fix a bug i need to debug source code(C files).
> I use gdb to debug.

If the bug is presumably in C, then using gdb works fine for me.

> But how can i get the exact file/point to fix the bug?

As usual: set breakpoints and watch points. In some cases, also augment
the C code to print out trace messages. Use the excellent python-gdb.py,
which requires a recent gdb version.

> How can i know quickly where the bug is?

The fastest way is probably Linus Torvald's approach: just look at the
code for 20 seconds, and see the bug without running the code. YMMV.

> How can i run python>>> from gdb and giving input there how can i test
> and debug to fix a bug?

If you start Python in gdb, then do "r", it will automatically start
interactive mode.

> Someone please explain/elaborate the process you use/do as usual with
> examples.

I wasn't quite sure whether your question is off-topic for python-dev:
this last request definitely is. python-dev is not a place to get free
education. Instead, it is a place where *you* contribute to Python. If
you work on a specific bug and have a specific question about it, feel
free to ask. However, "teach me how to debug" is best asked on other
mailing lists.

Regards,
Martin



More information about the Python-Dev mailing list