From d190263e9a1bab47283974f1d4de67d404eaeb30 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 27 Feb 2014 12:54:20 +0100 Subject: [PATCH] Debugger: Re-work qt namespace detection with gdb We can always use python now. Avoids one roundtrip on startup, a temporary file, and only does it when needed. Change-Id: Id32a812bec477307da1d93950f7758f3a5699464 Reviewed-by: Christian Stenger Reviewed-by: hjk --- share/qtcreator/debugger/gdbbridge.py | 12 ++++- src/plugins/debugger/gdb/gdbengine.cpp | 73 ++++++++------------------ src/plugins/debugger/gdb/gdbengine.h | 1 - 3 files changed, 34 insertions(+), 52 deletions(-) diff --git a/share/qtcreator/debugger/gdbbridge.py b/share/qtcreator/debugger/gdbbridge.py index 8a3011de4f4..2e88280d9fc 100644 --- a/share/qtcreator/debugger/gdbbridge.py +++ b/share/qtcreator/debugger/gdbbridge.py @@ -353,6 +353,7 @@ class Dumper(DumperBase): self.childEventAddress = None self.typesReported = {} self.typesToReport = {} + self.qtNamespaceToReport = None def run(self, args): self.output = [] @@ -494,6 +495,10 @@ class Dumper(DumperBase): self.output.append(']') self.typesToReport = {} + if self.qtNamespaceToReport: + self.output.append(',qtnamespace="%s"' % self.qtNamespaceToReport) + self.qtNamespaceToReport = None + return "".join(self.output) def enterSubItem(self, item): @@ -1567,8 +1572,13 @@ class Dumper(DumperBase): pos2 = out.find("QString::Null") if pos1 > -1 and pos2 > -1: namespace = out[pos1:pos2] + + # Doesn't work + #gdb.write('=qt-namespace-detected,ns="%s"' % namespace) + self.qtNamespaceToReport = namespace + self.cachedQtNamespace = namespace - self.ns = lambda: self.cachedQtNamespace + self.qtNamespace = lambda: self.cachedQtNamespace except: pass diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index a1da12ab81c..13bf270f4aa 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -4608,56 +4608,6 @@ void GdbEngine::handleInferiorPrepared() void GdbEngine::finishInferiorSetup() { QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state()); - // Extract Qt namespace. - QString fileName; - { - QTemporaryFile symbols(QDir::tempPath() + _("/gdb_ns_")); - symbols.open(); - fileName = symbols.fileName(); - } - postCommand("maint print msymbols \"" + fileName.toLocal8Bit() + '"', - CB(handleNamespaceExtraction), fileName); -} - -void GdbEngine::handleDebugInfoLocation(const GdbResponse &response) -{ - if (response.resultClass == GdbResultDone) { - const QByteArray debugInfoLocation = startParameters().debugInfoLocation.toLocal8Bit(); - if (QFile::exists(QString::fromLocal8Bit(debugInfoLocation))) { - const QByteArray curDebugInfoLocations = response.consoleStreamOutput.split('"').value(1); - if (curDebugInfoLocations.isEmpty()) { - postCommand("set debug-file-directory " + debugInfoLocation); - } else { - postCommand("set debug-file-directory " + debugInfoLocation - + HostOsInfo::pathListSeparator().toLatin1() - + curDebugInfoLocations); - } - } - } -} - -void GdbEngine::handleNamespaceExtraction(const GdbResponse &response) -{ - QFile file(response.cookie.toString()); - file.open(QIODevice::ReadOnly); - QByteArray ba = file.readAll(); - file.close(); - file.remove(); - QByteArray ns; - int pos = ba.indexOf("7QString16fromAscii_helper"); - if (pos > -1) { - int pos1 = pos - 1; - while (pos1 > 0 && ba.at(pos1) != 'N' && ba.at(pos1) > '@') - --pos1; - ++pos1; - ns = ba.mid(pos1, pos - pos1); - } - if (ns.isEmpty()) { - showMessage(_("FOUND NON-NAMESPACED QT")); - } else { - showMessage(_("FOUND NAMESPACED QT: " + ns)); - setQtNamespace(ns + "::"); - } if (startParameters().startMode == AttachCore) { notifyInferiorSetupOk(); // No breakpoints in core files. @@ -4679,6 +4629,23 @@ void GdbEngine::handleNamespaceExtraction(const GdbResponse &response) } } +void GdbEngine::handleDebugInfoLocation(const GdbResponse &response) +{ + if (response.resultClass == GdbResultDone) { + const QByteArray debugInfoLocation = startParameters().debugInfoLocation.toLocal8Bit(); + if (QFile::exists(QString::fromLocal8Bit(debugInfoLocation))) { + const QByteArray curDebugInfoLocations = response.consoleStreamOutput.split('"').value(1); + if (curDebugInfoLocations.isEmpty()) { + postCommand("set debug-file-directory " + debugInfoLocation); + } else { + postCommand("set debug-file-directory " + debugInfoLocation + + HostOsInfo::pathListSeparator().toLatin1() + + curDebugInfoLocations); + } + } + } +} + void GdbEngine::handleBreakOnQFatal(const GdbResponse &response) { if (response.resultClass == GdbResultDone) { @@ -5074,6 +5041,12 @@ void GdbEngine::handleStackFramePython(const GdbResponse &response) all.fromStringMultiple(out); GdbMi data = all["data"]; + GdbMi ns = all["qtnamespace"]; + if (ns.isValid()) { + setQtNamespace(ns.data()); + showMessage(_("FOUND NAMESPACED QT: " + ns.data())); + } + WatchHandler *handler = watchHandler(); QList list; diff --git a/src/plugins/debugger/gdb/gdbengine.h b/src/plugins/debugger/gdb/gdbengine.h index 6941e6a9243..78a822385df 100644 --- a/src/plugins/debugger/gdb/gdbengine.h +++ b/src/plugins/debugger/gdb/gdbengine.h @@ -96,7 +96,6 @@ protected: ////////// Gdb Process Management ////////// void startGdb(const QStringList &args = QStringList()); void handleInferiorShutdown(const GdbResponse &response); void handleGdbExit(const GdbResponse &response); - void handleNamespaceExtraction(const GdbResponse &response); void loadInitScript();