Commit fa2ac442 authored by hjk's avatar hjk Committed by David Schulz
Browse files

Debugger: Add a convenience function GdbMi::toInt()



Saves some line noise on the user side.

Change-Id: I9c6d7542195fc7485ac4ee466cd42a28be95b8da
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent 4f063d5b
......@@ -2036,7 +2036,7 @@ unsigned CdbEngine::examineStopReason(const GdbMi &stopReason,
rc |= StopReportLog;
return rc;
}
const int threadId = stopReason["threadId"].data().toInt();
const int threadId = stopReason["threadId"].toInt();
if (reason == "breakpoint") {
// Note: Internal breakpoints (run to line) are reported with id=0.
// Step out creates temporary breakpoints with id 10000.
......
......@@ -423,7 +423,7 @@ void WinException::fromGdbMI(const GdbMi &gdbmi)
}
const GdbMi gLineNumber = gdbmi["exceptionLine"];
if (gLineNumber.isValid()) {
lineNumber = gLineNumber.data().toInt();
lineNumber = gLineNumber.toInt();
file = gdbmi["exceptionFile"].data();
}
function = gdbmi["exceptionFunction"].data();
......
......@@ -123,6 +123,7 @@ public:
QByteArray toString(bool multiline = false, int indent = 0) const;
qulonglong toAddress() const;
int toInt() const { return m_data.toInt(); }
void fromString(const QByteArray &str);
void fromStringMultiple(const QByteArray &str);
......
......@@ -307,9 +307,9 @@ bool DumperHelper::parseQuery(const GdbMi &contents)
int qtv = 0;
const GdbMi qtversion = contents["qtversion"];
if (qtversion.children().size() == 3) {
qtv = (qtversion.childAt(0).data().toInt() << 16)
+ (qtversion.childAt(1).data().toInt() << 8)
+ qtversion.childAt(2).data().toInt();
qtv = (qtversion.childAt(0).toInt() << 16)
+ (qtversion.childAt(1).toInt() << 8)
+ qtversion.childAt(2).toInt();
}
m_qtVersion = qtv;
// Get list of helpers
......@@ -329,7 +329,7 @@ bool DumperHelper::parseQuery(const GdbMi &contents)
foreach (const GdbMi &sizesList, contents["sizes"].children()) {
const int childCount = sizesList.childCount();
if (childCount > 1) {
const int size = sizesList.childAt(0).data().toInt();
const int size = sizesList.childAt(0).toInt();
for (int c = 1; c < childCount; c++)
addSize(sizesList.childAt(c).data(), size);
}
......
......@@ -1437,7 +1437,7 @@ void GdbEngine::handleStopResponse(const GdbMi &data)
if (frame.isValid()) {
const GdbMi lineNumberG = frame["line"];
if (lineNumberG.isValid()) {
lineNumber = lineNumberG.data().toInt();
lineNumber = lineNumberG.toInt();
fullName = cleanupFullName(QString::fromLocal8Bit(frame["fullname"].data()));
if (fullName.isEmpty())
fullName = QString::fromLocal8Bit(frame["file"].data());
......@@ -1864,7 +1864,7 @@ void GdbEngine::handlePythonSetup(const GdbResponse &response)
watchHandler()->addTypeFormats(type, formats);
}
const GdbMi hasInferiorThreadList = data["hasInferiorThreadList"];
m_hasInferiorThreadList = (hasInferiorThreadList.data().toInt() != 0);
m_hasInferiorThreadList = (hasInferiorThreadList.toInt() != 0);
}
}
......@@ -2474,7 +2474,7 @@ void GdbEngine::updateResponse(BreakpointResponse &response, const GdbMi &bkpt)
// The line numbers here are the uncorrected ones. So don't
// change it if we know better already.
if (response.correctedLineNumber == 0)
response.lineNumber = child.data().toInt();
response.lineNumber = child.toInt();
} else if (child.hasName("cond")) {
// gdb 6.3 likes to "rewrite" conditions. Just accept that fact.
response.condition = child.data();
......@@ -2493,7 +2493,7 @@ void GdbEngine::updateResponse(BreakpointResponse &response, const GdbMi &bkpt)
ba = ba.mid(1, ba.size() - 2);
response.functionName = _(ba);
} else if (child.hasName("thread")) {
response.threadSpec = child.data().toInt();
response.threadSpec = child.toInt();
} else if (child.hasName("type")) {
// "breakpoint", "hw breakpoint", "tracepoint", "hw watchpoint"
// {bkpt={number="2",type="hw watchpoint",disp="keep",enabled="y",
......@@ -2845,7 +2845,7 @@ void GdbEngine::handleBreakList(const GdbMi &table)
bkpts = table.children();
// Remove the 'hdr' and artificial items.
for (int i = bkpts.size(); --i >= 0; ) {
int num = bkpts.at(i)["number"].data().toInt();
int num = bkpts.at(i)["number"].toInt();
if (num <= 0)
bkpts.removeAt(i);
}
......@@ -3663,7 +3663,7 @@ StackFrame GdbEngine::parseStackFrame(const GdbMi &frameMi, int level)
frame.file = QFile::decodeName(frameMi["file"].data());
frame.function = _(frameMi["func"].data());
frame.from = _(frameMi["from"].data());
frame.line = frameMi["line"].data().toInt();
frame.line = frameMi["line"].toInt();
frame.address = frameMi["addr"].toAddress();
frame.usable = QFileInfo(frame.file).isReadable();
return frame;
......@@ -3795,7 +3795,7 @@ void GdbEngine::handleThreadListIds(const GdbResponse &response)
const QList<GdbMi> items = response.data["thread-ids"].children();
for (int index = 0, n = items.size(); index != n; ++index) {
ThreadData thread;
thread.id = ThreadId(items.at(index).data().toInt());
thread.id = ThreadId(items.at(index).toInt());
handler->updateThread(thread);
}
reloadStack(false); // Will trigger register reload.
......@@ -3809,9 +3809,9 @@ void GdbEngine::handleThreadNames(const GdbResponse &response)
names.fromString(response.consoleStreamOutput);
foreach (const GdbMi &name, names.children()) {
ThreadData thread;
thread.id = ThreadId(name["id"].data().toInt());
thread.id = ThreadId(name["id"].toInt());
thread.name = decodeData(name["value"].data(),
name["valueencoded"].data().toInt());
name["valueencoded"].toInt());
handler->updateThread(thread);
}
updateViews();
......@@ -3935,7 +3935,7 @@ void GdbEngine::handleRegisterListValues(const GdbResponse &response)
const GdbMi values = response.data["register-values"];
QTC_ASSERT(registerCount == values.children().size(), return);
foreach (const GdbMi &item, values.children()) {
const int number = item["number"].data().toInt();
const int number = item["number"].toInt();
if (number >= 0 && number < gdbRegisterCount)
registers[m_registerNumbers[number]].value = item["value"].data();
}
......@@ -4310,7 +4310,7 @@ WatchData GdbEngine::localVariable(const GdbMi &item,
GdbMi t = item["numchild"];
if (t.isValid())
data.setHasChildren(t.data().toInt() > 0);
data.setHasChildren(t.toInt() > 0);
else if (isPointerType(data.type) || data.name == QLatin1String("this"))
data.setHasChildren(true);
return data;
......
......@@ -424,10 +424,10 @@ void LldbEngine::updateBreakpointData(const GdbMi &bkpt, bool added)
response.id = rid;
QTC_CHECK(response.id == rid);
response.address = 0;
response.enabled = bkpt["enabled"].data().toInt();
response.ignoreCount = bkpt["ignorecount"].data().toInt();
response.enabled = bkpt["enabled"].toInt();
response.ignoreCount = bkpt["ignorecount"].toInt();
response.condition = bkpt["condition"].data();
response.hitCount = bkpt["hitcount"].data().toInt();
response.hitCount = bkpt["hitcount"].toInt();
if (added) {
// Added.
......@@ -463,7 +463,7 @@ void LldbEngine::refreshDisassembly(const GdbMi &data)
{
DisassemblerLines result;
int cookie = data["cookie"].data().toInt();
int cookie = data["cookie"].toInt();
QPointer<DisassemblerAgent> agent = m_disassemblerAgents.key(cookie);
if (!agent.isNull()) {
foreach (const GdbMi &line, data["lines"].children()) {
......@@ -481,8 +481,8 @@ void LldbEngine::refreshDisassembly(const GdbMi &data)
void LldbEngine::refreshMemory(const GdbMi &data)
{
int cookie = data["cookie"].data().toInt();
qulonglong addr = data["address"].data().toInt();
int cookie = data["cookie"].toInt();
qulonglong addr = data["address"].toInt();
QPointer<MemoryAgent> agent = m_memoryAgents.key(cookie);
if (!agent.isNull()) {
QPointer<QObject> token = m_memoryAgentTokens.value(cookie);
......@@ -851,16 +851,16 @@ void LldbEngine::refreshStack(const GdbMi &stack)
StackFrames frames;
foreach (const GdbMi &item, stack["frames"].children()) {
StackFrame frame;
frame.level = item["level"].data().toInt();
frame.level = item["level"].toInt();
frame.file = QString::fromLatin1(item["file"].data());
frame.function = QString::fromLatin1(item["func"].data());
frame.from = QString::fromLatin1(item["func"].data());
frame.line = item["line"].data().toInt();
frame.line = item["line"].toInt();
frame.address = item["addr"].toAddress();
frame.usable = QFileInfo(frame.file).isReadable();
frames.append(frame);
}
bool canExpand = stack["hasmore"].data().toInt();
bool canExpand = stack["hasmore"].toInt();
debuggerCore()->action(ExpandStack)->setEnabled(canExpand);
handler->setFrames(frames);
}
......@@ -938,7 +938,7 @@ void LldbEngine::refreshState(const GdbMi &reportedState)
void LldbEngine::refreshLocation(const GdbMi &reportedLocation)
{
QByteArray file = reportedLocation["file"].data();
int line = reportedLocation["line"].data().toInt();
int line = reportedLocation["line"].toInt();
gotoLocation(Location(QString::fromUtf8(file), line));
}
......
......@@ -435,7 +435,7 @@ void ThreadsHandler::updateThreads(const GdbMi &data)
const GdbMi item = items.at(index);
const GdbMi frame = item["frame"];
ThreadData thread;
thread.id = ThreadId(item["id"].data().toInt());
thread.id = ThreadId(item["id"].toInt());
thread.targetId = QString::fromLatin1(item["target-id"].data());
thread.details = QString::fromLatin1(item["details"].data());
thread.core = QString::fromLatin1(item["core"].data());
......@@ -443,7 +443,7 @@ void ThreadsHandler::updateThreads(const GdbMi &data)
thread.address = frame["addr"].data().toULongLong(&ok, 0);
thread.function = QString::fromLatin1(frame["func"].data());
thread.fileName = QString::fromLatin1(frame["fullname"].data());
thread.lineNumber = frame["line"].data().toInt();
thread.lineNumber = frame["line"].toInt();
thread.module = QString::fromLocal8Bit(frame["from"].data());
thread.stopped = true;
// Non-GDB (Cdb2) output name here.
......
......@@ -417,7 +417,7 @@ void WatchData::updateValue(const GdbMi &item)
{
GdbMi value = item["value"];
if (value.isValid()) {
int encoding = item["valueencoded"].data().toInt();
int encoding = item["valueencoded"].toInt();
setValue(decodeData(value.data(), encoding));
} else {
setValueNeeded();
......@@ -434,7 +434,7 @@ void setWatchDataValueToolTip(WatchData &data, const GdbMi &mi,
void WatchData::updateChildCount(const GdbMi &mi)
{
if (mi.isValid())
setHasChildren(mi.data().toInt() > 0);
setHasChildren(mi.toInt() > 0);
}
static void setWatchDataValueEnabled(WatchData &data, const GdbMi &mi)
......@@ -589,7 +589,7 @@ void parseWatchData(const QSet<QByteArray> &expandedINames,
mi = item["editformat"];
if (mi.isValid())
data.editformat = mi.data().toInt();
data.editformat = mi.toInt();
mi = item["typeformats"];
if (mi.isValid())
......@@ -597,11 +597,11 @@ void parseWatchData(const QSet<QByteArray> &expandedINames,
mi = item["bitpos"];
if (mi.isValid())
data.bitpos = mi.data().toInt();
data.bitpos = mi.toInt();
mi = item["bitsize"];
if (mi.isValid())
data.bitsize = mi.data().toInt();
data.bitsize = mi.toInt();
mi = item["origaddr"];
if (mi.isValid())
......@@ -634,7 +634,7 @@ void parseWatchData(const QSet<QByteArray> &expandedINames,
mi = item["arraydata"];
if (mi.isValid()) {
int encoding = item["arrayencoding"].data().toInt();
int encoding = item["arrayencoding"].toInt();
childtemplate.iname = data.iname + '.';
childtemplate.address = addressBase;
decodeArray(list, childtemplate, mi.data(), encoding);
......@@ -664,7 +664,7 @@ void parseWatchData(const QSet<QByteArray> &expandedINames,
}
QByteArray key = child["key"].data();
if (!key.isEmpty()) {
int encoding = child["keyencoded"].data().toInt();
int encoding = child["keyencoded"].toInt();
QString skey = decodeData(key, encoding);
if (skey.size() > 13) {
skey = skey.left(12);
......
......@@ -727,7 +727,7 @@ void tst_Dumpers::dumper()
dummy.iname = child["iname").data();
dummy.name = QLatin1String(child["name").data());
if (dummy.iname == "local.qtversion")
context.qtVersion = child["value").data().toInt();
context.qtVersion = child["value").toInt();
else
parseWatchData(expandedINames, dummy, child, &list);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment