forked from qt-creator/qt-creator
		
	debugger: more robust version string parsing
Fix for QTCREATORBUG-1490 Reviewed-By: Friedemann Kleint
This commit is contained in:
		@@ -1470,70 +1470,22 @@ void GdbEngine::handleInfoProc(const GdbResponse &response)
 | 
			
		||||
 | 
			
		||||
void GdbEngine::handleShowVersion(const GdbResponse &response)
 | 
			
		||||
{
 | 
			
		||||
    //qDebug () << "VERSION 2:" << response.data.findChild("consolestreamoutput").data();
 | 
			
		||||
    //qDebug () << "VERSION:" << response.toString();
 | 
			
		||||
    debugMessage(_("VERSION: " + response.toString()));
 | 
			
		||||
    debugMessage(_("PARSING VERSION: " + response.toString()));
 | 
			
		||||
    if (response.resultClass == GdbResultDone) {
 | 
			
		||||
        m_gdbVersion = 100;
 | 
			
		||||
        m_gdbBuildVersion = -1;
 | 
			
		||||
        m_isMacGdb = false;
 | 
			
		||||
        GdbMi version = response.data.findChild("consolestreamoutput");
 | 
			
		||||
        QString msg = QString::fromLocal8Bit(version.data());
 | 
			
		||||
 | 
			
		||||
        bool foundIt = false;
 | 
			
		||||
 | 
			
		||||
        QRegExp supported(_("GNU gdb(.*) (\\d+)\\.(\\d+)(\\.(\\d+))?(-(\\d+))?"));
 | 
			
		||||
        if (supported.indexIn(msg) >= 0) {
 | 
			
		||||
        extractGdbVersion(msg,
 | 
			
		||||
              &m_gdbVersion, &m_gdbBuildVersion, &m_isMacGdb);
 | 
			
		||||
        if (m_gdbVersion > 60500 && m_gdbVersion < 200000)
 | 
			
		||||
            debugMessage(_("SUPPORTED GDB VERSION ") + msg);
 | 
			
		||||
            m_gdbVersion = 10000 * supported.cap(2).toInt()
 | 
			
		||||
                         +   100 * supported.cap(3).toInt()
 | 
			
		||||
                         +     1 * supported.cap(5).toInt();
 | 
			
		||||
            m_gdbBuildVersion = supported.cap(7).toInt();
 | 
			
		||||
            m_isMacGdb = msg.contains(__("Apple version"));
 | 
			
		||||
            foundIt = true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // OpenSUSE managed to ship "GNU gdb (GDB) SUSE (6.8.91.20090930-2.4).
 | 
			
		||||
        if (!foundIt && msg.startsWith(_("GNU gdb (GDB) SUSE "))) {
 | 
			
		||||
            supported.setPattern(_("[^\\d]*(\\d+).(\\d+).(\\d+).*"));
 | 
			
		||||
            if (supported.indexIn(msg) >= 0) {
 | 
			
		||||
                debugMessage(_("SUSE PATCHED GDB VERSION ") + msg);
 | 
			
		||||
                m_gdbVersion = 10000 * supported.cap(1).toInt()
 | 
			
		||||
                             +   100 * supported.cap(2).toInt()
 | 
			
		||||
                             +     1 * supported.cap(3).toInt();
 | 
			
		||||
                m_gdbBuildVersion = -1;
 | 
			
		||||
                m_isMacGdb = false;
 | 
			
		||||
                foundIt = true;
 | 
			
		||||
            } else {
 | 
			
		||||
                debugMessage(_("UNPARSABLE SUSE PATCHED GDB VERSION ") + msg);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!foundIt) {
 | 
			
		||||
        else
 | 
			
		||||
            debugMessage(_("UNSUPPORTED GDB VERSION ") + msg);
 | 
			
		||||
#if 0
 | 
			
		||||
            QStringList list = msg.split(_c('\n'));
 | 
			
		||||
            while (list.size() > 2)
 | 
			
		||||
                list.removeLast();
 | 
			
		||||
            msg = tr("The debugger you are using identifies itself as:")
 | 
			
		||||
                + _("<p><p>") + list.join(_("<br>")) + _("<p><p>")
 | 
			
		||||
                + tr("This version is not officially supported by Qt Creator.\n"
 | 
			
		||||
                     "Debugging will most likely not work well.\n"
 | 
			
		||||
                     "Using gdb 7.1 or later is strongly recommended.");
 | 
			
		||||
#if 0
 | 
			
		||||
            // ugly, but 'Show again' check box...
 | 
			
		||||
            static QErrorMessage *err = new QErrorMessage(mainWindow());
 | 
			
		||||
            err->setMinimumSize(400, 300);
 | 
			
		||||
            err->showMessage(msg);
 | 
			
		||||
#else
 | 
			
		||||
            //showMessageBox(QMessageBox::Information, tr("Warning"), msg);
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        debugMessage(_("USING GDB VERSION: %1, BUILD: %2%3").arg(m_gdbVersion)
 | 
			
		||||
            .arg(m_gdbBuildVersion).arg(_(m_isMacGdb ? " (APPLE)" : "")));
 | 
			
		||||
        //qDebug () << "VERSION 3:" << m_gdbVersion << m_gdbBuildVersion;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -32,6 +32,7 @@
 | 
			
		||||
#include <utils/qtcassert.h>
 | 
			
		||||
 | 
			
		||||
#include <QtCore/QByteArray>
 | 
			
		||||
#include <QtCore/QRegExp>
 | 
			
		||||
#include <QtCore/QTextStream>
 | 
			
		||||
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
@@ -400,5 +401,50 @@ QByteArray GdbResponse::toString() const
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
//
 | 
			
		||||
// GdbResponse
 | 
			
		||||
//
 | 
			
		||||
//////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
 | 
			
		||||
void extractGdbVersion(const QString &msg,
 | 
			
		||||
    int *gdbVersion, int *gdbBuildVersion, bool *isMacGdb)
 | 
			
		||||
{
 | 
			
		||||
    const QChar dot(QLatin1Char('.'));
 | 
			
		||||
 | 
			
		||||
    QString cleaned;
 | 
			
		||||
    QString build;
 | 
			
		||||
    bool inClean = true;
 | 
			
		||||
    foreach (QChar c, msg) {
 | 
			
		||||
        if (inClean && !cleaned.isEmpty() && c != dot && (c.isPunct() || c.isSpace()))
 | 
			
		||||
            inClean = false;
 | 
			
		||||
        if (inClean) {
 | 
			
		||||
            if (c.isDigit())
 | 
			
		||||
                cleaned.append(c);
 | 
			
		||||
            else if (!cleaned.isEmpty() && !cleaned.endsWith(dot))
 | 
			
		||||
                cleaned.append(dot);
 | 
			
		||||
        } else {
 | 
			
		||||
            if (c.isDigit())
 | 
			
		||||
                build.append(c);
 | 
			
		||||
            else if (!build.isEmpty() && !build.endsWith(dot))
 | 
			
		||||
                build.append(dot);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    *isMacGdb = msg.contains(QLatin1String("Apple version"));
 | 
			
		||||
 | 
			
		||||
    *gdbVersion = 10000 * cleaned.section(dot, 0, 0).toInt()
 | 
			
		||||
                  + 100 * cleaned.section(dot, 1, 1).toInt()
 | 
			
		||||
                    + 1 * cleaned.section(dot, 2, 2).toInt();
 | 
			
		||||
    if (cleaned.count(dot) >= 3)
 | 
			
		||||
        *gdbBuildVersion = cleaned.section(dot, 3, 3).toInt();
 | 
			
		||||
    else
 | 
			
		||||
        *gdbBuildVersion = build.section(dot, 0, 0).toInt();
 | 
			
		||||
 | 
			
		||||
    if (*isMacGdb)
 | 
			
		||||
        *gdbBuildVersion = build.section(dot, 1, 1).toInt();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace Internal
 | 
			
		||||
} // namespace Debugger
 | 
			
		||||
 
 | 
			
		||||
@@ -168,6 +168,9 @@ public:
 | 
			
		||||
    QVariant       cookie;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void extractGdbVersion(const QString &msg,
 | 
			
		||||
    int *gdbVersion, int *gdbBuildVersion, bool *isMacGdb);
 | 
			
		||||
 | 
			
		||||
} // namespace Internal
 | 
			
		||||
} // namespace Debugger
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user