1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
/*
* GDB Debugger Support
*
* Copyright 2006 Vladimir Prus <ghost@cs.msu.su>
* Copyright 2007 Hamish Rodda <rodda@kde.org>
* Copyright 2009 Andreas Pakulat <apaku@gmx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "debugjob.h"
#include "debuggerplugin.h"
#include <interfaces/ilaunchconfiguration.h>
#include <util/environmentgrouplist.h>
#include <interfaces/icore.h>
#include <interfaces/iplugincontroller.h>
#include <outputview/outputmodel.h>
#include <execute/iexecuteplugin.h>
#include "debugsession.h"
using namespace GDBDebugger;
using namespace KDevelop;
DebugJob::DebugJob( GDBDebugger::CppDebuggerPlugin* p, KDevelop::ILaunchConfiguration* launchcfg, QObject* parent)
: KDevelop::OutputJob(parent), m_launchcfg( launchcfg )
{
setCapabilities(Killable);
m_session = p->createSession();
connect(m_session, SIGNAL(applicationStandardOutputLines(QStringList)), SLOT(stderrReceived(QStringList)));
connect(m_session, SIGNAL(applicationStandardErrorLines(QStringList)), SLOT(stdoutReceived(QStringList)));
connect(m_session, SIGNAL(finished()), SLOT(done()) );
setObjectName(launchcfg->name());
}
void DebugJob::start()
{
KConfigGroup grp = m_launchcfg->config();
KDevelop::EnvironmentGroupList l(KGlobal::config());
IExecutePlugin* iface = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IExecutePlugin")->extension<IExecutePlugin>();
Q_ASSERT(iface);
QString err;
QString executable = iface->executable( m_launchcfg, err ).toLocalFile();
QString envgrp = iface->environmentGroup( m_launchcfg );
if( !err.isEmpty() )
{
setError( -1 );
setErrorText( err );
emitResult();
return;
}
if( envgrp.isEmpty() )
{
kWarning() << i18n("No environment group specified, looks like a broken "
"configuration, please check run configuration '%1'. "
"Using default environment group.", m_launchcfg->name() );
envgrp = l.defaultGroup();
}
QStringList arguments = iface->arguments( m_launchcfg, err );
if( !err.isEmpty() )
{
setError( -1 );
setErrorText( err );
}
if( error() != 0 )
{
emitResult();
return;
}
setStandardToolView(KDevelop::IOutputView::DebugView);
setBehaviours(KDevelop::IOutputView::AllowUserClose | KDevelop::IOutputView::AutoScroll);
setModel( new KDevelop::OutputModel(), KDevelop::IOutputView::TakeOwnership );
setTitle(m_launchcfg->name());
startOutput();
m_session->startProgram( m_launchcfg );
}
bool DebugJob::doKill()
{
kDebug();
m_session->stopDebugger();
return true;
}
void DebugJob::stderrReceived(const QStringList& l )
{
if (KDevelop::OutputModel* m = model()) {
m->appendLines( l );
}
}
void DebugJob::stdoutReceived(const QStringList& l )
{
if (KDevelop::OutputModel* m = model()) {
m->appendLines( l );
}
}
KDevelop::OutputModel* DebugJob::model()
{
return dynamic_cast<KDevelop::OutputModel*>( KDevelop::OutputJob::model() );
}
void DebugJob::done()
{
emitResult();
}
KillSessionJob::KillSessionJob(DebugSession *session, QObject* parent): m_session(session), KJob(parent)
{
connect(m_session, SIGNAL(finished()), SLOT(sessionFinished()));
setCapabilities(Killable);
}
void KillSessionJob::start()
{
//NOOP
}
bool KillSessionJob::doKill()
{
m_session->stopDebugger();
return true;
}
void KillSessionJob::sessionFinished()
{
emitResult();
}
|