Repository: microsoft/ptvsd

Issue:
"pydevdSystemInfo" does not report "ppid" on Python 2.7 on Windows
`os.getppid()` was not available on Windows until Python 3.2. Pydevd catches any exceptions from that call, and omits the property from JSON, so this doesn't crash the debugger. But because the adapter doesn't receive "ppid" for the incoming server connection, it doesn't know which of the existing debug sessions is the parent, and doesn't send the subprocess notification to any of them. This effectively breaks multiproc debugging on 2.7.




Discussion:
Pydevd might have to propagate the parent PID via command line when spawning the child process to ensure that it's always available. Or perhaps there's a way to re-implement `os.getppid()` in 2.7 in a way similar to how it's done in 3.2.
The fix doesn't seem to be working reliably. This is from a test run for `test_flask_breakpoint_multiproc[launch(integratedTerminal)]`:
```
D+00001.268: Server[?] <-- {
                 "seq": 1, 
                 "type": "request", 
                 "command": "pydevdSystemInfo"
             }

D+00001.277: Server[?] --> {
                 "pydevd_cmd_id": 502, 
                 "seq": 2, 
                 "type": "response", 
                 "request_seq": 1, 
                 "success": true, 
                 "command": "pydevdSystemInfo", 
                 "body": {
                     "process": {
                         "pid": 128364, 
                         "bitness": 64, 
                         "executable": "c:\\git\\ptvsd\\.tox\\py27\\scripts\\python.exe"
                     }, 
                     "python": {
                         "version": "2.7.16final0", 
                         "implementation": {
                             "description": "CPython", 
                             "version": "", 
                             "name": ""
                         }
                     }, 
                     "platform": {
                         "name": "win32"
                     }
                 }
             }
```
Note the missing "ppid". Looking at pydevd log for the process reporting, it has this entry in it, but no further details:
```
Process32First failed (getting process from CreateToolhelp32Snapshot).
```

I'm investigating.

Resolving patch:
diff --git a/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py b/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
--- a/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
+++ b/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
@@ -957,15 +957,15 @@ def _list_ppid_and_pid():
     _TH32CS_SNAPPROCESS = 0x00000002
 
     class PROCESSENTRY32(ctypes.Structure):
-        _fields_ = [("dwSize", ctypes.c_ulong),
-                    ("cntUsage", ctypes.c_ulong),
-                    ("th32ProcessID", ctypes.c_ulong),
-                    ("th32DefaultHeapID", ctypes.c_ulong),
-                    ("th32ModuleID", ctypes.c_ulong),
-                    ("cntThreads", ctypes.c_ulong),
-                    ("th32ParentProcessID", ctypes.c_ulong),
-                    ("pcPriClassBase", ctypes.c_ulong),
-                    ("dwFlags", ctypes.c_ulong),
+        _fields_ = [("dwSize", ctypes.c_uint32),
+                    ("cntUsage", ctypes.c_uint32),
+                    ("th32ProcessID", ctypes.c_uint32),
+                    ("th32DefaultHeapID", ctypes.c_size_t),
+                    ("th32ModuleID", ctypes.c_uint32),
+                    ("cntThreads", ctypes.c_uint32),
+                    ("th32ParentProcessID", ctypes.c_uint32),
+                    ("pcPriClassBase", ctypes.c_long),
+                    ("dwFlags", ctypes.c_uint32),
                     ("szExeFile", ctypes.c_char * 260)]
 
     kernel32 = ctypes.windll.kernel32


Test patch: