Bug 416714

Summary: KDevelop crashed when pressing "update signature" on problem solver
Product: [Applications] kdevelop Reporter: Ismael Asensio <isma.af>
Component: generalAssignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: crash CC: benjamin-huth, jonathan.verner, kde
Priority: NOR Keywords: drkonqi
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In: 5.8.220401
Attachments: New crash information added by DrKonqi
New crash information added by DrKonqi
New crash information added by DrKonqi

Description Ismael Asensio 2020-01-24 22:05:17 UTC
Application: kdevelop (5.5.40)
 (Compiled from sources)
Qt Version: 5.12.4
Frameworks Version: 5.67.0
Operating System: Linux 5.3.0-23-generic x86_64
Distribution: Ubuntu 19.10

-- Information about the crash:
- What I was doing when the application crashed:
Change a function declaration on a C++ header file, KDevelop marks it as possible error and suggests to update the signature as the solution. Clicking on the solution makes KDevelop crash.
I'm using clang as the code analyzer

The crash can be reproduced every time.

-- Backtrace (Reduced):
#6  0x00007fb5941883eb in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#7  0x00007fb594167899 in __GI_abort () at abort.c:79
#8  0x00007fb5945a8a99 in  () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#9  0x00007fb5945a7ee7 in qt_assert_x(char const*, char const*, char const*, int) () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#10 0x00007fb55a77e5da in AdaptSignatureAction::execute() (this=0x559ae019bb70) at /home/isma/kde/src/kdevelop/plugins/clang/codegen/adaptsignatureaction.cpp:83


Possible duplicates by query: bug 416549, bug 416494, bug 416379, bug 416113, bug 416051.

Reported using DrKonqi
Comment 1 Ismael Asensio 2020-01-24 22:05:19 UTC
Created attachment 125381 [details]
New crash information added by DrKonqi

DrKonqi auto-attaching complete backtrace.
Comment 2 Jonathan Verner 2020-07-30 10:51:08 UTC
Created attachment 130510 [details]
New crash information added by DrKonqi

kdevelop (5.5.40) using Qt 5.14.2

- What I was doing when the application crashed:

I changed a class method declaration and then clicked on the suggested solution to update the method signature in the implementation file which lead to this crash. 

Looking at `plugins/clang/codegen/adaptsignatureaction.cpp:83` the crash seems to happen because of a failed assert in `ENSURE_CHAIN_NOT_LOCKED`, i.e. because the DU chain is locked for some reason.

-- Backtrace (Reduced):
#4  0x00007fd7b59c0f47 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x00007fd7b59c28b1 in __GI_abort () at abort.c:79
#6  0x00007fd7b618a68b in qt_message_fatal (context=..., message=<synthetic pointer>...) at global/qlogging.cpp:1914
#7  0x00007fd7b618a68b in QMessageLogger::fatal(char const*, ...) const (this=this@entry=0x7ffd9e94d860, msg=msg@entry=0x7fd7b648a9a0 "ASSERT: \"%s\" in file %s, line %d") at global/qlogging.cpp:893
#8  0x00007fd7b6189e81 in qt_assert(char const*, char const*, int) (assertion=<optimized out>, file=<optimized out>, line=<optimized out>) at global/qglobal.cpp:3342
Comment 3 Benjamin Huth 2021-10-18 16:33:27 UTC
Created attachment 142580 [details]
New crash information added by DrKonqi

kdevelop (5.6.40) using Qt 5.15.2

- What I was doing when the application crashed:

I pressed "update signature" after changing the signature of a constructor in the header file, then KDevelop crashed.

-- Backtrace (Reduced):
#7  0x00007fb65ad5a85c in qt_assert_x(char const*, char const*, char const*, int) () at /lib64/libQt5Core.so.5
#8  0x00007fb5f863b51b in AdaptSignatureAction::execute() (this=0x2da76d0) at /home/benjamin/Applications/kdevelop/plugins/clang/codegen/adaptsignatureaction.cpp:83
#9  0x00007fb65df82c35 in KDevelop::ProblemNavigationContext::executeAction(int) (this=0x48e0bf0, index=0) at /home/benjamin/Applications/kdevelop/kdevplatform/language/duchain/navigation/problemnavigationcontext.cpp:258
#10 0x00007fb65df82b5f in KDevelop::ProblemNavigationContext::executeKeyAction(QString const&) (this=0x48e0bf0, key=...) at /home/benjamin/Applications/kdevelop/kdevplatform/language/duchain/navigation/problemnavigationcontext.cpp:243
#11 0x00007fb65df89bcc in KDevelop::AbstractNavigationContext::execute(KDevelop::NavigationAction const&) (this=0x48e0bf0, action=...) at /home/benjamin/Applications/kdevelop/kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:183
Comment 4 Jonathan Verner 2021-10-28 23:17:01 UTC
Hmm, the problem seems to be that the DUChain is readlocked in
`AbstractNavigationWidgetPrivate::anchorClicked`. However, that
lock was added there to fix bug 386901 so it cannot just be removed.

Probably the solution is to move the lock further down the call chain
for bug 386901, though its not completely clear to me where...

The call chain triggering bug 386901 without the lock acquired in `anchorClicked`
looks as follows (from outer caller to inner caller):


