Repository: microsoft/ptvsd

Issue:
CMD_SET_NEXT_STATEMENT followed by CMD_STEP_OVER_MY_CODE crashes debuggee
This surfaced while working with #18. The working theory is that this has something to do with single-thread notifications - I notice that for `CMD_SET_NEXT_STATEMENT`, thread suspend/resume only uses `CMD_THREAD_RUN` and `CMD_THREAD_SUSPEND`, not the newer `..._SINGLE_NOTIFICATION` stuff.

Log of manual repro using VS with `PTVSD_DEBUG=True` to capture pydevd protocol messages.

```
<- 503 (CMD_SET_PROTOCOL)       [1000000000]: |json|
<- 501 (CMD_VERSION)            [1000000001]: |1.1      WINDOWS ID|
-> 503 (CMD_SET_PROTOCOL)       [1000000000]: |\n|
-> 501 (CMD_VERSION)            [1000000001]: |@@BUILD_NUMBER@@\n|
<- -1 (???)                     [1000000002]: |{'command': 'launch', 'arguments': {'noDebug': False, 'exe': 'C:\\Python\\3.6-32\\python.exe', 'cwd': 'C:\\Users\\int19\\source\\repos\\PythonApplication9\\', 'remoteMachine': '', 'args': 'C:\\Users\\int19\\source\\repos\\PythonApplication9\\PythonApplication9.py', 'options': 'WAIT_ON_ABNORMAL_EXIT=True;WAIT_ON_NORMAL_EXIT=True;REDIRECT_OUTPUT=True;SHOW_RETURN_VALUE=True;VERSION=3.6;INTERPRETER_OPTIONS=', 'env': [{'name': 'PROCESSOR_ARCHITEW6432', 'value': 'AMD64'}, {'name': 'DriverData', 'value': 'C:\\Windows\\System32\\Drivers\\DriverData'}, {'name': 'COMPUTERNAME', 'value': 'ANGBAND'}, {'name': 'CommonProgramFiles(x86)', 'value': 'C:\\Program Files (x86)\\Common Files'}, {'name': 'OneDrive', 'value': 'C:\\Users\\int19\\OneDrive'}, {'name': 'HOMEPATH', 'value': '\\Users\\int19'}, {'name': 'VisualStudioEdition', 'value': 'Microsoft Visual Studio Enterprise 2019'}, {'name': '_PTVS_PID', 'value': '7688'}, {'name': 'PROCESSOR_REVISION', 'value': '0802'}, {'name': 'VS100COMNTOOLS', 'value': 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\Tools\\'}, {'name': 'PATHEXT', 'value': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW'}, {'name': 'PkgDefApplicationConfigFile', 'value': 'C:\\Users\\int19\\AppData\\Local\\Microsoft\\VisualStudio\\16.0_085c89ff\\devenv.exe.config'}, {'name': 'TMP', 'value': 'C:\\Users\\int19\\AppData\\Local\\Temp'}, {'name': 'TEMP', 'value': 'C:\\Users\\int19\\AppData\\Local\\Temp'}, {'name': 'LOCALAPPDATA', 'value': 'C:\\Users\\int19\\AppData\\Local'}, {'name': 'PUBLIC', 'value': 'C:\\Users\\Public'}, {'name': 'PROCESSOR_IDENTIFIER', 'value': 'AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD'}, {'name': 'GOPATH', 'value': 'C:\\Users\\int19\\go'}, {'name': 'USERDOMAIN', 'value': 'ANGBAND'}, {'name': 'ProgramFiles(x86)', 'value': 'C:\\Program Files (x86)'}, {'name': 'CORMANLISP_HOME', 'value': 'C:\\Program Files (x86)\\Corman Lisp\\'}, {'name': 'Path', 'value': 'C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Python\\3.7-64\\Scripts\\;C:\\Python\\3.7-64\\;C:\\Python\\3.7-32\\Scripts\\;C:\\Python\\3.7-32\\;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Program Files\\ImageMagick-7.0.7-Q16;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Python\\3.6-32\\Scripts\\;C:\\Python\\3.6-32\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Geth;C:\\Program Files\\nodejs\\;C:\\Program Files (x86)\\Yarn\\bin\\;C:\\Program Files\\Git\\cmd;C:\\Program Files (x86)\\BaseX\\bin;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\Steel Bank Common Lisp\\1.4.2\\;C:\\Program Files (x86)\\Calibre2\\;C:\\Go\\bin;C:\\FPC\\3.0.4\\bin\\i386-Win32;C:\\Program Files (x86)\\Corman Lisp\\;C:\\TDM-GCC-64\\bin;C:\\Program Files\\CMake\\bin;C:\\Users\\int19\\.cargo\\bin;C:\\Users\\int19\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\int19\\AppData\\Local\\GitHubDesktop\\bin;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Users\\int19\\AppData\\Roaming\\npm;C:\\Users\\int19\\AppData\\Local\\Yarn\\bin;c:\\Program Files\\Saxonica\\SaxonHE9.8N\\bin;C:\\Users\\int19\\.dotnet\\tools;C:\\Users\\int19\\go\\bin;C:\\Users\\int19\\AppData\\Local\\Microsoft\\WindowsApps;'}, {'name': 'PROCESSOR_LEVEL', 'value': '23'}, {'name': 'SBCL_HOME', 'value': 'C:\\Program Files\\Steel Bank Common Lisp\\1.4.2\\'}, {'name': 'VisualStudioVersion', 'value': '16.0'}, {'name': 'PSModulePath', 'value': 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\Modules'}, {'name': 'NUMBER_OF_PROCESSORS', 'value': '16'}, {'name': 'FPS_BROWSER_USER_PROFILE_STRING', 'value': 'Default'}, {'name': 'CommonProgramFiles', 'value': 'C:\\Program Files (x86)\\Common Files'}, {'name': 'VisualStudioDir', 'value': 'C:\\Users\\int19\\OneDrive\\Documents\\Visual Studio 2019'}, {'name': 'ProgramData', 'value': 'C:\\ProgramData'}, {'name': 'ProgramW6432', 'value': 'C:\\Program Files'}, {'name': 'ProgramFiles', 'value': 'C:\\Program Files (x86)'}, {'name': 'VSSKUEDITION', 'value': 'Enterprise'}, {'name': 'SystemRoot', 'value': 'C:\\WINDOWS'}, {'name': 'VSAPPIDDIR', 'value': 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview\\Common7\\IDE\\'}, {'name': 'SESSIONNAME', 'value': 'Console'}, {'name': 'GOROOT', 'value': 'C:\\Go\\'}, {'name': 'CommonProgramW6432', 'value': 'C:\\Program Files\\Common Files'}, {'name': 'LOGONSERVER', 'value': '\\\\ANGBAND'}, {'name': 'VSAPPIDNAME', 'value': 'devenv.exe'}, {'name': 'USERPROFILE', 'value': 'C:\\Users\\int19'}, {'name': 'MSBuildLoadMicrosoftTargetsReadOnly', 'value': 'true'}, {'name': 'VS140COMNTOOLS', 'value': 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\Tools\\'}, {'name': 'VSLANG', 'value': '1033'}, {'name': 'USERDOMAIN_ROAMINGPROFILE', 'value': 'ANGBAND'}, {'name': 'APPDATA', 'value': 'C:\\Users\\int19\\AppData\\Roaming'}, {'name': 'HOMEDRIVE', 'value': 'C:'}, {'name': 'OneDriveConsumer', 'value': 'C:\\Users\\int19\\OneDrive'}, {'name': 'USERNAME', 'value': 'int19'}, {'name': 'PYTHONPATH', 'value': 'C:\\Users\\int19\\source\\repos\\PythonApplication9\\;C:\\git\\ptvsd\\src'}, {'name': 'FPS_BROWSER_APP_PROFILE_STRING', 'value': 'Internet Explorer'}, {'name': 'PROCESSOR_ARCHITECTURE', 'value': 'x86'}, {'name': 'OS', 'value': 'Windows_NT'}, {'name': 'ComSpec', 'value': 'C:\\WINDOWS\\system32\\cmd.exe'}, {'name': 'SystemDrive', 'value': 'C:'}, {'name': 'windir', 'value': 'C:\\WINDOWS'}, {'name': 'ETHEREUM_SOCKET', 'value': '\\\\.\\pipe\\geth.ipc'}, {'name': 'ALLUSERSPROFILE', 'value': 'C:\\ProgramData'}, {'name': 'PYDEV_DEBUG', 'value': 'False'}, {'name': 'PTVSD_DEBUG', 'value': 'True'}]}, 'type': 'request', 'seq': 1000000002}|
<- 122 (CMD_ADD_EXCEPTION_BREAK) [1000000003]: |python-BaseException    0       1       1|
-> 502 (CMD_RETURN)             [1000000002]: |{'type': 'response', 'request_seq': 1000000002, 'success': True, 'command': 'launch', 'seq': 2, 'pydevd_cmd_id': 502}|
<- 122 (CMD_ADD_EXCEPTION_BREAK) [1000000004]: |python-GeneratorExit    0       1       1|
<- 122 (CMD_ADD_EXCEPTION_BREAK) [1000000005]: |python-IndexError       0       1       1|
<- 111 (CMD_SET_BREAK)          [1000000006]: |{'command': 'setBreakpoints', 'arguments': {'source': {'path': 'c:\\Users\\int19\\source\\repos\\PythonApplication9\\PythonApplication9.py', 'sources': [], 'checksums': []}, 'breakpoints': [{'line': 2, 'column': 1}], 'lines': [2]}, 'type': 'request', 'seq': 1000000006}|
<- 122 (CMD_ADD_EXCEPTION_BREAK) [1000000007]: |python-StopIteration    0       1       1|
<- 111 (CMD_SET_BREAK)          [1000000008]: |{'command': 'setBreakpoints', 'arguments': {'source': {'path': 'c:\\Users\\int19\\source\\repos\\PythonApplication9\\PythonApplication9.py', 'sources': [], 'checksums': []}, 'breakpoints': [{'line': 2, 'column': 1}], 'lines': [2]}, 'type': 'request', 'seq': 1000000008}|
<- 122 (CMD_ADD_EXCEPTION_BREAK) [1000000009]: |python-AttributeError   0       1       1|
-> 502 (CMD_RETURN)             [1000000006]: |{'type': 'response', 'request_seq': 1000000006, 'success': True, 'command': 'setBreakpoints', 'body': {'breakpoints': [{'id': 0, 'verified': True, 'line': 2}]}, 'seq': 4, 'pydevd_cmd_id': 502}|
<- 122 (CMD_ADD_EXCEPTION_BREAK) [1000000010]: |python-KeyError 0       1       1|
-> 502 (CMD_RETURN)             [1000000008]: |{'type': 'response', 'request_seq': 1000000008, 'success': True, 'command': 'setBreakpoints', 'body': {'breakpoints': [{'id': 1, 'verified': True, 'line': 2}]}, 'seq': 6, 'pydevd_cmd_id': 502}|
<- 200 (CMD_REDIRECT_OUTPUT)    [1000000011]: |STDOUT   STDERR|
<- 146 (CMD_SHOW_RETURN_VALUES) [1000000012]: |1        1|
<- 156 (CMD_PYDEVD_JSON_CONFIG) [1000000013]: |{"skip_suspend_on_breakpoint_exception": ["BaseException"], "skip_print_breakpoint_exception": ["NameError"], "multi_threads_single_notification": true}|
<- 501 (CMD_VERSION)            [1000000014]: |1.1      WINDOWS ID|
-> 501 (CMD_VERSION)            [1000000014]: |@@BUILD_NUMBER@@\n|
<- 101 (CMD_RUN)                [1000000015]: ||
ready to debug
-> 103 (CMD_THREAD_CREATE)      [         8]: |{'type': 'event', 'event': 'thread', 'body': {'reason': 'started', 'threadId': 'pid_22904_id_13979856'}, 'seq': 8, 'pydevd_cmd_id': 103}|
3
-> 105 (CMD_THREAD_SUSPEND)     [        14]: |<xml><thread id="pid_22904_id_13979856" stop_reason="111" message="" suspend_type="trace"><frame id="66129184" name="func" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="2"></frame><frame id="66396208" name="&lt;module&gt;" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="5"></frame><frame id="56176048" name="_run" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="141"></frame><frame id="52097488" name="run_file" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="80"></frame><frame id="59335552" name="debug" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5Cdebugger.py" line="37"></frame><frame id="11978512" name="&lt;module&gt;" file="C%3A%5CProgram Files %28x86%29%5CMicrosoft Visual Studio%5C2019%5CPreview%5CCommon7%5CIDE%5CExtensions%5CMicrosoft%5CPython%5CCore%5Cptvsd_launcher.py" line="119"></frame></thread></xml>\n|
-> 157 (CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION) [        16]: |{"thread_id": "pid_22904_id_13979856", "stop_reason": 111}\n|
<- 102 (CMD_LIST_THREADS)       [1000000016]: ||
-> 502 (CMD_RETURN)             [1000000016]: |{'type': 'response', 'request_seq': 1000000016, 'success': True, 'command': 'threads', 'body': {'threads': [{'id': 'pid_22904_id_13979856', 'name': 'MainThread'}]}, 'seq': 18, 'pydevd_cmd_id': 502}|
<- 152 (CMD_GET_THREAD_STACK)   [1000000017]: |pid_22904_id_13979856|
-> 152 (CMD_GET_THREAD_STACK)   [1000000017]: |<xml><thread id="pid_22904_id_13979856"><frame id="66129184" name="func" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="2"></frame><frame id="66396208" name="&lt;module&gt;" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="5"></frame><frame id="56176048" name="_run" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="141"></frame><frame id="52097488" name="run_file" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="80"></frame><frame id="59335552" name="debug" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5Cdebugger.py" line="37"></frame><frame id="11978512" name="&lt;module&gt;" file="C%3A%5CProgram Files %28x86%29%5CMicrosoft Visual Studio%5C2019%5CPreview%5CCommon7%5CIDE%5CExtensions%5CMicrosoft%5CPython%5CCore%5Cptvsd_launcher.py" line="119"></frame></thread></xml>\n|
<- 152 (CMD_GET_THREAD_STACK)   [1000000018]: |pid_22904_id_13979856|
-> 152 (CMD_GET_THREAD_STACK)   [1000000018]: |<xml><thread id="pid_22904_id_13979856"><frame id="66129184" name="func" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="2"></frame><frame id="66396208" name="&lt;module&gt;" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="5"></frame><frame id="56176048" name="_run" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="141"></frame><frame id="52097488" name="run_file" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="80"></frame><frame id="59335552" name="debug" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5Cdebugger.py" line="37"></frame><frame id="11978512" name="&lt;module&gt;" file="C%3A%5CProgram Files %28x86%29%5CMicrosoft Visual Studio%5C2019%5CPreview%5CCommon7%5CIDE%5CExtensions%5CMicrosoft%5CPython%5CCore%5Cptvsd_launcher.py" line="119"></frame></thread></xml>\n|
<- 127 (CMD_SET_NEXT_STATEMENT) [1000000019]: |pid_22904_id_13979856    3       *|
-> 127 (CMD_SET_NEXT_STATEMENT) [        20]: |True     \n|
-> 106 (CMD_THREAD_RUN)         [        22]: |pid_22904_id_13979856    127\n|
-> 105 (CMD_THREAD_SUSPEND)     [        24]: |<xml><thread id="pid_22904_id_13979856" stop_reason="127" message="" suspend_type="trace"><frame id="66129184" name="func" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="3"></frame><frame id="66396208" name="&lt;module&gt;" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="5"></frame><frame id="56176048" name="_run" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="141"></frame><frame id="52097488" name="run_file" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="80"></frame><frame id="59335552" name="debug" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5Cdebugger.py" line="37"></frame><frame id="11978512" name="&lt;module&gt;" file="C%3A%5CProgram Files %28x86%29%5CMicrosoft Visual Studio%5C2019%5CPreview%5CCommon7%5CIDE%5CExtensions%5CMicrosoft%5CPython%5CCore%5Cptvsd_launcher.py" line="119"></frame></thread></xml>\n|
<- 102 (CMD_LIST_THREADS)       [1000000020]: ||
-> 502 (CMD_RETURN)             [1000000020]: |{'type': 'response', 'request_seq': 1000000020, 'success': True, 'command': 'threads', 'body': {'threads': [{'id': 'pid_22904_id_13979856', 'name': 'MainThread'}]}, 'seq': 26, 'pydevd_cmd_id': 502}|
<- 152 (CMD_GET_THREAD_STACK)   [1000000021]: |pid_22904_id_13979856|
-> 152 (CMD_GET_THREAD_STACK)   [1000000021]: |<xml><thread id="pid_22904_id_13979856"><frame id="66129184" name="func" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="3"></frame><frame id="66396208" name="&lt;module&gt;" file="C%3A%5CUsers%5Cint19%5Csource%5Crepos%5CPythonApplication9%5CPythonApplication9.py" line="5"></frame><frame id="56176048" name="_run" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="141"></frame><frame id="52097488" name="run_file" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5C_local.py" line="80"></frame><frame id="59335552" name="debug" file="C%3A%5Cgit%5Cptvsd%5Csrc%5Cptvsd%5Cdebugger.py" line="37"></frame><frame id="11978512" name="&lt;module&gt;" file="C%3A%5CProgram Files %28x86%29%5CMicrosoft Visual Studio%5C2019%5CPreview%5CCommon7%5CIDE%5CExtensions%5CMicrosoft%5CPython%5CCore%5Cptvsd_launcher.py" line="119"></frame></thread></xml>\n|
<- 159 (CMD_STEP_OVER_MY_CODE)  [1000000022]: |pid_22904_id_13979856|
-> 106 (CMD_THREAD_RUN)         [        28]: |pid_22904_id_13979856    159\n|
-> 158 (CMD_THREAD_RESUME_SINGLE_NOTIFICATION) [        30]: |{"thread_id": "pid_22904_id_13979856"}\n|
Traceback (most recent call last):
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 587, in trace_dispatch
    self.do_wait_suspend(thread, frame, event, arg)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 78, in do_wait_suspend
    self._args[0].do_wait_suspend(*args, **kwargs)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 1259, in do_wait_suspend
    self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)
  File "C:\Python\3.6-32\lib\contextlib.py", line 88, in __exit__
    next(self.gen)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 328, in notify_thread_suspended
    yield
  File "C:\Python\3.6-32\lib\contextlib.py", line 88, in __exit__
    next(self.gen)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 294, in notify_thread_suspended
    self._suspended_thread_ids.remove(thread_id)
KeyError: 'pid_22904_id_13979856'
Traceback (most recent call last):
  File "c:\program files (x86)\microsoft visual studio\2019\preview\common7\ide\extensions\microsoft\python\core\ptvsd_launcher.py", line 119, in <module>
    vspd.debug(filename, port_num, debug_id, debug_options, run_as)
  File "C:\git\ptvsd\src\ptvsd\debugger.py", line 37, in debug
    run(address, filename, *args, **kwargs)
  File "C:\git\ptvsd\src\ptvsd\_local.py", line 80, in run_file
    run(argv, addr, **kwargs)
  File "C:\git\ptvsd\src\ptvsd\_local.py", line 141, in _run
    _pydevd.main()
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 2218, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 1560, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 1567, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\_pydev_imps\_pydev_execfile.py", line 25, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:\Users\int19\source\repos\PythonApplication9\PythonApplication9.py", line 5, in <module>
    func()
  File "C:\Users\int19\source\repos\PythonApplication9\PythonApplication9.py", line 3, in func
    print(2)    #@inner2
  File "C:\Users\int19\source\repos\PythonApplication9\PythonApplication9.py", line 3, in func
    print(2)    #@inner2
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 587, in trace_dispatch
    self.do_wait_suspend(thread, frame, event, arg)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\_pydevd_bundle\pydevd_frame.py", line 78, in do_wait_suspend
    self._args[0].do_wait_suspend(*args, **kwargs)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 1259, in do_wait_suspend
    self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)
  File "C:\Python\3.6-32\lib\contextlib.py", line 88, in __exit__
    next(self.gen)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 328, in notify_thread_suspended
    yield
  File "C:\Python\3.6-32\lib\contextlib.py", line 88, in __exit__
    next(self.gen)
  File "C:\git\ptvsd\src\ptvsd\_vendored\pydevd\pydevd.py", line 294, in notify_thread_suspended
    self._suspended_thread_ids.remove(thread_id)
KeyError: 'pid_22904_id_13979856'
handling atexit
Press any key to continue . . . proc stopping
closing daemon after single session
```


