wlav / cppyy

Other
411 stars 42 forks source link

Cling crash on Windows #74

Open N-Coder opened 2 years ago

N-Coder commented 2 years ago

I'm getting a somewhat weird crash from within CLing on Windows 10, both locally and also in the GitHub Actions CI (see the "Testing wheel" step of the build). My library loads fine and I can also use some variables defined statically (the json info dump right before the crash in the CI was generated from macros and static variables in the library), but as soon as I try to do a little more (like listing members of the namespace by pressing Tab in a python shell), Cling seems to crash. The actual exception seems to be the following, although WinDbg already stops a little earlier in the same function, see the full dump below. I'm not really an expert in Windows topics, could you give me some pointers how to debug, fix and/or circumvent this?

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 00007ffa9fd94b38 (libCling!cling::runtime::internal::setValueWithAlloc+0x0000000000085f34)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 0000000000000000
   Parameter[1]: ffffffffffffffff
Attempt to read from address ffffffffffffffff

FAULTING_THREAD:  000061c4

PROCESS_NAME:  python_uwp.exe

READ_ADDRESS:  ffffffffffffffff 

ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.

EXCEPTION_CODE_STR:  c0000005

EXCEPTION_PARAMETER1:  0000000000000000

EXCEPTION_PARAMETER2:  ffffffffffffffff

STACK_TEXT:  
00000014`421eddd0 00007ffa`a122dca9     : 00000000`00000001 00000000`00000042 000001a4`4f5adc50 00007ffa`a122bb93 : libCling!cling::runtime::internal::setValueWithAlloc+0x85f34
00000014`421ede40 00007ffa`a122662a     : 000001a4`4f5adc51 000001a4`4f5b88e0 00000014`421edee0 00007ffa`a122d9dd : libCling!cling::runtime::internal::setValueWithAlloc+0x151f0a5

The packages I use should be the most recent: CPyCppyy | 1.12.11 cppyy | 2.4.0 cppyy-backend | 1.14.9 cppyy-cling | 6.27.0

