From c23bf0daa5fb41d7c53b2e96724e8f5a82ae14da Mon Sep 17 00:00:00 2001 From: hjk <qthjk@ovi.com> Date: Thu, 23 Aug 2012 18:42:45 +0200 Subject: [PATCH] debugger: use gdb again to read executable file name from core Change-Id: I035d1260c5cf08d4a65adb4494a5f83045effecf Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: hjk <qthjk@ovi.com> --- src/plugins/debugger/gdb/coregdbadapter.cpp | 35 +++++++++++++++++++-- src/plugins/debugger/gdb/coregdbadapter.h | 1 + 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/plugins/debugger/gdb/coregdbadapter.cpp b/src/plugins/debugger/gdb/coregdbadapter.cpp index 90f77262b80..00ff8628398 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.cpp +++ b/src/plugins/debugger/gdb/coregdbadapter.cpp @@ -88,13 +88,44 @@ void GdbCoreEngine::setupEngine() unpackCoreIfNeeded(); } +QString GdbCoreEngine::readExecutableNameFromCore(bool *isCore) +{ +#if 0 + ElfReader reader(coreFileName()); + return QString::fromLocal8Bit(reader.readCoreName(isCore)); +#else + const DebuggerStartParameters &sp = startParameters(); + QStringList args; + args.append(QLatin1String("-nx")); + args.append(QLatin1String("-batch")); + args.append(QLatin1String("-c")); + args.append(coreFileName()); + QProcess proc; + proc.start(sp.debuggerCommand, args); + if (proc.waitForFinished()) { + QByteArray ba = proc.readAllStandardOutput(); + // Core was generated by `/data/dev/creator-2.6/bin/qtcreator'. + // Program terminated with signal 11, Segmentation fault. + int pos1 = ba.indexOf("Core was generated by"); + if (pos1 != -1) { + pos1 += 23; + int pos2 = ba.indexOf('\'', pos1); + if (pos2 != -1) { + *isCore = true; + return QString::fromLocal8Bit(ba.mid(pos1, pos2 - pos1)); + } + } + } + return QString(); +#endif +} + void GdbCoreEngine::continueSetupEngine() { if (m_executable.isEmpty()) { // Read executable from core. - ElfReader reader(coreFileName()); bool isCore = false; - m_executable = QString::fromLocal8Bit(reader.readCoreName(&isCore)); + m_executable = readExecutableNameFromCore(&isCore); if (!isCore) { showMessageBox(QMessageBox::Warning, diff --git a/src/plugins/debugger/gdb/coregdbadapter.h b/src/plugins/debugger/gdb/coregdbadapter.h index 1027fffbbf4..269d7857e14 100644 --- a/src/plugins/debugger/gdb/coregdbadapter.h +++ b/src/plugins/debugger/gdb/coregdbadapter.h @@ -68,6 +68,7 @@ private: void unpackCoreIfNeeded(); QString coreFileName() const; Q_SLOT void continueSetupEngine(); + QString readExecutableNameFromCore(bool *isCore); QString coreName() const; QString m_executable; -- GitLab