Discussion:
As a note, I just noted that there's no UI for this in VSCode (depends on: https://github.com/Microsoft/vscode/issues/25653) -- probably useful for Visual Studio thought.
@fabioz, yes this is VS Specific.

Resolving patch:
diff --git a/src/ptvsd/_vendored/pydevd/pydevd.py b/src/ptvsd/_vendored/pydevd/pydevd.py
--- a/src/ptvsd/_vendored/pydevd/pydevd.py
+++ b/src/ptvsd/_vendored/pydevd/pydevd.py
@@ -1265,10 +1265,16 @@ def do_wait_suspend(self, thread, frame, event, arg, is_unhandled_exception=Fals
                     from_this_thread.append(frame_custom_thread_id)
 
             with self._threads_suspended_single_notification.notify_thread_suspended(thread_id, stop_reason):
-                self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)
+                keep_suspended = self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)
+
+        if keep_suspended:
+            # This means that we should pause again after a set next statement.
+            self._threads_suspended_single_notification.increment_suspend_time()
+            self.do_wait_suspend(thread, frame, event, arg, is_unhandled_exception)
 
     def _do_wait_suspend(self, thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker):
         info = thread.additional_info
+        keep_suspended = False
 
         if info.pydev_state == STATE_SUSPEND and not self._finish_debugging_session:
             in_main_thread = is_current_thread_main_thread()
