From f65cb6ae4df6734231bfd0a3cf4428366292d764 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 11 Feb 2015 16:05:55 +0100 Subject: [PATCH] Debugger: Complete switch to Python for GDB stack generation The iteration in Python was only used for the 'native mixed' case before. Seems reasonably fast and robust now to always enable it. Also, make the calling code use 'runCommand'. Change-Id: I10565a725dfaa9bf46c28739c69e9f2546498929 Reviewed-by: Christian Stenger --- share/qtcreator/debugger/gdbbridge.py | 32 ++++++---------------- src/plugins/debugger/gdb/gdbengine.cpp | 38 +++++++++++--------------- src/plugins/debugger/gdb/gdbengine.h | 2 +- 3 files changed, 25 insertions(+), 47 deletions(-) diff --git a/share/qtcreator/debugger/gdbbridge.py b/share/qtcreator/debugger/gdbbridge.py index 6df555bee23..6c5e0585bce 100644 --- a/share/qtcreator/debugger/gdbbridge.py +++ b/share/qtcreator/debugger/gdbbridge.py @@ -1620,14 +1620,19 @@ class Dumper(DumperBase): self.typesToReport[typestring] = typeobj return typeobj - def stackListFrames(self, n, options): + def stackListFrames(self, args): + limit = int(args['limit']) + if limit <= 0: + limit = 10000 + options = args['options'] + self.prepare("options:" + options + ",pe") self.output = [] frame = gdb.newest_frame() i = 0 self.currentCallContext = None - while i < n and frame: + while i < limit and frame: with OutputSafer(self): name = frame.name() functionName = "??" if name is None else name @@ -1675,8 +1680,7 @@ class Dumper(DumperBase): frame = frame.older() i += 1 - - return ''.join(self.output) + print(''.join(self.output)) def createResolvePendingBreakpointsHookBreakpoint(self, args): class Resolver(gdb.Breakpoint): @@ -1864,26 +1868,6 @@ def threadnames(arg): registerCommand("threadnames", threadnames) -####################################################################### -# -# StackFrames Command -# -####################################################################### - -def stackListFrames(arg): - try: - args = arg.split(' ') - limit = int(args[0]) if len(args) > 0 else 10000 - if limit <= 0: - limit = 10000 - options = args[1] if len(args) > 1 else "" - return theDumper.stackListFrames(limit, options) - except: - import traceback - traceback.print_exc() - -registerCommand("stackListFrames", stackListFrames) - ####################################################################### # # Native Mixed diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 8a81b49c729..841f9508a6c 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -1227,9 +1227,10 @@ void GdbEngine::updateAll() //PENDING_DEBUG("UPDATING ALL\n"); QTC_CHECK(state() == InferiorUnrunnable || state() == InferiorStopOk); reloadModulesInternal(); - int depth = action(MaximalStackDepth)->value().toInt(); - postCommand(stackCommand(depth), NoFlags, - [this](const DebuggerResponse &r) { handleStackListFrames(r, false); }); + DebuggerCommand cmd = stackCommand(action(MaximalStackDepth)->value().toInt()); + cmd.flags = NoFlags; + cmd.callback = [this](const DebuggerResponse &r) { handleStackListFrames(r, false); }; + runCommand(cmd); stackHandler()->setCurrentIndex(0); postCommand("-thread-info", NoFlags, CB(handleThreadInfo)); reloadRegisters(); @@ -3182,8 +3183,10 @@ void GdbEngine::reloadFullStack() { PENDING_DEBUG("RELOAD FULL STACK"); resetLocation(); - postCommand(stackCommand(-1), Discardable, - [this](const DebuggerResponse &r) { handleStackListFrames(r, true); }); + DebuggerCommand cmd = stackCommand(-1); + cmd.flags = Discardable; + cmd.callback = [this](const DebuggerResponse &r) { handleStackListFrames(r, true); }; + runCommand(cmd); } void GdbEngine::loadAdditionalQmlStack() @@ -3270,30 +3273,21 @@ void GdbEngine::handleQmlStackTrace(const DebuggerResponse &response) stackHandler()->prependFrames(qmlFrames); } -QByteArray GdbEngine::stackCommand(int depth) +DebuggerCommand GdbEngine::stackCommand(int depth) { - QByteArray cmd; - if (isNativeMixedEnabled()) { - cmd = "stackListFrames " + QByteArray::number(depth) + ' '; - if (isNativeMixedActive()) - cmd += "nativemixed"; - else - cmd += "noopt"; - } else { - if (depth == -1) - cmd = "-stack-list-frames"; - else - cmd = "-stack-list-frames 0 " + QByteArray::number(depth); - } + DebuggerCommand cmd("stackListFrames"); + cmd.arg("limit", depth); + cmd.arg("options", isNativeMixedActive() ? "nativemixed" : ""); return cmd; } void GdbEngine::reloadStack() { PENDING_DEBUG("RELOAD STACK"); - int depth = action(MaximalStackDepth)->value().toInt(); - postCommand(stackCommand(depth), Discardable, - [this](const DebuggerResponse &r) { handleStackListFrames(r, false); }); + DebuggerCommand cmd = stackCommand(action(MaximalStackDepth)->value().toInt()); + cmd.flags = Discardable; + cmd.callback = [this](const DebuggerResponse &r) { handleStackListFrames(r, false); }; + runCommand(cmd); } StackFrame GdbEngine::parseStackFrame(const GdbMi &frameMi, int level) diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index fbf7372d076..24130b6168d 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -369,7 +369,7 @@ protected: void handleThreadListIds(const DebuggerResponse &response); void handleThreadInfo(const DebuggerResponse &response); void handleThreadNames(const DebuggerResponse &response); - QByteArray stackCommand(int depth); + DebuggerCommand stackCommand(int depth); Q_SLOT void reloadStack(); Q_SLOT virtual void reloadFullStack(); virtual void loadAdditionalQmlStack();