internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: microsoft/ptvsd

Issue:
Ignore unsupported values in debugOptions
Currently if unsupported values are sent in debugOptions, the debugger falls over (see https://github.com/Microsoft/ptvsd/pull/379).

Ideally the code should be defensive and ignore unsupported values, rather than just falling over.
This makes it easier for us to code it in VSC layer as well (rather than having to hard code values that are supported/not supported by PTVSD).


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1009,7 +1009,10 @@ def bool_parser(str):
                 key, value = opt.split('=')
             except ValueError:
                 continue
-            options[key] = DEBUG_OPTIONS_PARSER[key](value)
+            try:
+                options[key] = DEBUG_OPTIONS_PARSER[key](value)
+            except KeyError:
+                continue
 
         if 'WINDOWS_CLIENT' not in options:
             options['WINDOWS_CLIENT'] = platform.system() == 'Windows' # noqa


Test patch:
Repository: microsoft/ptvsd

Issue:
Execution when debugging is incorrect
From developer community
https://developercommunity.visualstudio.com/content/problem/254447/python-execute-problem.html?childToView=255082#comment-255082

```
import pymysql
db = pymysql.connect(host="localhost",user="root",password="",database="zhidao",charset='utf8')
cursor_select = db.cursor()
sql_select = "select question_id from zhidao"
size_select = cursor_select.execute(sql_select)
for i in range(size_select):
	data = cursor_select.fetchone()
	print(data[0])
db.close()
```

Table zhidao is a small one, which has about 1400 rows, it works fine if you execute the code directly, but if you set a breakpoint and execute "size_select = cursor_select.execute(sql_select)" using F10, data will become NoneType somehow, if you check this problem deeper, you can find execution using F10 will somehow change cursor_select.rownumber to nonzero, related code of pymysql is here: https://github.com/PyMySQL/PyMySQL/blob/master/pymysql/cursors.py
I hope this is helpful.
Version:
Win10 1803
VS Community 2017 - 15.7.1
Python - 15.7.18116.1
Python 3.6(64-bit) 



Discussion:

Resolving patch:
diff --git a/ptvsd/safe_repr.py b/ptvsd/safe_repr.py
--- a/ptvsd/safe_repr.py
+++ b/ptvsd/safe_repr.py
@@ -27,11 +27,15 @@ class SafeRepr(object):
         set_info = (set, '{', '}', False)
         frozenset_info = (frozenset, 'frozenset({', '})', False)
         int_types = (int,)
+        long_iter_types = (list, tuple, bytearray, range,
+                           dict, set, frozenset)
     else:
         string_types = (str, unicode)
         set_info = (set, 'set([', '])', False)
         frozenset_info = (frozenset, 'frozenset([', '])', False)
         int_types = (int, long)  # noqa
+        long_iter_types = (list, tuple, bytearray, xrange,
+                           dict, set, frozenset, buffer)  # noqa
 
     # Collection types are recursively iterated for each limit in
     # maxcollection.
@@ -125,6 +129,12 @@ def _is_long_iter(self, obj, level=0):
             if not hasattr(obj, '__iter__'):
                 return False
 
+            # If it's not an instance of these collection types then it
+            # is fine. Note: this is a fix for
+            # https://github.com/Microsoft/ptvsd/issues/406
+            if not isinstance(obj, self.long_iter_types):
+                return False
+
             # Iterable is its own iterator - this is a one-off iterable
             # like generator or enumerate(). We can't really count that,
             # but repr() for these should not include any elements anyway,


Test patch:
Repository: microsoft/ptvsd

Issue:
ptvsd opens file in another tab on breakpoint hit in attach
This occurs on windows. see `test.py` opened up in a separate window.
![image](https://user-images.githubusercontent.com/3840081/40737739-776a834c-63f6-11e8-8bc5-e7ac973fa6ba.png)

Repro code, this is the same code from our docs:
```
import random
import ptvsd

ptvsd.enable_attach()
print("test!!!!!!!!!!!!!!!!!!!! wait for attach")
ptvsd.wait_for_attach()
print('ptvsd version: %s' % ptvsd.__version__)
guesses_made = 0
name = input('Hello! What is your name?\n')
number = random.randint(1, 20)
print('Well, {0}, I am thinking of a number between 1 and 20.'.format(name))

while guesses_made < 6:
    guess = int(input('Take a guess: '))
    guesses_made += 1
    if guess < number:
        print('Your guess is too low.')
    if guess > number:
        print('Your guess is too high.')
    if guess == number:
        break
if guess == number:
    print('Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made))
else:
    print('Nope. The number I was thinking of was {0}'.format(number))
```

This used to work in 4.1.1a1.
@DonJayamanne , @ericsnowcurrently 


Discussion:
FWIW, I'm not able to reproduce this on linux (using VSC).
This occurs only on windows. I suspect it is the drive letter capitalization, that might be causing this.
I'll look into this.
Will submit PR, fix requires a change in both PTVSD as well as VSC Python Extension

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1211,7 +1211,11 @@ def get_source_reference(self, filename):
         except KeyError:
             # If attaching to a local process (then remote and local are same)
             for local_prefix, remote_prefix in pydevd_file_utils.PATHS_FROM_ECLIPSE_TO_PYTHON: # noqa
-                if local_prefix == remote_prefix and filename.startswith(local_prefix): # noqa
+                if local_prefix != remote_prefix:
+                    continue
+                if filename.startswith(local_prefix): # noqa
+                    return 0
+                if platform.system() == 'Windows' and filename.upper().startswith(local_prefix.upper()): # noqa
                     return 0
 
         server_filename = pydevd_file_utils.norm_file_to_server(filename)


Test patch:
Repository: microsoft/ptvsd

Issue:
PyPI package missing information
Looking at https://pypi.org/project/ptvsd/4.0.0a1/ we are currently missing:
* link to GitHub
* long description
* specific classifiers
* any mention of VS Code
* link to doc pages

Would be nice to get these added.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -39,6 +39,10 @@ def iter_vendored_files():
             yield filename
 
 
+with open('DESCRIPTION.md', 'r') as fh:
+    long_description = fh.read()
+
+
 if __name__ == '__main__':
     if not os.getenv('SKIP_CYTHON_BUILD'):
         cython_build()
@@ -47,17 +51,22 @@ def iter_vendored_files():
         name='ptvsd',
         version=versioneer.get_version(),
         description='Remote debugging server for Python support in Visual Studio and Visual Studio Code', # noqa
-        #long_description=open('DESCRIPTION.md').read(),
-        #long_description_content_type='text/markdown',
+        long_description=long_description,
+        long_description_content_type='text/markdown',
         license='MIT',
         author='Microsoft Corporation',
         author_email='ptvshelp@microsoft.com',
         url='https://aka.ms/ptvs',
+        python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*",
         classifiers=[
             'Development Status :: 3 - Alpha',
-            'Programming Language :: Python',
-            'Programming Language :: Python :: 2',
-            'Programming Language :: Python :: 3',
+            'Programming Language :: Python :: 2.7',
+            'Programming Language :: Python :: 3.5',
+            'Programming Language :: Python :: 3.6',
+            'Programming Language :: Python :: 3.7',
+            'Topic :: Software Development :: Debuggers',
+            'Operating System :: OS Independent',
+            'License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)',
             'License :: OSI Approved :: MIT License',
         ],
         packages=[


Test patch:
Repository: microsoft/ptvsd

Issue:
Debugger doesn't stop at breakpoint
VS, Python 2.7, Just My Code ON or OFF

```
res = raw_input('>')
res = 'hello'
print(res) # < breakpoint on this line
```

F5
Press enter when asked for input in console
Breakpoint on print is not hit



Discussion:
Not seeing a suspended event from `pydevd`. Seems to be specific after `raw_input`.

@fabioz cc
Note: can replicate this using vscode+pydevd (on linux) but not pydev+pydevd (on windows).

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -2121,6 +2121,15 @@ def on_setDebuggerProperty(self, request, args):
 
     # PyDevd protocol event handlers
 
+    @pydevd_events.handler(pydevd_comm.CMD_INPUT_REQUESTED)
+    def on_pydevd_input_requested(self, seq, args):
+        '''
+        no-op: if stdin is requested, right now the user is expected to enter
+        text in the terminal and the debug adapter doesn't really do anything
+        (although in the future it could see that stdin is being requested and
+        redirect any evaluation request to stdin).
+        '''
+
     @pydevd_events.handler(pydevd_comm.CMD_THREAD_CREATE)
     def on_pydevd_thread_create(self, seq, args):
         # If this is the first thread reported, report process creation


Test patch:
Repository: microsoft/ptvsd

Issue:
on_stackTrace() returns 0 frames when there is exactly 1.
In `on_pydevd_thread_suspend()` we store the current stack frames for later use in `on_stackTrace()`.  The actual object we store is the one we got by parsing the XML response.  It is an XML wrapper that *mostly* acts like a list.  However, if it is a single item then some list-like properties do not work right (in particular, `len(xframes)` returns 0).

The fact that `len(xframes)` (in `on_stackTrace()`) returns 0 is a problem.  Later in `on_stackTrace()` we track stack depth by that length.  So if there is only one frame (e.g. due to a breakpoint at the top-level of a script) then `on_stackTrace()` will response with 0 frames instead of 1.

FWIW, this may impact other code where we expect a list from XML results.

I'll have a PR up momentarily that fixes this.


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -2184,7 +2184,7 @@ def on_pydevd_thread_suspend(self, seq, args):
         vsc_tid = self.thread_map.to_vscode(pyd_tid, autogen=False)
 
         with self.stack_traces_lock:
-            self.stack_traces[pyd_tid] = xml.thread.frame
+            self.stack_traces[pyd_tid] = list(xml.thread.frame)
 
         description = None
         text = None


Test patch:
diff --git a/tests/highlevel/test_messages.py b/tests/highlevel/test_messages.py
--- a/tests/highlevel/test_messages.py
+++ b/tests/highlevel/test_messages.py
@@ -281,6 +281,36 @@ def test_basic(self):
         ])
         self.assert_received(self.debugger, [])
 
+    def test_one_frame(self):
+        with self.launched():
+            with self.hidden():
+                tid, thread = self.set_thread('x')
+                self.suspend(thread, CMD_THREAD_SUSPEND, *[
+                    # (pfid, func, file, line)
+                    (2, 'spam', 'abc.py', 10),
+                ])
+            self.send_request(
+                threadId=tid,
+            )
+            received = self.vsc.received
+
+        self.assert_vsc_received(received, [
+            self.expected_response(
+                stackFrames=[
+                    {
+                        'id': 1,
+                        'name': 'spam',
+                        'source': {'path': 'abc.py', 'sourceReference': 0},
+                        'line': 10,
+                        'column': 1,
+                    },
+                ],
+                totalFrames=1,
+            ),
+            # no events
+        ])
+        self.assert_received(self.debugger, [])
+
     def test_with_frame_format(self):
         with self.launched():
             with self.hidden():
Repository: microsoft/ptvsd

Issue:
Have repl handle multi-line console commands
Currently newlines characters within the `expression` payload in an `evaluate` DAP are not preserved when passed to the debuggee, probably because pydev's message format uses whitespace as delimiters. 

I want my debug adapter protocol client's debug console (repl) to mimic a notebook experience, where users might potentially write multi-line exploratory console commands. 


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1858,7 +1858,7 @@ def on_evaluate(self, request, args):
         """Handles DAP EvaluateRequest."""
 
         # pydevd message format doesn't permit tabs in expressions
-        expr = args['expression'].replace('\t', ' ')
+        expr = args['expression'].replace('\n', '@LINE@').replace('\t', ' ')
         fmt = args.get('format', {})
 
         vsc_fid = int(args['frameId'])


Test patch:
diff --git a/tests/highlevel/test_messages.py b/tests/highlevel/test_messages.py
--- a/tests/highlevel/test_messages.py
+++ b/tests/highlevel/test_messages.py
@@ -1,6 +1,7 @@
 import os
 import sys
 import unittest
+from textwrap import dedent
 
 from _pydevd_bundle.pydevd_comm import (
     CMD_ADD_EXCEPTION_BREAK,
@@ -728,6 +729,42 @@ def test_basic(self):
                 '{}\t5\tLOCAL\tspam + 1\t1'.format(thread.id)),
         ])
 
