Commit 055c4ecb authored by hjk's avatar hjk

Debugger: PdbEngine cleanup

Change-Id: I39f072fe819da746c624e6028b0e5e17f1f1f111
Reviewed-by: default avatarhjk <hjk@theqtcompany.com>
parent 324854a5
......@@ -8,7 +8,10 @@ import os
def qdebug(cmd, args):
class Dumper:
def __init__(self):
pass
self.output = ''
def evaluateTooltip(self, args):
self.updateData(args)
def updateData(self, args):
self.expandedINames = set(args.get("expanded", []))
......@@ -16,8 +19,6 @@ def qdebug(cmd, args):
self.formats = args.get("formats", {})
self.watchers = args.get("watchers", {})
self.output = "data={"
# self.handleListModules()
# self.handleListSymbols(expanded)
# Trigger error to get a backtrace.
frame = None
......@@ -49,7 +50,11 @@ def qdebug(cmd, args):
#sys.stdout.flush()
self.output += '}'
self.flushOutput()
def flushOutput(self):
sys.stdout.write(self.output)
self.output = ""
def put(self, value):
#sys.stdout.write(value)
......@@ -61,9 +66,6 @@ def qdebug(cmd, args):
def putItemCount(self, count):
self.put('value="<%s items>",' % count)
def putEllipsis(self):
self.put('{name="<incomplete>",value="",type="",numchild="0"},')
def cleanType(self, type):
t = str(type)
if t.startswith("<type '") and t.endswith("'>"):
......@@ -75,9 +77,6 @@ def qdebug(cmd, args):
def putType(self, type, priority = 0):
self.putField("type", self.cleanType(type))
def putAddress(self, addr):
self.put('addr="%s",' % cleanAddress(addr))
def putNumChild(self, numchild):
self.put('numchild="%s",' % numchild)
......@@ -217,7 +216,7 @@ def qdebug(cmd, args):
def warn(self, msg):
self.putField("warning", msg)
def handleListModules(self):
def listModules(self, args):
self.put("modules=[");
for name in sys.modules:
self.put("{")
......@@ -225,18 +224,14 @@ def qdebug(cmd, args):
self.putValue(sys.modules[name])
self.put("},")
self.put("]")
#sys.stdout.flush()
def handleListSymbols(self, module):
#self.put("symbols=%s" % dir(sys.modules[module]))
self.put("symbols=[");
for name in sys.modules:
self.put("{")
self.putName(name)
#self.putValue(sys.modules[name])
self.put("},")
self.put("]")
#sys.stdout.flush()
self.flushOutput()
def listSymbols(self, args):
moduleName = args['module']
module = sys.modules.get(moduleName, None)
self.put("symbols={module='%s',symbols='%s'}"
% (module, dir(module) if module else []))
self.flushOutput()
def stackListFrames(self, args):
#isNativeMixed = int(args.get('nativeMixed', 0))
......
......@@ -89,7 +89,7 @@ typedef QVector<Section> Sections;
class Module
{
public:
Module() : symbolsRead(UnknownReadState) {}
Module() : symbolsRead(UnknownReadState), startAddress(0), endAddress(0) {}
public:
enum SymbolReadState {
......
......@@ -398,16 +398,14 @@ void PdbEngine::loadAllSymbols()
void PdbEngine::reloadModules()
{
//postCommand("qdebug('listmodules')", CB(handleListModules));
runCommand("listModules");
}
void PdbEngine::handleListModules(const DebuggerResponse &response)
void PdbEngine::refreshModules(const GdbMi &modules)
{
GdbMi out;
out.fromString(response.logStreamOutput.trimmed());
ModulesHandler *handler = modulesHandler();
handler->beginUpdateAll();
foreach (const GdbMi &item, out.children()) {
foreach (const GdbMi &item, modules.children()) {
Module module;
module.moduleName = _(item["name"].data());
QString path = _(item["value"].data());
......@@ -428,30 +426,21 @@ void PdbEngine::handleListModules(const DebuggerResponse &response)
void PdbEngine::requestModuleSymbols(const QString &moduleName)
{
postCommand("qdebug('listsymbols','" + moduleName.toLatin1() + "')",
[this, moduleName](const DebuggerResponse &r) { handleListSymbols(r, moduleName); });
postCommand("qdebug('listSymbols',{'module':'" + moduleName.toLatin1() + "'})");
}
void PdbEngine::handleListSymbols(const DebuggerResponse &response, const QString &moduleName)
void PdbEngine::refreshSymbols(const GdbMi &symbols)
{
GdbMi out;
out.fromString(response.logStreamOutput.trimmed());
Symbols symbols;
foreach (const GdbMi &item, out.children()) {
QString moduleName = symbols["module"].toUtf8();
Symbols syms;
foreach (const GdbMi &item, symbols["symbols"].children()) {
Symbol symbol;
symbol.name = _(item["name"].data());
symbols.append(symbol);
symbol.name = item["name"].toUtf8();
syms.append(symbol);
}
Internal::showModuleSymbols(moduleName, symbols);
Internal::showModuleSymbols(moduleName, syms);
}
//////////////////////////////////////////////////////////////////////
//
// Tooltip specific stuff
//
//////////////////////////////////////////////////////////////////////
bool PdbEngine::setToolTipExpression(TextEditor::TextEditorWidget *,
const DebuggerToolTipContext &ctx)
{
......@@ -460,17 +449,11 @@ bool PdbEngine::setToolTipExpression(TextEditor::TextEditorWidget *,
DebuggerCommand cmd("evaluateTooltip");
ctx.appendFormatRequest(&cmd);
watchHandler()->appendFormatRequests(&cmd);
runCommand(cmd);
return true;
}
//////////////////////////////////////////////////////////////////////
//
// Watch specific stuff
//
//////////////////////////////////////////////////////////////////////
void PdbEngine::assignValueInDebugger(const Internal::WatchData *, const QString &expression, const QVariant &value)
{
Q_UNUSED(expression);
......@@ -579,75 +562,56 @@ void PdbEngine::handleOutput(const QByteArray &data)
//m_inbuffer.clear();
}
void PdbEngine::handleOutput2(const QByteArray &data)
{
QByteArray lineContext;
foreach (QByteArray line, data.split('\n')) {
// line = line.trimmed();
DebuggerResponse response;
response.logStreamOutput = line;
response.data.fromString(line);
GdbMi data;
data.fromString(line);
showMessage(_("LINE: " + line));
if (line.startsWith("stack={")) {
refreshStack(response.data);
continue;
}
if (line.startsWith("data={")) {
refreshLocals(response.data);
continue;
}
if (line.startsWith("Breakpoint")) {
refreshStack(data);
} else if (line.startsWith("data={")) {
refreshLocals(data);
} else if (line.startsWith("modules=[")) {
refreshModules(data);
} else if (line.startsWith("symbols={")) {
refreshSymbols(data);
} else if (line.startsWith("Breakpoint")) {
DebuggerResponse response;
response.data = data;
response.logStreamOutput = line;
handleBreakInsert(response, Breakpoint());
continue;
}
if (line.startsWith("> /")) {
lineContext = line;
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;
if (state() == InferiorRunOk) {
showMessage(QString::fromLatin1("STOPPED AT: %1:%2").arg(frame.file).arg(frame.line));
gotoLocation(frame);
notifyInferiorSpontaneousStop();
updateAll();
continue;
} else {
if (line.startsWith("> /")) {
lineContext = line;
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;
if (state() == InferiorRunOk) {
showMessage(QString::fromLatin1("STOPPED AT: %1:%2").arg(frame.file).arg(frame.line));
gotoLocation(frame);
notifyInferiorSpontaneousStop();
updateAll();
continue;
}
}
}
showMessage(_(" #### ... UNHANDLED"));
}
if (line.startsWith("-> ")) {
// Current line
}
showMessage(_(" #### ... UNHANDLED"));
}
// DebuggerResponse response;
// response.logStreamOutput = data;
// showMessage(_(data));
// QTC_ASSERT(!m_commands.isEmpty(), qDebug() << "RESPONSE: " << data; return);
// DebuggerCommand cmd = m_commands.dequeue();
// qDebug() << "DEQUE: " << cmd.function;
// if (cmd.callback) {
// //qDebug() << "EXECUTING CALLBACK " << cmd.callbackName
// // << " RESPONSE: " << response.data;
// cmd.callback(response);
// } else {
// qDebug() << "NO CALLBACK FOR RESPONSE: " << response.logStreamOutput;
// }
}
/*
void PdbEngine::handleResponse(const QByteArray &response0)
{
......@@ -747,7 +711,6 @@ void PdbEngine::updateLocals()
const static bool alwaysVerbose = !qgetenv("QTC_DEBUGGER_PYTHON_VERBOSE").isEmpty();
cmd.arg("passexceptions", alwaysVerbose);
cmd.arg("fancy", boolSetting(UseDebuggingHelpers));
// cmd.arg("partial", params.tryPartial);
cmd.beginList("watchers");
......@@ -779,34 +742,11 @@ void PdbEngine::updateLocals()
runCommand(cmd);
}
void PdbEngine::handleListLocals(const DebuggerResponse &response)
{
//qDebug() << " LOCALS: '" << response.data << "'";
QByteArray out = response.logStreamOutput.trimmed();
GdbMi all;
all.fromStringMultiple(out);
//qDebug() << "ALL: " << all.toString();
//GdbMi data = all.findChild("data");
WatchHandler *handler = watchHandler();
QSet<QByteArray> toDelete;
foreach (WatchItem *item, handler->model()->treeLevelItems<WatchItem *>(2))
toDelete.insert(item->d.iname);
foreach (const GdbMi &child, all.children()) {
WatchItem *item = new WatchItem(child);
handler->insertItem(item);
toDelete.remove(item->d.iname);
}
handler->purgeOutdatedItems(toDelete);
}
bool PdbEngine::hasCapability(unsigned cap) const
{
return cap & (ReloadModuleCapability|BreakConditionCapability);
return cap & (ReloadModuleCapability
| BreakConditionCapability
| ShowModuleSymbolsCapability);
}
DebuggerEngine *createPdbEngine(const DebuggerStartParameters &startParameters)
......
......@@ -57,6 +57,8 @@ public:
void refreshStack(const GdbMi &stack);
void runCommand(const DebuggerCommand &cmd);
void refreshLocals(const GdbMi &vars);
void refreshModules(const GdbMi &modules);
void refreshSymbols(const GdbMi &symbols);
private:
// DebuggerEngine implementation
......@@ -126,9 +128,6 @@ private:
void handleFirstCommand(const DebuggerResponse &response);
void handleExecuteDebuggerCommand(const DebuggerResponse &response);
void handleStop(const DebuggerResponse &response);
void handleListLocals(const DebuggerResponse &response);
void handleListModules(const DebuggerResponse &response);
void handleListSymbols(const DebuggerResponse &response, const QString &moduleName);
void handleBreakInsert(const DebuggerResponse &response, Breakpoint bp);
void handleChildren(const WatchData &data0, const GdbMi &item,
......@@ -140,7 +139,6 @@ private:
QQueue<DebuggerCommand> m_commands;
QByteArray m_inbuffer;
QString m_scriptFileName;
QProcess m_pdbProc;
QString m_pdb;
};
......
Markdown is supported
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