From a927c2cc0e80e7192969d0cbf718cfa0debb35a0 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 21 Nov 2021 10:36:50 +0800 Subject: [PATCH] work save --- RedPandaIDE/debugger.cpp | 39 +++++++++++++++++-------------- RedPandaIDE/gdbmiresultparser.cpp | 36 ++++++++++++++++++++++++++++ RedPandaIDE/gdbmiresultparser.h | 3 +++ 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 3c006403..a3fb8282 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -1203,28 +1203,35 @@ void DebugReader::processResult(const QByteArray &result) } } -void DebugReader::processExecAsyncRecord(const QString &line) +void DebugReader::processExecAsyncRecord(const QByteArray &line) { - if (line.startsWith("*running")) { + QByteArray result; + GDBMIResultParser::ParseObject multiValues; + GDBMIResultParser parser; + if (!parser.parseAsyncResult(line,result,multiValues)) + return; + if (result == "running") { mInferiorPaused = false; return; } - if (line.startsWith("*stopped")) { + if (result == "*stopped") { mInferiorPaused = true; - QStringList props = line.split(','); - if (props.count()<2) - return; - QString reason = props[1]; - QRegExp exp("^reason=\"(.+)\"$"); - reason = exp.cap(1); - if (reason.isEmpty()) - return; - if (reason.startsWith("exited")) { + QByteArray reason = multiValues["reason"].value(); + if (reason == "exited") { //inferior exited, gdb should terminate too mProcessExited = true; return; } - if (reason==("signal-received")) { + if (reason == "exited-normally") { + //inferior exited, gdb should terminate too + mProcessExited = true; + return; + } + if (reason == "signal-received") { + //todo: signal received + return; + } + if (reason == "breakpoint-hit") { //todo: signal received return; } @@ -1718,7 +1725,7 @@ QStringList DebugReader::tokenize(const QString &s) void DebugReader::handleBreakpoint(const GDBMIResultParser::ParseObject& breakpoint) { // gdb use system encoding for file path - QString filename = QString::fromLocal8Bit(breakpoint["filename"].value()); + QString filename = QFileInfo(QString::fromLocal8Bit(breakpoint["filename"].value())).absoluteFilePath(); int line = breakpoint["line"].intValue(); int number = breakpoint["number"].intValue(); emit breakpointInfoGetted(filename, line , number); @@ -2046,10 +2053,8 @@ 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) { + if (bp->filename == filename && bp->line == line) { bp->number = number; } } diff --git a/RedPandaIDE/gdbmiresultparser.cpp b/RedPandaIDE/gdbmiresultparser.cpp index 44b719d8..4a0620c4 100644 --- a/RedPandaIDE/gdbmiresultparser.cpp +++ b/RedPandaIDE/gdbmiresultparser.cpp @@ -31,6 +31,42 @@ bool GDBMIResultParser::parse(const QByteArray &record, GDBMIResultType &type, P return true; } +bool GDBMIResultParser::parseAsyncResult(const QByteArray &record, QByteArray &result, ParseObject &multiValue) +{ + const char* p =record.data(); + if (*p!='*') + return false; + p++; + const char* start; + while (*p && *p!=',') + p++; + result = QByteArray(start,p-start); + if (*p==0) + return true; + return parseMultiValues(p,multiValue); +} + +bool GDBMIResultParser::parseMultiValues(const char* p, ParseObject &multiValue) +{ + while (*p) { + QByteArray propName; + ParseValue propValue; + bool result = parseNameAndValue(p,propName,propValue); + if (result) { + multiValue[propName]=propValue; + } else { + return false; + } + skipSpaces(p); + if (*p!=',') + return false; + p++; //skip ',' + skipSpaces(p); + p++; + } + return true; +} + bool GDBMIResultParser::parseNameAndValue(const char *&p, QByteArray &name, ParseValue &value) { skipSpaces(p); diff --git a/RedPandaIDE/gdbmiresultparser.h b/RedPandaIDE/gdbmiresultparser.h index f16781aa..4ae71eb4 100644 --- a/RedPandaIDE/gdbmiresultparser.h +++ b/RedPandaIDE/gdbmiresultparser.h @@ -53,6 +53,7 @@ public: const QByteArray &value() const; const QList &array() const; const ParseObject &object() const; + int intValue(int defaultValue=-1) const; ParseValueType type() const; ParseValue& operator=(const QByteArray& value); ParseValue& operator=(const ParseObject& object); @@ -70,7 +71,9 @@ public: public: GDBMIResultParser(); bool parse(const QByteArray& record, GDBMIResultType& type, ParseValue& value); + bool parseAsyncResult(const QByteArray& record, QByteArray& result, ParseObject& multiValue); private: + bool parseMultiValues(const char*p, ParseObject& multiValue); bool parseNameAndValue(const char *&p,QByteArray& name, ParseValue& value); bool parseValue(const char* &p, ParseValue& value); bool parseStringValue(const char*&p, QByteArray& stringValue);