+    def test_multiline(self):
+        with self.launched():
+            with self.hidden():
+                _, thread = self.pause('x', *[
+                    # (pfid, func, file, line)
+                    (2, 'spam', 'abc.py', 10),  # VSC frame ID 1
+                    (5, 'eggs', 'xyz.py', 2),  # VSC frame ID 2
+                ])
+            expr = dedent("""
+            def my_sqr(x):
+                return x*x
+            my_sqr(7)""")
+            self.set_debugger_response(
+                (expr, 49),
+            )
+            self.send_request(
+                frameId=2,
+                expression=expr,
+                context=None,
+            )
+            received = self.vsc.received
+
+        self.assert_vsc_received(received, [
+            self.expected_response(
+                type='int',
+                result='49',
+            ),
+            # no events
+        ])
+
+        expr_rec = '@LINE@def my_sqr(x):@LINE@    return x*x@LINE@my_sqr(7)'
+        self.assert_received(self.debugger, [
+            self.expected_pydevd_request(
+                '{}\t5\tLOCAL\t{}\t1'.format(thread.id, expr_rec)),
+        ])
+
     def test_hover(self):
         with self.launched():
             with self.hidden():
Repository: microsoft/ptvsd

Issue:
Errors logged on VSTS 
```
2018-07-05T19:13:17.5780150Z .Traceback (most recent call last):
2018-07-05T19:13:17.5795340Z   File "/Users/vsts/agent/2.134.2/work/1/s/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command.py", line 749, in process_net_command
2018-07-05T19:13:17.5813150Z     py_db.enable_output_redirection('STDOUT' in text, 'STDERR' in text)
2018-07-05T19:13:17.5831030Z   File "/Users/vsts/agent/2.134.2/work/1/s/ptvsd/_vendored/pydevd/pydevd.py", line 361, in enable_output_redirection
2018-07-05T19:13:17.5847040Z     init_stdout_redirect()
2018-07-05T19:13:17.5862230Z   File "/Users/vsts/agent/2.134.2/work/1/s/ptvsd/_vendored/pydevd/pydevd.py", line 1199, in init_stdout_redirect
2018-07-05T19:13:17.5878570Z     sys.stdout = pydevd_io.IORedirector(original, sys._pydevd_out_buffer_, wrap_buffer) #@UndefinedVariable
2018-07-05T19:13:17.5895080Z   File "/Users/vsts/agent/2.134.2/work/1/s/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py", line 24, in __init__
2018-07-05T19:13:17.5913010Z     self.buffer = IORedirector(original.buffer, new_redirect.buffer, False)
2018-07-05T19:13:17.5939400Z AttributeError: '_DuplicateWriter' object has no attribute 'buffer'
```

