Removing a TopDUContext

Jonathan Verner jonathan at
Sat May 4 21:25:28 BST 2019


I have a probably stupid question... I am slowly getting to the point where my experimental C# plugin becomes usable. However, right now KDevelop crashes on me whenever I close an open file. The crash happens on line 1493 in duchain.cpp in the documentClosed method...  There, kdevelop iterates over m_openDocumentContexts and, if the match the url of the document to be closed, they are removed... It seems that one of these context pointers is no longer valid. Now my theory is that this is due to the way I handle constructing the DU Chain.  What I do is I always construct a DU Chain from scratch. If a DUChain is already available for the document, I remove it first using:


However, this seems not to remove it from the m_openDocumentContexts list and later leads to a crash (that is my theory, at least---supported by the crashes disappearing when I comment out the removeDocumentChain call :-)).  So my question is: How do I dispose of the old DU Chain? Or do I just reuse the TopDUContetx? Doesn't that clutter up memory with old declarations/uses/contexts and interfere with code navigation?

Currently my code looks like this (

328    DUChainWriteLocker lock( DUChain::lock() );
330   /* If there was a DU chain for the document, remove it first */
331    m_top_context = DUChainUtils::standardContextForUrl(m_url.toUrl());
334    if (m_top_context) {
335        qCDebug(PLUGIN_DUSERVER) << "Removing top DU Chain";
336       DUChain::self()->removeDocumentChain(m_top_context);
337    }
339    /* Create a new top DU chain for the document */
340    ParsingEnvironmentFile* file = new ParsingEnvironmentFile(m_url);
341    //     file->setLanguage(DUServerLang::languageString());
342    m_top_context = new TopDUContext(m_url, RangeInRevision( CursorInRevision( 0, 0 ), CursorInRevision( INT_MAX, INT_MAX ) ), file);
343    m_top_context->setType( DUContext::Global );
345    /* Register the DU chain */
346    DUChain::self()->addDocumentChain( m_top_context );
348    /* Build the DU chain */
349    for(const TreeNode &node: m_root->children())
350        build(node, m_top_context);
352    build_uses();
354    return m_top_context;

So I guess the code on 336 should be replaced with something else... Perhaps the whole condition on 334 should be inverted and the construction
of the new TopDUContext on line 342 and following be moved inside?



Jonathan Verner, PhD
Department of Logic, Charles University
Palachovo nám. 2, 116 38 Praha 1
Czech Republic

More information about the KDevelop-devel mailing list