Is it possible to use GDB's reverse debugging with Python? How?

Question:

I am trying to use GDB’s reverse debugging with a Django application. I get it running in GDB, but I can’t make it run backwards.

I stopped my Django app with Ctrl-Z and then entered reverse-next at the gdb prompt, getting the error message “Target multi-thread does not support this command.”

Am I doing it wrong? Isn’t this possible? Both?

Asked By: Daniel Gasull

||

Answers:

That’s an amazingly good question.

My first impulse would be to ensure I was using IPython as my shell for django and see if it’s pdb support would help in this case. Pdb should have a very similar interface to gdb. As I recall, gdb is what’s used to debug C/C++ programs, while django is being executed by a python interpreter. Using Pdb is here:

http://ericholscher.com/blog/2008/aug/31/using-pdb-python-debugger-django-debugging-series-/

Also you might want to try using django-extensions, for access to the werkzeug debugging view.

Answered By: chiggsy

Before you can use GDB for reverse debugging, you must tell it to record your program execution (so it can play it back) via target record command, as documented here.

I am not sure this will help you debug your Django application though — GDB is well suited for debugging “native” code (compiled C/C++), and is not well suited for debugging “interpreted” code (in either forward or reverse direction).

Answered By: Employed Russian

RevDB

https://bitbucket.org/pypy/revdb

https://morepypy.blogspot.co.uk/2016/07/reverse-debugging-for-python.html

This project aims to allow pdb-like reverse debugging, which is likely what you want unless you are debugging the Python interpreter itself.

It is still in early stages as of 2017, and you must build from source.

How to question that does not mention GDB: Is it possible to step backwards in pdb?

Finally, GDB reverse debugging is quite immature, e.g. does not deal with AVX extensions Disable AVX-optimized functions in glibc (LD_HWCAP_MASK, /etc/ld.so.nohwcap) for valgrind & gdb record , so I strongly recommend using rr instead: https://github.com/mozilla/rr (on which RevDB claims to take inspiration from).

Related for JavaScript: How to go backwards while debugging Javascript in Chrome sources debugging?