Debugger: PdbEngine cleanup

Change-Id: I39f072fe819da746c624e6028b0e5e17f1f1f111
Reviewed-by: hjk <hjk@theqtcompany.com>
This commit is contained in:
hjk
2015-02-13 16:46:27 +01:00
parent 324854a5cf
commit 055c4ecb53
4 changed files with 70 additions and 137 deletions

View File

@@ -8,7 +8,10 @@ import os
def qdebug(cmd, args): def qdebug(cmd, args):
class Dumper: class Dumper:
def __init__(self): def __init__(self):
pass self.output = ''
def evaluateTooltip(self, args):
self.updateData(args)
def updateData(self, args): def updateData(self, args):
self.expandedINames = set(args.get("expanded", [])) self.expandedINames = set(args.get("expanded", []))
@@ -16,8 +19,6 @@ def qdebug(cmd, args):
self.formats = args.get("formats", {}) self.formats = args.get("formats", {})
self.watchers = args.get("watchers", {}) self.watchers = args.get("watchers", {})
self.output = "data={" self.output = "data={"
# self.handleListModules()
# self.handleListSymbols(expanded)
# Trigger error to get a backtrace. # Trigger error to get a backtrace.
frame = None frame = None
@@ -49,7 +50,11 @@ def qdebug(cmd, args):
#sys.stdout.flush() #sys.stdout.flush()
self.output += '}' self.output += '}'
self.flushOutput()
def flushOutput(self):
sys.stdout.write(self.output) sys.stdout.write(self.output)
self.output = ""
def put(self, value): def put(self, value):
#sys.stdout.write(value) #sys.stdout.write(value)
@@ -61,9 +66,6 @@ def qdebug(cmd, args):
def putItemCount(self, count): def putItemCount(self, count):
self.put('value="<%s items>",' % count) self.put('value="<%s items>",' % count)
def putEllipsis(self):
self.put('{name="<incomplete>",value="",type="",numchild="0"},')
def cleanType(self, type): def cleanType(self, type):
t = str(type) t = str(type)
if t.startswith("<type '") and t.endswith("'>"): if t.startswith("<type '") and t.endswith("'>"):
@@ -75,9 +77,6 @@ def qdebug(cmd, args):
def putType(self, type, priority = 0): def putType(self, type, priority = 0):
self.putField("type", self.cleanType(type)) self.putField("type", self.cleanType(type))
def putAddress(self, addr):
self.put('addr="%s",' % cleanAddress(addr))
def putNumChild(self, numchild): def putNumChild(self, numchild):
self.put('numchild="%s",' % numchild) self.put('numchild="%s",' % numchild)
@@ -217,7 +216,7 @@ def qdebug(cmd, args):
def warn(self, msg): def warn(self, msg):
self.putField("warning", msg) self.putField("warning", msg)
def handleListModules(self): def listModules(self, args):
self.put("modules=["); self.put("modules=[");
for name in sys.modules: for name in sys.modules:
self.put("{") self.put("{")
@@ -225,18 +224,14 @@ def qdebug(cmd, args):
self.putValue(sys.modules[name]) self.putValue(sys.modules[name])
self.put("},") self.put("},")
self.put("]") self.put("]")
#sys.stdout.flush() self.flushOutput()
def handleListSymbols(self, module): def listSymbols(self, args):
#self.put("symbols=%s" % dir(sys.modules[module])) moduleName = args['module']
self.put("symbols=["); module = sys.modules.get(moduleName, None)
for name in sys.modules: self.put("symbols={module='%s',symbols='%s'}"
self.put("{") % (module, dir(module) if module else []))
self.putName(name) self.flushOutput()
#self.putValue(sys.modules[name])
self.put("},")
self.put("]")
#sys.stdout.flush()
def stackListFrames(self, args): def stackListFrames(self, args):
#isNativeMixed = int(args.get('nativeMixed', 0)) #isNativeMixed = int(args.get('nativeMixed', 0))

View File

