Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Don't try to patch arguments when not dealing with python. Fixes #1548
Browse files Browse the repository at this point in the history
… (#1588)

* Properly try to resolve_label multiple times in attach to pid.

* Don't try to patch arguments when not dealing with python. Fixes #1548
  • Loading branch information
fabioz authored and karthiknadig committed Jul 12, 2019
1 parent 76863a9 commit 62501ba
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ def resolve_label(process, label):
for i in range(max_attempts):
try:
address = process.resolve_label(label)
if not address:
raise AssertionError('%s not resolved.' % (label,))
return address
except:
try:
Expand Down
4 changes: 3 additions & 1 deletion src/ptvsd/multiproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from _pydev_bundle import pydev_monkey
from _pydevd_bundle.pydevd_comm import get_global_debugger


subprocess_lock = threading.Lock()

subprocess_listener_socket = None
Expand Down Expand Up @@ -136,6 +135,7 @@ def _subprocess_listener():


def _handle_subprocess(n, stream):

class Handlers(object):
_pid = None

Expand Down Expand Up @@ -250,6 +250,8 @@ def patch_args(args):
for i, arg in enumerate(args):
# Skip Python binary.
if i == 0:
if not pydev_monkey.is_python(arg):
return args # We're not dealing with Python, so, don't do anything.
continue

if arg == '-':
Expand Down
53 changes: 52 additions & 1 deletion tests/func/test_multiproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
reason='Debugging multiprocessing module only works on Windows')
@pytest.mark.parametrize('start_method', ['launch', 'attach_socket_cmdline'])
def test_multiprocessing(pyfile, run_as, start_method):

@pyfile
def code_to_debug():
import multiprocessing
Expand Down Expand Up @@ -127,6 +128,7 @@ def child(q):
reason='Bug #935')
@pytest.mark.parametrize('start_method', ['launch', 'attach_socket_cmdline'])
def test_subprocess(pyfile, run_as, start_method):

@pyfile
def child():
import sys
Expand Down Expand Up @@ -186,6 +188,7 @@ def parent():
reason='Bug #935')
@pytest.mark.parametrize('start_method', ['launch', 'attach_socket_cmdline'])
def test_autokill(pyfile, run_as, start_method):

@pyfile
def child():
from dbgimporter import import_and_enable_debugger
Expand Down Expand Up @@ -231,10 +234,11 @@ def parent():
@pytest.mark.skipif(sys.version_info < (3, 0) and (platform.system() != 'Windows'),
reason='Bug #935')
def test_argv_quoting(pyfile, run_as, start_method):

@pyfile
def args():
# import_and_enable_debugger
args = [ # noqa
args = [ # noqa
r'regular',
r'',
r'with spaces'
Expand Down Expand Up @@ -286,3 +290,50 @@ def child():
assert expected_args == actual_args

session.wait_for_exit()


def test_echo_and_shell(pyfile, run_as, start_method):
'''
Checks https://github.com/microsoft/ptvsd/issues/1548
'''

@pyfile
def code_to_run():
from dbgimporter import import_and_enable_debugger
import_and_enable_debugger()

import sys
import subprocess
import os

if sys.platform == 'win32':
args = ['dir', '-c', '.']
else:
args = ['ls', '-c', '-la']

p = subprocess.Popen(
args,
shell=True,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
cwd=os.path.dirname(os.path.abspath(__file__)),
)
stdout, _stderr = p.communicate()
if sys.version_info[0] >= 3:
stdout = stdout.decode('utf-8')

if "code_to_run.py" not in stdout:
raise AssertionError(
'Did not find "code_to_run.py" when listing this dir with subprocess. Contents: %s' % (
stdout,)
)

with DebugSession() as session:
session.multiprocess = True
session.initialize(
target=(run_as, code_to_run),
start_method=start_method,
)

session.start_debugging()
session.wait_for_exit()

0 comments on commit 62501ba

Please sign in to comment.