Very strange crash when the DUChain is cleaned up

Denis Steckelmacher steckdenis at yahoo.fr
Fri Aug 1 12:58:53 UTC 2014


Hi,

As suggested several days ago by Milian on IRC, I'm changing how 
function contexts are handled in the QML/JS language plugin. The 
structure that I try to use looks like the one used by Clang: the 
internal context of a function declaration contains its parameters and 
two sub-contexts: the one of the body (type Other) and the prototype 
context (that contains the "class members" of the function, type 
Function). The prototype context is also put in internalFunctionContext, 
the reason is given in duchain/functiondeclaration.h (in 
kde:scratch/dsteckelmacher/kdev-qmljs.git, branch "wip").

This new structure allowed me to simplify some parts of the plugin, and 
I have managed to make all the unit tests pass. The problem is that I 
now have a very strange crash that happens under very precise 
circumstances. I have attached a backtrace to this email, so that 
someone who better knows the internals of DUChain can have a look at it.

What happens is that the testsuite passes, then KDevelop frees all the 
memory used by the DUChain. At the very end of this process, the 
contexts and declarations are deleted, and this crash happens. I've put 
debug statements everywhere and I've verified that each context is 
deleted only once (no ~DUContext gets called more than once) and each 
declaration is also deleted only once. So, this crash does not seem to 
be caused by a duplicate deletion of something.

The crash can be reproduced by building my wip branch of kdev-qmljs, 
then running "./tests/filetest" in the build directory. What is very 
strange is that launching the tests one at a time does not cause any 
crash: "./tests/filetest testQMLCustomComponent" then "testNodeJS" then 
"testJSUsesBetweenFiles" and finally "testFiles" works flawlessly.

So, something wrong seems to be happening, and I have absolutely no 
idea. I'm fighting this bug for nearly three days and I've not found any 
solution. The only think that I may have discovered is that this bug is 
very complex and seems to be timing-related: when run as a whole, the 
testsuite sometimes fails, sometimes not (but always crashes at the 
end). When the tests are run independently, they all always pass. 
Helgrind procudes thousands of races (most of them in Qt, QMutex and 
DUChain::shouldUseReferenceCounting or something like that, none in 
kdev-qmljs), and Memcheck does not detect any bad memory access. I'm on 
IRC if you want more details.

Note: the crash happens only with my latest commit (of "wip") applied, 
but the random failure of the tests was already there for some time.

Thanks for any idea!
Denis
-------------- next part --------------
#0  0x00007ffff3546849 in raise () from /lib64/libc.so.6
#1  0x00007ffff3547cd8 in abort () from /lib64/libc.so.6
#2  0x00007ffff77424f4 in qt_message_output(QtMsgType, char const*) () from /usr/lib64/libQtCore.so.4
#3  0x00007ffff7742679 in ?? () from /usr/lib64/libQtCore.so.4
#4  0x00007ffff7742e84 in qFatal(char const*, ...) () from /usr/lib64/libQtCore.so.4
#5  0x00007ffff7742eca in qt_assert(char const*, char const*, int) () from /usr/lib64/libQtCore.so.4
#6  0x00007ffff724b92c in KDevelop::ItemRepository<KDevelop::IdentifierPrivate<false>, KDevelop::IdentifierItemRequest, true, true, 0u, 1048576u>::itemFromIndex (this=
    0x563100, index=13631488) at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/repositories/itemrepository.h:1656
