[Lldb-commits] [PATCH] D61686: Disable pty redirection on Windows and add a method to get the parent pid

Aaron Smith via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed May 8 08:42:38 PDT 2019


asmith created this revision.
asmith added reviewers: labath, rnk.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

More changes for lldb-server on Windows

- Disable pty redirection for Windows since there is no pty support currently
- Add a method to get the parent pid for a process on Windows


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D61686

Files:
  source/Host/windows/Host.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
  source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp


Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -214,8 +214,14 @@
   m_process_launch_info.GetFlags().Set(eLaunchFlagDebug);
 
   if (should_forward_stdio) {
+    // There is no pty support on Windows currently which means O* and I*
+    // notification packets will not be generated about the inferior.
+    // In most cases the missing notifications do not affect lldb-server
+    // so we are temporarily relaxing the following for Windows.
+#if !defined(_WIN32)
     if (llvm::Error Err = m_process_launch_info.SetUpPtyRedirection())
       return Status(std::move(Err));
+#endif
   }
 
   {
Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -1185,12 +1185,17 @@
 void GDBRemoteCommunicationServerCommon::
     CreateProcessInfoResponse_DebugServerStyle(
         const ProcessInstanceInfo &proc_info, StreamString &response) {
+#if defined(_WIN32)
+  response.Printf("pid:%" PRIx64 ";parent-pid:%" PRIx64 ";",
+                  proc_info.GetProcessID(), proc_info.GetParentProcessID());
+#else
   response.Printf("pid:%" PRIx64 ";parent-pid:%" PRIx64
                   ";real-uid:%x;real-gid:%x;effective-uid:%x;effective-gid:%x;",
                   proc_info.GetProcessID(), proc_info.GetParentProcessID(),
                   proc_info.GetUserID(), proc_info.GetGroupID(),
                   proc_info.GetEffectiveUserID(),
                   proc_info.GetEffectiveGroupID());
+#endif
 
   const ArchSpec &proc_arch = proc_info.GetArchitecture();
   if (proc_arch.IsValid()) {
Index: source/Host/windows/Host.cpp
===================================================================
--- source/Host/windows/Host.cpp
+++ source/Host/windows/Host.cpp
@@ -169,7 +169,23 @@
   GetProcessExecutableAndTriple(handle, process_info);
 
   // Need to read the PEB to get parent process and command line arguments.
-  return true;
+
+  AutoHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0));
+  if (!snapshot.IsValid())
+    return false;
+
+  PROCESSENTRY32W pe;
+  pe.dwSize = sizeof(PROCESSENTRY32W);
+  if (Process32FirstW(snapshot.get(), &pe)) {
+    do {
+      if (pe.th32ProcessID == pid) {
+        process_info.SetParentProcessID(pe.th32ParentProcessID);
+        return true;
+      }
+    } while (Process32NextW(snapshot.get(), &pe));
+  }
+
+  return false;
 }
 
 HostThread Host::StartMonitoringChildProcess(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61686.198670.patch
Type: text/x-patch
Size: 2841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190508/03b79892/attachment.bin>


More information about the lldb-commits mailing list