2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-09-23 13:37:39 +02:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-09-23 13:37:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-09-23 13:37:39 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2009-09-23 13:37:39 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-09-23 13:37:39 +02:00
|
|
|
|
|
|
|
|
#include "coregdbadapter.h"
|
2010-11-10 16:33:11 +01:00
|
|
|
|
2013-01-24 10:38:40 +01:00
|
|
|
#include "debuggercore.h"
|
|
|
|
|
#include "debuggerprotocol.h"
|
|
|
|
|
#include "debuggerstartparameters.h"
|
2009-09-25 15:02:16 +02:00
|
|
|
#include "debuggerstringutils.h"
|
2009-09-23 13:37:39 +02:00
|
|
|
|
2012-06-06 16:08:59 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-09-23 13:37:39 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QMessageBox>
|
2012-06-06 16:08:59 +02:00
|
|
|
#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) \
|
2012-06-13 10:15:56 +02:00
|
|
|
static_cast<GdbEngine::GdbCommandCallback>(&GdbCoreEngine::callback), \
|
2009-09-23 13:37:39 +02:00
|
|
|
STRINGIFY(callback)
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// CoreGdbAdapter
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-08-15 14:33:39 +02:00
|
|
|
GdbCoreEngine::GdbCoreEngine(const DebuggerStartParameters &startParameters)
|
|
|
|
|
: GdbEngine(startParameters)
|
2010-07-15 13:23:44 +02:00
|
|
|
{}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
GdbCoreEngine::~GdbCoreEngine()
|
2012-06-06 16:08:59 +02:00
|
|
|
{
|
|
|
|
|
if (false && !m_tempCoreName.isEmpty()) {
|
|
|
|
|
QFile tmpFile(m_tempCoreName);
|
|
|
|
|
tmpFile.remove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::setupEngine()
|
2009-09-23 13:37:39 +02:00
|
|
|
{
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 18:42:45 +02:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::continueSetupEngine()
|
2012-06-06 16:08:59 +02:00
|
|
|
{
|
2012-06-05 19:55:32 +02:00
|
|
|
if (m_executable.isEmpty()) {
|
|
|
|
|
// Read executable from core.
|
2012-06-08 14:40:18 +02:00
|
|
|
bool isCore = false;
|
2012-08-23 18:42:45 +02:00
|
|
|
m_executable = readExecutableNameFromCore(&isCore);
|
2012-06-08 14:40:18 +02:00
|
|
|
|
|
|
|
|
if (!isCore) {
|
|
|
|
|
showMessageBox(QMessageBox::Warning,
|
|
|
|
|
tr("Error Loading Core File"),
|
|
|
|
|
tr("The specified file does not appear to be a core file."));
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyEngineSetupFailed();
|
2012-06-08 14:40:18 +02:00
|
|
|
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-13 10:15:56 +02:00
|
|
|
notifyEngineSetupFailed();
|
2012-06-05 19:55:32 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-13 10:15:56 +02:00
|
|
|
startGdb();
|
2012-06-05 11:05:58 +02:00
|
|
|
}
|
2009-09-23 13:37:39 +02:00
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::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);
|
2010-01-05 16:51:55 +01:00
|
|
|
QByteArray path = fi.absoluteFilePath().toLocal8Bit();
|
2012-06-13 10:15:56 +02:00
|
|
|
postCommand("-file-exec-and-symbols \"" + path + '"',
|
2010-01-05 16:51:55 +01:00
|
|
|
CB(handleFileExecAndSymbols));
|
2009-09-23 13:37:39 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::handleFileExecAndSymbols(const GdbResponse &response)
|
2009-09-30 12:27:03 +02:00
|
|
|
{
|
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-13 10:15:56 +02:00
|
|
|
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.");
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
2009-10-20 18:05:56 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::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.
|
2013-01-09 14:51:49 +01:00
|
|
|
tryLoadPythonDumpers();
|
2010-06-14 18:19:02 +02:00
|
|
|
showMessage(tr("Attached to core."), StatusBar);
|
2012-06-13 10:15:56 +02:00
|
|
|
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.
|
2012-06-13 10:15:56 +02:00
|
|
|
reloadStack(true);
|
|
|
|
|
reloadModulesInternal();
|
|
|
|
|
postCommand("p 5", CB(handleRoundTrip));
|
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());
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorSetupFailed(msg);
|
2009-10-05 13:47:55 +02:00
|
|
|
}
|
2009-10-20 11:02:16 +02:00
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::handleRoundTrip(const GdbResponse &response)
|
2010-12-21 14:41:17 +01:00
|
|
|
{
|
2012-06-13 10:15:56 +02:00
|
|
|
Q_UNUSED(response);
|
2010-12-21 14:41:17 +01:00
|
|
|
loadSymbolsForStack();
|
|
|
|
|
QTimer::singleShot(1000, this, SLOT(loadAllSymbols()));
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::runEngine()
|
2010-07-08 18:10:50 +02:00
|
|
|
{
|
2010-07-09 17:07:59 +02:00
|
|
|
QTC_ASSERT(state() == EngineRunRequested, qDebug() << state());
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyInferiorUnrunnable();
|
|
|
|
|
updateAll();
|
2010-07-08 18:10:50 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::interruptInferior()
|
2009-09-23 13:37:39 +02:00
|
|
|
{
|
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-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::shutdownEngine()
|
2010-07-09 17:07:59 +02:00
|
|
|
{
|
2012-06-13 10:15:56 +02:00
|
|
|
notifyAdapterShutdownOk();
|
2010-07-09 17:07:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
void GdbCoreEngine::unpackCoreIfNeeded()
|
2010-07-09 17:07:59 +02:00
|
|
|
{
|
2012-06-06 16:08:59 +02:00
|
|
|
if (!m_coreName.endsWith(QLatin1String(".lzo"))) {
|
2012-06-13 10:15:56 +02:00
|
|
|
continueSetupEngine();
|
2012-06-06 16:08:59 +02:00
|
|
|
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());
|
2012-08-22 11:58:33 +02:00
|
|
|
QStringList arguments;
|
|
|
|
|
arguments << QLatin1String("-o") << m_tempCoreName << QLatin1String("-x") << m_coreName;
|
|
|
|
|
process->start(QLatin1String("/usr/bin/lzop"), arguments);
|
2012-06-13 10:15:56 +02:00
|
|
|
connect(process, SIGNAL(finished(int)), SLOT(continueSetupEngine()));
|
2012-06-06 16:08:59 +02:00
|
|
|
}
|
|
|
|
|
|
2012-06-13 10:15:56 +02:00
|
|
|
QString GdbCoreEngine::coreFileName() const
|
2012-06-06 16:08:59 +02:00
|
|
|
{
|
|
|
|
|
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
|