#7  0x00007ffff7245892 in KDevelop::Identifier::Identifier (this=0x7fffffffc360, index=13631488)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/identifier.cpp:361
#8  0x00007ffff724972e in KDevelop::IndexedIdentifier::operator KDevelop::Identifier (this=0x2430964)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/identifier.cpp:1399
#9  0x00007ffff724e12b in KDevelop::QualifiedIdentifierPrivate<true>::hash (this=0x2310150)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/identifier.cpp:260
#10 0x00007ffff724d384 in KDevelop::QualifiedIdentifierItemRequest::QualifiedIdentifierItemRequest (this=0x7fffffffc3f0, identifier=...)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/identifier.cpp:277
#11 0x00007ffff7247187 in KDevelop::QualifiedIdentifier::makeConstant (this=0x7fffffffc560)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/identifier.cpp:1118
#12 0x00007ffff72470f9 in KDevelop::QualifiedIdentifier::index (this=0x7fffffffc560)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/identifier.cpp:616
#13 0x00007ffff724ad41 in KDevelop::IndexedQualifiedIdentifier::IndexedQualifiedIdentifier (this=0x7fffffffc558, id=...)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/identifier.cpp:1440
#14 0x00007ffff7226c38 in KDevelop::Declaration::~Declaration (this=0x7fffc8b30f20)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/declaration.cpp:179
#15 0x00007ffff7238205 in KDevelop::ClassMemberDeclaration::~ClassMemberDeclaration (this=0x7fffc8b30f20)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/classmemberdeclaration.cpp:89
#16 0x00007ffff72381d9 in KDevelop::ClassMemberDeclaration::~ClassMemberDeclaration (this=0x7fffc8b30f20)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/classmemberdeclaration.cpp:88
#17 0x00007ffff71e087c in KDevelop::DUContext::deleteLocalDeclarations (this=0x7fffc8b2fdb0)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/ducontext.cpp:1063
#18 0x00007ffff71dff5c in KDevelop::DUContext::~DUContext (this=0x7fffc8b2fdb0)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/ducontext.cpp:498
#19 0x00007ffff7f1f9c5 in QmlJS::QmlJSDUContext<KDevelop::DUContext, 111>::~QmlJSDUContext (this=0x7fffc8b2fdb0)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/duchain/qmljsducontext.h:40
#20 0x00007ffff7f1f9e9 in QmlJS::QmlJSDUContext<KDevelop::DUContext, 111>::~QmlJSDUContext (this=0x7fffc8b2fdb0)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/duchain/qmljsducontext.h:40
#21 0x00007ffff71e0467 in KDevelop::DUContext::deleteChildContextsRecursively (this=0x7fffc876f480)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/ducontext.cpp:1080
#22 0x00007ffff71dfea5 in KDevelop::DUContext::~DUContext (this=0x7fffc876f480)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/ducontext.cpp:493
#23 0x00007ffff7f1f9c5 in QmlJS::QmlJSDUContext<KDevelop::DUContext, 111>::~QmlJSDUContext (this=0x7fffc876f480)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/duchain/qmljsducontext.h:40
#24 0x00007ffff7f1f9e9 in QmlJS::QmlJSDUContext<KDevelop::DUContext, 111>::~QmlJSDUContext (this=0x7fffc876f480)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/duchain/qmljsducontext.h:40
#25 0x00007ffff71e0467 in KDevelop::DUContext::deleteChildContextsRecursively (this=0x7fffc86c1710)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/ducontext.cpp:1080
#26 0x00007ffff7204b89 in KDevelop::TopDUContext::~TopDUContext (this=0x7fffc86c1710)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/topducontext.cpp:566
#27 0x00007ffff7f1fa35 in QmlJS::QmlJSDUContext<KDevelop::TopDUContext, 110>::~QmlJSDUContext (this=0x7fffc86c1710)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/duchain/qmljsducontext.h:40
#28 0x00007ffff7f1fa59 in QmlJS::QmlJSDUContext<KDevelop::TopDUContext, 110>::~QmlJSDUContext (this=0x7fffc86c1710)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/duchain/qmljsducontext.h:40
#29 0x00007ffff7204ed5 in KDevelop::TopDUContext::deleteSelf (this=0x7fffc86c1710)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/topducontext.cpp:578
#30 0x00007ffff71b101e in KDevelop::DUChainPrivate::removeDocumentChainFromMemory (this=0x1071690, context=0x7fffc86c1710)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/duchain.cpp:409
#31 0x00007ffff71b629e in KDevelop::DUChainPrivate::clear (this=0x1071690)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/duchain.cpp:372
#32 0x00007ffff71ae2cd in KDevelop::DUChain::shutdown (this=0x1072e10)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/language/duchain/duchain.cpp:1586
#33 0x00007ffff6f75039 in KDevelop::Core::cleanup (this=0x5946d0) at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/shell/core.cpp:416
#34 0x00007ffff6f74e4e in KDevelop::Core::shutdown (this=0x5946d0) at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/shell/core.cpp:377
#35 0x00007ffff7f98a3c in KDevelop::TestCore::shutdown () at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdevplatform/tests/testcore.cpp:89
#36 0x000000000040a811 in TestFiles::cleanupTestCase (this=0x7fffffffd700)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/tests/test_files.cpp:57
#37 0x000000000040b41b in TestFiles::qt_static_metacall (_o=0x7fffffffd700, _c=QMetaObject::InvokeMetaMethod, _id=1, _a=0x7fffffffd430)
    at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/build/tests/test_files.moc:58
#38 0x00007ffff7856ae8 in QMetaMethod::invoke(QObject*, Qt::ConnectionType, QGenericReturnArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument, QGenericArgument) const () from /usr/lib64/libQtCore.so.4
#39 0x00007ffff7bc020e in ?? () from /usr/lib64/libQtTest.so.4
#40 0x00007ffff7bc3dc6 in QTest::qExec(QObject*, int, char**) () from /usr/lib64/libQtTest.so.4
#41 0x000000000040a3cd in main (argc=1, argv=0x7fffffffd928) at /run/media/steckdenis/22bf9818-cf8f-40f9-948d-9ab473a158c2/kdev-qmljs/tests/test_files.cpp:44


More information about the KDevelop-devel mailing list