@@ -89,7 +89,7 @@ typedef QVector<Section> Sections;
class Module class Module
{ {
public: public:
Module() : symbolsRead(UnknownReadState) {} Module() : symbolsRead(UnknownReadState), startAddress(0), endAddress(0) {}
public: public:
enum SymbolReadState { enum SymbolReadState {

View File

@@ -398,16 +398,14 @@ void PdbEngine::loadAllSymbols()
void PdbEngine::reloadModules() 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(); ModulesHandler *handler = modulesHandler();
handler->beginUpdateAll(); handler->beginUpdateAll();
foreach (const GdbMi &item, out.children()) { foreach (const GdbMi &item, modules.children()) {
Module module; Module module;
module.moduleName = _(item["name"].data()); module.moduleName = _(item["name"].data());
QString path = _(item["value"].data()); QString path = _(item["value"].data());
@@ -428,30 +426,21 @@ void PdbEngine::handleListModules(const DebuggerResponse &response)
void PdbEngine::requestModuleSymbols(const QString &moduleName) void PdbEngine::requestModuleSymbols(const QString &moduleName)
{ {
postCommand("qdebug('listsymbols','" + moduleName.toLatin1() + "')", postCommand("qdebug('listSymbols',{'module':'" + moduleName.toLatin1() + "'})");
[this, moduleName](const DebuggerResponse &r) { handleListSymbols(r, moduleName); });
} }
void PdbEngine::handleListSymbols(const DebuggerResponse &response, const QString &moduleName) void PdbEngine::refreshSymbols(const GdbMi &symbols)
{ {
GdbMi out; QString moduleName = symbols["module"].toUtf8();
out.fromString(response.logStreamOutput.trimmed()); Symbols syms;
Symbols symbols; foreach (const GdbMi &item, symbols["symbols"].children()) {
foreach (const GdbMi &item, out.children()) {
Symbol symbol; Symbol symbol;
symbol.name = _(item["name"].data()); symbol.name = item["name"].toUtf8();
symbols.append(symbol); syms.append(symbol);
} }
Internal::showModuleSymbols(moduleName, symbols); Internal::showModuleSymbols(moduleName, syms);
} }
//////////////////////////////////////////////////////////////////////
//
// Tooltip specific stuff
//
//////////////////////////////////////////////////////////////////////
bool PdbEngine::setToolTipExpression(TextEditor::TextEditorWidget *, bool PdbEngine::setToolTipExpression(TextEditor::TextEditorWidget *,
const DebuggerToolTipContext &ctx) const DebuggerToolTipContext &ctx)
{ {
@@ -460,17 +449,11 @@ bool PdbEngine::setToolTipExpression(TextEditor::TextEditorWidget *,
DebuggerCommand cmd("evaluateTooltip"); DebuggerCommand cmd("evaluateTooltip");
ctx.appendFormatRequest(&cmd); ctx.appendFormatRequest(&cmd);
watchHandler()->appendFormatRequests(&cmd);
runCommand(cmd); runCommand(cmd);
return true; return true;
} }
//////////////////////////////////////////////////////////////////////
//
// Watch specific stuff
//
//////////////////////////////////////////////////////////////////////
void PdbEngine::assignValueInDebugger(const Internal::WatchData *, const QString &expression, const QVariant &value) void PdbEngine::assignValueInDebugger(const Internal::WatchData *, const QString &expression, const QVariant &value)
{ {
Q_UNUSED(expression); Q_UNUSED(expression);
@@ -579,31 +562,30 @@ void PdbEngine::handleOutput(const QByteArray &data)
//m_inbuffer.clear(); //m_inbuffer.clear();
} }
void PdbEngine::handleOutput2(const QByteArray &data) void PdbEngine::handleOutput2(const QByteArray &data)
{ {
QByteArray lineContext; QByteArray lineContext;
foreach (QByteArray line, data.split('\n')) { foreach (QByteArray line, data.split('\n')) {
// line = line.trimmed();
DebuggerResponse response; GdbMi data;
response.logStreamOutput = line; data.fromString(line);
response.data.fromString(line);
showMessage(_("LINE: " + line)); showMessage(_("LINE: " + line));
if (line.startsWith("stack={")) { if (line.startsWith("stack={")) {
refreshStack(response.data); refreshStack(data);
continue; } else if (line.startsWith("data={")) {
} refreshLocals(data);
if (line.startsWith("data={")) { } else if (line.startsWith("modules=[")) {
refreshLocals(response.data); refreshModules(data);
continue; } else if (line.startsWith("symbols={")) {
} refreshSymbols(data);
if (line.startsWith("Breakpoint")) { } else if (line.startsWith("Breakpoint")) {
DebuggerResponse response;
response.data = data;
response.logStreamOutput = line;
handleBreakInsert(response, Breakpoint()); handleBreakInsert(response, Breakpoint());
continue; } else {
}
if (line.startsWith("> /")) { if (line.startsWith("> /")) {
lineContext = line; lineContext = line;
int pos1 = line.indexOf('('); int pos1 = line.indexOf('(');
@@ -625,29 +607,11 @@ void PdbEngine::handleOutput2(const QByteArray &data)
} }
} }
} }
if (line.startsWith("-> ")) {
// Current line
}
showMessage(_(" #### ... UNHANDLED")); 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) void PdbEngine::handleResponse(const QByteArray &response0)
{ {
@@ -747,7 +711,6 @@ void PdbEngine::updateLocals()
const static bool alwaysVerbose = !qgetenv("QTC_DEBUGGER_PYTHON_VERBOSE").isEmpty(); const static bool alwaysVerbose = !qgetenv("QTC_DEBUGGER_PYTHON_VERBOSE").isEmpty();
cmd.arg("passexceptions", alwaysVerbose); cmd.arg("passexceptions", alwaysVerbose);
cmd.arg("fancy", boolSetting(UseDebuggingHelpers)); cmd.arg("fancy", boolSetting(UseDebuggingHelpers));
// cmd.arg("partial", params.tryPartial);
cmd.beginList("watchers"); cmd.beginList("watchers");
@@ -779,34 +742,11 @@ void PdbEngine::updateLocals()
runCommand(cmd); 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 bool PdbEngine::hasCapability(unsigned cap) const
{ {
return cap & (ReloadModuleCapability|BreakConditionCapability); return cap & (ReloadModuleCapability
| BreakConditionCapability
| ShowModuleSymbolsCapability);
} }
DebuggerEngine *createPdbEngine(const DebuggerStartParameters &startParameters) DebuggerEngine *createPdbEngine(const DebuggerStartParameters &startParameters)

View File

@@ -57,6 +57,8 @@ public:
void refreshStack(const GdbMi &stack); void refreshStack(const GdbMi &stack);
void runCommand(const DebuggerCommand &cmd); void runCommand(const DebuggerCommand &cmd);
void refreshLocals(const GdbMi &vars); void refreshLocals(const GdbMi &vars);
void refreshModules(const GdbMi &modules);
void refreshSymbols(const GdbMi &symbols);
private: private:
// DebuggerEngine implementation // DebuggerEngine implementation
@@ -126,9 +128,6 @@ private:
void handleFirstCommand(const DebuggerResponse &response); void handleFirstCommand(const DebuggerResponse &response);
void handleExecuteDebuggerCommand(const DebuggerResponse &response); void handleExecuteDebuggerCommand(const DebuggerResponse &response);
void handleStop(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 handleBreakInsert(const DebuggerResponse &response, Breakpoint bp);
void handleChildren(const WatchData &data0, const GdbMi &item, void handleChildren(const WatchData &data0, const GdbMi &item,
@@ -140,7 +139,6 @@ private:
QQueue<DebuggerCommand> m_commands; QQueue<DebuggerCommand> m_commands;
QByteArray m_inbuffer; QByteArray m_inbuffer;
QString m_scriptFileName;
QProcess m_pdbProc; QProcess m_pdbProc;
QString m_pdb; QString m_pdb;
}; };