From 42e7369c2f1c1f445e0c8206a3829269c0ed770e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 28 Dec 2024 01:13:01 -0300 Subject: [PATCH] DAP WIP. --- bin/assets/plugins/debugger.json | 44 ++++++ src/tools/ecode/ecode.cpp | 16 ++- .../ecode/plugins/debugger/debuggerplugin.cpp | 132 ++++++++++++++++++ .../ecode/plugins/debugger/debuggerplugin.hpp | 39 ++++++ 4 files changed, 225 insertions(+), 6 deletions(-) create mode 100644 bin/assets/plugins/debugger.json create mode 100644 src/tools/ecode/plugins/debugger/debuggerplugin.cpp create mode 100644 src/tools/ecode/plugins/debugger/debuggerplugin.hpp diff --git a/bin/assets/plugins/debugger.json b/bin/assets/plugins/debugger.json new file mode 100644 index 000000000..0ee2919bf --- /dev/null +++ b/bin/assets/plugins/debugger.json @@ -0,0 +1,44 @@ +{ + "dap": [ + { + "name": "gdb", + "url": "https://www.gnu.org/software/gdb", + "run": { + "command": "gdb --interpreter=dap" + }, + "configurations": [ + { + "name": "launch binary", + "command": "launch", + "arguments": { + "program": "${file}", + "args": "${args}", + "cwd": "${cwd}", + "env": "${env}", + "stopOnEntry": "${stopOnEntry}" + } + } + ] + }, + { + "name": "lldb-dab", + "url": "https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/README.md", + "run": { + "command": "lldb-dap" + }, + "configurations": [ + { + "name": "launch binary", + "command": "launch", + "arguments": { + "program": "${file}", + "args": "${args}", + "cwd": "${cwd}", + "env": "${env}", + "stopOnEntry": "${stopOnEntry}" + } + } + ] + } + ] +} diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 9f0c7310e..19fbc2215 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -3,12 +3,6 @@ #include "iconmanager.hpp" #include "keybindingshelper.hpp" #include "pathhelper.hpp" -#include "plugins/autocomplete/autocompleteplugin.hpp" -#include "plugins/formatter/formatterplugin.hpp" -#include "plugins/git/gitplugin.hpp" -#include "plugins/linter/linterplugin.hpp" -#include "plugins/lsp/lspclientplugin.hpp" -#include "plugins/xmltools/xmltoolsplugin.hpp" #include "settingsactions.hpp" #include "settingsmenu.hpp" #include "uibuildsettings.hpp" @@ -23,6 +17,15 @@ #include #include +//! Plugins +#include "plugins/autocomplete/autocompleteplugin.hpp" +#include "plugins/formatter/formatterplugin.hpp" +#include "plugins/debugger/debuggerplugin.hpp" +#include "plugins/git/gitplugin.hpp" +#include "plugins/linter/linterplugin.hpp" +#include "plugins/lsp/lspclientplugin.hpp" +#include "plugins/xmltools/xmltoolsplugin.hpp" + #if EE_PLATFORM == EE_PLATFORM_LINUX // For malloc_trim, which is a GNU extension extern "C" { @@ -572,6 +575,7 @@ void App::initPluginManager() { } ); } }; + mPluginManager->registerPlugin( DebuggerPlugin::Definition() ); mPluginManager->registerPlugin( LinterPlugin::Definition() ); mPluginManager->registerPlugin( FormatterPlugin::Definition() ); mPluginManager->registerPlugin( AutoCompletePlugin::Definition() ); diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp new file mode 100644 index 000000000..ec652f911 --- /dev/null +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp @@ -0,0 +1,132 @@ +#include "debuggerplugin.hpp" +#include +#include +#include + +using namespace EE::UI; +using namespace EE::UI::Doc; + +using namespace std::literals; + +using json = nlohmann::json; + +#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ ) +#define DEBUGGER_THREADED 1 +#else +#define DEBUGGER_THREADED 0 +#endif + +namespace ecode { + +Plugin* DebuggerPlugin::New( PluginManager* pluginManager ) { + return eeNew( DebuggerPlugin, ( pluginManager, false ) ); +} + +Plugin* DebuggerPlugin::NewSync( PluginManager* pluginManager ) { + return eeNew( DebuggerPlugin, ( pluginManager, true ) ); +} + +DebuggerPlugin::DebuggerPlugin( PluginManager* pluginManager, bool sync ) : + PluginBase( pluginManager ) { + if ( sync ) { + load( pluginManager ); + } else { +#if defined( DEBUGGER_THREADED ) && DEBUGGER_THREADED == 1 + mThreadPool->run( [this, pluginManager] { load( pluginManager ); } ); +#else + load( pluginManager ); +#endif + } +} + +DebuggerPlugin::~DebuggerPlugin() { + waitUntilLoaded(); + mShuttingDown = true; +} + +void DebuggerPlugin::load( PluginManager* pluginManager ) { + Clock clock; + AtomicBoolScopedOp loading( mLoading, true ); + pluginManager->subscribeMessages( this, + [this]( const auto& notification ) -> PluginRequestHandle { + return processMessage( notification ); + } ); + + std::string path = pluginManager->getPluginsPath() + "debugger.json"; + if ( FileSystem::fileExists( path ) || + FileSystem::fileWrite( path, "{\n \"config\":{},\n \"keybindings\":{}\n}\n" ) ) { + mConfigPath = path; + } + std::string data; + if ( !FileSystem::fileGet( path, data ) ) + return; + mConfigHash = String::hash( data ); + + json j; + try { + j = json::parse( data, nullptr, true, true ); + } catch ( const json::exception& e ) { + Log::error( "DebuggerPlugin::load - Error parsing config from path %s, error: %s, config " + "file content:\n%s", + path.c_str(), e.what(), data.c_str() ); + // Recreate it + j = json::parse( "{\n \"config\":{},\n \"keybindings\":{},\n}\n", nullptr, true, true ); + } + + bool updateConfigFile = false; + + if ( j.contains( "config" ) ) { + } + + if ( mKeyBindings.empty() ) { + } + + if ( j.contains( "keybindings" ) ) { + auto& kb = j["keybindings"]; + std::initializer_list list = {}; + for ( const auto& key : list ) { + if ( kb.contains( key ) ) { + if ( !kb[key].empty() ) + mKeyBindings[key] = kb[key]; + } else { + kb[key] = mKeyBindings[key]; + updateConfigFile = true; + } + } + } + + if ( updateConfigFile ) { + std::string newData = j.dump( 2 ); + if ( newData != data ) { + FileSystem::fileWrite( path, newData ); + mConfigHash = String::hash( newData ); + } + } + + if ( getUISceneNode() ) { + // Init UI + } + + subscribeFileSystemListener(); + mReady = true; + fireReadyCbs(); + setReady( clock.getElapsedTime() ); +} + +PluginRequestHandle DebuggerPlugin::processMessage( const PluginMessage& msg ) { + switch ( msg.type ) { + case PluginMessageType::WorkspaceFolderChanged: { + + break; + } + case ecode::PluginMessageType::UIReady: { + // Init UI if not initialized + break; + } + default: + break; + } + return PluginRequestHandle::empty(); +} + +} // namespace ecode diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.hpp b/src/tools/ecode/plugins/debugger/debuggerplugin.hpp new file mode 100644 index 000000000..f9d689e53 --- /dev/null +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include "../plugin.hpp" +#include "../pluginmanager.hpp" + +using namespace EE::UI::Models; +using namespace EE::UI; + +namespace ecode { + +class DebuggerPlugin : public PluginBase { + public: + static PluginDefinition Definition() { + return { "debugger", "Debugger", "Debugger integration", + DebuggerPlugin::New, { 0, 0, 1 }, DebuggerPlugin::NewSync }; + } + + static Plugin* New( PluginManager* pluginManager ); + + static Plugin* NewSync( PluginManager* pluginManager ); + + virtual ~DebuggerPlugin(); + + std::string getId() override { return Definition().id; } + + std::string getTitle() override { return Definition().name; } + + std::string getDescription() override { return Definition().description; } + + protected: + DebuggerPlugin( PluginManager* pluginManager, bool sync ); + + void load( PluginManager* pluginManager ); + + PluginRequestHandle processMessage( const PluginMessage& msg ); + +}; + +} // namespace ecode