Repository: microsoft/ptvsd

Issue:
Debugging with new_ptvsd is crashing because of TypeError: Struct()
<!-- Please search existing issues to avoid creating duplicates. -->

## Environment data

- VS Code version: 1.40.1
- Extension version (available under the Extensions sidebar): 2019.11.49689
- OS and version: RH7.6
- Python version (& distribution if applicable, e.g. Anaconda): 2.7.5

## Expected behaviour

Debugger works fine

## Actual behaviour

It crashes..
stack:
```
[root@rh01 ~]# /usr/bin/python /root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher /root/helloworld/helloworld.py 
E+00000.020: /handling microsoft/vscode-python#1 request "launch" from Adapter-1/
             Handler 'launch_request' (file u'/root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher/../../ptvsd/launcher/adapter.py', line 35)
             couldn't handle microsoft/vscode-python#1 request "launch" from Adapter-1:
             
             Traceback (most recent call last):
               File "/root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher/../../ptvsd/common/messaging.py", line 763, in _handle
                 result = handler(self)
               File "/root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher/../../ptvsd/launcher/adapter.py", line 147, in launch_request
                 debuggee.spawn(process_name, cmdline, cwd, env, redirect_output)
               File "/root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher/../../ptvsd/launcher/debuggee.py", line 76, in spawn
                 "pointerSize": struct.calcsize("P") * 8,
             TypeError: Struct() argument 1 must be string, not unicode
             
             Stack where logged:
               File "/usr/lib64/python2.7/threading.py", line 785, in __bootstrap
                 self.__bootstrap_inner()
               File "/usr/lib64/python2.7/threading.py", line 812, in __bootstrap_inner
                 self.run()
               File "/usr/lib64/python2.7/threading.py", line 765, in run
                 self.__target(*self.__args, **self.__kwargs)
               File "/root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher/../../ptvsd/common/messaging.py", line 1520, in _run_handlers
                 handler()
               File "/root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher/../../ptvsd/common/messaging.py", line 809, in _handle
                 self.describe(),
```

## Steps to reproduce:

1. Just F5 to debug.
2. Getting this error
3. also getting an error to check launch,json - Launcher[1] disconnected unexpectedly
4. launcher is somehow still listening in the background

ps x | grep ptvsd
```
 9815 pts/3    S      0:00 /usr/bin/python /root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd --client --host 127.0.0.1 --port 41995 /root/helloworld/helloworld.py
 9869 pts/3    S      0:00 /usr/bin/python /root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd --client --host 127.0.0.1 --port 39855 /root/helloworld/helloworld.py

```
5. **it is verified to be working with the previous release of python extension** which does not make use of ptvsd_new


launch.json contents:
```
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}
```


Discussion:
This is a limitation of an older Python version - for Python 2, `struct` [added](http://python-future.org/stdlib_incompatibilities.html#struct-pack) support for Unicode strings to define the format in Python 2.7.7, to be consistent with Python 3. 

Is it possible for you to upgrade your Python version? The most recent release for Python 2.x is 2.7.17.
I think not, unfortunately not all of the enterprise distributions provides newer versions of python (officially).
since vscode-python extension contains the old ptvsd in the newer versions of the extension, it would be ideal if we can choose to use it through a setting configuration.

Thanks!
@duduz if you just change locally to use bytes in calcsize, do you have any other issues?

i.e.: use `struct.calcsize(b"P")` in `/root/.vscode-server/extensions/ms-python.python-2019.11.49689/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/launcher/../../ptvsd/launcher/debuggee.py", line 76, in spawn`
@fabioz I don't mind doing so. i think we're good. thank you.
i'll give it a try and close the issue later on.
@fabioz it worked, thank you.
any advantage to use `struct.calcsize("P")` instead of `struct.calcsize(b"P")` to support older versions of python?
@duduz The problem is that `b"P"` won't work on Python 3. We have a helper function that'll do the right thing on either version, in `ptvsd.common.compat`.

@int19h i understand, i've seen `ptvsd.common.compat` and it doesn't seems to cover this use case, it seems hardcoded in `ptvsd/launcher/debuggee.py`.
There's a function there, `force_str`, that will produce the right type of object depending on the Python version. 
@int19h the function is there, but still it won't be working with python 2.7.5 without editing `debuggee.py`
editing the file fixed it for me, if there's no point of creating fix for it, i don't mind closing the issue.

Resolving patch:
diff --git a/src/ptvsd/launcher/debuggee.py b/src/ptvsd/launcher/debuggee.py
--- a/src/ptvsd/launcher/debuggee.py
+++ b/src/ptvsd/launcher/debuggee.py
@@ -12,7 +12,7 @@
 import sys
 import threading
 
-from ptvsd.common import fmt, log, messaging
+from ptvsd.common import fmt, log, messaging, compat
 
 
 process = None
@@ -72,7 +72,7 @@ def spawn(process_name, cmdline, cwd, env, redirect_output):
                 "isLocalProcess": True,
                 "systemProcessId": process.pid,
                 "name": process_name,
-                "pointerSize": struct.calcsize("P") * 8,
+                "pointerSize": struct.calcsize(compat.force_str("P")) * 8,
             },
         )
 


Test patch: