File indexing completed on 2021-12-21 13:15:51

0001 /*
0002  * XDebug Debugger Support
0003  *
0004  * Copyright 1999-2001 John Birch <jbb@kdevelop.org>
0005  * Copyright 2001 by Bernd Gehrmann <bernd@kdevelop.org>
0006  * Copyright 2006 Vladimir Prus <ghost@cs.msu.su>
0007  * Copyright 2007 Hamish Rodda <rodda@kde.org>
0008  * Copyright 2009 Niko Sams <niko.sams@gmail.com>
0009  *
0010  * This program is free software; you can redistribute it and/or modify
0011  * it under the terms of the GNU General Public License as
0012  * published by the Free Software Foundation; either version 2 of the
0013  * License, or (at your option) any later version.
0014  *
0015  * This program is distributed in the hope that it will be useful,
0016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  * GNU General Public License for more details.
0019  *
0020  * You should have received a copy of the GNU General Public
0021  * License along with this program; if not, write to the
0022  * Free Software Foundation, Inc.,
0023  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0024  */
0025 
0026 #include "xdebugplugin.h"
0027 
0028 #include <QDir>
0029 #include <QToolTip>
0030 #include <QByteArray>
0031 #include <QTimer>
0032 #include <QMenu>
0033 #include <QDBusConnectionInterface>
0034 #include <QDBusInterface>
0035 #include <QSignalMapper>
0036 
0037 #include <KPluginFactory>
0038 
0039 #include <interfaces/icore.h>
0040 #include <interfaces/iuicontroller.h>
0041 #include <interfaces/idocumentcontroller.h>
0042 #include <interfaces/iprojectcontroller.h>
0043 #include <interfaces/iruncontroller.h>
0044 #include <interfaces/context.h>
0045 #include <interfaces/idebugcontroller.h>
0046 #include <interfaces/iplugincontroller.h>
0047 #include <interfaces/launchconfigurationtype.h>
0048 #include <executescript/iexecutescriptplugin.h>
0049 #include <iexecutebrowserplugin.h>
0050 
0051 #include "debugsession.h"
0052 #include "launchconfig.h"
0053 #include "debuggerdebug.h"
0054 
0055 K_PLUGIN_FACTORY_WITH_JSON(KDevXDebugDebuggerFactory, "kdevxdebug.json",
0056                            registerPlugin<XDebug::XDebugPlugin>();)
0057 
0058 namespace XDebug {
0059 XDebugPlugin::XDebugPlugin(QObject* parent, const QVariantList&) :
0060     KDevelop::IPlugin(QStringLiteral("kdevxdebug"), parent)
0061 {
0062     core()->debugController()->initializeUi();
0063 
0064     qCDebug(KDEV_PHP_DEBUGGER);
0065 //     connect(m_server, SIGNAL(sessionStarted(DebugSession*)), SLOT(sessionStarted(DebugSession*)));
0066 //     connect(m_server, SIGNAL(outputLine(DebugSession*,QString,KDevelop::IRunProvider::OutputTypes)), SLOT(outputLine(DebugSession*,QString,KDevelop::IRunProvider::OutputTypes)));
0067 //     connect(m_server, SIGNAL(stateChanged(DebugSession*,KDevelop::IDebugSession::DebuggerState)), SLOT(debuggerStateChanged(DebugSession*,KDevelop::IDebugSession::DebuggerState)));
0068     {
0069         IExecuteScriptPlugin* iface = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IExecuteScriptPlugin")->extension<IExecuteScriptPlugin>();
0070         Q_ASSERT(iface);
0071         KDevelop::LaunchConfigurationType* type = core()->runController()->launchConfigurationTypeForId(iface->scriptAppConfigTypeId());
0072         Q_ASSERT(type);
0073         type->addLauncher(new XDebugLauncher(this));
0074     }
0075     {
0076         IExecuteBrowserPlugin* iface = KDevelop::ICore::self()->pluginController()->pluginForExtension("org.kdevelop.IExecuteBrowserPlugin")->extension<IExecuteBrowserPlugin>();
0077         Q_ASSERT(iface);
0078         KDevelop::LaunchConfigurationType* type = core()->runController()->launchConfigurationTypeForId(iface->browserAppConfigTypeId());
0079         Q_ASSERT(type);
0080         type->addLauncher(new XDebugBrowserLauncher(this));
0081     }
0082 }
0083 
0084 XDebugPlugin::~XDebugPlugin()
0085 {
0086 }
0087 
0088 DebugSession* XDebugPlugin::createSession() const
0089 {
0090     DebugSession* session = new DebugSession();
0091     KDevelop::ICore::self()->debugController()->addSession(session);
0092     return session;
0093 }
0094 
0095 /*
0096 
0097    void XDebugPlugin::sessionStarted(DebugSession* session)
0098    {
0099     qCDebug(KDEV_PHP_DEBUGGER) << session;
0100     KDevelop::ICore::self()->debugController()->addSession(session);
0101    }
0102 
0103    void XDebugPlugin::outputLine(XDebug::DebugSession* session, QString line, KDevelop::IRunProvider::OutputTypes type)
0104    {
0105     if (session->process() && m_jobs.contains(session->process())) {
0106         emit output(m_jobs[session->process()], line, type);
0107     }
0108    }
0109 
0110    bool XDebugPlugin::execute(const KDevelop::IRun & run, KJob* job)
0111    {
0112     Q_ASSERT(instrumentorsProvided().contains(run.instrumentor()));
0113 
0114     QString path = run.executable().toLocalFile();
0115     if (path.endsWith("php")) {
0116         path = "";
0117     }
0118     path += " " + run.arguments().join(" ");
0119     path = path.trimmed();
0120     qCDebug(KDEV_PHP_DEBUGGER) << path;
0121 
0122     KProcess* process = m_server->startDebugger(path);
0123     m_jobs[process] = job;
0124 
0125     return !!job;
0126    }
0127 
0128    void XDebugPlugin::abort(KJob* job) {
0129 
0130    }
0131 
0132 
0133    void XDebugPlugin::debuggerStateChanged(DebugSession* session, KDevelop::IDebugSession::DebuggerState state)
0134    {
0135     switch (state) {
0136         case KDevelop::IDebugSession::StartingState:
0137         case KDevelop::IDebugSession::ActiveState:
0138             break;
0139         case KDevelop::IDebugSession::PausedState:
0140             break;
0141         case KDevelop::IDebugSession::NotStartedState:
0142         case KDevelop::IDebugSession::StoppingState:
0143         case KDevelop::IDebugSession::StoppedState:
0144             if (session->process() && m_jobs.contains(session->process())) {
0145                 emit finished(m_jobs[session->process()]);
0146             }
0147             break;
0148     }
0149    }
0150  */
0151 }
0152 
0153 #include "xdebugplugin.moc"