MCPcopy Create free account
hub / github.com/Vector35/debugger / ExecuteWithArgsInternal

Method ExecuteWithArgsInternal

core/adapters/dbgengadapter.cpp:347–446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345
346
347bool DbgEngAdapter::ExecuteWithArgsInternal(const std::string& path, const std::string& args,
348 const std::string& workingDir, const LaunchConfigurations& configs)
349{
350 m_aboutToBeKilled = false;
351
352 if (this->m_debugActive)
353 {
354 this->Reset();
355 }
356
357 if (!Start())
358 {
359 this->Reset();
360 DebuggerEvent event;
361 event.type = LaunchFailureEventType;
362 event.data.errorData.error = fmt::format("Failed to initialize DbgEng");
363 event.data.errorData.shortError = fmt::format("Failed to initialize DbgEng");
364 PostDebuggerEvent(event);
365 return false;
366 }
367
368 if (const auto result = this->m_debugControl->SetEngineOptions(DEBUG_ENGOPT_INITIAL_BREAK); result != S_OK)
369 {
370 this->Reset();
371 DebuggerEvent event;
372 event.type = LaunchFailureEventType;
373 event.data.errorData.error = fmt::format("Failed to engine option DEBUG_ENGOPT_INITIAL_BREAK");
374 event.data.errorData.shortError = fmt::format("Failed to engine option");
375 PostDebuggerEvent(event);
376 return false;
377 }
378
379 /* TODO: parse args better */
380 std::string path_with_args {path};
381 if (!args.empty())
382 {
383 path_with_args.append(" ");
384 path_with_args.append(args);
385 }
386
387 DEBUG_CREATE_PROCESS_OPTIONS options;
388 options.CreateFlags = DEBUG_ONLY_THIS_PROCESS;
389 options.EngCreateFlags = 0;
390 options.VerifierFlags = 0;
391 options.Reserved = 0;
392
393 // CreateProcess2() is picky about the InitialDirectory parameter. It is OK to send in a NULL, but if a non-NULL
394 // string which is empty gets passed in, the call fails.
395 char* directory = _strdup(workingDir.c_str());
396 if (workingDir.empty())
397 directory = nullptr;
398
399 if (const auto result = this->m_debugClient->CreateProcess2(m_server, const_cast<char*>(path_with_args.c_str()),
400 &options, sizeof(DEBUG_CREATE_PROCESS_OPTIONS), directory, nullptr);
401 result != S_OK)
402 {
403 this->Reset();
404 DebuggerEvent event;

Callers

nothing calls this directly

Calls 3

ResetMethod · 0.95
SetExecutionStatusMethod · 0.80
ModuleNameAndOffsetClass · 0.50

Tested by

no test coverage detected