Python3 w/ debug symbols

Hi,

Is there any way to tweak the python.rb formula to build a python interpreter with debug symbols - so that a python VM crash can be analyzed/debugged?

Thanks.

You could copy it over to a personal tap (see docs.brew.sh for info) and adjust the parameters to use the debug version.

Hi Sean,

Yes, no problem with that, sorry I’ve not described my actual issue.
Creating a dedicated tap and tweak the formula is ok.

However, I’m unable to find what commands or arguments to add or remove to obtain a Python interpreter with debug symbols (on macOS).

There are two distinct issues:

  • whereas the formula already uses -g - which should add DWARF info into the objects and the executable files, the resulting objects/executables contains no debug info. I think it is somewhat related to the way macOS handles debug info, but I’ve been unable to find a working solution,

  • --with-pydebug produces an interpreter with missing symbols, which makes for example Python dependencies based on SWIG to fail, e.g.

    Symbol not found: _PyModule_Create2
    

Any hints are warmly welcomed.

This answer to me suggests that there are some parts that also need to be recompiled. I suspect the python developers would be able to be more help here though.

I think it boils down to the use of framework: when python is build without --enable-framework, lldb has not issue located the debug symbols. However, when --enable-framework is used, lldb cannot find them.

There may be an extra step to generate, keep and/or store debug symbols along with the Python framework, but I do not get what to do for now…

Ok, Homebrew removes and replaces optimization flags, as well as -g, no wonder why I cannot get the debug symbols.

I’d love to find some docs about those design choices and how to alter them when needed.

The only, ugly solution I found up to now:

It would be nice to find a way to disable this behaviour through an option. Being able to build a formula while being unable to debug the code is quite unexpected.