| 293 | } |
| 294 | |
| 295 | void DebuggerClientDap::processRequest( const nlohmann::json& msg ) { |
| 296 | const auto reqSeq = msg.value( DAP_SEQ, 0 ); |
| 297 | if ( reqSeq == 0 ) |
| 298 | return; |
| 299 | const auto command = msg.value( DAP_COMMAND, "" ); |
| 300 | const auto args = msg.contains( DAP_ARGUMENTS ) ? msg[DAP_ARGUMENTS] : nlohmann::json{}; |
| 301 | |
| 302 | if ( DAP_RUN_IN_TERMINAL == command ) { |
| 303 | if ( !runInTerminalCb ) |
| 304 | return; |
| 305 | bool isIntegrated = args.value( "kind", "integrated" ) == "integrated"; |
| 306 | std::vector<std::string> largs; |
| 307 | if ( args.contains( "args" ) && args["args"].is_array() ) { |
| 308 | for ( const auto& jarg : args["args"] ) { |
| 309 | if ( jarg.is_string() ) |
| 310 | largs.emplace_back( jarg.get<std::string>() ); |
| 311 | } |
| 312 | } |
| 313 | std::unordered_map<std::string, std::string> lenv; |
| 314 | if ( args.contains( "env" ) && args["env"].is_object() ) { |
| 315 | for ( auto& [key, value] : args["env"].items() ) { |
| 316 | if ( value.is_string() ) |
| 317 | lenv.emplace( key, value.get<std::string>() ); |
| 318 | } |
| 319 | } |
| 320 | std::string cwd = args.value( "cwd", "" ); |
| 321 | if ( !largs.empty() ) { |
| 322 | std::string cmd = std::move( largs.front() ); |
| 323 | largs.erase( largs.begin() ); |
| 324 | runInTerminalCb( |
| 325 | isIntegrated, cmd, largs, cwd, lenv, [this, reqSeq, command]( int pid ) { |
| 326 | makeResponse( reqSeq, pid != 0, command, nlohmann::json{ { "processId", pid } }, |
| 327 | mCurrentSessionId ); |
| 328 | } ); |
| 329 | } |
| 330 | } else if ( DAP_START_DEBUGGING == command ) { |
| 331 | SessionId sessionId = |
| 332 | args.contains( "configuration" ) |
| 333 | ? args["configuration"].value( "__pendingTargetId", |
| 334 | "" ) // This is non-standard, we recover the target |
| 335 | // id for node, otherwise we will use an UUID |
| 336 | : ""; |
| 337 | if ( sessionId.empty() ) |
| 338 | sessionId = UUID().toString(); |
| 339 | |
| 340 | Lock l( mSessionsMutex ); |
| 341 | Session& newSession = mSessions[sessionId]; |
| 342 | newSession.launchRequestType = msg.value( DAP_REQUEST, "launch" ); |
| 343 | |
| 344 | if ( args.contains( "configuration" ) ) |
| 345 | newSession.launchArgs = args["configuration"]; |
| 346 | |
| 347 | newSession.state = State::Initializing; |
| 348 | |
| 349 | switch ( mSessions[mCurrentSessionId].bus->type() ) { |
| 350 | case Bus::Type::Process: { |
| 351 | BusProcess* prevBus = |
| 352 | static_cast<BusProcess*>( mSessions[mCurrentSessionId].bus.get() ); |
nothing calls this directly
no test coverage detected