``` !analyze -v ERROR: FindPlugIns 8007007b ******************************************************************************* * * * Exception Analysis * * * ******************************************************************************* *** WARNING: Unable to verify checksum for C:\Users\Niko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\cppyy_backend\bin\libCoreLegacy.dll *** WARNING: Unable to verify checksum for C:\Users\Niko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\cppyy_backend\lib\libcppyy_backend.dll *** WARNING: Unable to verify checksum for C:\Users\Niko\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\libcppyy.cp310-win_amd64.pyd KEY_VALUES_STRING: 1 Key : Analysis.CPU.mSec Value: 2218 Key : Analysis.DebugAnalysisManager Value: Create Key : Analysis.Elapsed.mSec Value: 70110 Key : Analysis.Init.CPU.mSec Value: 2140 Key : Analysis.Init.Elapsed.mSec Value: 164281 Key : Analysis.Memory.CommitPeak.Mb Value: 146 Key : Timeline.OS.Boot.DeltaSec Value: 737592 Key : Timeline.Process.Start.DeltaSec Value: 163 Key : WER.OS.Branch Value: vb_release Key : WER.OS.Timestamp Value: 2019-12-06T14:06:00Z Key : WER.OS.Version Value: 10.0.19041.1 Key : WER.Process.Version Value: 3.10.5150.1013 NTGLOBALFLAG: 70 PROCESS_BAM_CURRENT_THROTTLED: 0 PROCESS_BAM_PREVIOUS_THROTTLED: 0 APPLICATION_VERIFIER_FLAGS: 0 EXCEPTION_RECORD: (.exr -1) ExceptionAddress: 00007ffa9fd94b2d (libCling!cling::runtime::internal::setValueWithAlloc+0x0000000000085f29) ExceptionCode: 80000003 (Break instruction exception) ExceptionFlags: 00000000 NumberParameters: 1 Parameter[0]: 0000000000000000 FAULTING_THREAD: 000061c4 PROCESS_NAME: python_uwp.exe ERROR_CODE: (NTSTATUS) 0x80000003 - {EXCEPTION} Breakpoint A breakpoint has been reached. EXCEPTION_CODE_STR: 80000003 EXCEPTION_PARAMETER1: 0000000000000000 STACK_TEXT: 00000014`421ede38 00007ffa`a122dca9 : 00000000`00000001 00000000`00000042 000001a4`4f5adc50 00007ffa`a122bb93 : libCling!cling::runtime::internal::setValueWithAlloc+0x85f29 00000014`421ede40 00007ffa`a122662a : 000001a4`4f5adc51 000001a4`4f5b88e0 00000014`421edee0 00007ffa`a122d9dd : libCling!cling::runtime::internal::setValueWithAlloc+0x151f0a5 00000014`421edea0 00007ffa`a1226f8a : 000001a4`4f5af820 00000000`00000000 00000014`421edf60 000001a4`4f5af820 : libCling!cling::runtime::internal::setValueWithAlloc+0x1517a26 00000014`421edf20 00007ffa`a122692d : 000001a4`4f5b8a38 000001a4`4f5b89e0 000001a4`4f5b8a38 00000014`421ee000 : libCling!cling::runtime::internal::setValueWithAlloc+0x1518386 00000014`421edfa0 00007ffa`a1224250 : 000001a4`4f5bd998 00000014`421ee080 00000014`421ee110 000001a4`4f5bd998 : libCling!cling::runtime::internal::setValueWithAlloc+0x1517d29 00000014`421edfe0 00007ffa`a12252aa : 000001a4`45785000 00000014`421ee120 000001a4`4fefc2c0 00000014`421ee410 : libCling!cling::runtime::internal::setValueWithAlloc+0x151564c 00000014`421ee020 00007ffa`a119d6fa : 000001a4`4f5bd998 00000014`421ee470 000001a4`4f5bd998 00000000`00000000 : libCling!cling::runtime::internal::setValueWithAlloc+0x15166a6 00000014`421ee380 00007ffa`9fd21163 : 000001a4`4fefc2c0 00007de9`5fe8a57e 00000014`421ee410 000001a4`45fb6040 : libCling!cling::runtime::internal::setValueWithAlloc+0x148eaf6 00000014`421ee3f0 00007ffa`9fc7240a : ffffffff`421ef680 000001a4`4c0cf2a0 000001a4`4c0cf2a0 000001a4`4f5bd998 : libCling!cling::runtime::internal::setValueWithAlloc+0x1255f 00000014`421ee490 00007ffa`9fc3ccb1 : 00007ffa`a14c4cd0 00000000`00000000 00000000`000000e8 00007ffa`aaf9d907 : libCling!CppyyLegacy::TClingMethodInfo::GetMangledName+0xea 00000014`421ee540 00007ffa`aafff53d : 000001a4`51bf92f0 000001a4`51bf92f0 000001a4`51fe10e0 000001a4`51fe10e0 : libCling!CppyyLegacy::TCling::MethodInfo_GetMangledName+0x81 00000014`421ee5a0 00007ffa`ab009033 : 000001a4`537c8940 000001a4`51bf92f0 00000000`00000000 00000000`00000000 : libCoreLegacy!CppyyLegacy::TFunction::TFunction+0x11d 00000014`421ee5e0 00007ffa`ab00729c : 000001a4`537c8940 00000000`00000000 00000000`00000000 00000014`421ee8d0 : libCoreLegacy!CppyyLegacy::TMethod::TMethod+0x23 00000014`421ee620 00007ffa`ab0077f5 : 000001a4`4c0cf2a0 000001a4`4c0cf2a0 000001a4`52003440 000001a4`51fdf520 : libCoreLegacy!CppyyLegacy::TListOfFunctions::Get+0x24c 00000014`421ee6a0 00007ffa`aaff1208 : 000001a4`4c0cf2a0 00000000`00000001 00000014`421ee7a0 000001a4`4f3fb050 : libCoreLegacy!CppyyLegacy::TListOfFunctions::Load+0x165 00000014`421ee6e0 00007ffa`ee8cb319 : 000001a4`4c0cf2a0 000001a4`50bf97e0 000001a4`4c0cf2a0 000001a4`4f3fb050 : libCoreLegacy!CppyyLegacy::TClass::GetListOfMethods+0x88 00000014`421ee720 00007ffa`b2496b0b : 00000014`421ee8d0 00000000`00000000 00000000`00000000 00000000`00000000 : libcppyy_backend!Cppyy::GetMethodIndicesFromName+0xd9 00000014`421ee7e0 00007ffa`b0d70e36 : 000001a4`51f022e8 000001a4`4e7a68c0 000001a4`45a66230 00000000`00000003 : libcppyy_cp310_win_amd64!CPyCppyy::PyException::operator=+0x90bb 00000014`421eea20 00007ffa`b0d9a32b : 000001a4`45a66230 00000000`00000000 000001a4`436923d0 000001a4`4e7a68d0 : python310!PyNumber_Float+0x576 00000014`421eea50 00007ffa`b0d5928e : 00000000`00000000 00000014`421eebb0 00007ffa`b0d9a1d8 00007ffa`b0d9a1d8 : python310!PyObject_CallFunction+0xa3b 00000014`421eeab0 00007ffa`b0d53367 : 000001a4`436923d0 00000000`00000002 000001a4`53392c30 00000014`421eeed0 : python310!PyEval_EvalFrameDefault+0x4fbe 00000014`421eee10 00007ffa`b0da3da4 : 00007ffa`b11260d0 00000000`00000002 000001a4`436923d0 00000000`00000000 : python310!PyFunction_Vectorcall+0x87 00000014`421eee60 00007ffa`b0f3f919 : 00000000`00000000 00000000`00000001 000001a4`4f3fdf90 000001a4`436923d0 : python310!PyLong_Copy+0x204 00000014`421eeeb0 00007ffa`b0d95eb7 : 00000000`00000001 00000000`00000000 000001a4`435925c0 000001a4`48f45680 : python310!PyType_CheckConsistency+0xbfd 00000014`421eeef0 00007ffa`b0d56e57 : 000001a4`43693da4 00000014`421ef020 000001a4`4f3fdf90 00007ffa`b0d4e900 : python310!PyObject_GetAttr+0x47 00000014`421eef20 00007ffa`b0d53367 : 000001a4`436923d0 00000000`00000000 000001a4`53392e70 000001a4`45969da8 : python310!PyEval_EvalFrameDefault+0x2b87 00000014`421ef280 00007ffa`b0d549de : 00000014`421ef3d0 000001a4`45969da0 000001a4`45969c40 00007ffa`b110ebb0 : python310!PyFunction_Vectorcall+0x87 00000014`421ef2d0 00007ffa`b0d3c74d : 000001a4`436923d0 00000000`00000000 00000014`421ef6a0 00000000`00000000 : python310!PyEval_EvalFrameDefault+0x70e 00000014`421ef630 00007ffa`b0d3c6d6 : 000001a4`45a77480 000001a4`45a77480 000001a4`45a77480 00007ffa`b0d990fd : python310!PyEval_EvalCode+0xf9 00000014`421ef670 00007ffa`b0d3bc1a : 000001a4`45a77480 000001a4`45ab6970 000001a4`45a77480 00000000`00000000 : python310!PyEval_EvalCode+0x82 00000014`421ef6f0 00007ffa`b0d3bb9a : 000001a4`45ab6970 000001a4`45a77480 000001a4`45a77480 000001a4`45ab6970 : python310!Py_BuildValue+0x656 00000014`421ef720 00007ffa`b0da8088 : 00000000`00000000 000001a4`4369c750 000001a4`4579a4b0 00000000`00000001 : python310!Py_BuildValue+0x5d6 00000014`421ef760 00007ffa`b0da7f3d : 000001a4`45a7a7f0 00000000`00000001 000001a4`45a77480 000001a4`45a85990 : python310!PyRun_SimpleFileObject+0x268 00000014`421ef7d0 00007ffa`b0da7d80 : 000001a4`45a85990 00000014`421ef8a0 000001a4`4369c750 00000000`00000000 : python310!PyRun_SimpleFileObject+0x11d 00000014`421ef840 00007ffa`b0da7a03 : 000001a4`4369c750 00000000`00000000 000001a4`45a85990 00000000`00000000 : python310!PyRun_AnyFileObject+0x54 00000014`421ef870 00007ffa`b0da78bf : 000001a4`45a85990 ffffffff`ffffffff 000001a4`436af3f0 0000000a`00000000 : python310!Py_MakePendingCalls+0x35b 00000014`421ef940 00007ffa`b0e22860 : 000001a4`45a2ec10 000001a4`436af040 00000000`00000000 000001a4`436af3f0 : python310!Py_MakePendingCalls+0x217 00000014`421ef970 00007ffa`b0e226f1 : 00000014`421efa70 00000000`00000000 00000000`00000000 000001a4`45a2ec10 : python310!Py_RunMain+0x184 00000014`421ef9c0 00007ff7`334640b2 : 00000000`00000000 00000000`00000000 00000000`00000002 00000000`00000002 : python310!Py_RunMain+0x15 00000014`421ef9f0 00007ff7`334659e4 : 00000000`00000000 00000000`00000000 000001a4`4360bf10 00000000`00000000 : python_uwp+0x40b2 00000014`421efc90 00007ffb`00a97034 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : python_uwp+0x59e4 00000014`421efcd0 00007ffb`01ba2651 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14 00000014`421efd00 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21 SYMBOL_NAME: libCling+85f29 MODULE_NAME: libCling IMAGE_NAME: libCling.dll STACK_COMMAND: dt ntdll!LdrpLastDllInitializer BaseDllName ; dt ntdll!LdrpFailureData ; ~0s ; .cxr ; kb FAILURE_BUCKET_ID: BREAKPOINT_80000003_libCling.dll!Unknown OS_VERSION: 10.0.19041.1 BUILDLAB_STR: vb_release OSPLATFORM_TYPE: x64 OSNAME: Windows 10 FAILURE_ID_HASH: {6488b37f-fd83-77db-bf26-49898f654e25} Followup: MachineOwner --------- ```
wlav commented 2 years ago

Looks like some callee returns (void*)-1 as an error code, with the caller not handling said error. Probably b/c it's expecting a pointer and hence only checking for nullptr.

Listing or <tab> completion should not enter CPyCppyy::PyException::operator=, though. But setValueWithAlloc seems to be exclusively used for printing names, which makes sense in the context of building a list for <tab>-completion. Then again, I wouldn't expect GetMangledName() to show up.

Probably won't be able to say anything more sensible unless I can reproduce it. Is it just a matter of installing https://pypi.org/project/ogdf-python/ on Windows and hitting <tab>?

N-Coder commented 2 years ago

This is actually reproducible with plain cppyy, no pythonizations from ogdf-python (or binaries from ogdf-wheel) needed:

git clone --recursive  https://github.com/ogdf/ogdf.git
cd ogdf
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON '-DCMAKE_INSTALL_PREFIX=./install' -DCMAKE_BUILD_RPATH='$ORIGIN;@loader_path' -DCMAKE_INSTALL_RPATH='$ORIGIN;@loader_path' -DMACOSX_RPATH=TRUE
cmake --build . --config Release
cmake --install .
python
import cppyy
cppyy.add_library_path("install\\bin")
cppyy.add_include_path("install\\include")

cppyy.include("ogdf/basic/internal/config_autogen.h")
cppyy.include("ogdf/basic/internal/config.h")
cppyy.include("ogdf/basic/Graph.h")
cppyy.include("ogdf/fileformats/GraphIO.h")
cppyy.load_library("OGDF")

from cppyy.gbl import ogdf
ogdf.Graph()
<cppyy.gbl.ogdf.Graph object at 0x0000012C952F9830>
dir(ogdf) # or ogdf.G<TAB>
==========================================
=============== STACKTRACE ===============
==========================================

================ Thread 0 ================
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!cling::runtime::internal::setValueWithAlloc()
  libCling!CppyyLegacy::TClingMethodInfo::GetMangledName()
  libCling!CppyyLegacy::TCling::MethodInfo_GetMangledName()
  libCoreLegacy!CppyyLegacy::TFunction::TFunction()
  libCoreLegacy!CppyyLegacy::TMethod::TMethod()
  libCoreLegacy!CppyyLegacy::TListOfFunctions::Get()
  libCoreLegacy!CppyyLegacy::TListOfFunctions::Load()
  libCoreLegacy!CppyyLegacy::TClass::GetListOfMethods()
  libcppyy_backend!Cppyy::GetAllCppNames()
  libcppyy.cp310-win_amd64!CPyCppyy::PyException::operator=()
  python310!PyObject_GC_Malloc()
  python310!PySequence_Check()
  python310!PySequence_Check()
  python310!PySequence_Check()
  python310!PyDict_MergeFromSeq2()
  python310!PyEval_EvalFrameDefault()
  python310!PyEval_EvalCode()
  python310!PyEval_EvalCode()
  python310!Py_BuildValue()
  python310!Py_BuildValue()
  python310!PyRun_InteractiveOneObject()
  python310!PyRun_InteractiveLoopObject()
  python310!Py_gitversion()
  python310!PyRun_AnyFileExFlags()
  python310!Py_gitversion()
  python310!Py_RunMain()
  python310!Py_RunMain()
  python3.10!??
  python3.10!??
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

================ Thread 1 ================
  ntdll!ZwWaitForWorkViaWorkerFactory()
  ntdll!TpReleaseCleanupGroupMembers()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

================ Thread 2 ================
  ntdll!ZwWaitForMultipleObjects()
  KERNELBASE!WaitForMultipleObjectsEx()
  combase!CoRevokeInitializeSpy()
  combase!CoRevokeInitializeSpy()
  combase!CoRevokeInitializeSpy()
  combase!CoRevokeInitializeSpy()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

================ Thread 3 ================
  win32u!NtUserGetMessage()
  USER32!GetMessageW()
  combase!CoFreeUnusedLibraries()
  combase!CoFreeUnusedLibraries()
  combase!CoRevokeInitializeSpy()
  combase!CoRevokeInitializeSpy()
  KERNEL32!BaseThreadInitThunk()
  ntdll!RtlUserThreadStart()

==========================================
============= END STACKTRACE =============
==========================================
Process finished with exit code -2147483645
N-Coder commented 2 years ago

It even works entirely without the OGDF, the following is a MRE that yields the same crash and stacktrace:

import cppyy

cppyy.cppdef("""
namespace mynamespace {
    template<class E> class Foo {
        void bar(Foo<E> A);
    };

    template<class E>
    void Foo<E>::bar(Foo<E> A) {
    }
}
""")

from cppyy.gbl import mynamespace
print(dir(mynamespace))

Dropping the parameter from bar or giving its code inside the class "fixes" the crash. Foo<E>::bar used to be ogdf::Array<E, INDEX>::copy, if that is relevant.

N-Coder commented 2 years ago

Note: this is probably the same bug as https://github.com/kunitoki/popsicle/issues/10

N-Coder commented 2 years ago

Possibly related: using .Class crashes the root shell, e.g. following the example from here:

C:\Users\Niko>root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.26/06                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for win64 on Jul 28 2022, 18:08:51                         |
  | From tags/v6-26-06@v6-26-06                                      |
  | With MSVC 19.32.31332.0                                          |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] TLine l;
root [1] l.Print();
TLine  X1=0.000000 Y1=0.000000 X2=0.000000 Y2=0.000000
root [2] .Class TLine
List of classes===========================================================================
class type_info
SIZE: 24 FILE: vcruntime_typeinfo.h LINE: -1
List of member variables --------------------------------------------------
vcruntime_typeinfo.h  -1 0x8        private: mutable struct __std_type_info_data _Data, size = 16
vcruntime_typeinfo.h  -1   0x0        public: const char *_UndecoratedName
vcruntime_typeinfo.h  -1   0x8        public: const char _DecoratedName[1]
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
(compiled)     (NA):(NA) 0 public: type_info(const type_info &);
(compiled)     (NA):(NA) 0 public: class type_info &operator=(const class type_info &) = delete;
(compiled)     (NA):(NA) 0 public: size_t hash_code() const noexcept;
(compiled)     (NA):(NA) 0 public: _Bool operator==(const class type_info &_Other) const noexcept;
(compiled)     (NA):(NA) 0 public: _Bool operator!=(const class type_info &_Other) const noexcept;
(compiled)     (NA):(NA) 0 public: _Bool before(const class type_info &_Other) const noexcept;
(compiled)     (NA):(NA) 0 public: const char *name() const noexcept;
(compiled)     (NA):(NA) 0 public: const char *raw_name() const noexcept;
(compiled)     (NA):(NA) 0 public: virtual ~type_info() noexcept;
===========================================================================
struct __vcrt_va_list_is_reference<_Ty &>
SIZE: (NA) FILE: vadefs.h LINE: -1
List of member variables --------------------------------------------------
vadefs.h         -1 0x0      public: enum __vcrt_va_list_is_reference<type-parameter-0-0 &>::(anonymous at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\vadefs.h:182:13) __the_value
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
===========================================================================
struct __vcrt_va_list_is_reference<_Ty &&>
SIZE: (NA) FILE: vadefs.h LINE: -1
List of member variables --------------------------------------------------
vadefs.h         -1 0x0      public: enum __vcrt_va_list_is_reference<type-parameter-0-0 &&>::(anonymous at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\vadefs.h:188:13) __the_value
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
===========================================================================
struct _CrtEnableIf<true, _Ty>
SIZE: (NA) FILE: corecrt.h LINE: -1
List of member variables --------------------------------------------------
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
===========================================================================
struct __crt_locale_data_public
SIZE: 16 FILE: corecrt.h LINE: -1
List of member variables --------------------------------------------------
corecrt.h        -1 0x0        public: const unsigned short *_locale_pctype
corecrt.h        -1 0x8        public: int _locale_mb_cur_max
corecrt.h        -1 0xc        public: unsigned int _locale_lc_codepage
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
===========================================================================
struct __crt_locale_pointers
SIZE: 16 FILE: corecrt.h LINE: -1
List of member variables --------------------------------------------------
corecrt.h        -1 0x0        public: struct __crt_locale_data *locinfo
corecrt.h        -1 0x8        public: struct __crt_multibyte_data *mbcinfo
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
===========================================================================
Forwarded struct __crt_locale_data
SIZE: n/a FILE: corecrt.h LINE: -1
===========================================================================
Forwarded struct __crt_multibyte_data
SIZE: n/a FILE: corecrt.h LINE: -1
===========================================================================
struct _Mbstatet
SIZE: 8 FILE: corecrt.h LINE: -1
List of member variables --------------------------------------------------
corecrt.h        -1 0x0        public: unsigned long _Wchar
corecrt.h        -1 0x4        public: unsigned short _Byte
corecrt.h        -1 0x6        public: unsigned short _State
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
===========================================================================
struct std::nothrow_t
SIZE: 1 FILE: vcruntime_new.h LINE: -1
List of member variables --------------------------------------------------
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
(compiled)     (NA):(NA) 0 public: explicit nothrow_t();
===========================================================================
Forwarded struct _CrtMemBlockHeader
SIZE: n/a FILE: crtdbg.h LINE: -1
===========================================================================
struct _CrtMemState
SIZE: 104 FILE: crtdbg.h LINE: -1
List of member variables --------------------------------------------------
crtdbg.h         -1 0x0        public: struct _CrtMemBlockHeader *pBlockHeader
crtdbg.h         -1 0x8        public: size_t lCounts[5]
crtdbg.h         -1 0x30       public: size_t lSizes[5]
crtdbg.h         -1 0x58       public: size_t lHighWaterCount
crtdbg.h         -1 0x60       public: size_t lTotalCount
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
===========================================================================
class std::_Lockit
SIZE: 4 FILE: yvals.h LINE: -1
List of member variables --------------------------------------------------
yvals.h          -1 0x0        private: int _Locktype
List of member functions :---------------------------------------------------
filename     line:size busy function type and name
Assertion failed: isa<FunctionType>(type) == true && "AppendConstructorSignature, ctorDecl->getType is not a FunctionType", file C:\build\ws\BUILDTYPE\Release\LABEL\windows64\V\6-26\root\interpreter\cling\lib\MetaProcessor\Display.cpp, line 233

It kind of looks like it is picking up the wrong class and then things become weird very fast. This happens for any value I pass as classname (e.g. .Class 42foo - bar). Should I report this to the Root project (and if so, where)?

wlav commented 2 years ago

Just a note that I'm not ignoring this, I'm just swamped at the moment (paper deadline).

N-Coder commented 2 years ago

Hey, hopefully your paper went well! Could you take another look at this? This is the only thing keeping me from a doing a release and I'm pretty much stuck trying to debug this myself, so at least a pointer towards a way of fixing this would be awesome. ;)

wlav commented 2 years ago

Yes, won best paper award. :) Just back from the conference, but got the C there. :/ Recovering and only just coming back online. Have to revive my Windows machine, though, then may know more, as I don't see it crashing on Linux.

N-Coder commented 2 years ago

I just rebuilt the cppyy stack from source on my Windows machine to see whether I could get any more info out of this. Setting build mode to Debug here didn't work for cppyy-cling, so I stuck with RelWithDebInfo. The stacktrace now looks a little bit different, with llvm::DenseMap<...>::init() replacing setValueWithAlloc() as repeated topmost frame. Unfortunately, debug info is still missing for those frames. Do you know how to get debuginfo on the missing frames?

Code ```python import cppyy cppyy.cppdef(""" namespace mynamespace { template class Foo { public: void bar(Foo A); }; template void Foo::bar(Foo A) { } } """) from cppyy.gbl import mynamespace print(dir(mynamespace)) ```
Stacktrace ``` "C:\Program Files\Python310\python.exe" C:/Users/Niko/Documents/Projects/ogdf-wheel/win-cling-crash.py :14:9: warning: '__CLING__MSVC__' macro redefined [-Wmacro-redefined] #define __CLING__MSVC__ 1932 ^ :437:9: note: previous definition is here #define __CLING__MSVC__ 1915 ^ ========================================== =============== STACKTRACE =============== ========================================== ================ Thread 0 ================ libCling!llvm::DenseMap,llvm::detail::DenseMapPair >::init() libCling!llvm::DenseMap,llvm::detail::DenseMapPair >::init() libCling!llvm::DenseMap,llvm::detail::DenseMapPair >::init() libCling!llvm::DenseMap,llvm::detail::DenseMapPair >::init() libCling!llvm::DenseMap,llvm::detail::DenseMapPair >::init() libCling!llvm::DenseMap,llvm::detail::DenseMapPair >::init() libCling!clang::MangleContext::mangleName() libCling!cling::utils::Analyze::maybeMangleDeclName() C:\Users\Niko\Documents\Projects\cppyy-backend\cling\src\core\metacling\src\TClingMethodInfo.cxx(679): CppyyLegacy::TClingMethodInfo::GetMangledName() C:\Users\Niko\Documents\Projects\cppyy-backend\cling\src\core\metacling\src\TCling.cxx(8371): CppyyLegacy::TCling::MethodInfo_GetMangledName() C:\Users\Niko\Documents\Projects\cppyy-backend\cling\src\core\meta\src\TFunction.cxx(44): CppyyLegacy::TFunction::TFunction() C:\Users\Niko\Documents\Projects\cppyy-backend\cling\src\core\meta\src\TMethod.cxx(37): CppyyLegacy::TMethod::TMethod() C:\Users\Niko\Documents\Projects\cppyy-backend\cling\src\core\meta\src\TListOfFunctions.cxx(304): CppyyLegacy::TListOfFunctions::Get() C:\Users\Niko\Documents\Projects\cppyy-backend\cling\src\core\meta\src\TListOfFunctions.cxx(398): CppyyLegacy::TListOfFunctions::Load() C:\Users\Niko\Documents\Projects\cppyy-backend\cling\src\core\meta\src\TClass.cxx(2885): CppyyLegacy::TClass::GetListOfMethods() libcppyy_backend!Cppyy::GetAllCppNames() libcppyy.cp310-win_amd64!CPyCppyy::PyException::operator=() python310!PyObject_GC_Malloc() python310!PyArg_NoPositional() python310!PyArg_NoPositional() python310!PyArg_NoPositional() python310!PyType_IsSubtype() python310!PyEval_EvalFrameDefault() python310!PyMapping_Check() python310!PyEval_EvalCode() python310!PyArena_Free() python310!PyArena_Free() python310!PyRun_SimpleFileObject() python310!PyRun_SimpleFileObject() python310!PyRun_AnyFileObject() python310!PyPreConfig_InitIsolatedConfig() python310!PyPreConfig_InitIsolatedConfig() python310!Py_RunMain() python310!Py_RunMain() python310!Py_Main() python!?? KERNEL32!BaseThreadInitThunk() ntdll!RtlUserThreadStart() ================ Thread 1 ================ ntdll!ZwWaitForWorkViaWorkerFactory() ntdll!TpReleaseCleanupGroupMembers() KERNEL32!BaseThreadInitThunk() ntdll!RtlUserThreadStart() ================ Thread 2 ================ ntdll!ZwWaitForWorkViaWorkerFactory() ntdll!TpReleaseCleanupGroupMembers() KERNEL32!BaseThreadInitThunk() ntdll!RtlUserThreadStart() ================ Thread 3 ================ ntdll!ZwWaitForWorkViaWorkerFactory() ntdll!TpReleaseCleanupGroupMembers() KERNEL32!BaseThreadInitThunk() ntdll!RtlUserThreadStart() ========================================== ============= END STACKTRACE ============= ========================================== Process finished with exit code -2147483645 ```
N-Coder commented 2 years ago

