File indexing completed on 2024-05-12 08:39:50
0001 /* 0002 SPDX-FileCopyrightText: 2016 Aetf <aetf@unlimitedcodeworks.xyz> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "debuggerplugin.h" 0008 0009 #include "debuglog.h" 0010 #include "lldblauncher.h" 0011 #include "widgets/debuggerconsoleview.h" 0012 0013 #include <execute/iexecuteplugin.h> 0014 #include <interfaces/icore.h> 0015 #include <interfaces/iplugincontroller.h> 0016 #include <interfaces/iruncontroller.h> 0017 #include <interfaces/launchconfigurationtype.h> 0018 0019 #include <KPluginFactory> 0020 0021 using namespace KDevMI::LLDB; 0022 0023 inline void initMyResource() { Q_INIT_RESOURCE(kdevlldb); } 0024 0025 K_PLUGIN_FACTORY_WITH_JSON(LldbDebuggerFactory, "kdevlldb.json", registerPlugin<LldbDebuggerPlugin>(); ) 0026 0027 LldbDebuggerPlugin::LldbDebuggerPlugin(QObject *parent, const QVariantList &) 0028 : MIDebuggerPlugin(QStringLiteral("kdevlldb"), i18n("LLDB"), parent) 0029 , m_consoleFactory(nullptr) 0030 , m_disassembleFactory(nullptr) 0031 { 0032 initMyResource(); 0033 0034 setXMLFile(QStringLiteral("kdevlldbui.rc")); 0035 0036 auto pluginController = core()->pluginController(); 0037 const auto plugins = pluginController->allPluginsForExtension(QStringLiteral("org.kdevelop.IExecutePlugin")); 0038 for (auto plugin : plugins) { 0039 setupExecutePlugin(plugin, true); 0040 } 0041 0042 connect(pluginController, &KDevelop::IPluginController::pluginLoaded, 0043 this, [this](KDevelop::IPlugin* plugin) { 0044 setupExecutePlugin(plugin, true); 0045 }); 0046 0047 connect(pluginController, &KDevelop::IPluginController::unloadingPlugin, 0048 this, [this](KDevelop::IPlugin* plugin) { 0049 setupExecutePlugin(plugin, false); 0050 }); 0051 } 0052 0053 void LldbDebuggerPlugin::unload() 0054 { 0055 const auto plugins = core()->pluginController()->allPluginsForExtension(QStringLiteral("org.kdevelop.IExecutePlugin")); 0056 for (auto plugin : plugins) { 0057 setupExecutePlugin(plugin, false); 0058 } 0059 Q_ASSERT(m_launchers.isEmpty()); 0060 } 0061 0062 void LldbDebuggerPlugin::setupExecutePlugin(KDevelop::IPlugin* plugin, bool load) 0063 { 0064 if (plugin == this) { 0065 return; 0066 } 0067 0068 auto iface = plugin->extension<IExecutePlugin>(); 0069 if (!iface) { 0070 return; 0071 } 0072 0073 auto type = core()->runController()->launchConfigurationTypeForId(iface->nativeAppConfigTypeId()); 0074 Q_ASSERT(type); 0075 0076 if (load) { 0077 auto launcher = new LldbLauncher(this, iface); 0078 m_launchers.insert(plugin, launcher); 0079 type->addLauncher(launcher); 0080 } else { 0081 auto launcher = m_launchers.take(plugin); 0082 Q_ASSERT(launcher); 0083 0084 type->removeLauncher(launcher); 0085 delete launcher; 0086 } 0087 } 0088 0089 void LldbDebuggerPlugin::setupToolViews() 0090 { 0091 m_consoleFactory = new DebuggerToolFactory<NonInterruptDebuggerConsoleView>(this, 0092 QStringLiteral("org.kdevelop.debugger.LldbConsole"), Qt::BottomDockWidgetArea); 0093 core()->uiController()->addToolView(i18nc("@title:window", "LLDB Console"), m_consoleFactory); 0094 /* 0095 m_disassembleFactory = new DebuggerToolFactory<DisassembleWidget>(this, 0096 "org.kdevelop.debugger.LldbDisassemble", Qt::BottomDockWidgetArea); 0097 core()->uiController()->addToolView(i18nc("@title:window", "LLDB Disassemble/Register"), m_disassembleFactory); 0098 */ 0099 } 0100 0101 void LldbDebuggerPlugin::unloadToolViews() 0102 { 0103 if (m_consoleFactory) { 0104 qCDebug(DEBUGGERLLDB) << "Removing tool view"; 0105 core()->uiController()->removeToolView(m_consoleFactory); 0106 m_consoleFactory = nullptr; 0107 } 0108 /* 0109 core()->uiController()->removeToolView(m_disassembleFactory); 0110 core()->uiController()->removeToolView(memoryviewerfactory); 0111 */ 0112 } 0113 0114 LldbDebuggerPlugin::~LldbDebuggerPlugin() 0115 { 0116 } 0117 0118 DebugSession* LldbDebuggerPlugin::createSession() 0119 { 0120 auto *session = new DebugSession(this); 0121 core()->debugController()->addSession(session); 0122 connect(session, &DebugSession::showMessage, this, &LldbDebuggerPlugin::showStatusMessage); 0123 connect(session, &DebugSession::reset, this, &LldbDebuggerPlugin::reset); 0124 connect(session, &DebugSession::raiseDebuggerConsoleViews, 0125 this, &LldbDebuggerPlugin::raiseDebuggerConsoleViews); 0126 return session; 0127 } 0128 0129 #include "debuggerplugin.moc" 0130 #include "moc_debuggerplugin.cpp"