debugger: work on gdbmi test cases

This commit is contained in:
hjk
2009-04-06 14:33:45 +02:00
parent 494f0764dc
commit c1124a4f8a
2 changed files with 66 additions and 102 deletions

View File

@@ -115,18 +115,18 @@ void GdbMi::parseValue(const char *&from, const char *to)
{ {
//qDebug() << "parseValue: " << QByteArray::fromUtf16(from, to - from); //qDebug() << "parseValue: " << QByteArray::fromUtf16(from, to - from);
switch (*from) { switch (*from) {
case '{': case '{':
parseTuple(from, to); parseTuple(from, to);
break; break;
case '[': case '[':
parseList(from, to); parseList(from, to);
break; break;
case '"': case '"':
m_type = Const; m_type = Const;
m_data = parseCString(from, to); m_data = parseCString(from, to);
break; break;
default: default:
break; break;
} }
} }
@@ -215,48 +215,46 @@ QByteArray GdbMi::toString(bool multiline, int indent) const
{ {
QByteArray result; QByteArray result;
switch (m_type) { switch (m_type) {
case Invalid: case Invalid:
if (multiline) { if (multiline)
result += ind(indent) + "Invalid\n"; result += ind(indent) + "Invalid\n";
} else { else
result += "Invalid"; result += "Invalid";
} break;
break; case Const:
case Const: if (!m_name.isEmpty())
if (!m_name.isEmpty()) result += m_name + "=";
result += m_name + "="; if (multiline)
if (multiline) { result += "\"" + m_data + "\"";
result += "\"" + m_data + "\""; else
} else { result += "\"" + m_data + "\"";
result += "\"" + m_data + "\""; break;
} case Tuple:
break; if (!m_name.isEmpty())
case Tuple: result += m_name + "=";
if (!m_name.isEmpty()) if (multiline) {
result += m_name + "="; result += "{\n";
if (multiline) { dumpChildren(&result, multiline, indent + 1);
result += "{\n"; result += '\n' + ind(indent) + "}";
dumpChildren(&result, multiline, indent + 1); } else {
result += '\n' + ind(indent) + "}"; result += "{";
} else { dumpChildren(&result, multiline, indent + 1);
result += "{"; result += "}";
dumpChildren(&result, multiline, indent + 1); }
result += "}"; break;
} case List:
break; if (!m_name.isEmpty())
case List: result += m_name + "=";
if (!m_name.isEmpty()) if (multiline) {
result += m_name + "="; result += "[\n";
if (multiline) { dumpChildren(&result, multiline, indent + 1);
result += "[\n"; result += '\n' + ind(indent) + "]";
dumpChildren(&result, multiline, indent + 1); } else {
result += '\n' + ind(indent) + "]"; result += "[";
} else { dumpChildren(&result, multiline, indent + 1);
result += "["; result += "]";
dumpChildren(&result, multiline, indent + 1); }
result += "]"; break;
}
break;
} }
return result; return result;
} }

View File