@@ -1324,8 +1330,8 @@ def _do_wait_suspend(self, thread, frame, event, arg, suspend_type, from_this_th
                 self.writer.add_command(cmd)
                 info.pydev_state = STATE_SUSPEND
                 thread.stop_reason = CMD_SET_NEXT_STATEMENT
-                self.do_wait_suspend(thread, frame, event, arg)
-                return
+                keep_suspended = True
+
             else:
                 # Set next did not work...
                 info.pydev_step_cmd = -1
@@ -1333,8 +1339,7 @@ def _do_wait_suspend(self, thread, frame, event, arg, suspend_type, from_this_th
                 thread.stop_reason = CMD_THREAD_SUSPEND
                 # return to the suspend state and wait for other command (without sending any
                 # additional notification to the client).
-                self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)
-                return
+                return self._do_wait_suspend(thread, frame, event, arg, suspend_type, from_this_thread, frames_tracker)
 
         elif info.pydev_step_cmd in (CMD_STEP_RETURN, CMD_STEP_RETURN_MY_CODE):
             back_frame = frame.f_back
@@ -1370,6 +1375,8 @@ def _do_wait_suspend(self, thread, frame, event, arg, suspend_type, from_this_th
                 # print('Removing created frame: %s' % (frame_id,))
                 self.writer.add_command(self.cmd_factory.make_thread_killed_message(frame_id))
 
+        return keep_suspended
+
     def do_stop_on_unhandled_exception(self, thread, frame, frames_byid, arg):
         pydev_log.debug("We are stopping in post-mortem\n")
         try:
diff --git a/src/ptvsd/wrapper.py b/src/ptvsd/wrapper.py
--- a/src/ptvsd/wrapper.py
+++ b/src/ptvsd/wrapper.py
@@ -1000,7 +1000,7 @@ def _stop_event_loop(self):
     supportsSetVariable=True,
     supportsValueFormattingOptions=True,
     supportTerminateDebuggee=True,
-    supportsGotoTargetsRequest=False,  # https://github.com/Microsoft/ptvsd/issues/1163
+    supportsGotoTargetsRequest=True,
     exceptionBreakpointFilters=[
         {
             'filter': 'raised',
@@ -1244,6 +1244,10 @@ def __init__(
         self.internals_filter = InternalsFilter()
         self.new_thread_lock = threading.Lock()
 
+        # goto
+        self.goto_target_map = IDMap()
+        self.current_goto_request = None
+
         # adapter state
         self._detached = False
         self._path_mappings_received = False
@@ -2080,30 +2084,11 @@ def on_pydevd_thread_kill(self, seq, args):
     @pydevd_events.handler(pydevd_comm.CMD_THREAD_SUSPEND)
     @async_handler
     def on_pydevd_thread_suspend(self, seq, args):
-        xml = self.parse_xml_response(args)
-        reason = int(xml.thread['stop_reason'])
-
-        # Normally, we rely on CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION instead,
-        # but we only get this one in response to CMD_SET_NEXT_STATEMENT.
-        if reason == pydevd_comm.CMD_SET_NEXT_STATEMENT:
-            pyd_tid = xml.thread['id']
-            vsc_tid = self.thread_map.to_vscode(pyd_tid, autogen=False)
-            self.send_event(
-                'stopped',
-                reason='pause',
-                threadId=vsc_tid,
-                allThreadsStopped=True)
+        pass  # We only care about the thread suspend single notification.
 
     @pydevd_events.handler(pydevd_comm.CMD_THREAD_RUN)
     def on_pydevd_thread_run(self, seq, args):
-        pyd_tid, reason = args.split('\t', 2)
-        reason = int(reason)
-        vsc_tid = self.thread_map.to_vscode(pyd_tid, autogen=False)
-
-        # Normally, we rely on CMD_THREAD_RESUME_SINGLE_NOTIFICATION instead,
-        # but we only get this one in response to CMD_SET_NEXT_STATEMENT.
-        if reason == pydevd_comm.CMD_SET_NEXT_STATEMENT:
-            self.send_event('continued', threadId=vsc_tid)
+        pass  # We only care about the thread suspend single notification.
 
     @pydevd_events.handler(pydevd_comm_constants.CMD_THREAD_SUSPEND_SINGLE_NOTIFICATION)
     @async_handler


Test patch:
diff --git a/src/ptvsd/_vendored/pydevd/tests_python/test_debugger_json.py b/src/ptvsd/_vendored/pydevd/tests_python/test_debugger_json.py
--- a/src/ptvsd/_vendored/pydevd/tests_python/test_debugger_json.py
+++ b/src/ptvsd/_vendored/pydevd/tests_python/test_debugger_json.py
@@ -820,6 +820,7 @@ def test_hex_variables(case_setup):
         writer.finished_ok = True
 
 
+@pytest.mark.skipif(IS_JYTHON, reason='Flaky on Jython.')
 def test_pause_and_continue(case_setup):
     with case_setup.test_file('_debugger_case_pause_continue.py') as writer:
         json_facade = JsonFacade(writer)
@@ -852,14 +853,13 @@ def test_pause_and_continue(case_setup):
         scope = pydevd_schema.Scope(**next(iter(scopes_response.body.scopes)))
         frame_variables_reference = scope.variablesReference
 
-        if not IS_JYTHON:
-            set_variable_request = json_facade.write_request(
-                pydevd_schema.SetVariableRequest(pydevd_schema.SetVariableArguments(
-                    frame_variables_reference, 'loop', 'False'
-            )))
-            set_variable_response = json_facade.wait_for_response(set_variable_request)
-            set_variable_response_as_dict = set_variable_response.to_dict()['body']
-            assert set_variable_response_as_dict == {'value': "False", 'type': 'bool'}
+        set_variable_request = json_facade.write_request(
+            pydevd_schema.SetVariableRequest(pydevd_schema.SetVariableArguments(
+                frame_variables_reference, 'loop', 'False'
+        )))
+        set_variable_response = json_facade.wait_for_response(set_variable_request)
+        set_variable_response_as_dict = set_variable_response.to_dict()['body']
+        assert set_variable_response_as_dict == {'value': "False", 'type': 'bool'}
 
         continue_request = json_facade.write_request(
         pydevd_schema.ContinueRequest(pydevd_schema.ContinueArguments('*')))
diff --git a/tests/func/test_step.py b/tests/func/test_step.py
--- a/tests/func/test_step.py
+++ b/tests/func/test_step.py
@@ -12,17 +12,18 @@
 from tests.helpers.pattern import ANY
 
 
-@pytest.mark.skip(reason='https://github.com/Microsoft/ptvsd/issues/1163')
 def test_set_next_statement(pyfile, run_as, start_method):
+
     @pyfile
     def code_to_debug():
         from dbgimporter import import_and_enable_debugger
         import_and_enable_debugger()
 
         def func():
-            print(1)    #@inner1
-            print(2)    #@inner2
-        print(3)        #@outer3
+            print(1)  # @inner1
+            print(2)  # @inner2
+
+        print(3)  # @outer3
         func()
 
     line_numbers = get_marked_line_numbers(code_to_debug)
diff --git a/tests/helpers/__init__.py b/tests/helpers/__init__.py
--- a/tests/helpers/__init__.py
+++ b/tests/helpers/__init__.py
@@ -11,15 +11,14 @@
 import time
 import traceback
 
-
 if sys.version_info >= (3, 5):
     clock = time.monotonic
 else:
     clock = time.clock
 
-
 timestamp_zero = clock()
 
+
 def timestamp():
     return clock() - timestamp_zero
 
@@ -83,7 +82,7 @@ def get_marked_line_numbers(path):
     with open(path) as f:
         lines = {}
         for i, line in enumerate(f):
-            match = re.search(r'#@\s*(.*?)\s*$', line)
+            match = re.search(r'#\s*@\s*(.*?)\s*$', line)
             if match:
                 marker = match.group(1)
                 lines[marker] = i + 1