cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Add an option to include debug information in the Python executable and shared libraries in MacOS

Open pablogsal opened this issue 2 years ago • 4 comments

Because MacOS likes to do things differently, the DWARF debugging information is not included by default in the final executables and shared libraries. Instead, MacOS has a separate linker dsymutil that can link this information in the final binary. Because by default nobody is doing this, all the python installations in MacOS have no debug information at all making debuggers like lldb almost useless.

To solve this problem, add a new --with-dsymutil configure option that ensures that we package the debug information inside. In my M1 macos this makes the Python executable 0.2M bigger.

We should maybe discuss if we want to activate this by default.

pablogsal avatar Aug 14 '22 01:08 pablogsal

An lldb trace without --with-dsymutil:

...
    frame #18: 0x00000001001ab26c python3.12`Py_RunMain + 2196
    frame #19: 0x00000001001ab4b4 python3.12`pymain_main + 324
    frame #20: 0x00000001001ab554 python3.12`Py_BytesMain + 40
    frame #21: 0x000000010056d08c dyld`start + 520

and --with-dsymutil:

...
    frame #86: 0x00000001001aaefc python.exe`Py_RunMain [inlined] pymain_run_python(exitcode=0x000000016fdfe58c) at main.c:0 [opt]
    frame #87: 0x00000001001aada4 python.exe`Py_RunMain at main.c:689:5 [opt]
    frame #88: 0x00000001001ab4d4 python.exe`pymain_main(args=0x000000016fdfe8f0) at main.c:719:12 [opt]
    frame #89: 0x00000001001ab574 python.exe`Py_BytesMain(argc=<unavailable>, argv=<unavailable>) at main.c:743:12 [opt]
    frame #90: 0x000000010056d08c dyld`start + 520

(Also, inspecting variables, frames, and source works, which doesn't without debug information)

pablogsal avatar Aug 14 '22 01:08 pablogsal

@ronaldoussoren

ned-deily avatar Aug 14 '22 01:08 ned-deily

See also: https://github.com/conda-forge/python-feedstock/issues/354

pablogsal avatar Aug 14 '22 01:08 pablogsal

I like this. Personally I'd prefer to have this enabled at least for the installer builds as that makes developing C extensions using the installer on python.org more convenient.

ronaldoussoren avatar Aug 15 '22 06:08 ronaldoussoren