in KDevelop::AbstractNavigationWidgetPrivate::anchorClicked at kdevplatform/language/duchain/navigation/abstractnavigationwidget.cpp:285

in KDevelop::AbstractNavigationContext::acceptLink at kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:487

in KDevelop::AbstractNavigationContext::execute at kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:201

in KDevelop::AbstractNavigationContext::registerChild at kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:281

in ClangDUContext<KDevelop::TopDUContext, 140>::createNavigationWidget at plugins/clang/duchain/clangducontext.cpp:46

in ClangNavigationWidget::ClangNavigationWidget at plugins/clang/duchain/navigationwidget.cpp:98

in DeclarationNavigationContext::AbstractDeclarationNavigationContext at plugins/clang/duchain/navigationwidget.cpp:38

in AbstractDeclarationNavigationContext::AbstractDeclarationNavigationContext at kdevplatform/language/duchain/navigation/abstractdeclarationnavigationcontext.cpp:67

in KDevelop::FunctionDefinition::declaration at kdevplatform/language/duchain/functiondefinition.cpp:52


where an assert is hit in the `ENSURE_CAN_READ` macro.

(source code locations from master at 5b8c6afe6f1bdfc)
Comment 5 Bug Janitor Service 2021-10-29 15:38:42 UTC
A possibly relevant merge request was started @ https://invent.kde.org/kdevelop/kdevelop/-/merge_requests/277
Comment 6 Igor Kushnir 2021-11-14 14:18:33 UTC
*** Bug 401221 has been marked as a duplicate of this bug. ***
Comment 7 Igor Kushnir 2022-05-03 13:11:58 UTC
Git commit a947074f0872ad3245b8c73679143998a88e3753 by Igor Kushnir, on behalf of Jonathan L. Verner.
Committed on 01/05/2022 at 12:56.
Pushed by igorkushnir into branch 'release/22.04'.

Fix a crash in the "update signature action".

The problem seems to be that the DUChain is readlocked in
`AbstractNavigationWidgetPrivate::anchorClicked` (see also [2]),
which then proceeds through the following (backtrace-like) call chain

  #9  AdaptSignatureAction::execute()
      (at plugins/clang/codegen/adaptsignatureaction.cpp:83)
  #10 ProblemNavigationContext::executeAction(int)
(at kdevplatform/language/duchain/navigation
problemnavigationcontext.cpp:258)
  #11 ProblemNavigationContext::executeKeyAction(QString const&)
(at
kdevplatform/language/duchain/navigation/problemnavigationcontext.cpp:243)
const&)
(at
kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:183)
  #13 AbstractNavigationContext::acceptLink(QString const&)
(at
kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:487)
  #14 AbstractNavigationWidgetPrivate::anchorClicked

which ends at

  plugins/clang/codegen/adaptsignatureaction.cpp:83

with an `ENSURE_CHAIN_NOT_LOCKED` macro, which asserts.

However, the lock in `anchorClicked` was added there in
commit ff72bc32 to fix bug 386901 ([1]) so it cannot
just be removed. The callchain triggering the 386901 bug looks
as follows:

  #0 FunctionDefinition::declaration
     (at kdevplatform/language/duchain/functiondefinition.cpp:52)
  #1 FunctionDefinition::declaration
     (at kdevplatform/language/duchain/functiondefinition.cpp:52)
AbstractDeclarationNavigationContext::AbstractDeclarationNavigationContext
(at
kdevplatform/language/duchain/navigation/abstractdeclarationnavigationcontext.cpp:67)
  #3 DeclarationNavigationContext::AbstractDeclarationNavigationContext
     (at plugins/clang/duchain/navigationwidget.cpp:38)
  #4 ClangNavigationWidget::ClangNavigationWidget
     (at plugins/clang/duchain/navigationwidget.cpp:98)
  #5 ClangDUContext<KDevelop::TopDUContext, 140>::createNavigationWidget
     (at plugins/clang/duchain/clangducontext.cpp:46)
  #6 AbstractNavigationContext::registerChild
(at
kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:281)
  #7 AbstractNavigationContext::execute
(at
kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:201)
  #8 AbstractNavigationContext::acceptLink
(at
kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp:487)
  #9 AbstractNavigationWidgetPrivate::anchorClicked
(at
kdevplatform/language/duchain/navigation/abstractnavigationwidget.cpp:285)

which hits an assert at

   kdevplatform/language/duchain/functiondefinition.cpp:52

in the `ENSURE_CAN_READ` macro.

This commit moves the lock from `anchorClicked` into
`AbstractNavigationContext::registerChild`, which is the
last opportunity for a lock before a language-plugin specific
method is called (so that the bug does not reappear in
other language plugins).

References

[1] https://bugs.kde.org/show_bug.cgi?id=386901
[2] https://phabricator.kde.org/D22182
Related: bug 358787
FIXED-IN: 5.8.220401

M  +11   -0    kdevplatform/language/duchain/navigation/abstractnavigationcontext.cpp
M  +0    -2    kdevplatform/language/duchain/navigation/abstractnavigationwidget.cpp

https://invent.kde.org/kdevelop/kdevelop/commit/a947074f0872ad3245b8c73679143998a88e3753