work save

This commit is contained in:
royqh1979@gmail.com 2021-11-21 08:38:03 +08:00
parent c6080cdf59
commit aa17415b15
4 changed files with 52 additions and 24 deletions

View File

@ -63,6 +63,8 @@ bool Debugger::start()
connect(this, &Debugger::localsReady,pMainWindow,&MainWindow::onLocalsReady); connect(this, &Debugger::localsReady,pMainWindow,&MainWindow::onLocalsReady);
connect(mReader, &DebugReader::cmdStarted,pMainWindow, &MainWindow::disableDebugActions); connect(mReader, &DebugReader::cmdStarted,pMainWindow, &MainWindow::disableDebugActions);
connect(mReader, &DebugReader::cmdFinished,pMainWindow, &MainWindow::enableDebugActions); connect(mReader, &DebugReader::cmdFinished,pMainWindow, &MainWindow::enableDebugActions);
connect(mReader, &DebugReader::breakpointInfoGetted, mBreakpointModel,
&BreakpointModel::updateBreakpointNumber);
mReader->start(); mReader->start();
mReader->waitStart(); mReader->waitStart();
@ -1713,24 +1715,13 @@ QStringList DebugReader::tokenize(const QString &s)
return result; 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 // gdb use system encoding for file path
//because QJsonDocument only handle utf8-encoded json strings QString filename = QString::fromLocal8Bit(breakpoint["filename"].value());
QString temp = QString::fromLocal8Bit(breakpointRecord); int line = breakpoint["line"].intValue();
QByteArray record = temp.toUtf8(); int number = breakpoint["number"].intValue();
GDBMIResultParser parser; emit breakpointInfoGetted(filename, line , number);
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();
} }
QByteArray DebugReader::removeToken(const QByteArray &line) QByteArray DebugReader::removeToken(const QByteArray &line)
@ -1966,6 +1957,14 @@ void BreakpointModel::removeBreakpoint(int row)
endRemoveRows(); 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 BreakpointModel::setBreakPointCondition(int index, const QString &condition)
{ {
PBreakpoint breakpoint = mList[index]; 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) void BreakpointModel::onFileDeleteLines(const QString &filename, int startLine, int count)
{ {
for (int i = mList.count()-1;i>=0;i--){ for (int i = mList.count()-1;i>=0;i--){

View File

@ -100,6 +100,8 @@ public:
void save(const QString& filename); void save(const QString& filename);
void load(const QString& filename); void load(const QString& filename);
public slots: 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 onFileDeleteLines(const QString& filename, int startLine, int count);
void onFileInsertLines(const QString& filename, int startLine, int count); void onFileInsertLines(const QString& filename, int startLine, int count);
private: private:
@ -291,6 +293,8 @@ signals:
void changeDebugConsoleLastLine(const QString& text); void changeDebugConsoleLastLine(const QString& text);
void cmdStarted(); void cmdStarted();
void cmdFinished(); void cmdFinished();
void breakpointInfoGetted(const QString& filename, int line, int number);
private: private:
void clearCmdQueue(); void clearCmdQueue();
bool outputTerminated(QByteArray& text); bool outputTerminated(QByteArray& text);

View File

@ -194,21 +194,35 @@ void GDBMIResultParser::skipSpaces(const char *&p)
p++; p++;
} }
const QString &GDBMIResultParser::ParseValue::value() const const QByteArray &GDBMIResultParser::ParseValue::value() const
{ {
Q_ASSERT(mType == ParseValueType::Value);
return mValue; return mValue;
} }
const QList<::GDBMIResultParser::ParseObject> &GDBMIResultParser::ParseValue::array() const const QList<::GDBMIResultParser::ParseObject> &GDBMIResultParser::ParseValue::array() const
{ {
Q_ASSERT(mType == ParseValueType::Array);
return mArray; return mArray;
} }
const GDBMIResultParser::ParseObject &GDBMIResultParser::ParseValue::object() const const GDBMIResultParser::ParseObject &GDBMIResultParser::ParseValue::object() const
{ {
Q_ASSERT(mType == ParseValueType::Object);
return mObject; 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 GDBMIResultParser::ParseValueType GDBMIResultParser::ParseValue::type() const
{ {
return mType; return mType;
@ -219,7 +233,7 @@ GDBMIResultParser::ParseValue::ParseValue():
} }
GDBMIResultParser::ParseValue::ParseValue(const QString &value): GDBMIResultParser::ParseValue::ParseValue(const QByteArray &value):
mValue(value), mValue(value),
mType(ParseValueType::Value) mType(ParseValueType::Value)
{ {
@ -237,7 +251,7 @@ GDBMIResultParser::ParseValue::ParseValue(const QList<ParseObject> &array):
{ {
} }
GDBMIResultParser::ParseValue &GDBMIResultParser::ParseValue::operator=(const QString &value) GDBMIResultParser::ParseValue &GDBMIResultParser::ParseValue::operator=(const QByteArray &value)
{ {
Q_ASSERT(mType == ParseValueType::NotAssigned); Q_ASSERT(mType == ParseValueType::NotAssigned);
mType = ParseValueType::Value; mType = ParseValueType::Value;

View File

@ -46,20 +46,20 @@ public:
class ParseValue { class ParseValue {
public: public:
explicit ParseValue(); explicit ParseValue();
explicit ParseValue(const QString& value); explicit ParseValue(const QByteArray& value);
explicit ParseValue(const ParseObject &object); explicit ParseValue(const ParseObject &object);
explicit ParseValue(const QList<ParseObject>& array); explicit ParseValue(const QList<ParseObject>& array);
ParseValue(const ParseValue&) = delete; ParseValue(const ParseValue&) = delete;
const QString &value() const; const QByteArray &value() const;
const QList<ParseObject> &array() const; const QList<ParseObject> &array() const;
const ParseObject &object() const; const ParseObject &object() const;
ParseValueType type() const; ParseValueType type() const;
ParseValue& operator=(const QString& value); ParseValue& operator=(const QByteArray& value);
ParseValue& operator=(const ParseObject& object); ParseValue& operator=(const ParseObject& object);
ParseValue& operator=(const QList<ParseObject>& array); ParseValue& operator=(const QList<ParseObject>& array);
ParseValue& operator=(const ParseValue& value); ParseValue& operator=(const ParseValue& value);
private: private:
QString mValue; QByteArray mValue;
QList<ParseObject> mArray; QList<ParseObject> mArray;
ParseObject mObject; ParseObject mObject;
ParseValueType mType; ParseValueType mType;