Sorry for spamming in this issue, but I really tried hard to resolve this on my own while documenting my steps here. Unfortunately, this issue still prevents my library from being used on windows, which greatly reduces its usefullness to a broader audience, and it seems that I'm really unable to resolve this on my own. :(

My last attempt was to get just a tiny bit of more information out of the stack trace by trying to get actual debug builds of cppyy + its dependencies. The few changes I made to the cmake build are shown here. While the build process works, trying to load cppyy then fails with the following error, which I can't really make sense of. I don't know what else to try here to debug this and get windows support working, so I'm kind of giving up on this...

>>> import cppyy
Traceback (most recent call last):
  File "C:\Users\Niko\AppData\Roaming\Python\Python310\site-packages\cppyy_backend\loader.py", line 57, in _load_helper
    return ctypes.CDLL(os.path.join(pkgpath, 'lib', bkname), ctypes.RTLD_GLOBAL), errors
  File "C:\Program Files\Python310\lib\ctypes\__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 1114] A dynamic link library (DLL) initialization routine failed
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Niko\AppData\Roaming\Python\Python310\site-packages\cppyy\__init__.py", line 80, in <module>
    from ._cpython_cppyy import *
  File "C:\Users\Niko\AppData\Roaming\Python\Python310\site-packages\cppyy\_cpython_cppyy.py", line 21, in <module>
    c = loader.load_cpp_backend()
  File "C:\Users\Niko\AppData\Roaming\Python\Python310\site-packages\cppyy_backend\loader.py", line 92, in load_cpp_backend
    raise RuntimeError("could not load cppyy_backend library, details:\n%s" %
RuntimeError: could not load cppyy_backend library, details:
  Could not find module 'libcppyy_backend.cp310-win_amd64.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
  [WinError 1114] A dynamic link library (DLL) initialization routine failed
  Could not find module 'C:\Users\Niko\AppData\Roaming\Python\Python310\site-packages\cppyy_backend\lib\libcppyy_backend.cp310-win_amd64.pyd' (or one of its dependencies). Try using the full path with constructor syntax.
  Could not find module 'libcppyy_backend.dll' (or one of its dependencies). Try using the full path with constructor syntax.
wlav commented 1 year ago

Cling based on Clang9 can no longer parse the STL headers that ship with the latest MSVC (there was a macro that could be defined as a workaround, but this has been removed). Upstream has just finished Cling based on Clang13, so I hope to move soon. That will be necessary to run on Windows with the latest MSVC and also hopefully fix this issue.

N-Coder commented 1 year ago

Unfortunately, the CPyCppyy::PyException::operator= crash with the simple code from here ist still happening with cppyy 3.1.2 on Windows.