Refactoring of ManagedDebugger::RunProcess()
authorAndrey Okoshkin <a.okoshkin@samsung.com>
Wed, 28 Feb 2018 10:25:25 +0000 (13:25 +0300)
committerAndrey Okoshkin <a.okoshkin@samsung.com>
Fri, 23 Mar 2018 13:49:18 +0000 (16:49 +0300)
src/debug/netcoredbg/manageddebugger.cpp

index f97bfc94be010e959a48e4ad930cbac49f7d27d1..b32f56b20c89fd349f8c3acf812d8867b4c0847c 100644 (file)
@@ -973,21 +973,20 @@ HRESULT ManagedDebugger::RunProcess(std::string fileExec, std::vector<std::strin
 
     IfFailRet(CheckNoProcess());
 
-    std::stringstream ss;
+    std::ostringstream ss;
     ss << "\"" << fileExec << "\"";
-    for (std::string &arg : execArgs)
-    {
+    for (const std::string &arg : execArgs)
         ss << " \"" << EscapeShellArg(arg) << "\"";
-    }
 
     m_startupReady = false;
     m_clrPath.clear();
 
-    BOOL bSuspendProcess = TRUE;
-    LPVOID lpEnvironment = nullptr; // as current
-    LPCWSTR lpCurrentDirectory = nullptr; // as current
-    HANDLE resumeHandle;
-    IfFailRet(CreateProcessForLaunch(const_cast<LPWSTR>(to_utf16(ss.str()).c_str()), bSuspendProcess, lpEnvironment, lpCurrentDirectory, &m_processId, &resumeHandle));
+    HANDLE resumeHandle; // Fake thread handle for the process resume
+    IfFailRet(CreateProcessForLaunch(const_cast<LPWSTR>(to_utf16(ss.str()).c_str()),
+                                     /* Suspend process */ TRUE,
+                                     /* Current environment */ NULL,
+                                     /* Current working directory */ NULL,
+                                     &m_processId, &resumeHandle));
 
     IfFailRet(RegisterForRuntimeStartup(m_processId, ManagedDebugger::StartupCallback, this, &m_unregisterToken));
 
@@ -997,10 +996,10 @@ HRESULT ManagedDebugger::RunProcess(std::string fileExec, std::vector<std::strin
 
     // Wait for ManagedDebugger::StartupCallback to complete
 
-    // FIXME: if the process exits too soon the ManagedDebugger::StartupCallback()
-    // is never called (bug in dbgshim?).
-    // The workaround is to wait with timeout.
-    auto now = std::chrono::system_clock::now();
+    /// FIXME: if the process exits too soon the ManagedDebugger::StartupCallback()
+    /// is never called (bug in dbgshim?).
+    /// The workaround is to wait with timeout.
+    const auto now = std::chrono::system_clock::now();
 
     std::unique_lock<std::mutex> lock(m_startupMutex);
     if (!m_startupCV.wait_until(lock, now + startupCallbackWaitTimeout, [this](){return m_startupReady;}))