diff --git a/bin/assets/plugins/debugger.json b/bin/assets/plugins/debugger.json index 2a4a84139..6aa662355 100644 --- a/bin/assets/plugins/debugger.json +++ b/bin/assets/plugins/debugger.json @@ -20,21 +20,6 @@ "env": "${env}" } }, - { - "name": "Attach to Name", - "request": "attach", - "arguments": { - "program": "${file}" - } - }, - { - "name": "Attach to Name (wait)", - "request": "attach", - "arguments": { - "program": "${file}", - "waitFor": true - } - }, { "name": "Attach to PID", "request": "attach", @@ -87,15 +72,17 @@ } }, { - "name": "Attach to Name", + "name": "Attach to binary", "request": "attach", + "runTarget": true, "arguments": { "program": "${file}" } }, { - "name": "Attach to Name (wait)", + "name": "Attach to binary (wait)", "request": "attach", + "runTarget": true, "arguments": { "program": "${file}", "waitFor": true @@ -198,7 +185,7 @@ } }, { - "name": "Attach", + "name": "Attach to PID", "command_arguments": ["--pid", "${command:pickProcess}"], "request": "attach", "arguments": { diff --git a/src/tools/ecode/plugins/debugger/config.hpp b/src/tools/ecode/plugins/debugger/config.hpp index 4ca08c3d1..6efafa8be 100644 --- a/src/tools/ecode/plugins/debugger/config.hpp +++ b/src/tools/ecode/plugins/debugger/config.hpp @@ -48,6 +48,7 @@ struct ProtocolSettings { bool redirectStderr{ false }; bool redirectStdout{ false }; bool supportsSourceRequest{ true }; + bool runTarget{ false }; std::string launchRequestType{ "launch" }; json launchArgs; std::string locale{ "en-US" }; diff --git a/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp b/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp index a5a6bebde..713b04a93 100644 --- a/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp +++ b/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp @@ -153,6 +153,13 @@ void DebuggerClientDap::requestLaunchCommand() { setState( State::Failed ); } } ); + + if ( mProtocol.runTarget && runTargetCb ) { + if ( !mProtocol.launchArgs.contains( "waitFor" ) ) + runTargetCb(); + else + mWaitingToAttach = true; + } } void DebuggerClientDap::requestInitialize() { @@ -353,6 +360,11 @@ void DebuggerClientDap::processEventOutput( const nlohmann::json& body ) { Output output( body ); for ( auto listener : mListeners ) listener->outputProduced( output ); + + if ( mWaitingToAttach && mProtocol.runTarget && runTargetCb ) { + runTargetCb(); + mWaitingToAttach = false; + } } void DebuggerClientDap::processEventProcess( const nlohmann::json& body ) { diff --git a/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.hpp b/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.hpp index 729f60026..1738f6ffb 100644 --- a/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.hpp +++ b/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.hpp @@ -22,6 +22,8 @@ class DebuggerClientDap : public DebuggerClient { std::function doneFn )> runInTerminalCb; + std::function runTargetCb; + DebuggerClientDap( const ProtocolSettings& protocolSettings, std::unique_ptr&& bus ); virtual ~DebuggerClientDap(); diff --git a/src/tools/ecode/plugins/debugger/debuggerclient.hpp b/src/tools/ecode/plugins/debugger/debuggerclient.hpp index 6dfd1d9fa..2a44c1bab 100644 --- a/src/tools/ecode/plugins/debugger/debuggerclient.hpp +++ b/src/tools/ecode/plugins/debugger/debuggerclient.hpp @@ -129,6 +129,7 @@ class DebuggerClient { State mState{ State::None }; bool mLaunched{ false }; bool mConfigured{ false }; + bool mWaitingToAttach{ false }; std::vector mListeners; void checkRunning(); diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp index d25614c0c..e8d8d32e9 100644 --- a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp @@ -419,6 +419,7 @@ void DebuggerPlugin::loadDAPConfig( const std::string& path, bool updateConfigFi dapConfig.name = config.value( "name", "" ); if ( !dapConfig.name.empty() ) { dapConfig.request = config.value( "request", REQUEST_TYPE_LAUNCH ); + dapConfig.runTarget = config.value( "runTarget", false ); dapConfig.args = config["arguments"]; } if ( config.contains( "command_arguments" ) ) { @@ -1736,6 +1737,7 @@ void DebuggerPlugin::prepareAndRun( DapTool debugger, DapConfig config, int randomPort = Math::randi( 44000, 45000 ); ProtocolSettings protocolSettings; protocolSettings.launchRequestType = config.request; + protocolSettings.runTarget = config.runTarget; auto args = config.args; replaceKeysInJson( args, randomPort, solvedInputs ); protocolSettings.launchArgs = args; @@ -2027,6 +2029,11 @@ void DebuggerPlugin::run( const std::string& debugger, ProtocolSettings&& protoc } ); }; + dap->runTargetCb = [this] { + getUISceneNode()->runOnMainThread( + [this] { getPluginContext()->runCommand( "project-run-executable" ); } ); + }; + mDebugger->start(); } diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.hpp b/src/tools/ecode/plugins/debugger/debuggerplugin.hpp index 0eefd5389..9ce719990 100644 --- a/src/tools/ecode/plugins/debugger/debuggerplugin.hpp +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.hpp @@ -21,6 +21,7 @@ struct DapConfig { std::string request; std::vector cmdArgs; nlohmann::json args; + bool runTarget{ false }; }; struct DapTool {