2021-11-12 10:51:00 +08:00
|
|
|
#ifndef GDBMIRESULTPARSER_H
|
|
|
|
#define GDBMIRESULTPARSER_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
2021-11-13 10:55:10 +08:00
|
|
|
#include <QList>
|
2021-11-12 22:42:51 +08:00
|
|
|
#include <QVector>
|
2021-11-12 10:51:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum class GDBMIResultType {
|
|
|
|
Breakpoint,
|
|
|
|
BreakpointTable,
|
|
|
|
FrameStack,
|
|
|
|
LocalVariables,
|
|
|
|
Locals,
|
|
|
|
Frame,
|
|
|
|
Disassembly,
|
|
|
|
Evaluation,
|
|
|
|
RegisterNames,
|
|
|
|
RegisterValues,
|
|
|
|
Memory
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GDBMIResultParser
|
|
|
|
{
|
2021-11-12 22:42:51 +08:00
|
|
|
enum class ParseValueType {
|
|
|
|
Value,
|
|
|
|
Object,
|
|
|
|
Array,
|
|
|
|
NotAssigned
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParseObject;
|
|
|
|
|
|
|
|
class ParseValue {
|
|
|
|
public:
|
|
|
|
explicit ParseValue();
|
|
|
|
explicit ParseValue(const QString& value);
|
|
|
|
explicit ParseValue(const ParseObject &object);
|
|
|
|
explicit ParseValue(const QList<ParseObject>& array);
|
|
|
|
ParseValue(const ParseValue&) = delete;
|
|
|
|
const QString &value() const;
|
2021-11-13 10:55:10 +08:00
|
|
|
const QList<ParseObject> &array() const;
|
|
|
|
const ParseObject &object() const;
|
2021-11-12 22:42:51 +08:00
|
|
|
ParseValueType type() const;
|
|
|
|
ParseValue& operator=(const QString& value);
|
|
|
|
ParseValue& operator=(const ParseObject& object);
|
|
|
|
ParseValue& operator=(const QList<ParseObject>& array);
|
|
|
|
ParseValue& operator=(const ParseValue& value);
|
2021-11-12 10:51:00 +08:00
|
|
|
private:
|
2021-11-12 22:42:51 +08:00
|
|
|
QString mValue;
|
|
|
|
QList<ParseObject> mArray;
|
|
|
|
ParseObject mObject;
|
|
|
|
ParseValueType mType;
|
2021-11-12 10:51:00 +08:00
|
|
|
};
|
|
|
|
|
2021-11-12 22:42:51 +08:00
|
|
|
using PParseValue = std::shared_ptr<ParseValue>;
|
|
|
|
|
|
|
|
class ParseObject {
|
|
|
|
const ParseValue& operator[](const QByteArray& name) const;
|
|
|
|
ParseValue& operator[](const QByteArray& name);
|
|
|
|
ParseObject& operator=(const ParseObject& object);
|
|
|
|
private:
|
|
|
|
QHash<QByteArray, ParseValue> mProps;
|
2021-11-12 10:51:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
GDBMIResultParser();
|
2021-11-12 22:42:51 +08:00
|
|
|
bool parse(const QByteArray& record, GDBMIResultType& type, ParseValue& value);
|
|
|
|
private:
|
|
|
|
bool parseNameAndValue(char* &p,QByteArray& name, ParseValue& value);
|
|
|
|
bool parseValue(char* &p, ParseValue& value);
|
|
|
|
bool parseStringValue(char*&p, QByteArray& stringValue);
|
|
|
|
bool parseObject(char*&p, ParseObject& obj);
|
|
|
|
bool parseArray(char*&p, QList<ParseObject>& array);
|
|
|
|
void skipSpaces(char* &p);
|
|
|
|
bool isNameChar(char ch);
|
|
|
|
bool isSpaceChar(char ch);
|
|
|
|
private:
|
|
|
|
QHash<QByteArray, GDBMIResultType> mResultTypes;
|
2021-11-12 10:51:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GDBMIRESULTPARSER_H
|