<div><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">I'm building lldb with python3 support by using the framework that is shipped with the latest versions of Xcode.<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">I'm able to build and run lldb just fine but if I try to use the lldb python module on a python binary that is not the one from Xcode it segfaults when creating the module. I then tried with the stock lldb from Xcode and found the exact same issue </span><span style="font-size:0.9166666865348816rem;font-family:"Apple Color Emoji"">☹</span><span style="font-size:0.9166666865348816rem">. I don’t think this was a problem before?<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">I'm not sure why this happens and I wasn't able to debug the issue. I've already tried with a binary that has the exact same version of python but still the same problem:<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Works fine with the Xcode binary:<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">$ PYTHONPATH=`lldb -P` /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/bin/python3<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Python 3.7.3 (default, Sep 18 2019, 14:29:06)<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">[Clang 11.0.0 (clang-1100.0.33.8)] on darwin<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Type "help", "copyright", "credits" or "license" for more information.<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">>>> import lldb<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">>>><u></u> <u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Fails with any other:<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">$ PYTHONPATH=`lldb -P` /Users/aadsm/.pyenv/versions/3.7.3/bin/python<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Python 3.7.3 (default, Nov 12 2019, 23:19:54)<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">[Clang 11.0.0 (clang-1100.0.33.8)] on darwin<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Type "help", "copyright", "credits" or "license" for more information.<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">>>> import lldb<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Segmentation fault: 11<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">I attached lldb to see where it was failing and it's right after liblldb is loaded and python is trying to create the module itself, in the PyModule_Create2 function (<a href="https://github.com/python/cpython/blob/master/Objects/moduleobject.c#L173-L179" style="font-size:0.9166666865348816rem" target="_blank">https://github.com/python/cpython/blob/master/Objects/moduleobject.c#L173-L179</a>).<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">The disassembly shows:<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Process 89097 stopped<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    frame #0: 0x000000010f4cae5b Python3`PyModule_Create2 + 27<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Python3`PyModule_Create2:<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">->  0x10f4cae5b <+27>: movq   0x10(%rax), %rdi<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae5f <+31>: callq  0x10f5823b0               ; _PyImport_IsInitialized<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae64 <+36>: testl  %eax, %eax<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae66 <+38>: je     0x10f4cae77               ; <+55><u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Target 0: (Python) stopped.<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">(lldb) dis<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Python3`PyModule_Create2:<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae40 <+0>:  pushq  %rbp<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae41 <+1>:  movq   %rsp, %rbp<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:11pt">    </span><span lang="PT-BR" style="font-size:0.9166666865348816rem">0x10f4cae44 <+4>:  pushq  %r14<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span lang="PT-BR" style="font-size:0.9166666865348816rem">    0x10f4cae46 <+6>:  pushq  %rbx<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span lang="PT-BR" style="font-size:0.9166666865348816rem">    0x10f4cae47 <+7>:  movl   %esi, %r14d<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span lang="PT-BR" style="font-size:11pt">    </span><span style="font-size:0.9166666865348816rem">0x10f4cae4a <+10>: movq   %rdi, %rbx<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae4d <+13>: leaq   0x2226ac(%rip), %rax      ; _PyRuntime<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae54 <+20>: movq   0x5a0(%rax), %rax<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">->  0x10f4cae5b <+27>: movq   0x10(%rax), %rdi<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae5f <+31>: callq  0x10f5823b0               ; _PyImport_IsInitialized<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae64 <+36>: testl  %eax, %eax<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae66 <+38>: je     0x10f4cae77               ; <+55><u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:11pt">    </span><span lang="PT-BR" style="font-size:0.9166666865348816rem">0x10f4cae68 <+40>: movq   %rbx, %rdi<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span lang="PT-BR" style="font-size:0.9166666865348816rem">    0x10f4cae6b <+43>: movl   %r14d, %esi<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span lang="PT-BR" style="font-size:0.9166666865348816rem">    0x10f4cae6e <+46>: popq   %rbx<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span lang="PT-BR" style="font-size:0.9166666865348816rem">    0x10f4cae6f <+47>: popq   %r14<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span lang="PT-BR" style="font-size:11pt">    </span><span style="font-size:0.9166666865348816rem">0x10f4cae71 <+49>: popq   %rbp<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae72 <+50>: jmp    0x10f4cae90               ; _PyModule_CreateInitialized<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae77 <+55>: leaq   0x14f111(%rip), %rdi      ; "Python import machinery not initialized"<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae7e <+62>: callq  0x10f593d40               ; Py_FatalError<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae83 <+67>: nopw   %cs:(%rax,%rax)<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">    0x10f4cae8d <+77>: nopl   (%rax)<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:11pt"><u></u> <u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Not really sure how to debug this besides trying to build my own version of python and see if I can repro (I don't have this issue on linux). I’ve also checked the sys.abiflags and both binaries have the same ones.<u></u><u></u></span></p><p class="MsoNormal" style="font-size:16px;color:rgb(49,49,49);word-spacing:1px"><span style="font-size:0.9166666865348816rem">Has anyone experienced this before or has any pointers to debug it?</span></p></div><div><p class="MsoNormal" style="color:rgb(49,49,49);word-spacing:1px"><span style="font-size:14.666666984558105px">- Afonso</span></p>
</div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Best regards,<br>António Afonso</div></div>