Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging a segmentation fault in C++ code called from Python

I have a test that runs a python script, which calls into C++ code, where it segfaults and dumps core. I've tried to load the core file in GDB using /usr/bin/python2.6, but this just gives me ?? for all the items in the stack trace. How do I debug this core file?

like image 279
Nathaniel Flath Avatar asked Sep 14 '26 02:09

Nathaniel Flath


1 Answers

You need to compile a version of Python with debugging symbols. You can do this by building Python with ./configure --with-pydebug. Hopefully you will be able to find the error that way.

That will change the behavior of Python internally in some ways. If you don't still get the segfault that way, you might try running ./configure CFLAGS="-O0 -ggdb3" or even just ./configure CFLAGS=-ggdb3.

like image 156
Michael Hoffman Avatar answered Sep 15 '26 17:09

Michael Hoffman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!