Skip to content

Commit

Permalink
Improve attach to "Run Target". Now it's possible to debug a terminal…
Browse files Browse the repository at this point in the history
… application by using this attach.
  • Loading branch information
SpartanJ committed Feb 5, 2025
1 parent eae4337 commit 72c1d9f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
23 changes: 5 additions & 18 deletions bin/assets/plugins/debugger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -198,7 +185,7 @@
}
},
{
"name": "Attach",
"name": "Attach to PID",
"command_arguments": ["--pid", "${command:pickProcess}"],
"request": "attach",
"arguments": {
Expand Down
1 change: 1 addition & 0 deletions src/tools/ecode/plugins/debugger/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down
12 changes: 12 additions & 0 deletions src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 2 additions & 0 deletions src/tools/ecode/plugins/debugger/dap/debuggerclientdap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class DebuggerClientDap : public DebuggerClient {
std::function<void( int )> doneFn )>
runInTerminalCb;

std::function<void()> runTargetCb;

DebuggerClientDap( const ProtocolSettings& protocolSettings, std::unique_ptr<Bus>&& bus );

virtual ~DebuggerClientDap();
Expand Down
1 change: 1 addition & 0 deletions src/tools/ecode/plugins/debugger/debuggerclient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class DebuggerClient {
State mState{ State::None };
bool mLaunched{ false };
bool mConfigured{ false };
bool mWaitingToAttach{ false };
std::vector<Listener*> mListeners;

void checkRunning();
Expand Down
7 changes: 7 additions & 0 deletions src/tools/ecode/plugins/debugger/debuggerplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) ) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/ecode/plugins/debugger/debuggerplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct DapConfig {
std::string request;
std::vector<std::string> cmdArgs;
nlohmann::json args;
bool runTarget{ false };
};

struct DapTool {
Expand Down

0 comments on commit 72c1d9f

Please sign in to comment.