Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: debugging with gdb (on OSX)

There are quite a few tutorials on debugging with gdb for Python. Just to name a few among the best:

  • https://wiki.python.org/moin/DebuggingWithGdb
  • https://stripe.com/blog/exploring-python-using-gdb
  • http://scipy-lectures.github.io/advanced/debugging/#debugging-segmentation-faults-using-gdb

However all of them are targeted for the Linux OS. Is it feasible to install all the extension packages required on OSX ?

like image 846
thikonom Avatar asked Sep 24 '13 10:09

thikonom


1 Answers

You need to build gdb. Per this answer, you need to set CFLAGS=-Wno-string-plus-int before building (at least, for MacOS 10.9 and gdb 7.6.1).

You have to codesign gdb before you can use it.

Then you need get a 'real' executable out of the MacOS fat binary so gdb can read it:

lipo -thin x86_64 -output python-x86_64 /usr/bin/python

Then you can happily:

gdb --args /path/to/python-x86_64 myPythonScript.py arg1 arg2

Alternatively, you can use lldb.

like image 87
Paul Price Avatar answered Sep 29 '22 15:09

Paul Price