[Lldb-commits] [PATCH] D53090: [ProcessWindows] Fix a bug that causes lldb to freeze

Aaron Smith via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 10 10:13:56 PDT 2018


asmith created this revision.
asmith added reviewers: rnk, zturner, aleksandr.urakov.
Herald added a subscriber: lldb-commits.

If the process exits before any initial stop then notify the debugger 
of the error otherwise WaitForDebuggerConnection() will be blocked.
An example of this issue is when a process fails to load a dependent DLL.

     

In addition to the fix, remove a duplicate call to FreeProcessHandles() in DebuggerThread::HandleExitProcessEvent() and use decimal format 
for all thread IDs.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D53090

Files:
  source/Plugins/Process/Windows/Common/DebuggerThread.cpp
  source/Plugins/Process/Windows/Common/ProcessWindows.cpp


Index: source/Plugins/Process/Windows/Common/ProcessWindows.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -812,6 +812,14 @@
 
   SetProcessExitStatus(GetID(), true, 0, exit_code);
   SetPrivateState(eStateExited);
+
+  // If the process exits before any initial stop then notify the debugger 
+  // of the error otherwise WaitForDebuggerConnection() will be blocked.
+  // An example of this issue is when a process fails to load a dependent DLL. 
+  if (!m_session_data->m_initial_stop_received) {
+    Status error(exit_code, eErrorTypeWin32);
+    OnDebuggerError(error, 0);
+  }
 }
 
 void ProcessWindows::OnDebuggerConnected(lldb::addr_t image_base) {
Index: source/Plugins/Process/Windows/Common/DebuggerThread.cpp
===================================================================
--- source/Plugins/Process/Windows/Common/DebuggerThread.cpp
+++ source/Plugins/Process/Windows/Common/DebuggerThread.cpp
@@ -50,7 +50,7 @@
   lldb::pid_t m_pid;
   ProcessAttachInfo m_attach_info;
 };
-}
+} // namespace
 
 DebuggerThread::DebuggerThread(DebugDelegateSP debug_delegate)
     : m_debug_delegate(debug_delegate), m_pid_to_detach(0),
@@ -191,7 +191,8 @@
                handle, pid, terminate_suceeded);
     } else {
       LLDB_LOG(log,
-               "NOT calling TerminateProcess because the inferior is not valid ({0}, 0) (inferior={1})",
+               "NOT calling TerminateProcess because the inferior is not valid "
+               "({0}, 0) (inferior={1})",
                handle, pid);
     }
   }
@@ -267,6 +268,8 @@
     if (wait_result) {
       DWORD continue_status = DBG_CONTINUE;
       switch (dbe.dwDebugEventCode) {
+      default:
+        llvm_unreachable("Unhandle debug event code!");
       case EXCEPTION_DEBUG_EVENT: {
         ExceptionResult status =
             HandleExceptionEvent(dbe.u.Exception, dbe.dwThreadId);
@@ -330,7 +333,7 @@
   FreeProcessHandles();
 
   LLDB_LOG(log, "WaitForDebugEvent loop completed, exiting.");
-  SetEvent(m_debugging_ended_event);
+  ::SetEvent(m_debugging_ended_event);
 }
 
 ExceptionResult
@@ -381,7 +384,7 @@
                                         DWORD thread_id) {
   Log *log =
       ProcessWindowsLog::GetLogIfAny(WINDOWS_LOG_EVENT | WINDOWS_LOG_THREAD);
-  LLDB_LOG(log, "Thread {0:x} spawned in process {1}", thread_id,
+  LLDB_LOG(log, "Thread {0} spawned in process {1}", thread_id,
            m_process.GetProcessId());
   HostThread thread(info.hThread);
   thread.GetNativeThread().SetOwnsHandle(false);
@@ -439,7 +442,6 @@
 
   m_debug_delegate->OnExitProcess(info.dwExitCode);
 
-  FreeProcessHandles();
   return DBG_CONTINUE;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53090.169032.patch
Type: text/x-patch
Size: 2778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20181010/785e0381/attachment.bin>


More information about the lldb-commits mailing list