Bug 486932 - Crash when adding an #include statement during normal editing
Summary: Crash when adding an #include statement during normal editing
Status: CONFIRMED
Alias: None
Product: kdevelop
Classification: Applications
Component: Code completion (show other bugs)
Version: git master
Platform: Arch Linux Linux
: HI crash
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
: 487378 487674 493533 495546 498754 500089 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-05-12 21:02 UTC by JATothrim
Modified: 2025-02-16 19:38 UTC (History)
8 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description JATothrim 2024-05-12 21:02:47 UTC
SUMMARY
Thread 20 "KDevelop::Compl" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff99c006c0 (LWP 21210)]
0x00007fff9ac124a3 in ?? () from /usr/lib/libclang.so.17
(gdb) bt
#0  0x00007fff9ac124a3 in ??? () at /usr/lib/libclang.so.17
#1  0x00007fff9a223356 in ??? () at /usr/lib/libclang.so.17
#2  0x00007fff9a223d0d in ??? () at /usr/lib/libclang.so.17
#3  0x00007fff9a2249d3 in ??? () at /usr/lib/libclang.so.17
#4  0x00007fff9a225b94 in ??? () at /usr/lib/libclang.so.17
#5  0x00007fff99eaf2ac in clang_Location_isInSystemHeader () at /usr/lib/libclang.so.17
#6  0x00007fffac151251 in ??? () at /usr/lib/libKDevClangPrivate.so.515
#7  0x00007fff99e6c65e in ??? () at /usr/lib/libclang.so.17
#8  0x00007fff99e6df56 in ??? () at /usr/lib/libclang.so.17
#9  0x00007fff99e6e208 in ??? () at /usr/lib/libclang.so.17
#10 0x00007fff99e6b9be in ??? () at /usr/lib/libclang.so.17
#11 0x00007fff99e6eba0 in clang_visitChildren () at /usr/lib/libclang.so.17
#12 0x00007fffac152b8d in ??? () at /usr/lib/libKDevClangPrivate.so.515
#13 0x00007fffac15d2f8 in ClangCodeCompletionContext::ClangCodeCompletionContext(KDevelop::DUChainPointer<KDevelop::DUContext> const&, QExplicitlySharedDataPointer<ParseSessionData> const&, QUrl const&, KTextEditor::Cursor const&, QString const&, QString const&) () at /usr/lib/libKDevClangPrivate.so.515
#14 0x00007fffac16919c in ??? () at /usr/lib/libKDevClangPrivate.so.515
#15 0x00007ffff62c89a7 in ??? () at /usr/lib/libQt5Core.so.5
#16 0x00007ffff62ca4df in QTimer::timeout(QTimer::QPrivateSignal) () at /usr/lib/libQt5Core.so.5
#17 0x00007ffff62bb44e in QObject::event(QEvent*) () at /usr/lib/libQt5Core.so.5
#18 0x00007ffff6f578ff in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#19 0x00007ffff6293a68 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#20 0x00007ffff62e20db in QTimerInfoList::activateTimers() () at /usr/lib/libQt5Core.so.5
#21 0x00007ffff62e26ca in ??? () at /usr/lib/libQt5Core.so.5
#22 0x00007ffff224d199 in ??? () at /usr/lib/libglib-2.0.so.0
#23 0x00007ffff22ac3bf in ??? () at /usr/lib/libglib-2.0.so.0
#24 0x00007ffff224c712 in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#25 0x00007ffff62e288c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#26 0x00007ffff6292774 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#27 0x00007ffff60ef666 in QThread::exec() () at /usr/lib/libQt5Core.so.5
#28 0x00007ffff60eb88a in ??? () at /usr/lib/libQt5Core.so.5
#29 0x00007ffff5aaa1cf in ??? () at /usr/lib/libc.so.6
#30 0x00007ffff5b2b6ec in ??? () at /usr/lib/libc.so.6

STEPS TO REPRODUCE
1.  Open a project and let its parsing complete.
2.  Type "#include <some header>"
3.  KDevelop crashes before I finish typing the complete line, usually at "#include"

OBSERVED RESULT
A segfault

EXPECTED RESULT
No segfault

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux, Cinnamon DE
KDE Plasma Version: 
KDE Frameworks Version: KDE Frameworks 5.115.0
Qt Version: Versio 5.15.13
KDevelop: git version b5ab8f4435a0fac975f31b4409ca4dae66255349
ADDITIONAL INFORMATION

The parsing must complete before the bug can take place, then it
happens every time. Or at least so often that I'm expecting it.  KDevelop was built from git version b5ab8f4435a0fac975f31b4409ca4dae66255349

I perhaps should prevent the stripping of the debug info out from my production builds... :)
Comment 1 Igor Kushnir 2024-05-13 05:59:33 UTC
I don't find anything like this backtrace in my local collection. Could be a libclang 17 regression (I am still at v16).

> I perhaps should prevent the stripping of the debug info out from my production builds... :)
Yes, please use `options=(!strip)` and `-DCMAKE_BUILD_TYPE=RelWithDebInfo`. Though I suspect the bug is in libclang, in which case libclang debug symbols will be needed.
Comment 2 JATothrim 2024-05-13 10:19:57 UTC
> I don't find anything like this backtrace in my local collection. Could be a libclang 17 regression (I am still at v16).

Well, good then that I opened a bug report for this. I have had KDevelop crashing this way for about a month, and the backtrace is from KDevelop's project (via GDB). I have seen it crash even before completing "#include".

> Yes, please use `options=(!strip)` and `-DCMAKE_BUILD_TYPE=RelWithDebInfo`. 

I think I'll rebuild just to re-produce the bt and try print the locals just before descending into clang code. However, clang would be painful to build in this mode.. last time I did it the install directory was +10GiB o__O

I did have an idea for parser blacklist: if the text line is found from it, the code completion would not be triggered until the typed text is longer than best matching black list entry. This could perhaps allow the user (temporally) dealing with cases where the parser might crash on incomplete code, or just being too annoying.

For example, it doesn't make sense to start trying to suggest anything at "#include " for me, as the next two characters would greatly shrink the possibilities, and even suggesting anything at "#include <" is kind of just irritating.
I know an such blacklist entry would prevent completing the "#include" keyword, but I would like to suppress a such the code completion anyway.
Comment 3 Igor Kushnir 2024-05-13 11:41:39 UTC
(In reply to JATothrim from comment #2)
> I think I'll rebuild just to re-produce the bt and try print the locals just
> before descending into clang code. However, clang would be painful to build
> in this mode.. last time I did it the install directory was +10GiB o__O
Can't you just download Clang debug symbols from Arch's debuginfod?
Comment 4 Igor Kushnir 2024-05-19 16:24:59 UTC
The crash just happened once to me. But I cannot reproduce it. Here is a more detailed backtrace (still no libclang debug symbols):

[KCrash Handler]
#4  0x00007f4d271e2fdb in ??? () at /usr/lib/libclang.so.17
#5  0x00007f4d2644f6f7 in ??? () at /usr/lib/libclang.so.17
#6  0x00007f4d26af5423 in ??? () at /usr/lib/libclang.so.17
#7  0x00007f4d275eb473 in ??? () at /usr/lib/libclang.so.17
#8  0x00007f4d264618f0 in clang_tokenize () at /usr/lib/libclang.so.17
#9  0x00007f4d39396df8 in (anonymous namespace)::isInsideComment (position=<optimized out>, file=0x13, unit=0x7f4d113e1eb0) at kdevelop/plugins/clang/codecompletion/context.cpp:490
#10 ClangCodeCompletionContext::isValidPosition (this=this@entry=0x7f4d20001fc0, unit=0x7f4d113e1eb0, file=file@entry=0x7f4c719a0520) at kdevelop/plugins/clang/codecompletion/context.cpp:1081
#11 0x00007f4d39397b16 in ClangCodeCompletionContext::ClangCodeCompletionContext (this=0x7f4d20001fc0, context=<optimized out>, sessionData=<optimized out>, url=<optimized out>, position=<optimized out>, text=<optimized out>, followingText=<optimized out>, this=<optimized out>, context=<optimized out>, sessionData=<optimized out>, url=<optimized out>, position=<optimized out>, text=<optimized out>, followingText=<optimized out>) at kdevelop/plugins/clang/codecompletion/context.cpp:1067
#12 0x00007f4d393a5160 in QSharedPointer<ClangCodeCompletionContext>::create<KDevelop::DUChainPointer<KDevelop::DUContext> const&, QExplicitlySharedDataPointer<ParseSessionData> const&, QUrl const&, KTextEditor::Cursor const&, QString const&, QString const&> () at /usr/include/qt/QtCore/qsharedpointer_impl.h:444
#13 (anonymous namespace)::createCompletionContext (followingText=..., text=<optimized out>, position=<optimized out>, url=<optimized out>, session=..., context=...) at kdevelop/plugins/clang/codecompletion/model.cpp:48
#14 (anonymous namespace)::ClangCodeCompletionWorker::run (this=0x55817e19a390) at kdevelop/plugins/clang/codecompletion/model.cpp:115
#15 0x00007f4db18c89a7 in ??? () at /usr/lib/libQt5Core.so.5
#16 0x00007f4db18ca4df in QTimer::timeout(QTimer::QPrivateSignal) () at /usr/lib/libQt5Core.so.5
#17 0x00007f4db18bb44e in QObject::event(QEvent*) () at /usr/lib/libQt5Core.so.5
#18 0x00007f4db25578ff in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#19 0x00007f4db1893a68 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#20 0x00007f4db18e20db in QTimerInfoList::activateTimers() () at /usr/lib/libQt5Core.so.5
#21 0x00007f4db18e26ca in ??? () at /usr/lib/libQt5Core.so.5
#22 0x00007f4dad720199 in ??? () at /usr/lib/libglib-2.0.so.0
#23 0x00007f4dad77f3bf in ??? () at /usr/lib/libglib-2.0.so.0
#24 0x00007f4dad71f712 in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#25 0x00007f4db18e288c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#26 0x00007f4db1892774 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#27 0x00007f4db16ef666 in QThread::exec() () at /usr/lib/libQt5Core.so.5
#28 0x00007f4db16eb88a in ??? () at /usr/lib/libQt5Core.so.5
#29 0x00007f4db10aa1cf in ??? () at /usr/lib/libc.so.6
#30 0x00007f4db112b6ec in ??? () at /usr/lib/libc.so.6
Comment 5 Igor Kushnir 2024-05-22 16:16:52 UTC
(In reply to Igor Kushnir from comment #4)
> The crash just happened once to me. But I cannot reproduce it. Here is a
> more detailed backtrace (still no libclang debug symbols):
Managed to obtain a complete backtrace for the single crash that happened on my system. Here are the steps in case I or someone else needs them in the future (they can also be used to examine past core dumps with freshly downloaded KDevelop debug symbols).
1. Download debuginfod debug symbols for libclang:
$ debuginfod-find debuginfo /usr/lib/libclang.so.17
/home/igor/.cache/debuginfod_client/02120dc8526595aac7ab8bc78eca4efc936b09be/debuginfo
2. Trigger the "Run=>Examine Core File=>Examine Core File with GDB" action in KDevelop, select /bin/kdevelop and the crash coredump in the dialog that appears.
3. Activate KDevelop's GDB tool view. All commands in the following steps are entered into the GDB command line edit inside this tool view.
4. At this point the command `thread apply 15 bt` still shows a backtrace without libclang debug symbols. Read and follow the top answer here: https://stackoverflow.com/questions/30281766/need-to-load-debugging-symbols-for-shared-library-in-gdb
5. (gdb) 48info sharedlibrary
From To Syms Read Shared Object Library
...
0x00007f4d26433020 0x00007f4d277c3c54 Yes /usr/lib/libclang.so.17
...
6. (gdb) 49add-symbol-file /home/igor/.cache/debuginfod_client/02120dc8526595aac7ab8bc78eca4efc936b09be/debuginfo 0x00007f4d26433020
add symbol table from file "/home/igor/.cache/debuginfod_client/02120dc8526595aac7ab8bc78eca4efc936b09be/debuginfo" at
.text_addr = 0x7f4d26433020
(y or n) [answered Y; input not from terminal]
Reading symbols from /home/igor/.cache/debuginfod_client/02120dc8526595aac7ab8bc78eca4efc936b09be/debuginfo...
7. (gdb) 50thread apply 15 bt

Thread 15 (Thread 0x7f4d393616c0 (LWP 151298)):
#0 0x00007f4db111d9ed in poll () at /usr/lib/libc.so.6
#1 0x00007f4db31c6bca in ??? () at /usr/lib/libKF5Crash.so.5
#2 0x00007f4db31c782c in KCrash::defaultCrashHandler(int) () at /usr/lib/libKF5Crash.so.5
#3 0x00007f4db1058e20 in <signal handler called> () at /usr/lib/libc.so.6
#4 memcpy () at /usr/include/bits/string_fortified.h:29
#5 llvm::support::endian::read<unsigned int, 0ul> () at /usr/include/llvm/Support/Endian.h:66
#6 llvm::support::endian::readNext<unsigned int, 0ul, unsigned char> () at /usr/include/llvm/Support/Endian.h:84
#7 llvm::support::endian::readNext<unsigned int, (llvm::support::endianness)1, 0ul, unsigned char> () at /usr/include/llvm/Support/Endian.h:92
#8 llvm::OnDiskChainedHashTable<clang::serialization::reader::ASTIdentifierLookupTrait>::find_hashed () at /usr/include/llvm/Support/OnDiskHashTable.h:360
#9 operator() () at /usr/src/debug/clang/clang-17.0.6.src/lib/Serialization/ASTReader.cpp:2103
#10 clang::ASTReader::get () at /usr/src/debug/clang/clang-17.0.6.src/lib/Serialization/ASTReader.cpp:8174
#11 0x00007f4d2644f6f7 in clang::IdentifierTable::get () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/IdentifierTable.h:647
#12 0x00007f4d26af5423 in clang::Preprocessor::getIdentifierInfo () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Lex/Preprocessor.h:1516
#13 clang::Preprocessor::LookUpIdentifierInfo () at /usr/src/debug/clang/clang-17.0.6.src/lib/Lex/Preprocessor.cpp:715
#14 0x00007f4d275eb473 in getTokens(clang::ASTUnit*, clang::SourceRange, llvm::SmallVectorImpl<CXToken>&) [clone .constprop.0] () at /usr/src/debug/clang/clang-17.0.6.src/tools/libclang/CIndex.cpp:7248
#15 0x00007f4d264618f0 in clang_tokenize () at /usr/src/debug/clang/clang-17.0.6.src/tools/libclang/CIndex.cpp:7330
#16 0x00007f4d39396df8 in (anonymous namespace)::isInsideComment (position=<optimized out>, file=0x13, unit=0x7f4d113e1eb0) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/context.cpp:490
#17 ClangCodeCompletionContext::isValidPosition (this=this@entry=0x7f4d20001fc0, unit=0x7f4d113e1eb0, file=file@entry=0x7f4c719a0520) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/context.cpp:1081
#18 0x00007f4d39397b16 in ClangCodeCompletionContext::ClangCodeCompletionContext (this=0x7f4d20001fc0, context=<optimized out>, sessionData=<optimized out>, url=<optimized out>, position=<optimized out>, text=<optimized out>, followingText=<optimized out>, this=<optimized out>, context=<optimized out>, sessionData=<optimized out>, url=<optimized out>, position=<optimized out>, text=<optimized out>, followingText=<optimized out>) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/context.cpp:1067
#19 0x00007f4d393a5160 in QSharedPointer<ClangCodeCompletionContext>::create<KDevelop::DUChainPointer<KDevelop::DUContext> const&, QExplicitlySharedDataPointer<ParseSessionData> const&, QUrl const&, KTextEditor::Cursor const&, QString const&, QString const&> () at /usr/include/qt/QtCore/qsharedpointer_impl.h:444
#20 (anonymous namespace)::createCompletionContext (followingText="i\n#include \"ui_qthelpconfig.h\"\n#include \"ui_qthelpconfigeditdialog.h\"\n#include \"qthelp_config_shared.h\"\n#include \"debug.h\"\n#include \"qthelpplugin.h\"\n\nenum Column\n{\n NameColumn,\n PathColumn,\n "..., text=<optimized out>, position=<optimized out>, url=<optimized out>, session=..., context=...) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/model.cpp:48
#21 (anonymous namespace)::ClangCodeCompletionWorker::run (this=0x55817e19a390) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/model.cpp:115
#22 0x00007f4db18c89a7 in ??? () at /usr/lib/libQt5Core.so.5
#23 0x00007f4db18ca4df in QTimer::timeout(QTimer::QPrivateSignal) () at /usr/lib/libQt5Core.so.5
#24 0x00007f4db18bb44e in QObject::event(QEvent*) () at /usr/lib/libQt5Core.so.5
#25 0x00007f4db25578ff in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#26 0x00007f4db1893a68 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#27 0x00007f4db18e20db in QTimerInfoList::activateTimers() () at /usr/lib/libQt5Core.so.5
#28 0x00007f4db18e26ca in ??? () at /usr/lib/libQt5Core.so.5
#29 0x00007f4dad720199 in ??? () at /usr/lib/libglib-2.0.so.0
#30 0x00007f4dad77f3bf in ??? () at /usr/lib/libglib-2.0.so.0
#31 0x00007f4dad71f712 in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#32 0x00007f4db18e288c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#33 0x00007f4db1892774 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#34 0x00007f4db16ef666 in QThread::exec() () at /usr/lib/libQt5Core.so.5
#35 0x00007f4db16eb88a in ??? () at /usr/lib/libQt5Core.so.5
#36 0x00007f4db10aa1cf in ??? () at /usr/lib/libc.so.6
#37 0x00007f4db112b6ec in ??? () at /usr/lib/libc.so.6

--------------
Now we need to analyze the libclang backtrace and try to figure out the bug.
Comment 6 Igor Kushnir 2024-05-22 16:47:34 UTC
My previous comment missed preliminary coredumpctl steps:
0.1. coredumpctl list kdevelop --since 2024-05-19.
0.2. Locate the necessary entry in the printed table and show its details via `coredumpctl info 151255` (where 151255 is the PID of the entry).
0.3. Find the Storage line in the info output, e.g. "Storage: /var/lib/systemd/coredump/core.kdevelop.1000.df23a15637fe47fbae399826251ac233.151255.1716133189000000.zst (present)" and extract the .zst archive to obtain the actual debuggable core dump file.

Oh, and after these steps KDevelop's Frame Stack tool view also shows the backtrace with debug symbols. libclang headers can be opened and examined from the IDE right away. To examine libclang source files as well:
8. Download clang sources. I got the clang repository already, so just `git fetch origin` and `git checkout llvmorg-17.0.6` to match my system clang package version.
9. In the GDB tool view: set substitute-path /usr/src/debug/clang/clang-17.0.6.src /path/to/llvm-project/clang
10. Activate the Frame Stack tool view and switch to another thread, then back, to open libclang source files by clicking their lines in the backtrace.
Comment 7 Igor Kushnir 2024-05-28 09:31:16 UTC
*** Bug 487378 has been marked as a duplicate of this bug. ***
Comment 8 Igor Kushnir 2024-05-28 09:34:03 UTC
*** Bug 487674 has been marked as a duplicate of this bug. ***
Comment 9 Igor Kushnir 2024-05-30 13:04:54 UTC
Got another crash while completing an include. This time the first thread crashed and its backtrace matches the more common one in this and duplicate bug reports:
#0 0x00007f87588ac194 in ??? () at /usr/lib/libc.so.6
#1 0x00007f8758858d70 in raise () at /usr/lib/libc.so.6
#2 0x00007f875aaef88f in KCrash::defaultCrashHandler(int) () at /usr/lib/libKF5Crash.so.5
#3 0x00007f8758858e20 in <signal handler called> () at /usr/lib/libc.so.6
#4 clang::ASTReader::ReadSLocEntry () at /usr/src/debug/clang/clang-17.0.6.src/lib/Serialization/ASTReader.cpp:1497
#5 0x00007f86d1623356 in clang::ASTReader::ReadSLocEntry () at /usr/src/debug/clang/clang-17.0.6.src/lib/Serialization/ASTReader.cpp:1436
#6 clang::SourceManager::loadSLocEntry () at /usr/src/debug/clang/clang-17.0.6.src/lib/Basic/SourceManager.cpp:435
#7 0x00007f86d1251c31 in clang::SourceManager::getLoadedSLocEntry () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/SourceManager.h:1718
#8 clang::SourceManager::getLoadedSLocEntryByID () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/SourceManager.h:1822
#9 clang::SourceManager::getSLocEntryByID () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/SourceManager.h:1816
#10 clang::SourceManager::isOffsetInFileID () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/SourceManager.h:1866
#11 0x00007f86d1623eec in clang::SourceManager::getFileIDLoaded () at /usr/src/debug/clang/clang-17.0.6.src/lib/Basic/SourceManager.cpp:922
#12 clang::SourceManager::getFileIDLoaded () at /usr/src/debug/clang/clang-17.0.6.src/lib/Basic/SourceManager.cpp:866
#13 clang::SourceManager::getFileIDSlow () at /usr/src/debug/clang/clang-17.0.6.src/lib/Basic/SourceManager.cpp:779
#14 clang::SourceManager::getFileIDSlow () at /usr/src/debug/clang/clang-17.0.6.src/lib/Basic/SourceManager.cpp:771
#15 0x00007f86d1251e6b in clang::SourceManager::getFileID () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/SourceManager.h:1830
#16 clang::SourceManager::getFileID () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/SourceManager.h:1119
#17 clang::SourceManager::getDecomposedExpansionLoc () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/SourceManager.h:1259
#18 0x00007f86d1625b94 in clang::SourceManager::getFileCharacteristic () at /usr/src/debug/clang/clang-17.0.6.src/lib/Basic/SourceManager.cpp:1477
#19 0x00007f86d12af2ac in clang::SourceManager::isInSystemHeader () at /usr/src/debug/clang/clang-17.0.6.src/include/clang/Basic/SourceManager.h:1509
#20 clang_Location_isInSystemHeader () at /usr/src/debug/clang/clang-17.0.6.src/tools/libclang/CXSourceLocation.cpp:209
#21 0x00007f86d2e2a6e4 in (anonymous namespace)::declVisitor (cursor=..., parent=..., d=0x7f86d11fded0) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/completionhelper.cpp:224
#22 0x00007f86d126c65e in clang::cxcursor::CursorVisitor::Visit () at /usr/src/debug/clang/clang-17.0.6.src/tools/libclang/CIndex.cpp:224
#23 0x00007f86d126df56 in clang::cxcursor::CursorVisitor::handleDeclForVisitation () at /usr/src/debug/clang/clang-17.0.6.src/tools/libclang/CIndex.cpp:686
#24 0x00007f86d126e208 in clang::cxcursor::CursorVisitor::VisitDeclContext () at /usr/src/debug/clang/clang-17.0.6.src/tools/libclang/CIndex.cpp:647
#25 0x00007f86d126b9be in clang::cxcursor::CursorVisitor::VisitChildren () at /usr/src/debug/clang/clang-17.0.6.src/tools/libclang/CIndex.cpp:547
#26 0x00007f86d126eba0 in clang_visitChildren () at /usr/src/debug/clang/clang-17.0.6.src/tools/libclang/CIndex.cpp:4842
#27 0x00007f86d2e2e023 in CompletionHelper::computeCompletions (position=<optimized out>, file=<optimized out>, session=..., this=<optimized out>) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/completionhelper.cpp:394
#28 ClangCodeCompletionContext::ClangCodeCompletionContext (this=<optimized out>, context=<optimized out>, sessionData=<optimized out>, url=<optimized out>, position=<optimized out>, text=<optimized out>, followingText=<optimized out>, this=<optimized out>, context=<optimized out>, sessionData=<optimized out>, url=<optimized out>, position=<optimized out>, text=<optimized out>, followingText=<optimized out>) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/context.cpp:1072
#29 0x00007f86d2e3b160 in QSharedPointer<ClangCodeCompletionContext>::create<KDevelop::DUChainPointer<KDevelop::DUContext> const&, QExplicitlySharedDataPointer<ParseSessionData> const&, QUrl const&, KTextEditor::Cursor const&, QString const&, QString const&> () at /usr/include/qt/QtCore/qsharedpointer_impl.h:444
#30 (anonymous namespace)::createCompletionContext (followingText="inc\n#include <utility>\n\nnamespace KDevelop\n{\nQDebug operator<<(QDebug debug, const StatusBar::Message& s)\n{\n const QDebugStateSaver saver(debug);\n debug.nospace() << '{' << s.text << \", \" << s.t"..., text=<optimized out>, position=<optimized out>, url=<optimized out>, session=..., context=...) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/model.cpp:48
#31 (anonymous namespace)::ClangCodeCompletionWorker::run (this=0x562b9620f040) at /home/Mint14_home/igor/Install/abs/kdevelop-git/src/kdevelop/plugins/clang/codecompletion/model.cpp:115
#32 0x00007f87590c89a7 in ??? () at /usr/lib/libQt5Core.so.5
#33 0x00007f87590ca4df in QTimer::timeout(QTimer::QPrivateSignal) () at /usr/lib/libQt5Core.so.5
#34 0x00007f87590bb44e in QObject::event(QEvent*) () at /usr/lib/libQt5Core.so.5
#35 0x00007f8759d578ff in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /usr/lib/libQt5Widgets.so.5
#36 0x00007f8759093a68 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /usr/lib/libQt5Core.so.5
#37 0x00007f87590e20db in QTimerInfoList::activateTimers() () at /usr/lib/libQt5Core.so.5
#38 0x00007f87590e26ca in ??? () at /usr/lib/libQt5Core.so.5
#39 0x00007f875504d199 in ??? () at /usr/lib/libglib-2.0.so.0
#40 0x00007f87550ac3bf in ??? () at /usr/lib/libglib-2.0.so.0
#41 0x00007f875504c712 in g_main_context_iteration () at /usr/lib/libglib-2.0.so.0
#42 0x00007f87590e288c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#43 0x00007f8759092774 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () at /usr/lib/libQt5Core.so.5
#44 0x00007f8758eef666 in QThread::exec() () at /usr/lib/libQt5Core.so.5
#45 0x00007f8758eeb88a in ??? () at /usr/lib/libQt5Core.so.5
#46 0x00007f87588aa1cf in ??? () at /usr/lib/libc.so.6
#47 0x00007f875892b6ec in ??? () at /usr/lib/libc.so.6

Found a single similar backtrace in an existing bug report: https://github.com/llvm/llvm-project/issues/25216. The backtrace is reasonably close given the 8.5 year gap, but the crash is very old indeed. The LLVM issue description states that reverting a 9.5 year old commit works around the crash. Can anyone try to revert it and see if the crash disappears?
Comment 10 Dan Leinir Turthra Jensen 2024-06-26 15:21:51 UTC
Just adding my two eurocents to the thing, to say that i also got this while adding an #include. It does not happen fully consistently, but maybe every other time i try and add one (feels like more regularly than that, but that's probably more because i only really notice when i have to restart the program).

Backtrace:
Application: KDevelop (kdevelop), signal: Segmentation fault

[KCrash Handler]
#4  llvm::support::endian::read<unsigned int, 0ul>(void const*, llvm::endianness) (endian=llvm::endianness::little, memory=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/include/llvm/Support/Endian.h:61
#5  llvm::support::endian::readNext<unsigned int, 0ul, unsigned char>(unsigned char const*&, llvm::endianness) (endian=llvm::endianness::little, memory=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/include/llvm/Support/Endian.h:78
#6  llvm::support::endian::readNext<unsigned int, (llvm::endianness)1, 0ul, unsigned char>(unsigned char const*&) (memory=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/include/llvm/Support/Endian.h:86
#7  llvm::OnDiskChainedHashTable<clang::serialization::reader::ASTDeclContextNameLookupTrait>::find_hashed(clang::serialization::DeclarationNameKey const&, unsigned int, clang::serialization::reader::ASTDeclContextNameLookupTrait*) (this=0x7f481a5a1c28, IKey=..., KeyHash=2629119989, InfoPtr=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/include/llvm/Support/OnDiskHashTable.h:363
#8  clang::serialization::MultiOnDiskHashTable<clang::serialization::reader::ASTDeclContextNameLookupTrait>::find(clang::DeclarationName const&) (this=<optimized out>, EKey=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/lib/Serialization/MultiOnDiskHashTable.h:252
#9  clang::ASTReader::FindExternalVisibleDeclsByName(clang::DeclContext const*, clang::DeclarationName) (this=0x7f48a77b79d0, DC=0x7f481bd42e08, Name=...) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/lib/Serialization/ASTReader.cpp:7972
#10 0x00007f4aec96a0d9 in clang::DeclContext::lookup(clang::DeclarationName) const (this=0x7f481bd42e08, Name=...) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/lib/AST/DeclBase.cpp:1822
#11 0x00007f4aee6b6f0a in clang::ASTReader::CompleteRedeclChain(clang::Decl const*) (this=0x7f48a77b79d0, D=0x7f47cbe7c748) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/lib/Serialization/ASTReader.cpp:7535
#12 0x00007f4aec94de2d in clang::LazyGenerationalUpdatePtr<clang::Decl const*, clang::Decl*, &clang::ExternalASTSource::CompleteRedeclChain>::get(clang::Decl const*) (O=0x7f47cbe7c748, this=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/include/clang/AST/ExternalASTSource.h:449
#13 clang::Redeclarable<clang::FunctionDecl>::DeclLink::getPrevious(clang::FunctionDecl const*) const (this=0x7f47cbe7c7b0, D=0x7f47cbe7c748) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/include/clang/AST/Redeclarable.h:134
#14 clang::Redeclarable<clang::FunctionDecl>::getNextRedeclaration() const (this=0x7f47cbe7c7b0) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/include/clang/AST/Redeclarable.h:190
#15 clang::Redeclarable<clang::FunctionDecl>::redecl_iterator::operator++() (this=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/include/clang/AST/Redeclarable.h:273
#16 clang::FunctionDecl::hasBody(clang::FunctionDecl const*&) const (this=0x7f47cbe7c748, Definition=@0x7f4b1c9fe150: 0x0) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/lib/AST/Decl.cpp:3112
#17 0x00007f4aec94e1cf in clang::FunctionDecl::getBody(clang::FunctionDecl const*&) const (this=0x7f4b1c9fdbc0, Definition=<error reading variable: Cannot access memory at address 0x11126aa28a3a23dc>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/lib/AST/Decl.cpp:3192
#18 0x00007f4b2a8b0ae6 in clang_getCursorDefinition(CXCursor) (C=...) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:6911
#19 0x00007f4b2a981f44 in  () at /lib64/libKDevClangPrivate.so.514
#20 0x00007f4b2a8a23a7 in clang::cxcursor::CursorVisitor::Visit(CXCursor, bool) (this=0x7f4b1c9fe658, Cursor=..., CheckedRegionOfInterest=true) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:225
#21 clang::cxcursor::CursorVisitor::handleDeclForVisitation(clang::Decl const*) (this=0x7f4b1c9fe658, D=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:694
#22 0x00007f4b2a8a24f8 in clang::cxcursor::CursorVisitor::VisitDeclContext(clang::DeclContext*) (this=0x7f4b1c9fe658, DC=0x7f481bd42e08) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:655
#23 0x00007f4b2a8a100e in clang::declvisitor::Base<std::add_pointer, clang::cxcursor::CursorVisitor, bool>::Visit(clang::Decl*) (this=0x7f4b1c9fe658, D=0x7f481bd42dc8) at tools/clang/include/clang/AST/DeclNodes.inc:414
#24 clang::cxcursor::CursorVisitor::VisitChildren(CXCursor) (this=0x7f4b1c9fe658, Cursor=...) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:514
#25 0x00007f4b2a8aca20 in clang_visitChildren(CXCursor, CXCursorVisitor, CXClientData) (parent=..., visitor=<optimized out>, client_data=0x11126aa28a3a23dc) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:4914
#26 0x00007f4b2a981e86 in  () at /lib64/libKDevClangPrivate.so.514
#27 0x00007f4b2a8a23a7 in clang::cxcursor::CursorVisitor::Visit(CXCursor, bool) (this=0x7f4b1c9febd8, Cursor=..., CheckedRegionOfInterest=true) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:225
#28 clang::cxcursor::CursorVisitor::handleDeclForVisitation(clang::Decl const*) (this=0x7f4b1c9febd8, D=<optimized out>) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:694
#29 0x00007f4b2a8a24f8 in clang::cxcursor::CursorVisitor::VisitDeclContext(clang::DeclContext*) (this=0x7f4b1c9febd8, DC=0x7f483536b3c0) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:655
#30 0x00007f4b2a8a0dc2 in clang::cxcursor::CursorVisitor::VisitChildren(CXCursor) (this=0x7f4b1c9febd8, Cursor=...) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:548
#31 0x00007f4b2a8aca20 in clang_visitChildren(CXCursor, CXCursorVisitor, CXClientData) (parent=..., visitor=<optimized out>, client_data=0x11126aa28a3a23dc) at /home/abuild/rpmbuild/BUILD/llvm-18.1.6.src/tools/clang/tools/libclang/CIndex.cpp:4914
#32 0x00007f4b2a985282 in ClangCodeCompletionContext::ClangCodeCompletionContext(KDevelop::DUChainPointer<KDevelop::DUContext> const&, QExplicitlySharedDataPointer<ParseSessionData> const&, QUrl const&, KTextEditor::Cursor const&, QString const&, QString const&) () at /lib64/libKDevClangPrivate.so.514
#33 0x00007f4b2a991b2d in  () at /lib64/libKDevClangPrivate.so.514
#34 0x00007f4b69125b92 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7f4b1c9ff170, r=0x557c24d36500, this=0x7f4ae40016a0) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#35 doActivate<false>(QObject*, int, void**) (sender=0x7f4ae40015e0, signal_index=3, argv=0x7f4b1c9ff170) at kernel/qobject.cpp:3925
#36 0x00007f4b6911e7ef in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (sender=<optimized out>, m=m@entry=0x7f4b693c69e0 <QTimer::staticMetaObject>, local_signal_index=local_signal_index@entry=0, argv=argv@entry=0x7f4b1c9ff170) at kernel/qobject.cpp:3985
#37 0x00007f4b6912996a in QTimer::timeout(QTimer::QPrivateSignal) (this=<optimized out>, _t1=...) at .moc/moc_qtimer.cpp:205
#38 0x00007f4b6911958b in QObject::event(QEvent*) (this=0x7f4ae40015e0, e=0x7f4b1c9ff2c0) at kernel/qobject.cpp:1369
#39 0x00007f4b69fa513e in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=<optimized out>, receiver=0x7f4ae40015e0, e=0x7f4b1c9ff2c0) at kernel/qapplication.cpp:3640
#40 0x00007f4b690ed8e8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x7f4ae40015e0, event=0x7f4b1c9ff2c0) at kernel/qcoreapplication.cpp:1064
#41 0x00007f4b690edaae in QCoreApplication::sendEvent(QObject*, QEvent*) (receiver=<optimized out>, event=<optimized out>) at kernel/qcoreapplication.cpp:1462
#42 0x00007f4b69145c19 in QTimerInfoList::activateTimers() (this=0x7f4ae4001150) at kernel/qtimerinfo_unix.cpp:643
#43 0x00007f4b691464c4 in timerSourceDispatch(GSource*, GSourceFunc, gpointer) (source=<optimized out>) at kernel/qeventdispatcher_glib.cpp:183
#44 0x00007f4b64f12740 in  () at /lib64/libglib-2.0.so.0
#45 0x00007f4b64f14388 in  () at /lib64/libglib-2.0.so.0
#46 0x00007f4b64f14a3c in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#47 0x00007f4b69146826 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x7f4ae4000b70, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#48 0x00007f4b690ec37b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (this=this@entry=0x7f4b1c9ff500, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#49 0x00007f4b68f0307e in QThread::exec() (this=<optimized out>) at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#50 0x00007f4b68f042ad in operator() (__closure=<optimized out>) at thread/qthread_unix.cpp:350
#51 (anonymous namespace)::terminate_on_exception<QThreadPrivate::start(void*)::<lambda()> > (t=<optimized out>) at thread/qthread_unix.cpp:287
#52 QThreadPrivate::start(void*) (arg=0x557c24ce6c80) at thread/qthread_unix.cpp:310
#53 0x00007f4b68692ba2 in start_thread () at /lib64/libc.so.6
#54 0x00007f4b6871400c in clone3 () at /lib64/libc.so.6
Comment 11 JATothrim 2024-08-03 16:51:21 UTC
I would like note that I'm using an "manual workaround" to avoid or at least reduce the chance of crashing the IDE:

If the parser ever sees an partial #include with "" or <> brackets that are not typed/closed fully, this seems provoke the crash. So, as an precaution I'm copy-pasting an existing #include line and then edit that, which seems to avoid the crashing most of the time.

Thanks for all continuing to investigate this bug.
Comment 12 Igor Kushnir 2024-09-23 16:09:35 UTC
*** Bug 493533 has been marked as a duplicate of this bug. ***
Comment 13 painless roaster 2024-09-24 12:46:43 UTC
is this it?

https://github.com/llvm/llvm-project/issues/105994 ?
Comment 14 Igor Kushnir 2024-09-24 15:24:25 UTC
(In reply to painless roaster from comment #13)
> is this it?
> 
> https://github.com/llvm/llvm-project/issues/105994 ?
Probably not. I don't think this KDevelop crash can be reproduced via a regular compilation. The backtrace looks different.
Comment 15 Igor Kushnir 2024-10-30 12:10:42 UTC
*** Bug 495546 has been marked as a duplicate of this bug. ***
Comment 16 Igor Kushnir 2025-01-17 10:12:59 UTC
*** Bug 498754 has been marked as a duplicate of this bug. ***
Comment 17 Igor Kushnir 2025-02-16 09:59:25 UTC
*** Bug 500089 has been marked as a duplicate of this bug. ***
Comment 18 painless roaster 2025-02-16 16:48:04 UTC
The bug has been around for a long time and is on a request to be placed in a mental institution. Could you please make a workaround to not run the background parser if you are cursor on a macro line?
Comment 19 Igor Kushnir 2025-02-16 19:38:59 UTC
Heuristic disabling of auto-completion may be possible, but not necessarily easy to implement. Also not a good long-term solution.

Perhaps finding the root cause and fixing the libclang bug is a better investment of time. The bug appeared somewhere between Clang versions 16.06 and 17.06. One could examine git blame or git log of seemingly related files looking for potential culprit commits. Or even bisect and find the commit that introduced the regression, given a fast enough computer.