forked from qt-creator/qt-creator
Debugger: Populate stack view with LLDB backend
Change-Id: I9808829559da65cd152d2455737f6c7f394da6b3 Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -489,12 +489,12 @@ try:
|
||||
def fieldCount(type):
|
||||
return type.fieldCount();
|
||||
|
||||
def threadsData(threadsOptions):
|
||||
def threadsData(options):
|
||||
result = "threads={threads=["
|
||||
for i in range(lldb.process.num_threads):
|
||||
thread = lldb.process.GetThreadAtIndex(i)
|
||||
for thread in lldb.process.threads:
|
||||
result += "{id=\"%d\"" % thread.id
|
||||
result += ",target-id=\"%s\"" % thread.id
|
||||
result += ",index=\"%s\"" % thread.idx
|
||||
result += ",stop-reason=\"%s\"" % thread.stop_reason
|
||||
|
||||
if thread.IsSuspended():
|
||||
@@ -508,7 +508,6 @@ try:
|
||||
result += ",frame={"
|
||||
frame = thread.GetFrameAtIndex(0)
|
||||
result += "pc=\"%s\"" % frame.pc
|
||||
result += ",level=\"%d\"" % i
|
||||
result += ",addr=\"%s\"" % frame.pc
|
||||
result += ",fp=\"%s\"" % frame.fp
|
||||
result += ",func=\"%s\"" % frame.function.name
|
||||
@@ -520,19 +519,45 @@ try:
|
||||
result += "],current-thread-id=\"%s\"}" % lldb.process.GetSelectedThread().id
|
||||
return result
|
||||
|
||||
def stackData(stackOptions):
|
||||
result = "stack=["
|
||||
result += "],"
|
||||
def stackData(options):
|
||||
try:
|
||||
thread = lldb.process.GetThreadById(options["threadid"])
|
||||
except:
|
||||
thread = lldb.process.GetThreadAtIndex(0)
|
||||
result = "stack={frames=["
|
||||
for frame in thread.frames:
|
||||
result += "{pc=\"%s\"" % frame.pc
|
||||
result += ",level=\"%d\"" % frame.idx
|
||||
result += ",addr=\"%s\"" % frame.pc
|
||||
result += ",fp=\"%s\"" % frame.fp
|
||||
result += ",func=\"%s\"" % frame.function.name
|
||||
result += ",line=\"%s\"" % frame.line_entry.line
|
||||
result += ",fullname=\"%s\"" % frame.line_entry.file
|
||||
result += ",usable=\"1\""
|
||||
result += ",file=\"%s\"}," % frame.line_entry.file
|
||||
|
||||
hasmore = "0"
|
||||
result += "],hasmore=\"%s\"}, " % hasmore
|
||||
return result
|
||||
|
||||
def updateData(parts, localsOptions, stackOptions, threadsOptions):
|
||||
def parseOptions(optionstring):
|
||||
options = {}
|
||||
for opt in optionstring.split(","):
|
||||
try:
|
||||
key, value = opt.split(":")
|
||||
options[key] = value
|
||||
except:
|
||||
pass
|
||||
return options
|
||||
|
||||
def updateData(parts, localsOptions, stackOptions, threadOptions):
|
||||
result = "";
|
||||
if parts & 1:
|
||||
result += bb(localsOptions) + ','
|
||||
result += bb(localsOptions) + ","
|
||||
if parts & 2:
|
||||
result += stackData(stackOptions)
|
||||
result += stackData(parseOptions(stackOptions))
|
||||
if parts & 4:
|
||||
result += threadsData(threadsOptions)
|
||||
result += threadsData(parseOptions(threadOptions))
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "watchutils.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/savedaction.h>
|
||||
|
||||
#include <texteditor/itexteditor.h>
|
||||
#include <coreplugin/idocument.h>
|
||||
@@ -808,6 +809,13 @@ void LldbEngine::updateData(DataKind kind)
|
||||
+ "watcher:" + watchers.toHex();
|
||||
}
|
||||
|
||||
if (kind & StackData) {
|
||||
int maxdepth = debuggerCore()->action(MaximalStackDepth)->value().toInt();
|
||||
ThreadId curthread = threadsHandler()->currentThread();
|
||||
stackOptions += "maxdepth:" + QByteArray::number(maxdepth);
|
||||
stackOptions += "curthread:" + QByteArray::number(curthread.raw());
|
||||
}
|
||||
|
||||
postCommand("script updateData(" + QByteArray::number(kind) + ','
|
||||
+ '\'' + localsOptions + "',"
|
||||
+ '\'' + stackOptions + "',"
|
||||
@@ -815,52 +823,6 @@ void LldbEngine::updateData(DataKind kind)
|
||||
CB(handleUpdateData));
|
||||
}
|
||||
|
||||
void LldbEngine::handleBacktrace(const LldbResponse &response)
|
||||
{
|
||||
// Populate stack view.
|
||||
StackFrames stackFrames;
|
||||
int level = 0;
|
||||
int currentIndex = -1;
|
||||
foreach (const QByteArray &line, response.data.split('\n')) {
|
||||
//qDebug() << " LINE: '" << line << "'";
|
||||
if (line.startsWith("> ") || line.startsWith(" ")) {
|
||||
int pos1 = line.indexOf('(');
|
||||
int pos2 = line.indexOf(')', pos1);
|
||||
if (pos1 != -1 && pos2 != -1) {
|
||||
int lineNumber = line.mid(pos1 + 1, pos2 - pos1 - 1).toInt();
|
||||
QByteArray fileName = line.mid(2, pos1 - 2);
|
||||
//qDebug() << " " << pos1 << pos2 << lineNumber << fileName
|
||||
// << line.mid(pos1 + 1, pos2 - pos1 - 1);
|
||||
StackFrame frame;
|
||||
frame.file = _(fileName);
|
||||
frame.line = lineNumber;
|
||||
frame.function = _(line.mid(pos2 + 1));
|
||||
frame.usable = QFileInfo(frame.file).isReadable();
|
||||
if (frame.line > 0 && QFileInfo(frame.file).exists()) {
|
||||
if (line.startsWith("> "))
|
||||
currentIndex = level;
|
||||
frame.level = level;
|
||||
stackFrames.prepend(frame);
|
||||
++level;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const int frameCount = stackFrames.size();
|
||||
for (int i = 0; i != frameCount; ++i)
|
||||
stackFrames[i].level = frameCount - stackFrames[i].level - 1;
|
||||
stackHandler()->setFrames(stackFrames);
|
||||
|
||||
// Select current frame.
|
||||
if (currentIndex != -1) {
|
||||
currentIndex = frameCount - currentIndex - 1;
|
||||
stackHandler()->setCurrentIndex(currentIndex);
|
||||
gotoLocation(stackFrames.at(currentIndex));
|
||||
}
|
||||
|
||||
updateData(LocalsData);
|
||||
}
|
||||
|
||||
GdbMi LldbEngine::parseFromString(QByteArray out)
|
||||
{
|
||||
GdbMi all;
|
||||
@@ -941,6 +903,22 @@ void LldbEngine::handleUpdateData(const LldbResponse &response)
|
||||
if (stack.isValid()) {
|
||||
//if (!partial)
|
||||
// emit stackFrameCompleted();
|
||||
StackHandler *handler = stackHandler();
|
||||
StackFrames frames;
|
||||
foreach (const GdbMi &item, stack.findChild("frames").children()) {
|
||||
StackFrame frame;
|
||||
frame.level = item.findChild("level").data().toInt();
|
||||
frame.file = QString::fromLatin1(item.findChild("file").data());
|
||||
frame.function = QString::fromLatin1(item.findChild("func").data());
|
||||
frame.from = QString::fromLatin1(item.findChild("func").data());
|
||||
frame.line = item.findChild("line").data().toInt();
|
||||
frame.address = item.findChild("addr").data().toULongLong();
|
||||
frame.usable = QFileInfo(frame.file).isReadable();
|
||||
frames.append(frame);
|
||||
}
|
||||
bool canExpand = stack.findChild("hasmore").data().toInt();
|
||||
debuggerCore()->action(ExpandStack)->setEnabled(canExpand);
|
||||
handler->setFrames(frames);
|
||||
}
|
||||
|
||||
GdbMi threads = all.findChild("threads");
|
||||
|
||||
@@ -150,7 +150,6 @@ private:
|
||||
};
|
||||
|
||||
void handleStop(const LldbResponse &response);
|
||||
void handleBacktrace(const LldbResponse &response);
|
||||
void handleListLocals(const LldbResponse &response);
|
||||
void handleListModules(const LldbResponse &response);
|
||||
void handleListSymbols(const LldbResponse &response);
|
||||
|
||||
Reference in New Issue
Block a user