Commit d190263e authored by hjk's avatar hjk

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: default avatarChristian Stenger <christian.stenger@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 762f3e32
......@@ -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
......
......@@ -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<WatchData> list;
......
......@@ -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();
......
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