@@ -8,51 +8,50 @@ using namespace Debugger;
using namespace Debugger::Internal; using namespace Debugger::Internal;
static const char test1[] = static const char test1[] =
"1^done,stack=[frame={level=\"0\",addr=\"0x00000000004061ca\"," "[frame={level=\"0\",addr=\"0x00000000004061ca\","
"func=\"main\",file=\"test1.cpp\"," "func=\"main\",file=\"test1.cpp\","
"fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]"; "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]";
static const char test2[] = static const char test2[] =
"2^done,stack=[frame={level=\"0\",addr=\"0x00002ac058675840\"," "[frame={level=\"0\",addr=\"0x00002ac058675840\","
"func=\"QApplication\",file=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\"," "func=\"QApplication\",file=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\","
"fullname=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\",line=\"592\"}," "fullname=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\",line=\"592\"},"
"frame={level=\"1\",addr=\"0x00000000004061e0\",func=\"main\",file=\"test1.cpp\"," "frame={level=\"1\",addr=\"0x00000000004061e0\",func=\"main\",file=\"test1.cpp\","
"fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]\n"; "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]";
static const char test3[] = static const char test3[] =
"3^done,stack=[frame={level=\"0\",addr=\"0x00000000004061ca\"," "[stack={frame={level=\"0\",addr=\"0x00000000004061ca\","
"func=\"main\",file=\"test1.cpp\"," "func=\"main\",file=\"test1.cpp\","
"fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]\n"; "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}}]";
static const char test4[] = static const char test4[] =
"&\"source /home/apoenitz/dev/ide/main/bin/gdb/qt4macros\\n\"\n" "&\"source /home/apoenitz/dev/ide/main/bin/gdb/qt4macros\\n\""
"4^done\n"; "4^done\n";
static const char test5[] = static const char test5[] =
"1*stopped,reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"1\"," "[reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"1\","
"frame={addr=\"0x0000000000405738\",func=\"main\"," "frame={addr=\"0x0000000000405738\",func=\"main\","
"args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\"0x7fff1ac78f28\"}]," "args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\"0x7fff1ac78f28\"}],"
"file=\"test1.cpp\",fullname=\"/home/apoenitz/work/test1/test1.cpp\"," "file=\"test1.cpp\",fullname=\"/home/apoenitz/work/test1/test1.cpp\","
"line=\"209\"}\n"; "line=\"209\"}]";
static const char test6[] =
"{u = {u = 2048, v = 16788279, w = -689265400}, a = 1, b = -689265424, c = 11063, s = {static null = {<No data fields>}, static shared_null = {ref = {value = 2}, alloc = 0, size = 0, data = 0x6098da, clean = 0, simpletext = 0, righttoleft = 0, asciiCache = 0, capacity = 0, reserved = 0, array = {0}}, static shared_empty = {ref = {value = 1}, alloc = 0, size = 0, data = 0x2b37d84f8fba, clean = 0, simpletext = 0, righttoleft = 0, asciiCache = 0, capacity = 0, reserved = 0, array = {0}}, d = 0x6098c0, static codecForCStrings = 0x0}}";
static const char test8[] = static const char test8[] =
"8^done,data={locals={{name=\"a\"},{name=\"w\"}}}\n"; "[data={locals={{name=\"a\"},{name=\"w\"}}}]";
static const char test9[] = static const char test9[] =
"9^done,data={locals=[name=\"baz\",name=\"urgs\",name=\"purgs\"]}\n"; "[data={locals=[name=\"baz\",name=\"urgs\",name=\"purgs\"]}]";
static const char test10[] = static const char test10[] =
"16^done,name=\"urgs\",numchild=\"1\",type=\"Urgs\"\n"; "[name=\"urgs\",numchild=\"1\",type=\"Urgs\"]";
static const char test11[] = static const char test11[] =
"[{name=\"size\",value=\"1\",type=\"size_t\",readonly=\"true\"}," "[{name=\"size\",value=\"1\",type=\"size_t\",readonly=\"true\"},"
"{name=\"0\",value=\"one\",type=\"QByteArray\"}]"; "{name=\"0\",value=\"one\",type=\"QByteArray\"}]";
static const char test12[] = static const char test12[] =
"{iname=\"local.hallo\",value=\"\\\"\\\"\",type=\"QByteArray\",numchild=\"0\"}"; "[{iname=\"local.hallo\",value=\"\\\"\\\"\",type=\"QByteArray\","
"numchild=\"0\"}]";
class tst_Debugger : public QObject class tst_Debugger : public QObject
{ {
@@ -67,45 +66,12 @@ public:
'\n' + QString(input)); '\n' + QString(input));
} }
void parse(const QByteArray &str)
{
QByteArray result;
result += "\n ";
int indent = 0;
int from = 0;
int to = str.size();
if (str.size() && str[0] == '{' /*'}'*/) {
++from;
--to;
}
for (int i = from; i < to; ++i) {
if (str[i] == '{')
result += "{\n" + QByteArray(2*++indent + 1, ' ');
else if (str[i] == '}') {
if (!result.isEmpty() && result[result.size() - 1] != '\n')
result += "\n";
result += QByteArray(2*--indent + 1, ' ') + "}\n";
}
else if (str[i] == ',') {
if (!result.isEmpty() && result[result.size() - 1] != '\n')
result += "\n";
result += QByteArray(2*indent, ' ');
}
else
result += str[i];
}
qDebug() << "result:\n" << result;
}
private slots: private slots:
void mi1() { testMi(test1); } void mi1() { testMi(test1); }
void mi2() { testMi(test2); } void mi2() { testMi(test2); }
void mi3() { testMi(test3); } void mi3() { testMi(test3); }
void mi4() { testMi(test4); } //void mi4() { testMi(test4); }
void mi5() { testMi(test5); } void mi5() { testMi(test5); }
void mi6() { testMi(test6); }
void mi8() { testMi(test8); } void mi8() { testMi(test8); }
void mi9() { testMi(test9); } void mi9() { testMi(test9); }
void mi10() { testMi(test10); } void mi10() { testMi(test10); }