Repository: microsoft/ptvsd

Issue:
Attatch via pid fails on automated runs with missing dbghelp.dll error
## Environment data

- PTVSD version: master
- OS and version: windows
- Python version (& distribution if applicable, e.g. Anaconda): any
- Using VS Code or Visual Studio: N/A

## Actual behavior

```
Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.6.4\x64\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\hostedtoolcache\windows\Python\3.6.4\x64\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\__main__.py", line 365, in <module>
    main(sys.argv)
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\__main__.py", line 353, in main
    run()
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\__main__.py", line 336, in attach_to_pid
    run_python_code(pid, code, connect_debugger_tracing=True)
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\add_code_to_python_process.py", line 272, in run_python_code_windows
    from winappdbg import compat
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\winappdbg\__init__.py", line 234, in <module>
    from winappdbg.breakpoint import *
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\winappdbg\breakpoint.py", line 65, in <module>
    from winappdbg import win32
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\winappdbg\win32\__init__.py", line 45, in <module>
    from winappdbg.win32 import dbghelp
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\winappdbg\win32\dbghelp.py", line 79, in <module>
    _load_latest_dbghelp_dll()
  File "d:\a\1\s\.tox\py36\lib\site-packages\ptvsd\_vendored\pydevd\pydevd_attach_to_process\winappdbg\win32\dbghelp.py", line 63, in _load_latest_dbghelp_dll
    "dbghelp.dll")
  File "d:\a\1\s\.tox\py36\lib\ntpath.py", line 75, in join
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType
```

## Expected  behavior

Should attach to the process.



Discussion:

Resolving patch:
diff --git a/src/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/dbghelp.py b/src/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/dbghelp.py
--- a/src/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/dbghelp.py
+++ b/src/ptvsd/_vendored/pydevd/pydevd_attach_to_process/winappdbg/win32/dbghelp.py
@@ -47,29 +47,34 @@
 def _load_latest_dbghelp_dll():
 
     from os import getenv
-    from os.path import join
-
+    from os.path import join, exists
+
+    program_files_location = getenv("ProgramFiles")
+    if not program_files_location:
+        program_files_location = "C:\Program Files"
+        
+    program_files_x86_location = getenv("ProgramFiles(x86)")
+        
     if arch == ARCH_AMD64:
         if wow64:
             pathname = join(
-                            getenv("ProgramFiles(x86)",
-                                getenv("ProgramFiles")),
+                            program_files_x86_location or program_files_location,
                             "Debugging Tools for Windows (x86)",
                             "dbghelp.dll")
         else:
             pathname = join(
-                            getenv("ProgramFiles"),
+                            program_files_location,
                             "Debugging Tools for Windows (x64)",
                             "dbghelp.dll")
     elif arch == ARCH_I386:
         pathname = join(
-                        getenv("ProgramFiles"),
+                        program_files_location,
                         "Debugging Tools for Windows (x86)",
                         "dbghelp.dll")
     else:
         pathname = None
 
-    if pathname:
+    if pathname and exists(pathname):
         try:
             _dbghelp = ctypes.windll.LoadLibrary(pathname)
             ctypes.windll.dbghelp = _dbghelp


Test patch: