From aa17415b154351c1d7ded232ca58e607355a6f2f Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 21 Nov 2021 08:38:03 +0800 Subject: [PATCH] work save --- RedPandaIDE/debugger.cpp | 44 +++++++++++++++++++------------ RedPandaIDE/debugger.h | 4 +++ RedPandaIDE/gdbmiresultparser.cpp | 20 +++++++++++--- RedPandaIDE/gdbmiresultparser.h | 8 +++--- 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index a873db04..3c006403 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -63,6 +63,8 @@ bool Debugger::start() connect(this, &Debugger::localsReady,pMainWindow,&MainWindow::onLocalsReady); connect(mReader, &DebugReader::cmdStarted,pMainWindow, &MainWindow::disableDebugActions); connect(mReader, &DebugReader::cmdFinished,pMainWindow, &MainWindow::enableDebugActions); + connect(mReader, &DebugReader::breakpointInfoGetted, mBreakpointModel, + &BreakpointModel::updateBreakpointNumber); mReader->start(); mReader->waitStart(); @@ -1713,24 +1715,13 @@ QStringList DebugReader::tokenize(const QString &s) return result; } -void DebugReader::handleBreakpoint(const QByteArray &breakpointRecord) +void DebugReader::handleBreakpoint(const GDBMIResultParser::ParseObject& breakpoint) { - //we have to convert record from local encoding to utf8 - //because QJsonDocument only handle utf8-encoded json strings - QString temp = QString::fromLocal8Bit(breakpointRecord); - QByteArray record = temp.toUtf8(); - GDBMIResultParser parser; - GDBMIR - parser.parse(breakpointRecord,) - QJsonParseError error; - QJsonDocument doc = QJsonDocument::fromJson(record,&error); - if (error.error!=QJsonParseError::NoError) { - mConsoleOutput.append(QString("Error when parsing breakpoint record \"%1\":").arg(temp)); - mConsoleOutput.append(error.errorString()); - return; - } - QJsonObject obj = doc.object(); - + // gdb use system encoding for file path + QString filename = QString::fromLocal8Bit(breakpoint["filename"].value()); + int line = breakpoint["line"].intValue(); + int number = breakpoint["number"].intValue(); + emit breakpointInfoGetted(filename, line , number); } QByteArray DebugReader::removeToken(const QByteArray &line) @@ -1966,6 +1957,14 @@ void BreakpointModel::removeBreakpoint(int row) endRemoveRows(); } +void BreakpointModel::invalidateAllBreakpointNumbers() +{ + foreach (PBreakpoint bp,mList) { + bp->number = -1; + } + //emit dateChanged(createIndex(0,0),) +} + PBreakpoint BreakpointModel::setBreakPointCondition(int index, const QString &condition) { PBreakpoint breakpoint = mList[index]; @@ -2045,6 +2044,17 @@ void BreakpointModel::load(const QString &filename) } } +void BreakpointModel::updateBreakpointNumber(const QString &filename, int line, int number) +{ + QFileInfo file(filename); + QString fn = file.absoluteFilePath(); + foreach (PBreakpoint bp, mList) { + if (bp->filename == fn && bp->line == line) { + bp->number = number; + } + } +} + void BreakpointModel::onFileDeleteLines(const QString &filename, int startLine, int count) { for (int i = mList.count()-1;i>=0;i--){ diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index 50259460..3619102a 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -100,6 +100,8 @@ public: void save(const QString& filename); void load(const QString& filename); public slots: + void updateBreakpointNumber(const QString& filename, int line, int number); + void invalidateAllBreakpointNumbers(); // call this when gdb is stopped void onFileDeleteLines(const QString& filename, int startLine, int count); void onFileInsertLines(const QString& filename, int startLine, int count); private: @@ -291,6 +293,8 @@ signals: void changeDebugConsoleLastLine(const QString& text); void cmdStarted(); void cmdFinished(); + + void breakpointInfoGetted(const QString& filename, int line, int number); private: void clearCmdQueue(); bool outputTerminated(QByteArray& text); diff --git a/RedPandaIDE/gdbmiresultparser.cpp b/RedPandaIDE/gdbmiresultparser.cpp index 218cc955..44b719d8 100644 --- a/RedPandaIDE/gdbmiresultparser.cpp +++ b/RedPandaIDE/gdbmiresultparser.cpp @@ -194,21 +194,35 @@ void GDBMIResultParser::skipSpaces(const char *&p) p++; } -const QString &GDBMIResultParser::ParseValue::value() const +const QByteArray &GDBMIResultParser::ParseValue::value() const { + Q_ASSERT(mType == ParseValueType::Value); return mValue; } const QList<::GDBMIResultParser::ParseObject> &GDBMIResultParser::ParseValue::array() const { + Q_ASSERT(mType == ParseValueType::Array); return mArray; } const GDBMIResultParser::ParseObject &GDBMIResultParser::ParseValue::object() const { + Q_ASSERT(mType == ParseValueType::Object); return mObject; } +int GDBMIResultParser::ParseValue::intValue(int defaultValue) const +{ + Q_ASSERT(mType == ParseValueType::Value); + bool ok; + int value = QString(mValue).toInt(&ok); + if (ok) + return value; + else + return defaultValue; +} + GDBMIResultParser::ParseValueType GDBMIResultParser::ParseValue::type() const { return mType; @@ -219,7 +233,7 @@ GDBMIResultParser::ParseValue::ParseValue(): } -GDBMIResultParser::ParseValue::ParseValue(const QString &value): +GDBMIResultParser::ParseValue::ParseValue(const QByteArray &value): mValue(value), mType(ParseValueType::Value) { @@ -237,7 +251,7 @@ GDBMIResultParser::ParseValue::ParseValue(const QList &array): { } -GDBMIResultParser::ParseValue &GDBMIResultParser::ParseValue::operator=(const QString &value) +GDBMIResultParser::ParseValue &GDBMIResultParser::ParseValue::operator=(const QByteArray &value) { Q_ASSERT(mType == ParseValueType::NotAssigned); mType = ParseValueType::Value; diff --git a/RedPandaIDE/gdbmiresultparser.h b/RedPandaIDE/gdbmiresultparser.h index b989d91e..f16781aa 100644 --- a/RedPandaIDE/gdbmiresultparser.h +++ b/RedPandaIDE/gdbmiresultparser.h @@ -46,20 +46,20 @@ public: class ParseValue { public: explicit ParseValue(); - explicit ParseValue(const QString& value); + explicit ParseValue(const QByteArray& value); explicit ParseValue(const ParseObject &object); explicit ParseValue(const QList& array); ParseValue(const ParseValue&) = delete; - const QString &value() const; + const QByteArray &value() const; const QList &array() const; const ParseObject &object() const; ParseValueType type() const; - ParseValue& operator=(const QString& value); + ParseValue& operator=(const QByteArray& value); ParseValue& operator=(const ParseObject& object); ParseValue& operator=(const QList& array); ParseValue& operator=(const ParseValue& value); private: - QString mValue; + QByteArray mValue; QList mArray; ParseObject mObject; ParseValueType mType;