From a974c3c66130f9e454de1006a7894e4002541dd0 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Fri, 23 Aug 2019 21:04:19 +0300 Subject: [PATCH] gdb: skip to GDB version string This change allows to use ~/.gdbinit file with constructions like `skip -gfi /usr/include/c++/*`. Problem with current implementation is that when .gdbinit contains such strings GDB output produced is following: ``` File(s) /usr/include/c++/* will be skipped when stepping. GNU gdb (Ubuntu 8.2.91.20190405-0ubuntu3) 8.2.91.20190405-git ``` And current implementation expects version on the first output from GDB. This change fixes it by adding skip functionality during GDB session initialization. BUG: 409702, 428688, 446786 FIXED-IN: 5.12.230800 --- plugins/gdb/debugsession.cpp | 44 ++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/plugins/gdb/debugsession.cpp b/plugins/gdb/debugsession.cpp index 05bd011c5d..5404335f60 100644 --- a/plugins/gdb/debugsession.cpp +++ b/plugins/gdb/debugsession.cpp @@ -267,24 +267,38 @@ bool DebugSession::loadCoreFile(KDevelop::ILaunchConfiguration*, void DebugSession::handleVersion(const QStringList& s) { - const auto response = s.value(0); - qCDebug(DEBUGGERGDB) << response; - // minimal version is 7.0,0 - QRegularExpression rx(QStringLiteral("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?")); - const auto match = rx.match(response); - if (!match.hasMatch() || QVersionNumber::fromString(match.capturedRef(0).toString()) < QVersionNumber(7, 0, 0)) { - if (!qobject_cast(qApp)) { - //for unittest - qFatal("You need a graphical application."); + static const QVersionNumber minRequiredVersion(7, 0, 0); + static const QRegularExpression versionRegExp(QStringLiteral("([0-9]+)\\.([0-9]+)(\\.([0-9]+))?")); + QString detectedVersion = i18n(""); + + for (const QString& response : s) { + qCDebug(DEBUGGERGDB) << response; + + if (!response.contains(QLatin1String{"GNU gdb"})) { + continue; // this line is not a version string, skip it } - const QString messageText = i18n("You need gdb 7.0.0 or higher.
" - "You are using: %1", - response); - auto* message = new Sublime::Message(messageText, Sublime::Message::Error); - ICore::self()->uiController()->postMessage(message); - stopDebugger(); + const auto match = versionRegExp.match(response); + if (match.hasMatch() && QVersionNumber::fromString(match.capturedView()) >= minRequiredVersion) { + return; // Early exit. Version check passed. + } + + detectedVersion = response; } + + if (!qobject_cast(qApp)) { + //for unittest + qFatal("You need a graphical application."); + } + + // TODO: reuse minRequiredVersion in the error message text when the minimum + // required GDB version changes or the message is modified for some other reason. + const QString messageText = i18n("You need gdb 7.0.0 or higher.
" + "You are using: %1", + detectedVersion); + auto* message = new Sublime::Message(messageText, Sublime::Message::Error); + ICore::self()->uiController()->postMessage(message); + stopDebugger(); } void DebugSession::handleFileExecAndSymbols(const ResultRecord& r)