work save

This commit is contained in:
royqh1979@gmail.com 2021-11-21 10:36:50 +08:00
parent aa17415b15
commit a927c2cc0e
3 changed files with 61 additions and 17 deletions

View File

@ -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;
}
}

View File

@ -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);

View File

@ -53,6 +53,7 @@ public:
const QByteArray &value() const;
const QList<ParseObject> &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);