2009-09-23 13:37:39 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2009-09-23 13:37:39 +02:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2009-09-23 13:37:39 +02:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2009-09-23 13:37:39 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2009-09-23 13:37:39 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "coregdbadapter.h"
|
2010-11-10 16:33:11 +01:00
|
|
|
|
2011-01-10 10:14:23 +01:00
|
|
|
#include "debuggerstartparameters.h"
|
2010-11-10 16:33:11 +01:00
|
|
|
#include "debuggercore.h"
|
2009-09-23 13:37:39 +02:00
|
|
|
#include "debuggeractions.h"
|
2009-09-25 15:02:16 +02:00
|
|
|
#include "debuggerstringutils.h"
|
2010-11-10 16:33:11 +01:00
|
|
|
#include "gdbmi.h"
|
|
|
|
|
#include "gdbengine.h"
|
2009-09-23 13:37:39 +02:00
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
#include <utils/consoleprocess.h>
|
2012-06-05 19:55:32 +02:00
|
|
|
#include <utils/elfreader.h>
|
2012-06-06 16:08:59 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/qtcprocess.h>
|
2009-09-23 13:37:39 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMessageBox>
|
2012-06-06 16:08:59 +02:00
|
|
|
#include <QProcess>
|
|
|
|
|
#include <QTemporaryFile>
|
2009-09-23 13:37:39 +02:00
|
|
|
|
2012-06-05 19:55:32 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
2009-09-23 13:37:39 +02:00
|
|
|
namespace Debugger {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
#define CB(callback) \
|
|
|
|
|
static_cast<GdbEngine::AdapterCallback>(&CoreGdbAdapter::callback), \
|
|
|
|
|
STRINGIFY(callback)
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// CoreGdbAdapter
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-03-24 15:05:45 +01:00
|
|
|
CoreGdbAdapter::CoreGdbAdapter(GdbEngine *engine)
|
2012-06-06 16:08:59 +02:00
|
|
|
: AbstractGdbAdapter(engine)
|
2010-07-15 13:23:44 +02:00
|
|
|
{}
|
|
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
CoreGdbAdapter::~CoreGdbAdapter()
|
|
|
|
|
{
|
|
|
|
|
if (false && !m_tempCoreName.isEmpty()) {
|
|
|
|
|
QFile tmpFile(m_tempCoreName);
|
|
|
|
|
tmpFile.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-23 13:37:39 +02:00
|
|
|
void CoreGdbAdapter::startAdapter()
|
|
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineSetupRequested, qDebug() << state());
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(_("TRYING TO START ADAPTER"));
|
2009-09-23 13:37:39 +02:00
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
const DebuggerStartParameters &sp = startParameters();
|
|
|
|
|
m_executable = sp.executable;
|
|
|
|
|
QFileInfo fi(sp.coreFile);
|
|
|
|
|
m_coreName = fi.absoluteFilePath();
|
|
|
|
|
|
|
|
|
|
unpackCoreIfNeeded();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CoreGdbAdapter::continueAdapterStart()
|
|
|
|
|
{
|
2012-06-05 19:55:32 +02:00
|
|
|
if (m_executable.isEmpty()) {
|
|
|
|
|
// Read executable from core.
|
2012-06-06 16:08:59 +02:00
|
|
|
ElfReader reader(coreFileName());
|
2012-06-08 14:40:18 +02:00
|
|
|
bool isCore = false;
|
|
|
|
|
m_executable = reader.readCoreName(&isCore);
|
|
|
|
|
|
|
|
|
|
if (!isCore) {
|
|
|
|
|
showMessageBox(QMessageBox::Warning,
|
|
|
|
|
tr("Error Loading Core File"),
|
|
|
|
|
tr("The specified file does not appear to be a core file."));
|
|
|
|
|
m_engine->notifyEngineSetupFailed();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-05 19:55:32 +02:00
|
|
|
|
|
|
|
|
// Strip off command line arguments. FIXME: make robust.
|
|
|
|
|
int idx = m_executable.indexOf(QLatin1Char(' '));
|
|
|
|
|
if (idx >= 0)
|
|
|
|
|
m_executable.truncate(idx);
|
|
|
|
|
if (m_executable.isEmpty()) {
|
|
|
|
|
showMessageBox(QMessageBox::Warning,
|
|
|
|
|
tr("Error Loading Symbols"),
|
2012-06-08 14:40:18 +02:00
|
|
|
tr("No executable to load symbols from specified core."));
|
2012-06-05 19:55:32 +02:00
|
|
|
m_engine->notifyEngineSetupFailed();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_engine->startGdb();
|
2012-06-05 11:05:58 +02:00
|
|
|
}
|
2009-09-23 13:37:39 +02:00
|
|
|
|
2012-06-05 11:05:58 +02:00
|
|
|
void CoreGdbAdapter::handleGdbStartFailed()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CoreGdbAdapter::handleGdbStartDone()
|
|
|
|
|
{
|
2012-06-05 19:55:32 +02:00
|
|
|
m_engine->handleAdapterStarted();
|
2010-07-15 13:23:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CoreGdbAdapter::setupInferior()
|
2009-10-05 13:47:55 +02:00
|
|
|
{
|
2010-07-15 11:37:06 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2009-10-20 18:05:56 +02:00
|
|
|
// Do that first, otherwise no symbols are loaded.
|
|
|
|
|
QFileInfo fi(m_executable);
|
2011-05-30 12:56:26 +02:00
|
|
|
const QByteArray sysroot = startParameters().sysroot.toLocal8Bit();
|
2010-01-05 16:51:55 +01:00
|
|
|
QByteArray path = fi.absoluteFilePath().toLocal8Bit();
|
2012-04-17 16:15:47 +02:00
|
|
|
if (!sysroot.isEmpty()) {
|
2011-05-30 12:56:26 +02:00
|
|
|
m_engine->postCommand("set sysroot " + sysroot);
|
2012-04-17 16:15:47 +02:00
|
|
|
// sysroot is not enough to correctly locate the sources, so explicitly
|
|
|
|
|
// relocate the most likely place for the debug source
|
|
|
|
|
m_engine->postCommand("set substitute-path /usr/src " + sysroot + "/usr/src");
|
|
|
|
|
}
|
2010-01-05 16:51:55 +01:00
|
|
|
m_engine->postCommand("-file-exec-and-symbols \"" + path + '"',
|
|
|
|
|
CB(handleFileExecAndSymbols));
|
2009-09-23 13:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
2009-09-30 12:27:03 +02:00
|
|
|
void CoreGdbAdapter::handleFileExecAndSymbols(const GdbResponse &response)
|
|
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2012-06-06 16:08:59 +02:00
|
|
|
QString core = coreFileName();
|
2009-09-30 12:27:03 +02:00
|
|
|
if (response.resultClass == GdbResultDone) {
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(tr("Symbols found."), StatusBar);
|
2012-06-06 16:08:59 +02:00
|
|
|
m_engine->postCommand("target core " + core.toLocal8Bit(),
|
2010-07-15 13:23:44 +02:00
|
|
|
CB(handleTargetCore));
|
|
|
|
|
return;
|
2009-09-30 12:27:03 +02:00
|
|
|
}
|
2010-10-11 16:55:18 +02:00
|
|
|
QString msg = tr("No symbols found in core file <i>%1</i>.")
|
2012-06-06 16:08:59 +02:00
|
|
|
.arg(core);
|
2010-10-11 16:55:18 +02:00
|
|
|
msg += _(" ");
|
|
|
|
|
msg += tr("This can be caused by a path length limitation in the "
|
|
|
|
|
"core file.");
|
|
|
|
|
msg += _(" ");
|
|
|
|
|
msg += tr("Try to specify the binary using the "
|
|
|
|
|
"<i>Debug->Start Debugging->Attach to Core</i> dialog.");
|
|
|
|
|
m_engine->notifyInferiorSetupFailed(msg);
|
2009-10-20 18:05:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CoreGdbAdapter::handleTargetCore(const GdbResponse &response)
|
2009-10-05 13:47:55 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == InferiorSetupRequested, qDebug() << state());
|
2009-10-05 13:47:55 +02:00
|
|
|
if (response.resultClass == GdbResultDone) {
|
2010-07-15 13:23:44 +02:00
|
|
|
// HACK: The namespace is not accessible in the initial run.
|
|
|
|
|
m_engine->loadPythonDumpers();
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(tr("Attached to core."), StatusBar);
|
2010-07-08 18:10:50 +02:00
|
|
|
m_engine->handleInferiorPrepared();
|
2010-12-21 14:41:17 +01:00
|
|
|
// Due to the auto-solib-add off setting, we don't have any
|
|
|
|
|
// symbols yet. Load them in order of importance.
|
|
|
|
|
m_engine->reloadStack(true);
|
|
|
|
|
m_engine->postCommand("info shared", CB(handleModulesList));
|
2010-07-15 13:23:44 +02:00
|
|
|
return;
|
2009-10-05 13:47:55 +02:00
|
|
|
}
|
2010-07-15 13:23:44 +02:00
|
|
|
QString msg = tr("Attach to core \"%1\" failed:\n")
|
|
|
|
|
.arg(startParameters().coreFile)
|
|
|
|
|
+ QString::fromLocal8Bit(response.data.findChild("msg").data());
|
|
|
|
|
m_engine->notifyInferiorSetupFailed(msg);
|
2009-10-05 13:47:55 +02:00
|
|
|
}
|
2009-10-20 11:02:16 +02:00
|
|
|
|
2010-12-21 14:41:17 +01:00
|
|
|
void CoreGdbAdapter::handleModulesList(const GdbResponse &response)
|
|
|
|
|
{
|
|
|
|
|
m_engine->handleModulesList(response);
|
|
|
|
|
loadSymbolsForStack();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CoreGdbAdapter::loadSymbolsForStack()
|
|
|
|
|
{
|
|
|
|
|
m_engine->loadSymbolsForStack();
|
|
|
|
|
QTimer::singleShot(1000, this, SLOT(loadAllSymbols()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CoreGdbAdapter::loadAllSymbols()
|
|
|
|
|
{
|
|
|
|
|
m_engine->loadAllSymbols();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-09 17:07:59 +02:00
|
|
|
void CoreGdbAdapter::runEngine()
|
2010-07-08 18:10:50 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
|
|
|
|
m_engine->notifyInferiorUnrunnable();
|
2010-07-08 18:10:50 +02:00
|
|
|
m_engine->updateAll();
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-23 13:37:39 +02:00
|
|
|
void CoreGdbAdapter::interruptInferior()
|
|
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
// A core never runs, so this cannot be called.
|
2011-07-29 12:00:11 +02:00
|
|
|
QTC_CHECK(false);
|
2009-09-23 13:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
void CoreGdbAdapter::shutdownAdapter()
|
2010-07-09 17:07:59 +02:00
|
|
|
{
|
2012-06-06 16:08:59 +02:00
|
|
|
m_engine->notifyAdapterShutdownOk();
|
2010-07-09 17:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
void CoreGdbAdapter::unpackCoreIfNeeded()
|
2010-07-09 17:07:59 +02:00
|
|
|
{
|
2012-06-06 16:08:59 +02:00
|
|
|
if (!m_coreName.endsWith(QLatin1String(".lzo"))) {
|
|
|
|
|
continueAdapterStart();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QString pattern = QDir::tempPath() + QLatin1String("/tmpcore-XXXXXX");
|
|
|
|
|
QTemporaryFile tmp(pattern, this);
|
|
|
|
|
tmp.open();
|
|
|
|
|
m_tempCoreName = tmp.fileName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QProcess *process = new QProcess(this);
|
|
|
|
|
process->setWorkingDirectory(QDir::tempPath());
|
|
|
|
|
process->start("/usr/bin/lzop", QStringList() << "-o" << m_tempCoreName << "-x" << m_coreName);
|
|
|
|
|
connect(process, SIGNAL(finished(int)), SLOT(continueAdapterStart()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString CoreGdbAdapter::coreFileName() const
|
|
|
|
|
{
|
|
|
|
|
return m_tempCoreName.isEmpty() ? m_coreName : m_tempCoreName;
|
2010-07-09 17:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2009-09-23 13:37:39 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Debugger
|