2021-11-12 10:51:00 +08:00
|
|
|
#ifndef GDBMIRESULTPARSER_H
|
|
|
|
#define GDBMIRESULTPARSER_H
|
|
|
|
|
|
|
|
#include <QByteArray>
|
2021-11-13 11:16:05 +08:00
|
|
|
#include <QHash>
|
2021-11-13 10:55:10 +08:00
|
|
|
#include <QList>
|
2021-11-13 11:16:05 +08:00
|
|
|
#include <memory>
|
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-13 11:16:05 +08:00
|
|
|
public:
|
2021-11-12 22:42:51 +08:00
|
|
|
enum class ParseValueType {
|
|
|
|
Value,
|
|
|
|
Object,
|
|
|
|
Array,
|
|
|
|
NotAssigned
|
|
|
|
};
|
|
|
|
|
2021-11-13 11:16:05 +08:00
|
|
|
class ParseValue;
|
|
|
|
|
|
|
|
class ParseObject {
|
|
|
|
public:
|
2021-11-24 17:53:25 +08:00
|
|
|
explicit ParseObject();
|
|
|
|
ParseObject(const ParseObject& object);
|
|
|
|
ParseValue operator[](const QByteArray& name) const;
|
2021-11-13 11:16:05 +08:00
|
|
|
ParseValue& operator[](const QByteArray& name);
|
|
|
|
ParseObject& operator=(const ParseObject& object);
|
|
|
|
private:
|
|
|
|
QHash<QByteArray, ParseValue> mProps;
|
|
|
|
};
|
2021-11-12 22:42:51 +08:00
|
|
|
|
|
|
|
class ParseValue {
|
|
|
|
public:
|
|
|
|
explicit ParseValue();
|
2021-11-21 08:38:03 +08:00
|
|
|
explicit ParseValue(const QByteArray& value);
|
2021-11-12 22:42:51 +08:00
|
|
|
explicit ParseValue(const ParseObject &object);
|
2021-11-23 21:08:33 +08:00
|
|
|
explicit ParseValue(const QList<ParseValue>& array);
|
2021-11-24 17:53:25 +08:00
|
|
|
ParseValue(const ParseValue& value);
|
2021-11-21 08:38:03 +08:00
|
|
|
const QByteArray &value() const;
|
2021-11-23 21:08:33 +08:00
|
|
|
const QList<ParseValue> &array() const;
|
2021-11-13 10:55:10 +08:00
|
|
|
const ParseObject &object() const;
|
2021-11-21 10:36:50 +08:00
|
|
|
int intValue(int defaultValue=-1) const;
|
2021-11-24 17:53:25 +08:00
|
|
|
int hexValue(int defaultValue=-1) const;
|
|
|
|
|
2021-11-23 21:08:33 +08:00
|
|
|
QString pathValue() const;
|
2021-11-12 22:42:51 +08:00
|
|
|
ParseValueType type() const;
|
2021-11-24 17:53:25 +08:00
|
|
|
bool isValid() const;
|
2021-11-21 08:38:03 +08:00
|
|
|
ParseValue& operator=(const QByteArray& value);
|
2021-11-12 22:42:51 +08:00
|
|
|
ParseValue& operator=(const ParseObject& object);
|
2021-11-23 21:08:33 +08:00
|
|
|
ParseValue& operator=(const QList<ParseValue>& array);
|
2021-11-12 22:42:51 +08:00
|
|
|
ParseValue& operator=(const ParseValue& value);
|
2021-11-12 10:51:00 +08:00
|
|
|
private:
|
2021-11-21 08:38:03 +08:00
|
|
|
QByteArray mValue;
|
2021-11-23 21:08:33 +08:00
|
|
|
QList<ParseValue> mArray;
|
2021-11-12 22:42:51 +08:00
|
|
|
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>;
|
|
|
|
|
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);
|
2021-11-21 10:36:50 +08:00
|
|
|
bool parseAsyncResult(const QByteArray& record, QByteArray& result, ParseObject& multiValue);
|
2021-11-12 22:42:51 +08:00
|
|
|
private:
|
2021-11-21 10:36:50 +08:00
|
|
|
bool parseMultiValues(const char*p, ParseObject& multiValue);
|
2021-11-13 11:16:05 +08:00
|
|
|
bool parseNameAndValue(const char *&p,QByteArray& name, ParseValue& value);
|
|
|
|
bool parseValue(const char* &p, ParseValue& value);
|
|
|
|
bool parseStringValue(const char*&p, QByteArray& stringValue);
|
|
|
|
bool parseObject(const char*&p, ParseObject& obj);
|
2021-11-23 21:08:33 +08:00
|
|
|
bool parseArray(const char*&p, QList<ParseValue>& array);
|
2021-11-13 11:16:05 +08:00
|
|
|
void skipSpaces(const char* &p);
|
2021-11-12 22:42:51 +08:00
|
|
|
bool isNameChar(char ch);
|
|
|
|
bool isSpaceChar(char ch);
|
|
|
|
private:
|
|
|
|
QHash<QByteArray, GDBMIResultType> mResultTypes;
|
2021-11-12 10:51:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GDBMIRESULTPARSER_H
|