8000 Debugging crash in Python 3.6 · Issue #884 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Debugging crash in Python 3.6 #884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Cronan opened this issue Jun 19, 2019 · 18 comments
Closed

Debugging crash in Python 3.6 #884

Cronan opened this issue Jun 19, 2019 · 18 comments

Comments

@Cronan
Copy link
Contributor
Cronan commented Jun 19, 2019

Environment

Details

I'm trying to debug a crash in pythonnet. I've built a debuggable version of .NET core, and can get stack trace etc from lldb.

CORE_ROOT=$HOME/dotnet_debug/ python -c 'import clr'
Segmentation fault (core dumped)
@Cronan
Copy link
Contributor Author
Cronan commented Jun 19, 2019
(lldb) clrstack -f
OS Thread Id: 0x4422 (1)
        Child SP               IP Call Site
00007FFFB92B1378 00007F8AA9F2835F libpython3.6m.so!Py_DecRef + 15
00007FFFB92B1380 00007F8A3CED902D 
00007FFFB92B1390                  [InlinedCallFrame: 00007fffb92b1390] Python.Runtime.dll!Python.Runtime.Runtime.Py_DecRef(IntPtr)
00007FFFB92B1390                  [InlinedCallFrame: 00007fffb92b1390] Python.Runtime.dll!Python.Runtime.Runtime.Py_DecRef(IntPtr)
00007FFFB92B1380 00007F8A3CED902D Python.Runtime.dll!DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr) + 157
00007FFFB92B1430 00007F8A3CED90CC Python.Runtime.dll!Python.Runtime.Runtime.XDecref(IntPtr) + 44 [/users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/runtime/runtime.cs @ 547]
00007FFFB92B1450 00007F8A3CED6BE5 Python.Runtime.dll!Python.Runtime.Runtime.Initialize() + 1861 [/users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/runtime/runtime.cs @ 292]
00007FFFB92B1610 00007F8A3CED5479 Python.Runtime.dll!Python.Runtime.PythonEngine.Initialize(System.Collections.Generic.IEnumerable`1<System.String>, Boolean) + 217 [/users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/runtime/pythonengine.cs @ 167]
00007FFFB92B1850 00007F8A3CED2C6B Python.Runtime.dll!Python.Runtime.PythonEngine.Initialize(Boolean) + 75 [/users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/runtime/pythonengine.cs @ 145]
00007FFFB92B1870 00007F8A3CED25E4 Python.Runtime.dll!Python.Runtime.PythonEngine.InitExt() + 68 [/users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/runtime/pythonengine.cs @ 239]
00007FFFB92B1910 00007F8AB58E354F libcoreclr.so!UMThunkStub + 294 at /coreclr/src/vm/amd64/umthunkstub.S:144
00007FFFB92B19E0 00007F8AB653E044 clr.cpython-36m-x86_64-linux-gnu.so!init + 580 at /users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/coreclr/pynetinit.c:190
00007FFFB92B1A40 00007F8AB653E0E8 clr.cpython-36m-x86_64-linux-gnu.so!PyNet_Init + 120 at /users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/coreclr/pynetinit.c:52
00007FFFB92B1A60 00007F8AB653E156 clr.cpython-36m-x86_64-linux-gnu.so!PyInit_clr + 70 at /users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/coreclr/clrmod.c:47
00007FFFB92B1A60 00007F8AB653E122 clr.cpython-36m-x86_64-linux-gnu.so!PyInit_clr + 18 at /users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/coreclr/clrmod.c:37
00007FFFB92B1A80 00005586BBBC48E5 python!_PyImport_LoadDynamicModuleWithSpec + 389
00007FFFB92B1AD0 00005586BBBC4AE5 python!_imp_create_dynamic + 197
00007FFFB92B1B30 00005586BBAC0A61 python!PyCFunction_Call + 305
00007FFFB92B1B70 00005586BBB74FDB python!_PyEval_EvalFrameDefault + 22043
00007FFFB92B1C90 00005586BBB46A94 python!_PyEval_EvalCodeWithName + 820
00007FFFB92B1D70 00005586BBB47941 python!fast_function + 833
00007FFFB92B1E00 00005586BBB4D755 python!call_function + 341
00007FFFB92B1E50 00005586BBB6FCBA python!_PyEval_EvalFrameDefault + 762
00007FFFB92B1F70 00005586BBB4770B python!fast_function + 267
00007FFFB92B1FB0 00005586BBB4D755 python!call_function + 341
00007FFFB92B2000 00005586BBB6FCBA python!_PyEval_EvalFrameDefault + 762
00007FFFB92B2120 00005586BBB4770B python!fast_function + 267
00007FFFB92B2160 00005586BBB4D755 python!call_function + 341
00007FFFB92B21B0 00005586BBB6FCBA python!_PyEval_EvalFrameDefault + 762
00007FFFB92B22D0 00005586BBB4770B python!fast_function + 267
00007FFFB92B2310 00005586BBB4D755 python!call_function + 341
00007FFFB92B2360 00005586BBB6FCBA python!_PyEval_EvalFrameDefault + 762
00007FFFB92B2480 00005586BBB4770B python!fast_function + 267
00007FFFB92B24C0 00005586BBB4D755 python!call_function + 341
00007FFFB92B2510 00005586BBB6FCBA python!_PyEval_EvalFrameDefault + 762
00007FFFB92B2630 00005586BBB47D7B python!_PyFunction_FastCallDict + 283
00007FFFB92B26C0 00005586BBABDF5F python!_PyObject_FastCallDict + 623
00007FFFB92B2710 00005586BBB02670 python!_PyObject_CallMethodIdObjArgs + 256
00007FFFB92B2850 00005586BBAB4A70 python!PyImport_ImportModuleLevelObject + 832
00007FFFB92B28C0 00005586BBB72033 python!_PyEval_EvalFrameDefault + 9843
00007FFFB92B29E0 00005586BBB48459 python!PyEval_EvalCodeEx + 809
00007FFFB92B2AA0 00005586BBB491EC python!PyEval_EvalCode + 28
00007FFFB92B2AE0 00005586BBBC39A4 python!run_mod + 52
00007FFFB92B2B00 00005586BBBC3A3D python!PyRun_StringFlags + 125
00007FFFB92B2B50 00005586BBBC3A9F python!PyRun_SimpleStringFlags + 63
00007FFFB92B2B70 00005586BBBC789B python!Py_Main + 1083
00007FFFB92B2C80 00005586BBA8F4BE python!main + 238
00007FFFB92B2CD0 00007F8ABD5DE445 libc.so.6!__libc_start_main + 245
00007FFFB92B2D90 00005586BBB76773 python!_start + 41

@Cronan
Copy link
Contributor Author
Cronan commented Jun 19, 2019
(lldb) eestack
---------------------------------------------
Thread   1
TEB information is not available so a stack size of 0xFFFF is assumed
Current frame: libpython3.6m.so!Py_DecRef + 0xf
Child-SP         RetAddr          Caller, Callee
00007FFFB92B1370 00007f8a3ced902d (MethodDesc 00007f8a3d31c6b8 + 0x9d DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr))
00007FFFB92B13B0 00007f8a3ced902d (MethodDesc 00007f8a3d31c6b8 + 0x9d DomainBoundILStubClass.IL_STUB_PInvoke(IntPtr))
00007FFFB92B1420 00007f8a3ced90cc (MethodDesc 00007f8a3d088a48 + 0x2c Python.Runtime.Runtime.XDecref(IntPtr)), calling 00007f8a3ced7520 (stub for Python.Runtime.Runtime.Py_DecRef(IntPtr))
00007FFFB92B1440 00007f8a3ced6be5 (MethodDesc 00007f8a3d088888 + 0x745 Python.Runtime.Runtime.Initialize()), calling (MethodDesc 00007f8a3d088a48 + 0 Python.Runtime.Runtime.XDecref(IntPtr))
00007FFFB92B1600 00007f8a3ced5479 (MethodDesc 00007f8a3b7d6dc0 + 0xd9 Python.Runtime.PythonEngine.Initialize(System.Collections.Generic.IEnumerable`1<System.String>, Boolean)), calling 00007f8a3ced4d80 (stub for Python.Runtime.Runtime.Initialize())
00007FFFB92B1840 00007f8a3ced2c6b (MethodDesc 00007f8a3b7d6d88 + 0x4b Python.Runtime.PythonEngine.Initialize(Boolean)), calling 00007f8a3ced2108 (stub for Python.Runtime.PythonEngine.Initialize(System.Collections.Generic.IEnumerable`1<System.String>, Boolean))
00007FFFB92B1860 00007f8a3ced25e4 (MethodDesc 00007f8a3b7d6df8 + 0x44 Python.Runtime.PythonEngine.InitExt()), calling 00007f8a3ced2100 (stub for Python.Runtime.PythonEngine.Initialize(Boolean))
00007FFFB92B1900 00007f8ab58e354f libcoreclr.so!UMThunkStub + 0x126 [/coreclr/src/vm/amd64/umthunkstub.S:144]
00007FFFB92B19D0 00007f8ab653e044 clr.cpython-36m-x86_64-linux-gnu.so!init + 0x244 [/users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/coreclr/pynetinit.c:190]
00007FFFB92B1A30 00007f8ab653e0e8 clr.cpython-36m-x86_64-linux-gnu.so!PyNet_Init + 0x78 [/users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/coreclr/pynetinit.c:52], calling clr.cpython-36m-x86_64-linux-gnu.so!init
00007FFFB92B1A50 00007f8ab653e156 clr.cpython-36m-x86_64-linux-gnu.so!PyInit_clr + 0x46 [/users/isys/my-user/git/medusa-recipes/pythonnet/2.3.0/ws/src/src/coreclr/clrmod.c:47], calling clr.cpython-36m-x86_64-linux-gnu.so!PyNet_Init
00007FFFB92B1A70 00005586bbbc48e5 python!_PyImport_LoadDynamicModuleWithSpec + 0x185
00007FFFB92B1AC0 00005586bbbc4ae5 python!_imp_create_dynamic + 0xc5, calling python!_PyImport_LoadDynamicModuleWithSpec
00007FFFB92B1B20 00005586bbac0a61 python!PyCFunction_Call + 0x131
00007FFFB92B1B60 00005586bbb74fdb python!_PyEval_EvalFrameDefault + 0x561b, calling python!PyCFunction_Call
00007FFFB92B1BE0 00005586bbab0a20 python!PyDict_GetItem + 0x70
00007FFFB92B1C30 00005586bbaee666 python!PyFrame_New + 0x146, calling python!PyType_IsSubtype
00007FFFB92B1C80 00005586bbb46a94 python!_PyEval_EvalCodeWithName + 0x334, calling python!PyEval_EvalFrameEx
00007FFFB92B1D60 00005586bbb47941 python!fast_function + 0x341, calling python!_PyEval_EvalCodeWithName
00007FFFB92B1DF0 00005586bbb4d755 python!call_function + 0x155, calling python!fast_function
00007FFFB92B1E40 00005586bbb6fcba python!_PyEval_EvalFrameDefault + 0x2fa, calling python!call_function
00007FFFB92B1EC0 00005586bbab0a20 python!PyDict_GetItem + 0x70
00007FFFB92B1F10 00005586bbaee7d8 python!PyFrame_New + 0x2b8, calling libc.so.6!__memset_sse2
00007FFFB92B1F60 00005586bbb4770b python!fast_function + 0x10b, calling python!PyEval_EvalFrameEx
00007FFFB92B1FA0 00005586bbb4d755 python!call_function + 0x155, calling python!fast_function
00007FFFB92B1FF0 00005586bbb6fcba python!_PyEval_EvalFrameDefault + 0x2fa, calling python!call_function
00007FFFB92B2070 00005586bbabb2fc python!_PyObject_GenericGetAttrWithDict + 0x1dc
00007FFFB92B20C0 00005586bbaa75ba python!PyErr_Occurred + 0xa, calling python!_PyThreadState_UncheckedGet
00007FFFB92B2110 00005586bbb4770b python!fast_function + 0x10b, calling python!PyEval_EvalFrameEx
00007FFFB92B2150 00005586bbb4d755 python!call_function + 0x155, calling python!fast_function
00007FFFB92B21A0 00005586bbb6fcba python!_PyEval_EvalFrameDefault + 0x2fa, calling python!call_function
00007FFFB92B2220 00005586bbaeec84 python!PyTuple_New + 0x64, calling libc.so.6!__memset_sse2
00007FFFB92B2270 00005586bbb47941 python!fast_function + 0x341, calling python!_PyEval_EvalCodeWithName
00007FFFB92B22C0 00005586bbb4770b python!fast_function + 0x10b, calling python!PyEval_EvalFrameEx
00007FFFB92B2300 00005586bbb4d755 python!call_function + 0x155, calling python!fast_function
00007FFFB92B2350 00005586bbb6fcba python!_PyEval_EvalFrameDefault + 0x2fa, calling python!call_function
00007FFFB92B23C0 00005586bbadc2ed python!PyObject_CallFunctionObjArgs + 0xed, calling python!_PyObject_FastCallDict
00007FFFB92B23D0 00005586bbaa75ba python!PyErr_Occurred + 0xa, calling python!_PyThreadState_UncheckedGet
00007FFFB92B2420 00005586bbaa75ba python!PyErr_Occurred + 0xa, calling python!_PyThreadState_UncheckedGet
00007FFFB92B2470 00005586bbb4770b python!fast_function + 0x10b, calling python!PyEval_EvalFrameEx
00007FFFB92B24B0 00005586bbb4d755 python!call_function + 0x155, calling python!fast_function
00007FFFB92B2500 00005586bbb6fcba python!_PyEval_EvalFrameDefault + 0x2fa, calling python!call_function
00007FFFB92B2580 00005586bbab0a20 python!PyDict_GetItem + 0x70
00007FFFB92B25A0 00005586bbad9dbe python!_Py_Call + 0x2e, calling python!PyArena_Malloc
00007FFFB92B25D0 00005586bbaee666 python!PyFrame_New + 0x146, calling python!PyType_IsSubtype
00007FFFB92B2620 00005586bbb47d7b python!_PyFunction_FastCallDict + 0x11b, calling python!PyEval_EvalFrameEx
00007FFFB92B2640 00005586bbab0a20 python!PyDict_GetItem + 0x70
00007FFFB92B26B0 00005586bbabdf5f python!_PyObject_FastCallDict + 0x26f, calling python!_PyFunction_FastCallDict
00007FFFB92B2700 00005586bbb02670 python!_PyObject_CallMethodIdObjArgs + 0x100, calling python!_PyObject_FastCallDict
00007FFFB92B27F0 00005586bbab0a76 python!PyDict_GetItem + 0xc6, calling python!PyErr_Clear
00007FFFB92B2840 00005586bbab4a70 python!PyImport_ImportModuleLevelObject + 0x340, calling python!_PyObject_CallMethodIdObjArgs
00007FFFB92B2860 00005586bbab0a20 python!PyDict_GetItem + 0x70
00007FFFB92B28B0 00005586bbb72033 python!_PyEval_EvalFrameDefault + 0x2673, calling python!PyImport_ImportModuleLevelObject
00007FFFB92B2930 00005586bbab0a20 python!PyDict_GetItem + 0x70
00007FFFB92B2950 00005586bba9e0da python!tupledealloc + 0x16a
00007FFFB92B2980 00005586bbaee92b python!PyFrame_New + 0x40b, calling python!PyModule_GetDict
00007FFFB92B29D0 00005586bbb48459 python!PyEval_EvalCodeEx + 0x329, calling python!PyEval_EvalFrameEx
00007FFFB92B2A30 00005586bbbc30c6 python!PyAST_CompileObject + 0x196
00007FFFB92B2A90 00005586bbb491ec python!PyEval_EvalCode + 0x1c, calling python!PyEval_EvalCodeEx
00007FFFB92B2AD0 00005586bbbc39a4 python!run_mod + 0x34, calling python!PyEval_EvalCode
00007FFFB92B2AF0 00005586bbbc3a3d python!PyRun_StringFlags + 0x7d, calling python!run_mod
00007FFFB92B2B40 00005586bbbc3a9f python!PyRun_SimpleStringFlags + 0x3f, calling python!PyRun_StringFlags
00007FFFB92B2B60 00005586bbbc789b python!Py_Main + 0x43b, calling python!PyRun_SimpleStringFlags
00007FFFB92B2C70 00005586bba8f4be python!main + 0xee, calling python!Py_Main
00007FFFB92B2C80 00005586bbbcb661 python!__libc_csu_init + 0x31 [/opt/conda/conda-bld/compilers_linux-64_1520532893746/work/.build/src/glibc-2.12.2/csu/elf-init.c:123], calling python!_init
00007FFFB92B2CC0 00007f8abd5de445 libc.so.6!__libc_start_main + 0xf5
00007FFFB92B2D40 00007f8abdbb4b03 ld-linux-x86-64.so.2!_dl_init_internal + 0x113
00007FFFB92B2D80 00005586bbb76773 python!_start + 0x29, calling python + 0xffffffff
---------------------------------------------
Thread   6
TEB information is not available so a stack size of 0xFFFF is assumed
Current frame: libpthread.so.0!__pthread_cond_timedwait + 0x132
Child-SP         RetAddr          Caller, Callee
00007F8AB146DD60 00007f8ab5e19395 libcoreclr.so!CorUnix::CPalSynchronizationManager::ThreadNativeWait(CorUnix::_ThreadNativeWaitData*, unsigned int, CorUnix::ThreadWakeupReason*, unsigned int*) + 0x2a5 [/coreclr/src/pal/src/synchmgr/synchmanager.cpp:484], calling libcoreclr.so!pthread_cond_timedwait
00007F8AB146DD70 00007f8ab5df99ee libcoreclr.so!ObtainCurrentThreadIdImpl(CorUnix::CPalThread*, char const*) + 0x4e [/coreclr/src/pal/src/sync/cs.cpp:184], calling libcoreclr.so!syscall
00007F8AB146DDA0 00007f8ab54c40bf libcoreclr.so!Volatile<unsigned int>::Store(unsigned int const&) + 0x1f [/coreclr/src/pal/../inc/volatile.h:312], calling libcoreclr.so!void VolatileStore<unsigned int>(unsigned int*, unsigned int) [/coreclr/src/inc/volatile.h:196]
00007F8AB146DDC0 00007f8ab5df99ee libcoreclr.so!ObtainCurrentThreadIdImpl(CorUnix::CPalThread*, char const*) + 0x4e [/coreclr/src/pal/src/sync/cs.cpp:184], calling libcoreclr.so!syscall
00007F8AB146DE10 00007f8ab54b78e5 libcoreclr.so!Volatile<int>::Load() const + 0x15 [/coreclr/src/pal/../inc/volatile.h:292], calling libcoreclr.so!int VolatileLoad<int>(int const*) [/coreclr/src/inc/volatile.h:136]
00007F8AB146DE80 00007f8ab54b78e5 libcoreclr.so!Volatile<int>::Load() const + 0x15 [/coreclr/src/pal/../inc/volatile.h:292], calling libcoreclr.so!int VolatileLoad<int>(int const*) [/coreclr/src/inc/volatile.h:136]
00007F8AB146DEC0 00007f8ab5e1861b libcoreclr.so!CorUnix::CPalSynchronizationManager::BlockThread(CorUnix::CPalThread*, unsigned int, bool, bool, CorUnix::ThreadWakeupReason*, unsigned int*) + 0x64b [/coreclr/src/pal/src/synchmgr/synchmanager.cpp:302], calling libcoreclr.so!CorUnix::CPalSynchronizationManager::ThreadNativeWait(CorUnix::_ThreadNativeWaitData*, unsigned int, CorUnix::ThreadWakeupReason*, unsigned int*) [/coreclr/src/pal/src/synchmgr/synchmanager.cpp:446]
00007F8AB146DF00 00007f8ab5a07991 libcoreclr.so!Volatile<int>::operator++(int) + 0x41 [/coreclr/src/pal/../inc/volatile.h:390], calling libcoreclr.so!Volatile<int>::Store(int const&) [/coreclr/src/inc/volatile.h:309]
00007F8AB146DF20 00007f8ab5e155a1 libcoreclr.so!CorUnix::CSynchCache<CorUnix::CSynchWaitController>::Unlock(CorUnix::CPalThread*) + 0x21 [/coreclr/src/pal/src/include/pal/synchcache.hpp:50], calling libcoreclr.so!CorUnix::InternalLeaveCriticalSection(CorUnix::CPalThread*, _CRITICAL_SECTION*) [/coreclr/src/pal/src/sync/cs.cpp:854]
00007F8AB146DF40 00007f8ab5e15495 libcoreclr.so!CorUnix::CSynchCache<CorUnix::CSynchWaitController>::Add(CorUnix::CPalThread*, CorUnix::CSynchWaitController*) + 0x105 [/coreclr/src/pal/src/include/pal/synchcache.hpp:166], calling libcoreclr.so!CorUnix::CSynchCache<CorUnix::CSynchWaitController>::Unlock(CorUnix::CPalThread*) [/coreclr/src/pal/src/include/pal/synchcache.hpp:50]
00007F8AB146DF90 00007f8ab5e142f4 libcoreclr.so!CorUnix::CPalSynchronizationManager::CacheAddWaitCtrlr(CorUnix::CPalThread*, CorUnix::CSynchWaitController*) + 0x34 [/coreclr/src/pal/src/synchmgr/synchmanager.hpp:731], calling libcoreclr.so!CorUnix::CSynchCache<CorUnix::CSynchWaitController>::Add(CorUnix::CPalThread*, CorUnix::CSynchWaitController*) [/coreclr/src/pal/src/include/pal/synchcache.hpp:138]
00007F8AB146DFC0 00007f8ab5e0a57f libcoreclr.so!CorUnix::CSynchControllerBase::Release() + 0x30f [/coreclr/src/pal/src/synchmgr/synchcontrollers.cpp:125], calling libcoreclr.so!CorUnix::CPalSynchronizationManager::CacheAddWaitCtrlr(CorUnix::CPalThread*, CorUnix::CSynchWaitController*) [/coreclr/src/pal/src/synchmgr/synchmanager.hpp:729]
00007F8AB146E070 00007f8ab5e1a546 libcoreclr.so!CorUnix::CPalSynchronizationManager::GetSynchWaitControllersForObjects(CorUnix::CPalThread*, CorUnix::IPalObject**, unsigned int, CorUnix::ISynchWaitController**) + 0x36 [/coreclr/src/pal/src/synchmgr/synchmanager.cpp:681], calling libcoreclr.so!CorUnix::CPalSynchronizationManager::GetSynchControllersForObjects(CorUnix::CPalThread*, CorUnix::IPalObject**, unsigned int, void**, CorUnix::CSynchControllerBase::ControllerType) [/coreclr/src/pal/src/synchmgr/synchmanager.cpp:721]
00007F8AB146E0B0 00007f8ab5e2acae libcoreclr.so!CorUnix::InternalWaitForMultipleObjectsEx(CorUnix::CPalThread*, unsigned int, void* const*, int, unsigned int, int, int) + 0x16ce [/coreclr/src/pal/src/synchmgr/wait.cpp:636]
00007F8AB146E4F0 00007f8ab5e2b8b1 libcoreclr.so!WaitForSingleObjectEx + 0x111 [/coreclr/src/pal/src/synchmgr/wait.cpp:139], calling libcoreclr.so!CorUnix::InternalWaitForMultipleObjectsEx(CorUnix::CPalThread*, unsigned int, void* const*, int, unsigned int, int, int) [/coreclr/src/pal/src/synchmgr/wait.cpp:363]
00007F8AB146E590 00007f8ab5869d40 libcoreclr.so!CLREventWaitHelper2(void*, unsigned int, int) + 0x30 [/coreclr/src/vm/synch.cpp:385], calling libcoreclr.so!WaitForSingleObjectEx [/coreclr/src/pal/src/synchmgr/wait.cpp:130]
00007F8AB146E5B0 00007f8ab5869bea libcoreclr.so!CLREventWaitHelper(void*, unsigned int, int)::$_1::operator()(CLREventWaitHelper(void*, unsigned int, int)::Param*) const + 0x2a [/coreclr/src/vm/synch.cpp:411], calling libcoreclr.so!CLREventWaitHelper2(void*, unsigned int, int) [/coreclr/src/vm/synch.cpp:381]
00007F8AB146E5D0 00007f8ab586845d libcoreclr.so!CLREventWaitHelper(void*, unsigned int, int) + 0x8d [/coreclr/src/vm/synch.cpp:413], calling libcoreclr.so!CLREventWaitHelper(void*, unsigned int, int)::$_1::operator()(CLREventWaitHelper(void*, unsigned int, int)::Param*) const [/coreclr/src/vm/synch.cpp:407]
00007F8AB146E690 00007f8ab58683ae libcoreclr.so!CLREventBase::WaitEx(unsigned int, WaitMode, PendingSync*) + 0x1ae [/coreclr/src/vm/synch.cpp:483], calling libcoreclr.so!CLREventWaitHelper(void*, unsigned int, int) [/coreclr/src/vm/synch.cpp:389]
00007F8AB146E6A0 00007f8ab5dbdbec libcoreclr.so!QueryPerformanceCounter + 0x23c [/coreclr/src/pal/src/misc/time.cpp:253], calling libcoreclr.so!Volatile<int>::operator int() const [/coreclr/src/inc/volatile.h:344]
00007F8AB146E6F0 00007f8ab58681ed libcoreclr.so!CLREventBase::Wait(unsigned int, int, PendingSync*) + 0x4d [/coreclr/src/vm/synch.cpp:426], calling libcoreclr.so!CLREventBase::WaitEx(unsigned int, WaitMode, PendingSync*) [/coreclr/src/vm/synch.cpp:431]
00007F8AB146E720 00007f8ab5733e9c libcoreclr.so!FinalizerThread::WaitForFinalizerEvent(CLREvent*) + 0x1c [/coreclr/src/vm/finalizerthread.cpp:408], calling libcoreclr.so!CLREventBase::Wait(unsigned int, int, PendingSync*) [/coreclr/src/vm/synch.cpp:424]
00007F8AB146E730 00007f8ab5503593 libcoreclr.so!Thread::CatchAtSafePoint() + 0x33 [/coreclr/src/vm/threads.h:1474], calling libcoreclr.so!Volatile<Thread::ThreadState>::operator Thread::ThreadState() const [/coreclr/src/inc/volatile.h:344]
00007F8AB146E750 00007f8ab54ff7ee libcoreclr.so!Thread::EnablePreemptiveGC() + 0xee [/coreclr/src/vm/threads.h:2162], calling libcoreclr.so!Thread::CatchAtSafePoint() [/coreclr/src/vm/threads.h:1472]
00007F8AB146E780 00007f8ab57342b6 libcoreclr.so!FinalizerThread::FinalizerThreadWorker(void*) + 0x116 [/coreclr/src/vm/finalizerthread.cpp:564], calling libcoreclr.so!FinalizerThread::WaitForFinalizerEvent(CLREvent*) [/coreclr/src/vm/finalizerthread.cpp:390]
00007F8AB146E7D0 00007f8ab5df99ee libcoreclr.so!ObtainCurrentThreadIdImpl(CorUnix::CPalThread*, char const*) + 0x4e [/coreclr/src/pal/src/sync/cs.cpp:184], calling libcoreclr.so!syscall
00007F8AB146E7F0 00007f8ab54ff6f8 libcoreclr.so!GetAppDomain + 0x28 [/coreclr/src/classlibnative/../vm/threads.inl:39], calling libcoreclr.so!__tls_get_addr
00007F8AB146E830 00007f8ab5647eae libcoreclr.so!ManagedThreadBase_DispatchInner(ManagedThreadCallState*) + 0xce [/coreclr/src/vm/threads.cpp:8850]
00007F8AB146E840 00007f8ab54ed81d libcoreclr.so!CLRException::HandlerState::HandlerState(Thread*) + 0x6d [/coreclr/src/binder/../vm/clrex.inl:32], calling libcoreclr.so!Thread::PreemptiveGCDisabled() [/coreclr/src/vm/threads.h:2177]
00007F8AB146E870 00007f8ab564d025 libcoreclr.so!ManagedThreadBase_DispatchMiddle(ManagedThreadCallState*) + 0x95 [/coreclr/src/vm/threads.cpp:8901], calling libcoreclr.so!ManagedThreadBase_DispatchInner(ManagedThreadCallState*) [/coreclr/src/vm/threads.cpp:8808]
00007F8AB146E890 00007f8ab54b78e5 libcoreclr.so!Volatile<int>::Load() const + 0x15 [/coreclr/src/pal/../inc/volatile.h:292], calling libcoreclr.so!int VolatileLoad<int>(int const*) [/coreclr/src/inc/volatile.h:136]
00007F8AB146E8B0 00007f8ab54b7895 libcoreclr.so!Volatile<int>::operator int() const + 0x15 [/coreclr/src/pal/../inc/volatile.h:346], calling libcoreclr.so!Volatile<int>::Load() const [/coreclr/src/inc/volatile.h:290]
00007F8AB146E8D0 00007f8ab5df99ee libcoreclr.so!ObtainCurrentThreadIdImpl(CorUnix::CPalThread*, char const*) + 0x4e [/coreclr/src/pal/src/sync/cs.cpp:184], calling libcoreclr.so!syscall
00007F8AB146E900 00007f8ab5df99ee libcoreclr.so!ObtainCurrentThreadIdImpl(CorUnix::CPalThread*, char const*) + 0x4e [/coreclr/src/pal/src/sync/cs.cpp:184], calling libcoreclr.so!syscall
00007F8AB146E920 00007f8ab5dfc061 libcoreclr.so!Volatile<unsigned int>::operator+=(unsigned int) + 0x41 [/coreclr/src/pal/../inc/volatile.h:376], calling libcoreclr.so!Volatile<unsigned int>::Store(unsigned int const&) [/coreclr/src/inc/volatile.h:309]
00007F8AB146E950 00007f8ab54b78e5 libcoreclr.so!Volatile<int>::Load() const + 0x15 [/coreclr/src/pal/../inc/volatile.h:292], calling libcoreclr.so!int VolatileLoad<int>(int const*) [/coreclr/src/inc/volatile.h:136]
0
8000
0007F8AB146E990 00007f8ab5df98bf libcoreclr.so!CorUnix::InternalLeaveCriticalSection(CorUnix::CPalThread*, _CRITICAL_SECTION*) + 0x74f [/coreclr/src/pal/src/sync/cs.cpp:907], calling libcoreclr.so!InterlockedCompareExchange [/coreclr/src/pal/inc/pal.h:3483]
00007F8AB146E9A0 00007f8ab54b78e5 libcoreclr.so!Volatile<int>::Load() const + 0x15 [/coreclr/src/pal/../inc/volatile.h:292], calling libcoreclr.so!int VolatileLoad<int>(int const*) [/coreclr/src/inc/volatile.h:136]
00007F8AB146E9C0 00007f8ab54b78e5 libcoreclr.so!Volatile<int>::Load() const + 0x15 [/coreclr/src/pal/../inc/volatile.h:292], calling libcoreclr.so!int VolatileLoad<int>(int const*) [/coreclr/src/inc/volatile.h:136]
00007F8AB146EA30 00007f8ab564ce5d libcoreclr.so!ManagedThreadBase_DispatchOuter(ManagedThreadCallState*)::$_8::operator()(ManagedThreadBase_DispatchOuter(ManagedThreadCallState*)::TryArgs*) const::{lambda(Param*)#1}::operator()(Param*) const + 0x1d [/coreclr/src/vm/threads.cpp:9141], calling libcoreclr.so!ManagedThreadBase_DispatchMiddle(ManagedThreadCallState*) [/coreclr/src/vm/threads.cpp:8855]
00007F8AB146EA50 00007f8ab564cc5f libcoreclr.so!ManagedThreadBase_DispatchOuter(ManagedThreadCallState*)::$_8::operator()(ManagedThreadBase_DispatchOuter(ManagedThreadCallState*)::TryArgs*) const + 0x6f [/coreclr/src/vm/threads.cpp:9141], calling libcoreclr.so!ManagedThreadBase_DispatchOuter(ManagedThreadCallState*)::$_8::operator()(ManagedThreadBase_DispatchOuter(ManagedThreadCallState*)::TryArgs*) const::{lambda(Param*)#1}::operator()(Param*) const [/coreclr/src/vm/threads.cpp:9137]
00007F8AB146EA70 00007f8ab5542eb5 libcoreclr.so!Frame::Push() + 0x25 [/coreclr/src/vm/frames.cpp:397], calling libcoreclr.so!Frame::Push(Thread*) [/coreclr/src/vm/frames.cpp:400]
00007F8AB146EAD0 00007f8ab5652309 libcoreclr.so!FrameWithCookie<DebuggerU2MCatchHandlerFrame>::FrameWithCookie() + 0x29 [/coreclr/src/vm/frames.h:3428], calling libcoreclr.so!DebuggerU2MCatchHandlerFrame::DebuggerU2MCatchHandlerFrame() [/coreclr/src/vm/frames.h:2851]
00007F8AB146EAF0 00007f8ab5647b39 libcoreclr.so!ManagedThreadBase_DispatchOuter(ManagedThreadCallState*) + 0xe9 [/coreclr/src/vm/threads.cpp:9178], calling libcoreclr.so!ManagedThreadBase_DispatchOuter(ManagedThreadCallState*)::$_8::operator()(ManagedThreadBase_DispatchOuter(ManagedThreadCallState*)::TryArgs*) const [/coreclr/src/vm/threads.cpp:9135]
00007F8AB146EBC0 00007f8ab5647a28 libcoreclr.so!ManagedThreadBase_NoADTransition(void (*)(void*), UnhandledExceptionLocation) + 0x58 [/coreclr/src/vm/threads.cpp:9223], calling libcoreclr.so!ManagedThreadBase_DispatchOuter(ManagedThreadCallState*) [/coreclr/src/vm/threads.cpp:9092]
00007F8AB146EC30 00007f8ab5647d6a libcoreclr.so!ManagedThreadBase::FinalizerBase(void (*)(void*)) + 0x1a [/coreclr/src/vm/threads.cpp:9250], calling libcoreclr.so!ManagedThreadBase_NoADTransition(void (*)(void*), UnhandledExceptionLocation) [/coreclr/src/vm/threads.cpp:9206]
00007F8AB146EC50 00007f8ab5734dd1 libcoreclr.so!FinalizerThread::FinalizerThreadStart(void*)::$_0::operator()(FinalizerThread::FinalizerThreadStart(void*)::__EEParam*) const + 0x61 [/coreclr/src/vm/finalizerthread.cpp:764], calling libcoreclr.so!ManagedThreadBase::FinalizerBase(void (*)(void*)) [/coreclr/src/vm/threads.cpp:9247]
00007F8AB146EC60 00007f8ab54ed7a8 libcoreclr.so!GetThread + 0x28 [/coreclr/src/binder/../vm/threads.inl:34], calling libcoreclr.so!__tls_get_addr
00007F8AB146ECA0 00007f8ab57349a5 libcoreclr.so!FinalizerThread::FinalizerThreadStart(void*) + 0x1e5 [/coreclr/src/vm/finalizerthread.cpp:847], calling libcoreclr.so!FinalizerThread::FinalizerThreadStart(void*)::$_0::operator()(FinalizerThread::FinalizerThreadStart(void*)::__EEParam*) const [/coreclr/src/vm/finalizerthread.cpp:735]
00007F8AB146ED20 00007f8ab5d903d9 libcoreclr.so!UnlockModuleList + 0x49 [/coreclr/src/pal/src/loader/module.cpp:1797], calling libcoreclr.so!CorUnix::InternalLeaveCriticalSection(CorUnix::CPalThread*, _CRITICAL_SECTION*) [/coreclr/src/pal/src/sync/cs.cpp:854]
00007F8AB146ED40 00007f8ab574823d libcoreclr.so!EEHeapFree(void*, unsigned int, void*) + 0x8d [/coreclr/src/vm/hosting.cpp:499], calling libcoreclr.so!HeapFree [/coreclr/src/pal/src/memory/heap.cpp:233]
00007F8AB146ED80 00007f8ab5d52c26 libcoreclr.so!CorUnix::CPalThread::SetLastError(unsigned int) + 0x16 [/coreclr/src/pal/src/include/pal/thread.hpp:485], calling libcoreclr.so!__errno_location
00007F8AB146EDE0 00007f8ab56394e7 libcoreclr.so!Thread::intermediateThreadProc(void*) + 0xa7 [/coreclr/src/vm/threads.cpp:2254]
00007F8AB146EE30 00007f8ab5e430bd libcoreclr.so!CorUnix::CPalThread::ThreadEntry(void*) + 0x68d [/coreclr/src/pal/src/thread/thread.cpp:1682]
00007F8AB146EFB0 00007f8abd6babad libc.so.6!__clone + 0x6d

@Cronan
Copy link
Contributor Author
Cronan commented Jun 19, 2019
(lldb) disass -a 00007F8AA9F2835F
libpython3.6m.so`Py_DecRef:
    0x7f8aa9f28350 <+0>:  testq  %rdi, %rdi
    0x7f8aa9f28353 <+3>:  je     0x7f8aa9f28370            ; <+32>
    0x7f8aa9f28355 <+5>:  subq   $0x1, (%rdi)
    0x7f8aa9f28359 <+9>:  jne    0x7f8aa9f28370            ; <+32>
    0x7f8aa9f2835b <+11>: movq   0x8(%rdi), %rax
->  0x7f8aa9f2835f <+15>: jmpq   *0x30(%rax)
    0x7f8aa9f28362 <+18>: nopl   (%rax)
    0x7f8aa9f28366 <+22>: nopw   %cs:(%rax,%rax)
    0x7f8aa9f28370 <+32>: retq   

@Cronan
Copy link
Contributor Author
Cronan commented Jun 19, 2019
(lldb) register read
General Purpose Registers:
       rax = 0x0000000000000000
       rbx = 0x00005586bca365b0
       rcx = 0x00005586bcaafe60
       rdx = 0xffffffffffffffff
       rdi = 0x00007f8aaa291be0  libpython3.6m.so`small_ints.lto_priv.1887 + 160
       rsi = 0x0000000000000000
       rbp = 0x00007fffb92b1420
       rsp = 0x00007fffb92b1378
        r8 = 0x00007f8abdcd7000
        r9 = 0x00005586bbef0a20  python`free_list.lto_priv.219
       r10 = 0x00007f8a3d088b28
       r11 = 0x0000000000000000
       r12 = 0x00005586bcaafe60
       r13 = 0x00007f8a14018500
       r14 = 0x00007f8abdd66f08
       r15 = 0x0000000000000001
       rip = 0x00007f8aa9f2835f  libpython3.6m.so`Py_DecRef + 15
    rflags = 0x0000000000010246
        cs = 0x0000000000000033
        fs = 0x0000000000000000
        gs = 0x0000000000000000
        ss = 0x000000000000002b
        ds = 0x0000000000000000
        es = 0x0000000000000000

@Cronan
Copy link
Contributor Author
Cronan commented Jun 19, 2019

According to Jan in the linked thread, it's:

The C# code is passing the value that you can see in RDI to the Py_DecRef function. Based on what I have googled, it is supposed to be PyObject *, but there is something wrong with that object. The Py_DecRef gets eight byte value from memory at that pointer plus 8 and it is zero (see RAX). Then the function tries to read value from memory at address RAX+0x30 and then jump to that address (jmpq *0x30(%rax)). Since RAX is zero, attempt to read from memory at address 0x30 obviously fails with sigsegv.

I don't known where the Python.Runtime.Runtime.XDecref gets the PyObject * that's wrong.

Does this help anyone more than it helps me? :-)

@amos402
Copy link
Member
amos402 commented Jun 21, 2019

It you are debugging on a python with Py_DEBUG, you can simply insert

// Auto-geerated from ................
public static int _ob_next = 0;
public static int _ob_prev =0;

// before public static int ob_refcnt = 0;

to src/runtime/interop36.cs to get the right offset.

@Cronan
Copy link
Contributor Author
Cronan commented Jun 21, 2019

Wow. Can you explain to me what this is doing please, I’d love to understand.

@amos402
Copy link
Member
amos402 commented Jun 22, 2019

I wonder if you are debugging on a debug version python, if so, you should care about the Py_XDECREF due to the debug version do more things than release version.
图片
图片
As you see, there is a _Py_ForgetReference(op); call in _Py_Decalloc, it would deal with the _ob_next and _ob_prev, but in pythonnet
图片
You can see that it just call Py_TYPE(op)->tp_dealloc without _Py_ForgetReference.
All these operations would mess your memory, thus crashing would 8000 be just sooner or later.
Well, it consider as a minor bug for pythonnet

@Cronan
Copy link
Contributor Author
Cronan commented Jun 22, 2019 via email

@amos402
Copy link
Member
amos402 commented Jun 22, 2019

Sometimes you can just use the release configure but set -O0 to make it easy for debugging.

@Cronan
Copy link
Contributor Author
Cronan commented Jun 24, 2019

@amos402 Looks like it's not the problem - back to the drawing board.
But thanks for the suggestion.

python -m sysconfig | grep Py_
	PY_CORE_CFLAGS = "-Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -I. -I./Include -I/opt/man/releases/python-medusa/36-1/include -fPIC -DPy_BUILD_CORE"
	Py_DEBUG = "0"
	Py_ENABLE_SHARED = "0"
	Py_HASH_ALGORITHM = "0"

@Cronan
Copy link
Contributor Author
Cronan commented Jun 25, 2019

It seems to be this:

internal static unsafe IntPtr PyObject_TYPE(IntPtr op)
        {
            var p = (void*)op;
            if ((void*)0 == p)
            {
                return IntPtr.Zero;
            }
#if PYTHON_WITH_PYDEBUG
            var n = 3;
#else
            var n = 1;
#endif
            return Is32Bit
                ? new IntPtr((void*)(*((uint*)p + n)))
                : new IntPtr((void*)(*((ulong*)p + n)));
        }

image

When called from here:

image

image

@Cronan
Copy link
Contributor Author
Cronan commented Jun 25, 2019

Something to do with the small int list?

Works:

PyObject_Type(PyFloat_FromDouble(0))
{94870065578976}

PyObject_Type(PyLong_FromLong(257))
{94870065574240}

Fails:

PyObject_Type(PyLong_FromLong(256))
{0}

@Cronan
Copy link
Contributor Author
Cronan commented Jun 25, 2019

OK - it seems the Python interpreter isn't initialized in Python 3, which is why the small_int cache is missing - anyone have any ideas why?

@amos402
Copy link
Member
amos402 commented Jun 26, 2019

Do you have the C code of your library? Is you interpreter a official version or the one you have been modified?

@Cronan
Copy link
Contributor Author
Cronan commented Jun 27, 2019 via email

@amos402
Copy link
Member
amos402 commented Jun 27, 2019

You can use GDB attach to the target process and use info share to validate your loaded library is correct or not.

@Cronan
Copy link
Contributor Author
Cronan commented Jun 27, 2019

So, to make a long story short .....

Some versions of python are compiled with the shared library support disabled.
See this discussion.

For example, the one my company uses:
https://anaconda.org/anaconda/python/3.6.5/download/linux-32/python-3.6.5-hc3d631a_2.tar.bz2

This does not mean that the libpython3.6m.so.1.0 is not created, it means that it is not used by the interpreter. The effect of this is that some Python C calls will work
(e.g. PyObject_Type(PyLong_FromLong(257))
but others will fail
(e.g. PyObject_Type(PyLong_FromLong(0)))

You can test for the setting by running the following (the result below means pythonnet will segfault):

python -m sysconfig | grep Py_ENABLE_SHARED
Py_ENABLE_SHARED = "0"

The only solution for me is to alter the version of the interpreter to use one that was compiled with the shared library support enabled.

We're going to be using this moving forward:
https://anaconda.org/conda-forge/python/3.6.5/download/linux-64/python-3.6.5-1.tar.bz2

Thank you to @amos402 for all your help.

@Cronan Cronan closed this as completed Jun 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0