Skip to content

Commit

Permalink
gdb: skip to GDB version string
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kvalme authored and vedgy committed Jul 25, 2023
1 parent f935cb2 commit a974c3c
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions plugins/gdb/debugsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QGuiApplication*>(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("<unknown version>");

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("<b>You need gdb 7.0.0 or higher.</b><br />"
"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<QGuiApplication*>(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("<b>You need gdb 7.0.0 or higher.</b><br />"
"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)
Expand Down

0 comments on commit a974c3c

Please sign in to comment.