The same errors are logged for Linux and Mac OS.
I'm using a Mac and cannot replicate this error.

/cc @fabioz 


Discussion:
Will take a look at this (seems to be a case where the user already had some other stub for `sys.stdout` and it didn't have a `buffer`).

Resolving patch:
diff --git a/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py b/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py
--- a/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py
+++ b/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_io.py
@@ -20,7 +20,7 @@ def __init__(self, original, new_redirect, wrap_buffer=False):
             tdout/stderr which has a buffer to write binary data).
         '''
         self._redirect_to = (original, new_redirect)
-        if wrap_buffer:
+        if wrap_buffer and hasattr(original, 'buffer'):
             self.buffer = IORedirector(original.buffer, new_redirect.buffer, False)
 
     def write(self, s):


Test patch:
diff --git a/ptvsd/_vendored/pydevd/tests_python/test_pydevd_io.py b/ptvsd/_vendored/pydevd/tests_python/test_pydevd_io.py
new file mode 100644
--- /dev/null
+++ b/ptvsd/_vendored/pydevd/tests_python/test_pydevd_io.py
@@ -0,0 +1,14 @@
+from _pydevd_bundle.pydevd_io import IORedirector
+
+
+def test_io_redirector():
+
+    class MyRedirection1(object):
+        pass
+
+    class MyRedirection2(object):
+        pass
+
+    # Check that we don't fail creating the IORedirector if the original
+    # doesn't have a 'buffer'.
+    IORedirector(MyRedirection1(), MyRedirection2(), wrap_buffer=True)
Repository: microsoft/ptvsd

Issue:
Program not continuing to run when disconnecting from remote session
## Environment data

- PTVSD version: Master
- OS and version: Mac
- Python version (& distribution if applicable, e.g. Anaconda): 3.6 Anaconda
- Using VS Code or Visual Studio: VSC

## Actual behavior

When disconnecting from a remote debug session the program does not continue to run.

## Expected  behavior

Should continue to run.

## Steps to reproduce:
1. Python code:
```python
import ptvsd
ptvsd.enable_attach(('0.0.0.0', 5678), False)
ptvsd.wait_for_attach()
import time
i = 0
while True:
    i += 1
    time.sleep(0.1)
    print(i)
```

* Add a breakpoint to a line in the `while` loop
* Connect
* Breakpoint will be hit
* Disconnect
* Program does not continue


This was deemed fixed https://github.com/Microsoft/ptvsd/issues/707
Hence classified as regression.

/cc @karthiknadig 


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1466,14 +1466,10 @@ def _reset_project_roots(self):
         # We leave the "project roots" alone (see CMD_SET_PROJECT_ROOTS).
         pass
 
-    def _clear_breakpoints(self, filename=None):
+    def _clear_breakpoints(self):
         cmd = pydevd_comm.CMD_REMOVE_BREAK
         for pyd_bpid, vsc_bpid in self.bp_map.pairs():
-            if filename is None:
-                filename = pyd_bpid[0]
-            elif pyd_bpid[0] != filename:
-                continue
-            msg = '{}\t{}\t{}'.format('python-line', filename, vsc_bpid)
+            msg = '{}\t{}\t{}'.format('python-line', pyd_bpid[0], vsc_bpid)
             self.pydevd_notify(cmd, msg)
             self.bp_map.remove(pyd_bpid, vsc_bpid)
         # TODO: Wait until the last request has been handled?


Test patch:
Repository: microsoft/ptvsd

Issue:
Handle detach does not clear template breakpoints
Currently `_handle_detach` only clears `python-line` breakpoints. It should clear `django-line` and `jinja-line` breakpoints. This was found by code inspection.


Discussion:

Resolving patch:
diff --git a/ptvsd/wrapper.py b/ptvsd/wrapper.py
--- a/ptvsd/wrapper.py
+++ b/ptvsd/wrapper.py
@@ -1471,7 +1471,8 @@ def _reset_project_roots(self):
     def _clear_breakpoints(self):
         cmd = pydevd_comm.CMD_REMOVE_BREAK
         for pyd_bpid, vsc_bpid in self.bp_map.pairs():
-            msg = '{}\t{}\t{}'.format('python-line', pyd_bpid[0], vsc_bpid)
+            bp_type = self._get_bp_type(pyd_bpid[0])
+            msg = '{}\t{}\t{}'.format(bp_type, pyd_bpid[0], vsc_bpid)
             self.pydevd_notify(cmd, msg)
             self.bp_map.remove(pyd_bpid, vsc_bpid)
         # TODO: Wait until the last request has been handled?
@@ -2042,6 +2043,15 @@ def _get_hit_condition_expression(self, hit_condition):
 
         return hit_condition
 
+    def _get_bp_type(self, path):
+        bp_type = 'python-line'
+        if not path.lower().endswith('.py'):
+            if self.debug_options.get('DJANGO_DEBUG', False):
+                bp_type = 'django-line'
+            elif self.debug_options.get('FLASK_DEBUG', False):
+                bp_type = 'jinja2-line'
+        return bp_type
+
     @async_handler
     def on_setBreakpoints(self, request, args):
         # TODO: docstring
@@ -2050,12 +2060,7 @@ def on_setBreakpoints(self, request, args):
         self.path_casing.track_file_path_case(path)
         src_bps = args.get('breakpoints', [])
 
-        bp_type = 'python-line'
-        if not path.lower().endswith('.py'):
-            if self.debug_options.get('DJANGO_DEBUG', False):
-                bp_type = 'django-line'
-            elif self.debug_options.get('FLASK_DEBUG', False):
-                bp_type = 'jinja2-line'
+        bp_type = self._get_bp_type(path)
 
         # First, we must delete all existing breakpoints in that source.
         # TODO: Call self._clear_breakpoints(path) instead?


Test patch:
Repository: microsoft/ptvsd

Issue:
Create release version of ptvsd
Create a release version of ptvsd version 4.1.1
- [x] Change development status to production from alpha
- [x]  Set version to 4.1.1




Discussion:
@DonJayamanne Let me know if you want to block this based any of the existing bugs.
Will go through the issues and let you know.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -59,7 +59,7 @@ def iter_vendored_files():
         url='https://aka.ms/ptvs',
         python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
         classifiers=[
-            'Development Status :: 3 - Alpha',
+            'Development Status :: 5 - Production/Stable',
             'Programming Language :: Python :: 2.7',
             'Programming Language :: Python :: 3.4',
             'Programming Language :: Python :: 3.5',


Test patch:
Repository: microsoft/ptvsd

Issue:
Add ability to launch the debugger in non-debug mode
Currently we can only launch the debugger in non-debug mode when using `-m`.
I'd like to have the same feature by importing PTVSD and invoking a function, similar to debugging using the `debug` function in `debugger.py`

Basically this is necessary to launch the debugger in non-debug mode when using a launcher script.


Discussion:

Resolving patch:
diff --git a/ptvsd/debugger.py b/ptvsd/debugger.py
--- a/ptvsd/debugger.py
+++ b/ptvsd/debugger.py
@@ -4,7 +4,7 @@
 
 import sys
 
-from ptvsd._local import run_module, run_file
+from ptvsd._local import run_module, run_file, run_main
 
 
 # TODO: not needed?
@@ -35,3 +35,9 @@ def debug(filename, port_num, debug_id, debug_options, run_as,
         args = _extra + list(args)
     kwargs.setdefault('singlesession', True)
     run(address, filename, *args, **kwargs)
+
+
+def run(filename, port_num, run_as,
+        *args, **kwargs):
+    address = (LOCALHOST, port_num)
+    run_main(address, filename, run_as, *args, **kwargs)


Test patch: