llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Nerixyz (Nerixyz)

<details>
<summary>Changes</summary>

I noticed that LLDB takes longer to stop than it should. Running a tiny program 
like `int main() { return 0; }` in LLDB with `lldb test.exe -o r -o q` takes 
about five seconds.

This is caused by the `WaitForMultipleObjects` in 
[`ConnectionGenericFile::Read`](https://github.com/llvm/llvm-project/blob/25976e83606f1a7615e3725e6038bb53ee96c3d5/lldb/source/Host/windows/ConnectionGenericFileWindows.cpp#L191-L192)
 timing out (it has a timeout of 5s).

It times out, because we never close the PTY created in 
[`ProcessLaunchInfo::SetUpPtyRedirection`](https://github.com/llvm/llvm-project/blob/25976e83606f1a7615e3725e6038bb53ee96c3d5/lldb/source/Host/common/ProcessLaunchInfo.cpp#L213).
 When we call `target-&gt;GetProcessLaunchInfo().GetPTY().Close()` in 
`ProcessWindows::OnExitProcess`, we don't access the PTY we created when 
setting up the redirection - we're closing some default constructed one. This 
is because the target's `m_launch_info` isn't the `launch_info` we get in 
[`Target::FinalizeFileActions`](https://github.com/llvm/llvm-project/blob/4a8a0593bdecee49331cb5c31a6c9b18d87ea41c/lldb/source/Target/Target.cpp#L3850)
 when calling `SetUpPtyRedirection`.

With this PR, we store the PTY that a process was launched with inside 
`ProcessWindows`, so we can later close it.

The wait of five seconds and a timed out `WaitForMultipleObjects` sounds 
similar to https://github.com/llvm/llvm-project/pull/159308, but it's a 
different call to `WaitForMultipleObjects` here. Still, I wonder if we could do 
something to detect this earlier. Maybe some warning message or debug-only 
assert if these waits time out?

---
Full diff: https://github.com/llvm/llvm-project/pull/175837.diff


2 Files Affected:

- (modified) lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
(+4-1) 
- (modified) lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h (+1) 


``````````diff
diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
index 127dd0f59e9ae..226cc147aadae 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.cpp
@@ -214,6 +214,7 @@ Status ProcessWindows::DoLaunch(Module *exe_module,
   error = LaunchProcess(launch_info, delegate);
   if (error.Success())
     SetID(launch_info.GetProcessID());
+  m_pty = launch_info.GetPTYSP();
   return error;
 }
 
@@ -650,8 +651,10 @@ void ProcessWindows::OnExitProcess(uint32_t exit_code) {
   Log *log = GetLog(WindowsLog::Process);
   LLDB_LOG(log, "Process {0} exited with code {1}", GetID(), exit_code);
 
+  if (m_pty)
+    m_pty->Close();
+
   TargetSP target = CalculateTarget();
-  target->GetProcessLaunchInfo().GetPTY().Close();
   if (target) {
     ModuleSP executable_module = target->GetExecutableModule();
     ModuleList unloaded_modules;
diff --git a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h 
b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h
index 33e4de6b85932..becab6964a4aa 100644
--- a/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h
+++ b/lldb/source/Plugins/Process/Windows/Common/ProcessWindows.h
@@ -117,6 +117,7 @@ class ProcessWindows : public Process, public 
ProcessDebugger {
   };
   std::map<lldb::break_id_t, WatchpointInfo> m_watchpoints;
   std::vector<lldb::break_id_t> m_watchpoint_ids;
+  std::shared_ptr<PTY> m_pty;
 };
 } // namespace lldb_private
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/175837
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to