Bug 386388 - kdevelop crash when opening a project containing javascript files [GccLikeCompiler::includes]
Summary: kdevelop crash when opening a project containing javascript files [GccLikeCom...
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: QML/JavaScript (show other bugs)
Version: git master
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-31 14:23 UTC by Urmet Saar
Modified: 2017-12-14 23:21 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
stack trace (30.21 KB, text/plain)
2017-10-31 14:23 UTC, Urmet Saar
Details
example crashing project (513 bytes, application/x-bzip)
2017-10-31 14:27 UTC, Urmet Saar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Urmet Saar 2017-10-31 14:23:54 UTC
Created attachment 108651 [details]
stack trace

After commit 9ec89cdc6a1f6ef2548d318f97a908d17a2440b0 kdevelop crashes after opening a project containing some javascript files.

Reverting that specific commit gets rid of the crashes and seems to have no bad side effects.

Attached is a stack trace.
Comment 1 Urmet Saar 2017-10-31 14:27:59 UTC
Created attachment 108652 [details]
example crashing project

Attached a project tarball. Containing only one 9-line javascript file. It alone has been able to crash kdevelop without failure.
Comment 2 Christoph Roick 2017-11-03 19:49:34 UTC
I cannot confirm. Did you try clearing the cache?
Comment 3 Kevin Funk 2017-11-04 17:02:55 UTC
Post stacktrace of crashing thread inline for SEO:

Thread 1 (Thread 0x7ff8b5152080 (LWP 17102)):
[KCrash Handler]
#6  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#7  0x00007ff8d9690c1a in __GI_abort () at abort.c:89
#8  0x00007ff8d9e9db0f in qt_message_fatal (context=..., message=<synthetic pointer>...) at global/qlogging.cpp:1690
#9  QMessageLogger::fatal (this=this@entry=0x7ffc4d24efe0, msg=msg@entry=0x7ff8da11a7d0 "ASSERT: \"%s\" in file %s, line %d") at global/qlogging.cpp:796
#10 0x00007ff8d9e966d6 in qt_assert (assertion=assertion@entry=0x7ff8da124cc2 "!d->ref.isShared()", file=file@entry=0x7ff8da124cb2 "tools/qlist.cpp", line=line@entry=139) at global/qglobal.cpp:3077
#11 0x00007ff8d9f00e39 in QListData::realloc (this=this@entry=0x7ffc4d24f0b0, alloc=alloc@entry=2) at tools/qlist.cpp:139
#12 0x00007ff8770d8315 in QList<QString>::reserve (alloc=2, this=0x7ffc4d24f0b0) at /usr/include/qt5/QtCore/qlist.h:574
#13 QList<QString>::QList (args=..., this=0x7ffc4d24f0b0) at /usr/include/qt5/QtCore/qlist.h:165
#14 QStringList::QStringList (args=..., this=0x7ffc4d24f0b0) at /usr/include/qt5/QtCore/qstringlist.h:112
#15 GccLikeCompiler::includes (this=0x2ba29c0, type=<optimized out>, arguments=...) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp:142
#16 0x00007ff8770c98cd in CompilerProvider::includes (this=<optimized out>, item=<optimized out>) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp:155
#17 0x00007ff8770a8fd4 in DefinesAndIncludesManager::includes (this=0x2b829e0, item=0x382a430, type=KDevelop::IDefinesAndIncludesManager::All) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/plugins/custom-definesandincludes/definesandincludesmanager.cpp:203
#18 0x00007ff8741c8f34 in QmlJsParseJob::QmlJsParseJob (this=<optimized out>, url=..., languageSupport=<optimized out>) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/plugins/qmljs/qmljsparsejob.cpp:86
#19 0x00007ff8741cfa86 in KDevQmlJsPlugin::createParseJob (this=0x5071450, url=...) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/plugins/qmljs/kdevqmljsplugin.cpp:93
#20 0x00007ff8d785e35a in KDevelop::BackgroundParserPrivate::createParseJob (this=this@entry=0xe1d5b0, url=..., parsePlan=...) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/kdevplatform/language/backgroundparser/backgroundparser.cpp:367
#21 0x00007ff8d786119b in KDevelop::BackgroundParserPrivate::parseDocumentsInternal (this=0xe1d5b0) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/kdevplatform/language/backgroundparser/backgroundparser.cpp:308
#22 0x00007ff8d785aeb4 in KDevelop::BackgroundParser::parseDocuments (this=0xe1d580) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/kdevplatform/language/backgroundparser/backgroundparser.cpp:657
#23 0x00007ff8d79efae5 in KDevelop::BackgroundParser::qt_static_metacall (_o=<optimized out>, _c=<optimized out>, _id=<optimized out>, _a=<optimized out>) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999_build/kdevplatform/language/KDevPlatformLanguage_autogen/7BZAXZBZPZ/moc_backgroundparser.cpp:249
Comment 4 Kevin Funk 2017-11-04 17:10:16 UTC
I can't reproduce either, but I can see how this fails:

#15 GccLikeCompiler::includes (this=0x2ba29c0, type=<optimized out>, arguments=...) at /usr/src/debug/dev-util/kdevelop-9999/kdevelop-9999/plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp:142

=> calls ::languageOption(type=Utils::Other) which runs into the default-case in the switch statement, not returning a value => crash.
Comment 5 Aaron Puchert 2017-11-04 17:40:00 UTC
I think we need to restrict to project-specific and user-defined includes in the constructor QmlJsParseJob::QmlJsParseJob. So replace

    IDefinesAndIncludesManager::manager()->includes(...)

by

    IDefinesAndIncludesManager::manager()->includes(..., IDefinesAndIncludesManager::ProjectSpecific | IDefinesAndIncludesManager::UserDefined)

The compiler-specific includes only make sense if we actually have a compiler backend that can provide them. (Right now ICompiler is implemented by NoCompiler, GccLikeCompiler, and MsvcCompiler - so no compiler for QML JS here.)
Comment 6 Aaron Puchert 2017-11-04 18:28:13 UTC
Another solution would be to ignore files of type `Utils::Other` in CompilerProvider::includes/defines.

The entire design is a bit problematic, because the QmlJS plugin asks the DefinesAndIncludesManager for include directories, but that manager is somehow tied to the idea of using the configured compiler (GCC/Clang/MSVC) to provide additional includes and defines. However, the configured compiler is obviously only used for C/C++ and similar languages, not QmlJS.

Before this change, the standard include directories for GCC/Clang (/usr/include and so on) were used to parse QmlJS files, which I guess is not intended. (Or is it?)
Comment 7 Aaron Puchert 2017-11-04 18:44:23 UTC
Possible fixes: https://phabricator.kde.org/D8653, https://phabricator.kde.org/D8654. I tested both on the attached project, and there is no more crash with either one.

Neither is particularly beautiful, but that's because the DefinesAndIncludesManager is mostly designed around C++ with other languages as afterthought. There is probably a better solution, but that needs more time.
Comment 8 Aaron Puchert 2017-11-07 12:44:30 UTC
The issue should now be fixed in master. Please check that it works for you.
Comment 9 Sven Brauch 2017-11-07 13:01:04 UTC
Thank you for working on this. If the fix is confirmed, can you cherry-pick the change into the 5.2 branch so we get this in 5.2.1?
Comment 10 Urmet Saar 2017-11-08 15:32:17 UTC
Seems to be fixed. I haven't been able to crash kdevelop today after updating to latest master.
Comment 11 Aaron Puchert 2017-12-14 02:08:52 UTC
I think this has been fixed, but I can't close the bug. Maybe someone with the appropriate permissions could do that.
Comment 12 Sven Brauch 2017-12-14 09:07:41 UTC
Do you know if this is also fixed in the 5.1 branch? Thanks for the feedback!
Comment 13 Aaron Puchert 2017-12-14 23:21:10 UTC
The crash came with some Q_UNREACHABLE()s I added, and only after 5.1 was released. The only problem (if any) on 5.1 is that the C++ compiler's include directories are passed to the QmlJS parser, but that didn't seem to lead to any problems. There should be no crash though.